Repository navigation
Description
Is your feature request related to a problem or challenge?
As part of making DataFusion even more customizable (#8045), it is valuable to let system designers mix and match different packages of functions to get the precise behavior they want (e.g. postgres style to_date or spark style to_date).
To support this functionality as well as to ensure the ScalarUDF API exposes the full power of DataFusion, we are in the process of extracting the "built in" functions out of the core and into separate crates.
This epic tracks the work to actually move the functions out of the core datafusion crate (spread through datafusion_expr and datafusion-physical-expr and into the new datafusion-functions / datafusion-functions-array crates
Tasks:
Here is list of many of the items necessary to complete this transition. Eventually there should be tickets for all tasks, and there are tickets for some already, but I don't want to make 100s of tickets all at once. I plan to make more as we make it through more of this project.
Anyone should feel free to make other tickets if they want to help with items below.
math_expressions
These should be located in the datafusion-functions crate (source link)
Code location: https://github.com/apache/arrow-datafusion/blob/main/datafusion/functions/src/math/mod.rs
- Move
nullifandisnanto datafusion-functions #9216 - Move
abstodatafusion_functions#9286 - refactor: move acos() to function crate #9297
- Abs, Asin,
- Atan, Atan2, Acosh, Asinh, Atanh,
- Cbrt, Ceil, Cos, Cosh, Degrees
- Exp, Factorial Move
ceil,exp,factorialtodatafusion-functionscrate #9939 - Floor, Gcd, Lcm, Ln, Log, Log10, Log2, Pi, Power,
- Radians, Signum, Sin, Sinh, Sqrt,
- Tan, Tanh, Trunc, Cot, Round, iszero
array_expressions
Note that given the size and specialization of these functions are put in their own subcrate, datafusion-functions-array
- ArrayToString Create
datafusion-functions-arraycrate and moveArrayToStringfunction into it #9113 - ArrayDims, ArrayNdims, Cardinality move ArrayDims, ArrayNdims and Cardinality to datafusion-function-crate #9425
- ArrayHas, ArrayHasAll, ArrayHasAny Port ArrayHas family to
functions-array#9496 - MakeArray, ArrayAppend, ArrayPrepend, ArrayConat move make_array array_append array_prepend array_concat function to datafusion-functions-array crate #9343 Move
make_arrayto datafusion-functions #9288 move make_array array_append array_prepend array_concat function to datafusion-functions-array crate #9504 - Range, GenSeries port range function and change gen_series logic #9352
- ArrayEmpty ArrayLength port array_empty and array_length to datafusion-function-array crate #9510
- Flatten port flatten to datafusion-function-array #9523
- StringToArray Port
StringToArraytofunction-arrays#9497 - ArraySort Port
ArraySorttofunction-arrayssubcrate #9551 - ArrayDistinct Port
ArrayDistincttofunctions-arraysubcrate #9549 - ArrayRepeat Port
ArrayRepeattofunctions-arraysubcrate #9565 - ArrayResize Port
ArrayResizetofunctions-arraysubcrate #9570 - ArrayElement, ArraySlice, ArrayPopFront, ArrayPopBack Port ArrayElem/Slice/PopFront/Back into
functions-array#9615 - ArrayPosition, ArrayPositions Port
ArrayPositionandArrayPositionstofunctions-arraysubcrate #9617 - ArrayReverse Add
array_reversefunction to datafusion-function-* crate #9630 - ArrayIntersect, ArrayUnion Port Array Union and Intersect to
functions-array#9629 - ArrayExcept Port
ArrayExcepttofunctions-arraysubcrate #9634 - ArrayRemove, ArrayRemoveN, ArrayRemoveAll Port
ArrayRemove,ArrayRemoveN,ArrayRemoveAlltofunctions-arraysubcrate #9635 - ArrayReplace, ArrayReplaceN, ArrayReplaceAll move array_replace family functions to datafusion-function-array crate #9651
-
MakeArray: construct an array from columns (union/except depends on this) - Move
datafusion_array_functionspecific rewrite rules like todatafusion_functions_arraycrate #9519
Core functions
These should be located in the datafusion-functions crate (source link)
Code location: https://github.com/apache/arrow-datafusion/blob/main/datafusion/functions/src/core/mod.rs
- Create
coremodule, extractnullif: Movenullifandisnanto datafusion-functions #9216 - Move
arrow_casttodatafusion-functionscrate #9287 - Move
ArrowTypeOf: return the arrow type of a value Portarrow_typeofto datafusion-function #9524 -
Coalesce: return the first non-null value -
Struct: Create a struct -
NullIf: return null if the two values are equal -
Random: return a random number -
Nanvl: return the first non-NaN value
crypto_expressions
These should be located in the datafusion-functions crate (source link)
Code location: https://github.com/apache/arrow-datafusion/blob/main/datafusion/functions/src/crypto/mod.rs
- Create
cryptomodule indatafusion/functions/src/cryptoandcrypto_expressionsfeature flag, movedigestfunction - Digest, MD5, SHA224, SHA256, SHA384, SHA512
string_expressions
These should be located in the datafusion-functions crate (source link)
Code location: https://github.com/apache/arrow-datafusion/blob/main/datafusion/functions/src/string/mod.rs
- concat, concat_ws, ends_with, initcap Move take concat, concat_ws, ends_with, initcap, to datafusion-functions #9540
- Create
stringmodule indatafusion/functions/src/stringandstring_expressionsfeature flag, moveasciifunction - ascii, bit_length, btrim, chr,
- instr, lower, ltrim, octet_length,
- repeat, replace, rtrim, split_part,
- starts_with, to_hex, trim, upper,
- levenshtein, uuid, overlay
unicode_expressions
These should be located in the datafusion-functions crate (source link)
Code location: https://github.com/apache/arrow-datafusion/blob/main/datafusion/functions/src/unicode/mod.rs
- Create
unicodemodule indatafusion/functions/src/unicodeandunicode_expressionsfeature flag, movecharlengthfunction - CharLength,
- Left, Lpad, Reverse, Right, Rpad,
- Strpos, Substr,
- Translate, SubstrIndex, FindInSet
regex_expressions
These should be located in the datafusion-functions crate (source link)
Code location: https://github.com/apache/arrow-datafusion/blob/main/datafusion/functions/src/regexp/mod.rs
- port reg_related function #9328
- RegexpMatch, RegexpReplace
- RegexpLike
datetime_expressions
These should be located in the datafusion-functions crate (source link)
Code location: https://github.com/apache/arrow-datafusion/blob/main/datafusion/functions/src/datetime/mod.rs
- Create
datetimemodule indatafusion/functions/src/datetimeanddatetime_expressionsfeature flag, movedate_part - Move the to_timestamp* functions to datafusion-functions #9291
- port benchmarks to datafusion-functions crate
- date_part, date_trunc, date_bin,
- to_timestamp, to_timestamp_millis, to_timestamp_micros, to_timestamp_nanos, to_timestamp_seconds,
- from_unixtime, now, current_date, current_time
Infrastructure
Describe alternatives you've considered
No response
Additional context
The organization was discussed in #9100
Activity
SteveLauC commentedon Feb 21, 2024
Let me give this a try:
Update:
Abshas been taken in #9286, I will handle the remaining 2 fnsLordworms commentedon Feb 21, 2024
I'll try to do regex_expressions parts.
guojidan commentedon Feb 23, 2024
I'll try to do array_expressions parts.
yyy1000 commentedon Feb 24, 2024
I filed #9336 which I think may be necessary before we port functions.
jayzhan211 commentedon Feb 27, 2024
work on
array_concatguojidan commentedon Feb 27, 2024
hi @jayzhan211 I already work on
array_concat#9343jayzhan211 commentedon Feb 27, 2024
Oh, sorry. I will work on other
jayzhan211 commentedon Feb 27, 2024
Take ArrayHas, ArrayHasAll, ArrayHasAny
SteveLauC commentedon Feb 28, 2024
Take Atan, Atan2, Acosh.
Weijun-H commentedon Feb 29, 2024
Take ArrayPopFront, ArrayPopBack, ArrayDistinct, ArrayElement
Weijun-H commentedon Mar 2, 2024
Take ArrayDims, ArrayNdims, Cardinality, ArrayNdims
#9425
jayzhan211 commentedon Mar 4, 2024
I think this needs to wait until
make_arrayis done and also move to rewrite to the optimizer.Take ArrayIntersect, ArrayUnion, ArrayExcept
Edit: general_set_op needs make_array too
Take: ArraySlice + ArrayElement
jayzhan211 commentedon Mar 4, 2024
While I worked on ArrayElement, I found that
GetFieldAccessExpr::ListIndexusesarray_elementin physical-expr https://github.com/apache/arrow-datafusion/blob/581fd98270e69221689ddd4c37566ef620a67167/datafusion/physical-expr/src/expressions/get_indexed_field.rs#L252-L257 ListRange likewise, which is kernel function infunction-arrayscrate, instead of converting ArrayRef to Expr, I'm thinking of making array function kernel public. @alamb Do you think we can make those array functions public? And, is importingfunction-arraysto cratephysical-expra concern like crateoptimizeis?If neither is a good idea, we may need to rewrite ListIndex and ListRange to array function early.
alamb commentedon Mar 4, 2024
I think making physical-exprs depend on datafusion-functions would be unfortunate (as it would still mean there could be dependencies / special cases from built in functions to "built in" user defined functions)
I agree if this is possible it would be the best approach from my perspective
I also though about about potentially adding the common code to the new
datafusion_common_runtimecrate (that @mustafasrepo added recently)https://github.com/apache/arrow-datafusion/tree/main/datafusion/common_runtime
But I think that would result in a tokio dependency on datafusion-functions which would be unwise.
15 remaining items
jayzhan211 commentedon Mar 15, 2024
Take
pop_frontandpop_back, they need to be moved together withsliceWeijun-H commentedon Mar 16, 2024
Take
ArrayReverseerenavsarogullari commentedon Mar 16, 2024
ArrayExcept: PR(#9634) has been submittedArrayRemove,ArrayRemoveN,ArrayRemoveAll: Work in Progress(#9635)Weijun-H commentedon Mar 17, 2024
take array_replace family
erenavsarogullari commentedon Mar 18, 2024
@jayzhan211 Just follow-up to our previous discussion (single func per file), we almost complete
functions-arraymigration. Itskernelsandudfsource files include more functions by our new pattern. Does it make sense to break them as well by aligning with the new pattern for the consistency?jayzhan211 commentedon Mar 18, 2024
jayzhan211 commentedon Mar 18, 2024
@erenavsarogullari
For consistency, I think we can also change the
invokewithmake_scalar_function(probably have a better name). It returns ColumnValue::Scalar if length of list is 1. It has no difference currently, since we have no optimization based on Scalar.erenavsarogullari commentedon Mar 18, 2024
@jayzhan211 Yes, makes sense. I have created #9660 for this refactoring effort. I will also include to be used
make_scalar_functionforinvokecalls.tinfoil-knight commentedon Mar 19, 2024
Take Ln, Log, Log10, Log2
Edit: Take Power since it's related to Log
Omega359 commentedon Mar 20, 2024
Take lower, ltrim, octet_length. Edit: all the trim functions use a common general function so I'll migrate all the trim functions first - rtrim, ltrim and btrim.
Omega359 commentedon Mar 23, 2024
take levenshtein, uuid, overlay
Weijun-H commentedon Mar 30, 2024
take Atan, Acosh, Asinh, Atanh, #9872
feat: migrate functions.rs
Upgrade Datafusion to v37.1.0 (#669)