You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by ag...@apache.org on 2025/02/25 00:14:53 UTC

(datafusion-comet) branch main updated: test: Register Spark-compatible expressions with a DataFusion context (#1432)

This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-comet.git


The following commit(s) were added to refs/heads/main by this push:
     new 36074b4db test: Register Spark-compatible expressions with a DataFusion context (#1432)
36074b4db is described below

commit 36074b4db48cbd7f3e54164ad6903f3792d42a23
Author: Saurav Verma <vi...@gmail.com>
AuthorDate: Mon Feb 24 16:14:50 2025 -0800

    test: Register Spark-compatible expressions with a DataFusion context (#1432)
---
 native/spark-expr/Cargo.toml              |  3 ++
 native/spark-expr/tests/spark_expr_reg.rs | 50 +++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/native/spark-expr/Cargo.toml b/native/spark-expr/Cargo.toml
index fc348f81b..cc5372bd3 100644
--- a/native/spark-expr/Cargo.toml
+++ b/native/spark-expr/Cargo.toml
@@ -78,3 +78,6 @@ harness = false
 name = "aggregate"
 harness = false
 
+[[test]]
+name = "test_udf_registration"
+path = "tests/spark_expr_reg.rs"
diff --git a/native/spark-expr/tests/spark_expr_reg.rs b/native/spark-expr/tests/spark_expr_reg.rs
new file mode 100644
index 000000000..6c94b458f
--- /dev/null
+++ b/native/spark-expr/tests/spark_expr_reg.rs
@@ -0,0 +1,50 @@
+// 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.
+
+#[cfg(test)]
+mod tests {
+    use arrow::datatypes::DataType;
+    use datafusion::error::Result;
+    use datafusion::execution::session_state::SessionStateBuilder;
+    use datafusion::execution::FunctionRegistry;
+    use datafusion::prelude::SessionContext;
+    use datafusion_comet_spark_expr::create_comet_physical_fun;
+
+    #[tokio::test]
+    async fn test_udf_registration() -> Result<()> {
+        // 1. Setup session with UDF registration of existing Spark-compatible expression
+        let mut session_state = SessionStateBuilder::new().build();
+        let _ = session_state.register_udf(create_comet_physical_fun(
+            "xxhash64",
+            DataType::Int64,
+            &session_state,
+        )?);
+        let ctx = SessionContext::new_with_state(session_state);
+
+        // 2. Execute SQL with literal values
+        let df = ctx
+            .sql("SELECT xxhash64('valid',64) AS hash_value")
+            .await
+            .unwrap();
+        let results = df.collect().await?;
+
+        // 3. Ensure results are returned, i.e UDF is registered. no need to validate the actual value
+        assert!(!results.is_empty(), "Results should not be empty");
+
+        Ok(())
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org