Repository navigation
[EPIC] Complete datafusion-spark Spark Compatible Functions #15914
Copy link
Copy link
Open
Labels
EPICA larger project, actively underway, with sub tasksA larger project, actively underway, with sub tasksenhancementNew feature or requestNew feature or request
Description
Is your feature request related to a problem or challenge?
Many DataFusion users are using DataFusion to execution workloads originally developed for Apache Spark. Examples include
- DataFusion Comet (@andygrove @comphead , etc)
- LakeHQ / Sail (@shehabgamin )
- Various internal pileines / engines (e.g. that @Omega359 and I think @Blizzara use)
They often do this for superior performance
- Part of running Spark workloads is emulating Spark sematics
- Emulating Spark semantics requires (among other things) functions compatible with Spark (which differs in semantics to the functions included in DataFusion)
Several projects are in the process of implementing Spark compatible function libraries using DataFusion's extension APIs. However. we concluded in #5600 that we could join forces and maintain a spark compatible funciton library in the core datafusion repo. @shehabgamin has implemented the first step in #15168 🙏
Describe the solution you'd like
This ticket tracks "completing" the spark function library started in #15168
Describe alternatives you've considered
datetime functions:
- [datafusion-spark] Implement Spark
datetimefunctionlast_day#16774 - [datafusion-spark] Implement Spark
datefunctionnext_day#16775
string functions:
math functions:
set functions:
- [datafusion-spark]: Implement collect_set #17924
- [datafusion-spark]: Implement collect_list/array_agg #17923
map/array functions:
Infrastructure and Testing:
- [DISCUSSION] Add separate crate to cover spark builtin functions #5600
- feat: Add
datafusion-sparkcrate #15168 - [datafusion-spark] Example of using Spark compatible function library #15915
- feat: Support test spark runner in
datafusion-sparkfor slt tests #17045 - SparkDateAdd should use wrapping addition/subtraction #17987
- Deduplicate Spark function code with native/default datafusion function code #17964
Related issues
- [datafusion-spark] Test integrating datafusion-spark code into comet datafusion-comet#1704
- [EPIC] Implement expressions as ScalarUDFImpl datafusion-comet#1819
- Spark-compatible CAST operation #11201
- SparkSha2 is not compliant with Spark and does not support Int32 type #16336
- Add xxhash algorithms in SQL and expression api #14367
- [datafusion-spark] [SQL] [TEST] IntervalMonthDayNano(0,0,0) give line blank #17455
Additional context
No response
Reacted by Andy Grove, Shehab Amin, Bruce Ritchie, aditya singh rathore, cht42, Heran Lin, Mimoune, Martin, Haresh Khanna, Peter Lee and 4 more
Metadata
Metadata
Assignees
Labels
EPICA larger project, actively underway, with sub tasksA larger project, actively underway, with sub tasksenhancementNew feature or requestNew feature or request
Activity
andygrove commentedon May 30, 2025
@shehabgamin @alamb I created an epic in Comet for implementing our current expressions as
ScalarUDFImplrather thanPhysicalExpras a first step towards contributing them in thedatafusion-sparkcrate: apache/datafusion-comet#1819shehabgamin commentedon Jun 1, 2025
Nice! I’ll create an epic shortly after the DataFusion 48 release for Sail to contribute all of our implemented functions (and corresponding tests) to
datafusion-spark.Also, @linhr has some ideas around making sqllogictests easier to work with, for example so that test files no longer need to explicitly cast data types. I’ll let him share more on that.
linhr commentedon Jun 3, 2025
Here is my idea to automate the test setup, without bringing Spark as a hard dependency.
alamb commentedon Jun 5, 2025
Using pyspark to generate expected input/output that gets checked in. sounds like a great idea to me
BTW i hope to devote some time next week to helping organize this effort a bit more, but have been totally bogged down in working on filtering in parquet
andygrove commentedon Jun 5, 2025
This sounds like a great idea. Thanks @linhr.
alamb commentedon Jun 11, 2025
I just had a chat with @shehabgamin
The current status is that we have not smoothed out the process to the point where contributors with minimal context can pick up a porting ticket and be successful porting the functions upstream. It seems writing / having tests tests are the last missing piece before we have a high likelihood of achieving this goal.
Here is the plan we came up with (please correct me if I am wrong):
.sltfiles from the sail gold master expected output (what @linhr describes on [EPIC] Completedatafusion-sparkSpark Compatible Functions #15914 (comment))..sltfiles that are disabled somehow.sltfile (maybe it can be @irenjj 's [datafusion-spark] Implement ceil&floor function for spark #15958)Then @alamb will create (copy/paste style) tickets for the remaining functions (based on #15916)
alamb commentedon Jun 11, 2025
I am not quite sure where @linhr imagines this CI workflow running -- maybe we can start with running it manually and then run it in CI if/when we find problems with accidental changes
alamb commentedon Jul 9, 2025
An update here is that we are waiting for one or two more good example PRs and then we'll turn the community on porting
If anyone wants to take a look / help out with #16612 / #16580 that would be super helpful
It might be something that codeing agents / claude code / etc can do easily 🤔
shehabgamin commentedon Jul 10, 2025
Would it be easier to pick a couple of functions that Sail has already implemented?
next_day and last_day are simple functions.
There are tests in DataFusion ready to go as well!
alamb commentedon Jul 14, 2025
I filed two tickets to track this suggestion and marked them as good first issues
datetimefunctionlast_day#16774datefunctionnext_day#16775Standing-Man commentedon Jul 25, 2025
Hi @alamb, I just wanted to clarify: if a Spark function appears in the sqllogictest tests, are we expected to implement it in DataFusion?
alamb commentedon Jul 25, 2025
@Standing-Man that is the intention. I haven't created individual tickets for all of them as it seems like it is more complicated to port than we initially thought so I wanted to get the process honed more (get some great examples) before we started porting things en-mass
However, since you have now done several others, perhaps you could try to port a few more (I suggest the non-string ones) and hopefully once we see the code flowing easily without much back and forth on the PRs we can start filing many more
Standing-Man commentedon Jul 25, 2025
Got it, that makes sense. I’ll go ahead and try porting a few more non-string functions next. Hopefully this helps smooth out the process for scaling up later. Thanks for the guidance!
andygrove commentedon Aug 7, 2025
I created an epic in Comet to track donating the remaining Spark expressions:
apache/datafusion-comet#2084
65 remaining items
feat(spark): add `concat_ws` with array support (apache#20928)
feat: add Spark-compatible hypot function (apache#23774)
feat: add Spark-compatible atan2 function (apache#23962)
feat: add Spark-compatible hypot function (apache#23774)
feat: add Spark-compatible atan2 function (apache#23962)
docs: add an agent skill for auditing datafusion-spark expressions (a…
docs: add an agent skill for auditing datafusion-spark expressions (a…
doc: add implementation guidelines for `datafusion-spark` (apache#24140)
feat(spark): add `to_binary` and `try_to_binary` (apache#24266)
fix: find_in_set internal error with two LargeUtf8 scalar arguments (a…
feat(spark): add equal_null (apache#24827)
feat(spark): add equal_null (apache#24827)
fix(spark): derive concat_ws nullability from separator (apache#26205)
fix(spark): derive concat_ws nullability from separator (apache#26205)
feat: support Spark-compatible `stack` function (apache#26266)