-
Notifications
You must be signed in to change notification settings - Fork 150
Add missing scalar functions #1470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
148f62e
ea2370a
02eb255
df1ead1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,7 @@ | |
| "array_to_string", | ||
| "array_union", | ||
| "arrow_cast", | ||
| "arrow_metadata", | ||
| "arrow_typeof", | ||
| "ascii", | ||
| "asin", | ||
|
|
@@ -152,6 +153,7 @@ | |
| "floor", | ||
| "from_unixtime", | ||
| "gcd", | ||
| "get_field", | ||
| "greatest", | ||
| "ifnull", | ||
| "in_list", | ||
|
|
@@ -250,6 +252,7 @@ | |
| "reverse", | ||
| "right", | ||
| "round", | ||
| "row", | ||
| "row_number", | ||
| "rpad", | ||
| "rtrim", | ||
|
|
@@ -290,12 +293,15 @@ | |
| "translate", | ||
| "trim", | ||
| "trunc", | ||
| "union_extract", | ||
| "union_tag", | ||
| "upper", | ||
| "uuid", | ||
| "var", | ||
| "var_pop", | ||
| "var_samp", | ||
| "var_sample", | ||
| "version", | ||
| "when", | ||
| # Window Functions | ||
| "window", | ||
|
|
@@ -2596,22 +2602,111 @@ def arrow_typeof(arg: Expr) -> Expr: | |
| return Expr(f.arrow_typeof(arg.expr)) | ||
|
|
||
|
|
||
| def arrow_cast(expr: Expr, data_type: Expr) -> Expr: | ||
| def arrow_cast(expr: Expr, data_type: Expr | str) -> Expr: | ||
| """Casts an expression to a specified data type. | ||
|
|
||
| Examples: | ||
| >>> ctx = dfn.SessionContext() | ||
|
Comment on lines
+2605
to
2609
|
||
| >>> df = ctx.from_pydict({"a": [1]}) | ||
| >>> data_type = dfn.string_literal("Float64") | ||
| >>> result = df.select( | ||
| ... dfn.functions.arrow_cast(dfn.col("a"), data_type).alias("c") | ||
| ... dfn.functions.arrow_cast(dfn.col("a"), "Float64").alias("c") | ||
| ... ) | ||
| >>> result.collect_column("c")[0].as_py() | ||
| 1.0 | ||
| """ | ||
| if isinstance(data_type, str): | ||
| data_type = Expr.string_literal(data_type) | ||
| return Expr(f.arrow_cast(expr.expr, data_type.expr)) | ||
|
|
||
|
|
||
| def arrow_metadata(expr: Expr, key: Expr | str | None = None) -> Expr: | ||
| """Returns the metadata of the input expression. | ||
|
|
||
| If called with one argument, returns a Map of all metadata key-value pairs. | ||
| If called with two arguments, returns the value for the specified metadata key. | ||
|
|
||
| Args: | ||
| expr: An expression whose metadata to retrieve. | ||
| key: Optional metadata key to look up. Can be a string or an Expr. | ||
|
|
||
| Returns: | ||
| A Map of metadata or a specific metadata value. | ||
| """ | ||
| if key is None: | ||
| return Expr(f.arrow_metadata(expr.expr)) | ||
| if isinstance(key, str): | ||
| key = Expr.string_literal(key) | ||
| return Expr(f.arrow_metadata(expr.expr, key.expr)) | ||
|
|
||
|
|
||
| def get_field(expr: Expr, name: Expr | str) -> Expr: | ||
| """Extracts a field from a struct or map by name. | ||
|
|
||
| Args: | ||
| expr: A struct or map expression. | ||
| name: The field name to extract. | ||
|
|
||
| Returns: | ||
| The value of the named field. | ||
| """ | ||
| if isinstance(name, str): | ||
| name = Expr.string_literal(name) | ||
| return Expr(f.get_field(expr.expr, name.expr)) | ||
|
|
||
|
|
||
| def union_extract(union_expr: Expr, field_name: Expr | str) -> Expr: | ||
| """Extracts a value from a union type by field name. | ||
|
|
||
| Returns the value of the named field if it is the currently selected | ||
| variant, otherwise returns NULL. | ||
|
|
||
| Args: | ||
| union_expr: A union-typed expression. | ||
| field_name: The name of the field to extract. | ||
|
|
||
| Returns: | ||
| The extracted value or NULL. | ||
| """ | ||
| if isinstance(field_name, str): | ||
| field_name = Expr.string_literal(field_name) | ||
| return Expr(f.union_extract(union_expr.expr, field_name.expr)) | ||
|
|
||
|
|
||
| def union_tag(union_expr: Expr) -> Expr: | ||
| """Returns the tag (active field name) of a union type. | ||
|
|
||
| Args: | ||
| union_expr: A union-typed expression. | ||
|
|
||
| Returns: | ||
| The name of the currently selected field in the union. | ||
| """ | ||
| return Expr(f.union_tag(union_expr.expr)) | ||
|
|
||
|
|
||
| def version() -> Expr: | ||
| """Returns the DataFusion version string. | ||
|
|
||
| Returns: | ||
| A string describing the DataFusion version. | ||
| """ | ||
| return Expr(f.version()) | ||
|
|
||
|
|
||
| def row(*args: Expr) -> Expr: | ||
| """Returns a struct with the given arguments. | ||
|
|
||
| This is an alias for :py:func:`struct`. | ||
|
|
||
| Args: | ||
| args: The expressions to include in the struct. | ||
|
|
||
| Returns: | ||
| A struct expression. | ||
| """ | ||
| return struct(*args) | ||
|
|
||
|
|
||
| def random() -> Expr: | ||
| """Returns a random value in the range ``0.0 <= x < 1.0``. | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.