Skip to content

Commit 29557ca

Browse files
feat: support spark bin function (#3928)
1 parent 30dbe74 commit 29557ca

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

docs/spark_expressions_support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@
296296
- [x] atan
297297
- [x] atan2
298298
- [ ] atanh
299-
- [ ] bin
299+
- [x] bin
300300
- [ ] bround
301301
- [ ] cbrt
302302
- [x] ceil

native/core/src/execution/jni_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ fn register_datafusion_spark_function(session_ctx: &SessionContext) {
564564
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkSpace::default()));
565565
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkBitCount::default()));
566566
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkArrayContains::default()));
567+
session_ctx.register_udf(ScalarUDF::new_from_impl(SparkBin::default()));
567568
}
568569

569570
/// Prepares arrow arrays for output.
@@ -1134,6 +1135,7 @@ pub extern "system" fn Java_org_apache_comet_Native_getRustThreadId(
11341135

11351136
use crate::execution::columnar_to_row::ColumnarToRowContext;
11361137
use arrow::ffi::{from_ffi, FFI_ArrowArray, FFI_ArrowSchema};
1138+
use datafusion_spark::function::math::bin::SparkBin;
11371139

11381140
/// Initialize a native columnar to row converter.
11391141
///

spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ object QueryPlanSerde extends Logging with CometExprShim {
122122
classOf[Cot] -> CometScalarFunction("cot"),
123123
classOf[UnaryMinus] -> CometUnaryMinus,
124124
classOf[Unhex] -> CometUnhex,
125-
classOf[Abs] -> CometAbs)
125+
classOf[Abs] -> CometAbs,
126+
classOf[Bin] -> CometScalarFunction("bin"))
126127

127128
private val mapExpressions: Map[Class[_ <: Expression], CometExpressionSerde[_]] = Map(
128129
classOf[GetMapValue] -> CometMapExtract,
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
statement
19+
CREATE TABLE test_bin(i int, l long, f float, d double) USING parquet
20+
21+
statement
22+
INSERT INTO test_bin VALUES
23+
(13, 1, 1.5, 1.5),
24+
(1, 1, 0.1, 0.1),
25+
(100, 100, 99.99, 99.99),
26+
(255, 255, 255.255, 255.255),
27+
(-13, -1, -1.5, -1.5),
28+
(-1, -1, -0.1, -0.1),
29+
(-100, -100, -99.99, -99.99),
30+
(-255, -255, -255.255, -255.255),
31+
(0, 0, 0.0, 0.0),
32+
(0, 0, -0.0, -0.0),
33+
(NULL, NULL, NULL, NULL),
34+
(2147483647, 9223372036854775807, cast('Infinity' as float), cast('Infinity' as double)),
35+
(-2147483648, -9223372036854775808, cast('-Infinity' as float), cast('-Infinity' as double)),
36+
(100, 100, cast('Infinity' as float), cast('Infinity' as double)),
37+
(200, 200, cast('-Infinity' as float), cast('-Infinity' as double)),
38+
(300, 300, cast('NaN' as float), cast('NaN' as double)),
39+
(5, 5, 1.401298464e-45, 4.9406564584124654e-324),
40+
(1000, 1000, 3.402823466e+38, 1.7976931348623157e+308),
41+
(7, 7, 0.1, 0.1),
42+
(8, 8, 0.2, 0.2),
43+
(9, 9, 0.3, 0.3),
44+
(10, 10, 0.3333333333333333, 0.3333333333333333),
45+
(500, 500, cast('NaN' as float), cast('Infinity' as double)),
46+
(501, 501, cast('Infinity' as float), cast('NaN' as double)),
47+
(502, 502, cast('-Infinity' as float), cast('NaN' as double)),
48+
(503, 503, cast('NaN' as float), cast('-Infinity' as double)),
49+
(123456789, 123456789, 123456.789, 123456789.123456789),
50+
(-123456789, -123456789, -123456.789, -123456789.123456789),
51+
(2147483646, 9223372036854775806, 999999.999, 999999999.999999999),
52+
(-2147483647, -9223372036854775807, -999999.999, -999999999.999999999),
53+
(999, NULL, NULL, 999.999),
54+
(NULL, 888, 888.888, NULL),
55+
(777, 777, NULL, 777.777),
56+
(666, 666, 666.666, NULL),
57+
(15, 15, 1.23456789, 1.2345678901234567),
58+
(16, 16, -1.23456789, -1.2345678901234567),
59+
(314, 314, 3.14159265, 3.14159265358979323846),
60+
(271, 271, 2.71828183, 2.71828182845904523536);
61+
62+
query
63+
SELECT bin(i), bin(l), bin(f), bin(d) FROM test_bin
64+
65+
-- literal arguments
66+
query
67+
SELECT bin(-5), bin(-1.5), bin(0), bin(NULL)

0 commit comments

Comments
 (0)