Skip to content

Commit 7fde76e

Browse files
JacobOgleJacob Ogle
andauthored
Support remaining functions in protobuf serialization, add expr_fn for StructFunction (#8100)
* working fix for #8098 * Added enum match for StringToArray * Added enum match for StructFun as well as mapping to a supporting scalar function * cargo fmt --------- Co-authored-by: Jacob Ogle <jacob@ghst.local>
1 parent fdf3f6c commit 7fde76e

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

datafusion/expr/src/expr_fn.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,13 @@ scalar_expr!(
871871

872872
scalar_expr!(ArrowTypeof, arrow_typeof, val, "data type");
873873

874+
scalar_expr!(
875+
Struct,
876+
struct_fun,
877+
val,
878+
"returns a vector of fields from the struct"
879+
);
880+
874881
/// Create a CASE WHEN statement with literal WHEN expressions for comparison to the base expression.
875882
pub fn case(expr: Expr) -> CaseBuilder {
876883
CaseBuilder::new(Some(Box::new(expr)), vec![], vec![], None)

datafusion/proto/src/logical_plan/from_proto.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@ use datafusion_expr::{
4343
array_has, array_has_all, array_has_any, array_length, array_ndims, array_position,
4444
array_positions, array_prepend, array_remove, array_remove_all, array_remove_n,
4545
array_repeat, array_replace, array_replace_all, array_replace_n, array_slice,
46-
array_to_string, ascii, asin, asinh, atan, atan2, atanh, bit_length, btrim,
47-
cardinality, cbrt, ceil, character_length, chr, coalesce, concat_expr,
46+
array_to_string, arrow_typeof, ascii, asin, asinh, atan, atan2, atanh, bit_length,
47+
btrim, cardinality, cbrt, ceil, character_length, chr, coalesce, concat_expr,
4848
concat_ws_expr, cos, cosh, cot, current_date, current_time, date_bin, date_part,
4949
date_trunc, decode, degrees, digest, encode, exp,
5050
expr::{self, InList, Sort, WindowFunction},
51-
factorial, floor, from_unixtime, gcd, isnan, iszero, lcm, left, ln, log, log10, log2,
51+
factorial, flatten, floor, from_unixtime, gcd, isnan, iszero, lcm, left, ln, log,
52+
log10, log2,
5253
logical_plan::{PlanType, StringifiedPlan},
5354
lower, lpad, ltrim, md5, nanvl, now, nullif, octet_length, pi, power, radians,
5455
random, regexp_match, regexp_replace, repeat, replace, reverse, right, round, rpad,
5556
rtrim, sha224, sha256, sha384, sha512, signum, sin, sinh, split_part, sqrt,
56-
starts_with, strpos, substr, substring, tan, tanh, to_hex, to_timestamp_micros,
57-
to_timestamp_millis, to_timestamp_nanos, to_timestamp_seconds, translate, trim,
58-
trunc, upper, uuid,
57+
starts_with, string_to_array, strpos, struct_fun, substr, substring, tan, tanh,
58+
to_hex, to_timestamp_micros, to_timestamp_millis, to_timestamp_nanos,
59+
to_timestamp_seconds, translate, trim, trunc, upper, uuid,
5960
window_frame::regularize,
6061
AggregateFunction, Between, BinaryExpr, BuiltInWindowFunction, BuiltinScalarFunction,
6162
Case, Cast, Expr, GetFieldAccess, GetIndexedField, GroupingSet,
@@ -1645,9 +1646,21 @@ pub fn parse_expr(
16451646
)),
16461647
ScalarFunction::Isnan => Ok(isnan(parse_expr(&args[0], registry)?)),
16471648
ScalarFunction::Iszero => Ok(iszero(parse_expr(&args[0], registry)?)),
1648-
_ => Err(proto_error(
1649-
"Protobuf deserialization error: Unsupported scalar function",
1649+
ScalarFunction::ArrowTypeof => {
1650+
Ok(arrow_typeof(parse_expr(&args[0], registry)?))
1651+
}
1652+
ScalarFunction::ToTimestamp => {
1653+
Ok(to_timestamp_seconds(parse_expr(&args[0], registry)?))
1654+
}
1655+
ScalarFunction::Flatten => Ok(flatten(parse_expr(&args[0], registry)?)),
1656+
ScalarFunction::StringToArray => Ok(string_to_array(
1657+
parse_expr(&args[0], registry)?,
1658+
parse_expr(&args[1], registry)?,
1659+
parse_expr(&args[2], registry)?,
16501660
)),
1661+
ScalarFunction::StructFun => {
1662+
Ok(struct_fun(parse_expr(&args[0], registry)?))
1663+
}
16511664
}
16521665
}
16531666
ExprType::ScalarUdfExpr(protobuf::ScalarUdfExprNode { fun_name, args }) => {

0 commit comments

Comments
 (0)