Skip to content

Commit 5e03c3a

Browse files
committed
refactor: rename utf8_literal to string_literal and add alias str_lit
1 parent 9216389 commit 5e03c3a

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

python/datafusion/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,16 @@ def literal(value):
107107
return Expr.literal(value)
108108

109109

110-
def utf8_literal(value):
111-
"""Create a UTF8 literal expression."""
112-
return Expr.utf8_literal(value)
110+
def string_literal(value):
111+
"""Create a UTF8 literal expression.
112+
It differs from `literal` creates a UTF8view literal.
113+
"""
114+
return Expr.string_literal(value)
115+
116+
117+
def str_lit(value):
118+
"""Alias for `string_literal`"""
119+
return string_literal(value)
113120

114121

115122
def lit(value):

python/datafusion/expr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def literal(value: Any) -> Expr:
381381
return Expr(expr_internal.Expr.literal(value))
382382

383383
@staticmethod
384-
def utf8_literal(value: str) -> Expr:
384+
def string_literal(value: str) -> Expr:
385385
"""Creates a new expression representing a UTF8 literal value.
386386
387387
It is different from `literal` because it is pa.string() instead of

python/tests/test_functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from datafusion import SessionContext, column
2525
from datafusion import functions as f
26-
from datafusion import literal, utf8_literal
26+
from datafusion import literal, string_literal
2727

2828
np.seterr(invalid="ignore")
2929

@@ -909,11 +909,11 @@ def test_temporal_functions(df):
909909

910910
def test_arrow_cast(df):
911911
df = df.select(
912-
# we use `utf8_literal` to return utf8 instead of `literal` which returns
912+
# we use `string_literal` to return utf8 instead of `literal` which returns
913913
# utf8view because datafusion.arrow_cast expects a utf8 instead of utf8view
914914
# https://github.com/apache/datafusion/blob/86740bfd3d9831d6b7c1d0e1bf4a21d91598a0ac/datafusion/functions/src/core/arrow_cast.rs#L179
915-
f.arrow_cast(column("b"), utf8_literal("Float64")).alias("b_as_float"),
916-
f.arrow_cast(column("b"), utf8_literal("Int32")).alias("b_as_int"),
915+
f.arrow_cast(column("b"), string_literal("Float64")).alias("b_as_float"),
916+
f.arrow_cast(column("b"), string_literal("Int32")).alias("b_as_int"),
917917
)
918918
result = df.collect()
919919
assert len(result) == 1

0 commit comments

Comments
 (0)