From 53e30ef271ebf8adc324065aec113eaf427b603c Mon Sep 17 00:00:00 2001 From: Rafael Fernandez Date: Wed, 25 Mar 2026 07:23:37 +0100 Subject: [PATCH] feat: Add support for Spark ToDegrees and ToRadians math expressions Add angle conversion functions by delegating to DataFusion's built-in degrees and radians implementations via CometScalarFunction. Includes SQL tests for column and literal arguments with edge cases. --- .../apache/comet/serde/QueryPlanSerde.scala | 2 ++ .../sql-tests/expressions/math/degrees.sql | 31 +++++++++++++++++++ .../sql-tests/expressions/math/radians.sql | 31 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 spark/src/test/resources/sql-tests/expressions/math/degrees.sql create mode 100644 spark/src/test/resources/sql-tests/expressions/math/radians.sql 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 02a76f69f0..139c6fe7f9 100644 --- a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala +++ b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala @@ -118,6 +118,8 @@ object QueryPlanSerde extends Logging with CometExprShim { classOf[Subtract] -> CometSubtract, classOf[Tan] -> CometTan, classOf[Tanh] -> CometScalarFunction("tanh"), + classOf[ToDegrees] -> CometScalarFunction("degrees"), + classOf[ToRadians] -> CometScalarFunction("radians"), classOf[Cot] -> CometScalarFunction("cot"), classOf[UnaryMinus] -> CometUnaryMinus, classOf[Unhex] -> CometUnhex, diff --git a/spark/src/test/resources/sql-tests/expressions/math/degrees.sql b/spark/src/test/resources/sql-tests/expressions/math/degrees.sql new file mode 100644 index 0000000000..3bcb005d05 --- /dev/null +++ b/spark/src/test/resources/sql-tests/expressions/math/degrees.sql @@ -0,0 +1,31 @@ +-- 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 + +statement +CREATE TABLE test_degrees(d double) USING parquet + +statement +INSERT INTO test_degrees VALUES (0.0), (3.141592653589793), (1.5707963267948966), (-3.141592653589793), (6.283185307179586), (NULL), (cast('NaN' as double)) + +query tolerance=1e-6 +SELECT degrees(d) FROM test_degrees + +-- literal arguments +query tolerance=1e-6 +SELECT degrees(0.0), degrees(3.141592653589793), degrees(NULL) diff --git a/spark/src/test/resources/sql-tests/expressions/math/radians.sql b/spark/src/test/resources/sql-tests/expressions/math/radians.sql new file mode 100644 index 0000000000..e29dbd4f01 --- /dev/null +++ b/spark/src/test/resources/sql-tests/expressions/math/radians.sql @@ -0,0 +1,31 @@ +-- 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 + +statement +CREATE TABLE test_radians(d double) USING parquet + +statement +INSERT INTO test_radians VALUES (0.0), (90.0), (180.0), (360.0), (-180.0), (NULL), (cast('NaN' as double)) + +query tolerance=1e-6 +SELECT radians(d) FROM test_radians + +-- literal arguments +query tolerance=1e-6 +SELECT radians(0.0), radians(90.0), radians(180.0), radians(NULL)