diff --git a/docs/spark_expressions_support.md b/docs/spark_expressions_support.md index 2c18cbd08d..5474894108 100644 --- a/docs/spark_expressions_support.md +++ b/docs/spark_expressions_support.md @@ -234,7 +234,7 @@ ### hash_funcs -- [ ] crc32 +- [x] crc32 - [ ] hash - [x] md5 - [ ] sha diff --git a/native/core/src/execution/jni_api.rs b/native/core/src/execution/jni_api.rs index c2cb1d9102..436e5e99c5 100644 --- a/native/core/src/execution/jni_api.rs +++ b/native/core/src/execution/jni_api.rs @@ -46,6 +46,7 @@ use datafusion_spark::function::datetime::date_add::SparkDateAdd; use datafusion_spark::function::datetime::date_sub::SparkDateSub; use datafusion_spark::function::datetime::last_day::SparkLastDay; use datafusion_spark::function::datetime::next_day::SparkNextDay; +use datafusion_spark::function::hash::crc32::SparkCrc32; use datafusion_spark::function::hash::sha1::SparkSha1; use datafusion_spark::function::hash::sha2::SparkSha2; use datafusion_spark::function::map::map_from_entries::MapFromEntries; @@ -375,6 +376,7 @@ fn register_datafusion_spark_function(session_ctx: &SessionContext) { session_ctx.register_udf(ScalarUDF::new_from_impl(SparkHex::default())); session_ctx.register_udf(ScalarUDF::new_from_impl(SparkWidthBucket::default())); session_ctx.register_udf(ScalarUDF::new_from_impl(MapFromEntries::default())); + session_ctx.register_udf(ScalarUDF::new_from_impl(SparkCrc32::default())); } /// Prepares arrow arrays for output. diff --git a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala index f627b0c465..efac8fed5d 100644 --- a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala +++ b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala @@ -139,6 +139,7 @@ object QueryPlanSerde extends Logging with CometExprShim { classOf[StructsToCsv] -> CometStructsToCsv) private val hashExpressions: Map[Class[_ <: Expression], CometExpressionSerde[_]] = Map( + classOf[Crc32] -> CometScalarFunction("crc32"), classOf[Md5] -> CometScalarFunction("md5"), classOf[Murmur3Hash] -> CometMurmur3Hash, classOf[Sha2] -> CometSha2, diff --git a/spark/src/test/resources/sql-tests/expressions/hash/crc32.sql b/spark/src/test/resources/sql-tests/expressions/hash/crc32.sql new file mode 100644 index 0000000000..64b401c98c --- /dev/null +++ b/spark/src/test/resources/sql-tests/expressions/hash/crc32.sql @@ -0,0 +1,32 @@ +-- 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. + +-- ConfigMatrix: parquet.enable.dictionary=false,true + +-- crc32 function +statement +CREATE TABLE test(col string, a int, b float) USING parquet + +statement +INSERT INTO test VALUES ('Spark SQL ', 10, 1.2), (NULL, NULL, NULL), ('', 0, 0.0), ('苹果手机', NULL, 3.999999), ('Spark SQL ', 10, 1.2), (NULL, NULL, NULL), ('', 0, 0.0), ('苹果手机', NULL, 3.999999) + +query +SELECT crc32(col), crc32(cast(a as string)), crc32(cast(b as string)) FROM test + +-- literal arguments +query +SELECT crc32('Spark SQL') diff --git a/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala b/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala index 415d8c3a19..f0f022868f 100644 --- a/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala +++ b/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala @@ -1987,6 +1987,7 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper { |md5(col), md5(cast(a as string)), md5(cast(b as string)), |hash(col), hash(col, 1), hash(col, 0), hash(col, a, b), hash(b, a, col), |xxhash64(col), xxhash64(col, 1), xxhash64(col, 0), xxhash64(col, a, b), xxhash64(b, a, col), + |crc32(col), crc32(cast(a as string)), crc32(cast(b as string)), |sha2(col, 0), sha2(col, 256), sha2(col, 224), sha2(col, 384), sha2(col, 512), sha2(col, 128), sha2(col, -1), |sha1(col), sha1(cast(a as string)), sha1(cast(b as string)) |from test @@ -2097,6 +2098,7 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper { |md5(col), md5(cast(a as string)), --md5(cast(b as string)), |hash(col), hash(col, 1), hash(col, 0), hash(col, a, b), hash(b, a, col), |xxhash64(col), xxhash64(col, 1), xxhash64(col, 0), xxhash64(col, a, b), xxhash64(b, a, col), + |crc32(col), crc32(cast(a as string)), |sha2(col, 0), sha2(col, 256), sha2(col, 224), sha2(col, 384), sha2(col, 512), sha2(col, 128), sha2(col, -1), |sha1(col), sha1(cast(a as string)) |from test