Add polymorphic arithmetic scalar functions#18171
Add polymorphic arithmetic scalar functions#18171xiangfu0 wants to merge 1 commit intoapache:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors and expands Pinot’s arithmetic scalar functions to support polymorphism across numeric Pinot types (including BIG_DECIMAL), while keeping legacy “fallback to DOUBLE” coercions for non-numeric inputs. It also wires these functions into Calcite/MSE and adds unit + planner + integration regression coverage.
Changes:
- Introduce polymorphic scalar-function implementations for
abs/mod/moduloOrZero/positiveModulo/negate/least/greatestunderorg.apache.pinot.common.function.scalar.arithmetic. - Update query-runtime UDF plumbing (e.g.,
AbsUdf) to provide the new scalar-function implementations. - Register new functions for Calcite planning and add coverage across parser, planner, registry, and end-to-end integration tests (plus expected UDF inventory updates).
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/function/AbsUdf.java | Switches abs UDF to return the new AbsScalarFunction implementation. |
| pinot-query-planner/src/test/java/org/apache/pinot/query/QueryCompilationTest.java | Adds planner regression coverage for polymorphic arithmetic functions. |
| pinot-query-planner/src/main/java/org/apache/pinot/calcite/sql/fun/PinotOperatorTable.java | Adjusts scalar-function registration to safely skip alias collisions (e.g., min/max). |
| pinot-integration-tests/src/test/resources/udf-test-results/all-functions.yaml | Updates expected scalar-function identifiers to the new class-based implementations. |
| pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/ArithmeticFunctionsIntegrationTest.java | Adds E2E coverage validating runtime execution + typing across INT/LONG/FLOAT/DOUBLE/BIG_DECIMAL. |
| pinot-core/src/test/java/org/apache/pinot/core/function/FunctionRegistryTest.java | Adds registry-level tests ensuring type-based resolution selects the correct overload. |
| pinot-common/src/test/java/org/apache/pinot/sql/parsers/CalciteSqlCompilerTest.java | Adds parser/compiler coverage ensuring functions compile and operators are canonicalized. |
| pinot-common/src/test/java/org/apache/pinot/common/function/scalar/arithmetic/ArithmeticScalarFunctionTest.java | Adds edge-case tests for overflow behavior in abs and negate. |
| pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java | Keeps legacy entrypoints but delegates implementations to the new polymorphic scalar functions. |
| pinot-common/src/main/java/org/apache/pinot/common/function/scalar/arithmetic/PositiveModuloScalarFunction.java | Adds polymorphic positiveModulo scalar function + Calcite registration helper. |
| pinot-common/src/main/java/org/apache/pinot/common/function/scalar/arithmetic/PolymorphicUnaryArithmeticScalarFunction.java | New base for unary polymorphic arithmetic scalar functions with legacy arity fallback. |
| pinot-common/src/main/java/org/apache/pinot/common/function/scalar/arithmetic/PolymorphicBinaryArithmeticScalarFunction.java | Updates binary polymorphic type-promotion logic (incl. BIG_DECIMAL) with legacy DOUBLE fallback. |
| pinot-common/src/main/java/org/apache/pinot/common/function/scalar/arithmetic/NegateScalarFunction.java | Adds polymorphic negate scalar function + Calcite registration helper. |
| pinot-common/src/main/java/org/apache/pinot/common/function/scalar/arithmetic/ModuloOrZeroScalarFunction.java | Adds polymorphic moduloOrZero scalar function + Calcite registration helper. |
| pinot-common/src/main/java/org/apache/pinot/common/function/scalar/arithmetic/ModScalarFunction.java | Adds polymorphic mod scalar function implementation. |
| pinot-common/src/main/java/org/apache/pinot/common/function/scalar/arithmetic/LeastScalarFunction.java | Adds polymorphic least scalar function with min alias. |
| pinot-common/src/main/java/org/apache/pinot/common/function/scalar/arithmetic/GreatestScalarFunction.java | Adds polymorphic greatest scalar function with max alias. |
| pinot-common/src/main/java/org/apache/pinot/common/function/scalar/arithmetic/ArithmeticFunctionUtils.java | Adds Calcite return-type inference helpers for unary/binary arithmetic scalar functions. |
| pinot-common/src/main/java/org/apache/pinot/common/function/scalar/arithmetic/AbsScalarFunction.java | Adds polymorphic abs scalar function with explicit overflow handling for integral min values. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #18171 +/- ##
============================================
+ Coverage 63.13% 63.16% +0.02%
- Complexity 1610 1616 +6
============================================
Files 3213 3222 +9
Lines 195730 195973 +243
Branches 30240 30263 +23
============================================
+ Hits 123583 123793 +210
- Misses 62281 62295 +14
- Partials 9866 9885 +19
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
org.apache.pinot.common.function.scalar.arithmeticBIG_DECIMAL, while preserving legacy double fallback coercionsmin/maxalias collisions safely, and add parser/planner/integration regression coverageTesting
./mvnw -pl pinot-common -Dtest=CalciteSqlCompilerTest,ArithmeticScalarFunctionTest test -Dsurefire.failIfNoSpecifiedTests=false./mvnw -pl pinot-query-planner -Dtest=QueryCompilationTest test -Dsurefire.failIfNoSpecifiedTests=false./mvnw -pl pinot-integration-tests -Dtest=ArithmeticFunctionsIntegrationTest -Dsurefire.failIfNoSpecifiedTests=false test./mvnw spotless:apply -pl pinot-common,pinot-core,pinot-query-runtime,pinot-query-planner,pinot-integration-tests -DskipTests./mvnw checkstyle:check -pl pinot-common,pinot-core,pinot-query-runtime,pinot-query-planner,pinot-integration-tests -DskipTests./mvnw license:format -pl pinot-common,pinot-core,pinot-query-runtime,pinot-query-planner,pinot-integration-tests -DskipTests./mvnw license:check -pl pinot-common,pinot-core,pinot-query-runtime,pinot-query-planner,pinot-integration-tests -DskipTests