Skip to content

feat: Add datafusion-spark crate #15168

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 29 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
57018b7
feat: Add datafusion-spark crate
shehabgamin Mar 11, 2025
762ef03
spark crate setup
shehabgamin Mar 13, 2025
6e1aa06
clean up 2 example functions
shehabgamin Mar 13, 2025
eba0a51
cleanup crate
shehabgamin Mar 13, 2025
9ca4a52
Spark crate setup
shehabgamin Mar 13, 2025
074fc70
fix lint issue
shehabgamin Mar 13, 2025
4e28310
cargo cleanup
shehabgamin Mar 13, 2025
7f448f3
fix collision in sqllogic
shehabgamin Mar 13, 2025
c29a9e4
remove redundant test
shehabgamin Mar 13, 2025
b0cdaf3
fix merge conflict
shehabgamin Mar 14, 2025
b2e9135
test float precision when casting to string
shehabgamin Mar 14, 2025
4fedbf4
reorder
shehabgamin Mar 14, 2025
9482964
undo
shehabgamin Mar 14, 2025
4964b0f
save
shehabgamin Apr 23, 2025
82a55d9
save
shehabgamin Apr 23, 2025
b0da0df
Merge branch 'main' of github.com:lakehq/datafusion into add-spark-crate
shehabgamin Apr 23, 2025
4bac6ce
save
shehabgamin Apr 23, 2025
2d7b44e
add spark crate
shehabgamin Apr 23, 2025
ac2b90d
remove spark from core
shehabgamin Apr 25, 2025
6070e0e
add comment to import tests
shehabgamin Apr 25, 2025
4235fcc
Merge branch 'main' of github.com:lakehq/datafusion into add-spark-crate
shehabgamin Apr 25, 2025
4608b2a
Fix: reset submodule to main pointer and clean state
shehabgamin Apr 25, 2025
dd48fa0
Save
shehabgamin Apr 25, 2025
51b882f
fix registration
shehabgamin Apr 26, 2025
0514ba6
modify float64 precision for spark
shehabgamin Apr 26, 2025
2601c26
Update datafusion/spark/src/lib.rs
shehabgamin Apr 29, 2025
e7f6d5f
clean up code
shehabgamin Apr 29, 2025
269edcd
Merge branch 'add-spark-crate' of github.com:lakehq/datafusion into a…
shehabgamin Apr 29, 2025
2b02e3f
code cleanup
shehabgamin Apr 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ members = [
"datafusion/proto-common",
"datafusion/proto-common/gen",
"datafusion/session",
"datafusion/spark",
"datafusion/sql",
"datafusion/sqllogictest",
"datafusion/substrait",
Expand Down Expand Up @@ -138,6 +139,7 @@ datafusion-physical-plan = { path = "datafusion/physical-plan", version = "47.0.
datafusion-proto = { path = "datafusion/proto", version = "47.0.0" }
datafusion-proto-common = { path = "datafusion/proto-common", version = "47.0.0" }
datafusion-session = { path = "datafusion/session", version = "47.0.0" }
datafusion-spark = { path = "datafusion/spark", version = "47.0.0" }
datafusion-sql = { path = "datafusion/sql", version = "47.0.0" }
doc-comment = "0.3"
env_logger = "0.11"
Expand Down
4 changes: 2 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Apache DataFusion
Copyright 2019-2024 The Apache Software Foundation
Copyright 2019-2025 The Apache Software Foundation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
The Apache Software Foundation (http://www.apache.org/).
3 changes: 3 additions & 0 deletions datafusion/functions-aggregate/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

#[macro_export]
macro_rules! make_udaf_expr {
($EXPR_FN:ident, $($arg:ident)*, $DOC:expr, $AGGREGATE_UDF_FN:ident) => {
// "fluent expr_fn" style function
Expand All @@ -34,6 +35,7 @@ macro_rules! make_udaf_expr {
};
}

#[macro_export]
macro_rules! make_udaf_expr_and_func {
($UDAF:ty, $EXPR_FN:ident, $($arg:ident)*, $DOC:expr, $AGGREGATE_UDF_FN:ident) => {
make_udaf_expr!($EXPR_FN, $($arg)*, $DOC, $AGGREGATE_UDF_FN);
Expand All @@ -59,6 +61,7 @@ macro_rules! make_udaf_expr_and_func {
};
}

#[macro_export]
macro_rules! create_func {
($UDAF:ty, $AGGREGATE_UDF_FN:ident) => {
create_func!($UDAF, $AGGREGATE_UDF_FN, <$UDAF>::default());
Expand Down
2 changes: 2 additions & 0 deletions datafusion/functions/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
/// Exported functions accept:
/// - `Vec<Expr>` argument (single argument followed by a comma)
/// - Variable number of `Expr` arguments (zero or more arguments, must be without commas)
#[macro_export]
macro_rules! export_functions {
($(($FUNC:ident, $DOC:expr, $($arg:tt)*)),*) => {
$(
Expand Down Expand Up @@ -69,6 +70,7 @@ macro_rules! export_functions {
/// named `$NAME` which returns that singleton.
///
/// This is used to ensure creating the list of `ScalarUDF` only happens once.
#[macro_export]
macro_rules! make_udf_function {
($UDF:ty, $NAME:ident) => {
#[doc = concat!("Return a [`ScalarUDF`](datafusion_expr::ScalarUDF) implementation of ", stringify!($NAME))]
Expand Down
2 changes: 1 addition & 1 deletion datafusion/functions/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ get_optimal_return_type!(utf8_to_int_type, DataType::Int64, DataType::Int32);
/// Creates a scalar function implementation for the given function.
/// * `inner` - the function to be executed
/// * `hints` - hints to be used when expanding scalars to arrays
pub(super) fn make_scalar_function<F>(
pub fn make_scalar_function<F>(
inner: F,
hints: Vec<Hint>,
) -> impl Fn(&[ColumnarValue]) -> Result<ColumnarValue>
Expand Down
46 changes: 46 additions & 0 deletions datafusion/spark/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[package]
name = "datafusion-spark"
description = "DataFusion expressions that emulate Apache Spark's behavior"
version = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
authors = { workspace = true }
readme = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[package.metadata.docs.rs]
all-features = true

[lints]
workspace = true

[lib]
name = "datafusion_spark"

[dependencies]
arrow = { workspace = true }
datafusion-catalog = { workspace = true }
datafusion-common = { workspace = true }
datafusion-execution = { workspace = true }
datafusion-expr = { workspace = true }
datafusion-functions = { workspace = true }
datafusion-macros = { workspace = true }
log = { workspace = true }
1 change: 1 addition & 0 deletions datafusion/spark/LICENSE.txt
1 change: 1 addition & 0 deletions datafusion/spark/NOTICE.txt
40 changes: 40 additions & 0 deletions datafusion/spark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

# datafusion-spark: Spark-compatible Expressions

This crate provides Apache Spark-compatible expressions for use with DataFusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing instructions here

## Testing Guide

When testing functions by directly invoking them (e.g., `test_scalar_function!()`), input coercion (from the `signature`
or `coerce_types`) is not applied.

Therefore, direct invocation tests should only be used to verify that the function is correctly implemented.

Please be sure to add additional tests beyond direct invocation.
For more detailed testing guidelines, refer to
the [Spark SQLLogicTest README](../sqllogictest/test_files/spark/README.md).

## Implementation References

When implementing Spark-compatible functions, you can check if there are existing implementations in
the [Sail](https://github.com/lakehq/sail) or [Comet](https://github.com/apache/datafusion-comet) projects first.
If you do port functionality from these sources, make sure to port over the corresponding tests too, to ensure
correctness and compatibility.
25 changes: 25 additions & 0 deletions datafusion/spark/src/function/aggregate/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use datafusion_expr::AggregateUDF;
use std::sync::Arc;

pub mod expr_fn {}

pub fn functions() -> Vec<Arc<AggregateUDF>> {
vec![]
}
25 changes: 25 additions & 0 deletions datafusion/spark/src/function/array/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use datafusion_expr::ScalarUDF;
use std::sync::Arc;

pub mod expr_fn {}

pub fn functions() -> Vec<Arc<ScalarUDF>> {
vec![]
}
25 changes: 25 additions & 0 deletions datafusion/spark/src/function/bitwise/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use datafusion_expr::ScalarUDF;
use std::sync::Arc;

pub mod expr_fn {}

pub fn functions() -> Vec<Arc<ScalarUDF>> {
vec![]
}
25 changes: 25 additions & 0 deletions datafusion/spark/src/function/collection/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use datafusion_expr::ScalarUDF;
use std::sync::Arc;

pub mod expr_fn {}

pub fn functions() -> Vec<Arc<ScalarUDF>> {
vec![]
}
25 changes: 25 additions & 0 deletions datafusion/spark/src/function/conditional/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use datafusion_expr::ScalarUDF;
use std::sync::Arc;

pub mod expr_fn {}

pub fn functions() -> Vec<Arc<ScalarUDF>> {
vec![]
}
25 changes: 25 additions & 0 deletions datafusion/spark/src/function/conversion/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use datafusion_expr::ScalarUDF;
use std::sync::Arc;

pub mod expr_fn {}

pub fn functions() -> Vec<Arc<ScalarUDF>> {
vec![]
}
25 changes: 25 additions & 0 deletions datafusion/spark/src/function/csv/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use datafusion_expr::ScalarUDF;
use std::sync::Arc;

pub mod expr_fn {}

pub fn functions() -> Vec<Arc<ScalarUDF>> {
vec![]
}
Loading