From 87349b62af5f557acaa49629be62ff0f28ef5d85 Mon Sep 17 00:00:00 2001 From: Rafael Fernandez Date: Wed, 25 Mar 2026 07:24:00 +0100 Subject: [PATCH] feat: Add support for Spark Pi math expression Add Pi constant function by delegating to DataFusion's built-in pi() implementation via CometScalarFunction. Includes SQL test verifying the constant value. --- .../apache/comet/serde/QueryPlanSerde.scala | 1 + .../sql-tests/expressions/math/pi.sql | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 spark/src/test/resources/sql-tests/expressions/math/pi.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..85277dce2e 100644 --- a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala +++ b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala @@ -106,6 +106,7 @@ object QueryPlanSerde extends Logging with CometExprShim { classOf[Log2] -> CometLog2, classOf[Log10] -> CometLog10, classOf[Multiply] -> CometMultiply, + classOf[Pi] -> CometScalarFunction("pi"), classOf[Pow] -> CometScalarFunction("pow"), classOf[Rand] -> CometRand, classOf[Randn] -> CometRandn, diff --git a/spark/src/test/resources/sql-tests/expressions/math/pi.sql b/spark/src/test/resources/sql-tests/expressions/math/pi.sql new file mode 100644 index 0000000000..28081ea9fe --- /dev/null +++ b/spark/src/test/resources/sql-tests/expressions/math/pi.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_pi(d double) USING parquet + +statement +INSERT INTO test_pi VALUES (1.0) + +query tolerance=1e-15 +SELECT pi() FROM test_pi + +-- literal arguments +query tolerance=1e-15 +SELECT pi()