Skip to content

Add polymorphic arithmetic scalar functions#18171

Open
xiangfu0 wants to merge 1 commit intoapache:masterfrom
xiangfu0:codex/polymorphic-arithmetic-scalars
Open

Add polymorphic arithmetic scalar functions#18171
xiangfu0 wants to merge 1 commit intoapache:masterfrom
xiangfu0:codex/polymorphic-arithmetic-scalars

Conversation

@xiangfu0
Copy link
Copy Markdown
Contributor

Summary

  • move arithmetic scalar implementations for abs/mod/moduloOrZero/positiveModulo/negate/least/greatest into org.apache.pinot.common.function.scalar.arithmetic
  • make these functions polymorphic across Pinot numeric types, including BIG_DECIMAL, while preserving legacy double fallback coercions
  • register the moved functions for Calcite/MSE, handle min/max alias collisions safely, and add parser/planner/integration regression coverage

Testing

  • ./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

@xiangfu0 xiangfu0 added the functions Related to scalar or aggregation functions label Apr 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/greatest under org.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-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 11, 2026

Codecov Report

❌ Patch coverage is 64.59144% with 91 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.16%. Comparing base (34d3fd6) to head (94fb8f3).

Files with missing lines Patch % Lines
...calar/arithmetic/PositiveModuloScalarFunction.java 50.00% 18 Missing and 1 partial ⚠️
...ion/scalar/arithmetic/ArithmeticFunctionUtils.java 58.33% 11 Missing and 4 partials ⚠️
.../function/scalar/arithmetic/AbsScalarFunction.java 70.37% 6 Missing and 2 partials ⚠️
...ot/common/function/scalar/ArithmeticFunctions.java 0.00% 7 Missing ⚠️
...tion/scalar/arithmetic/GreatestScalarFunction.java 72.00% 6 Missing and 1 partial ⚠️
...unction/scalar/arithmetic/LeastScalarFunction.java 72.00% 6 Missing and 1 partial ⚠️
.../scalar/arithmetic/ModuloOrZeroScalarFunction.java 72.00% 6 Missing and 1 partial ⚠️
.../function/scalar/arithmetic/ModScalarFunction.java 75.00% 5 Missing and 1 partial ⚠️
...nction/scalar/arithmetic/NegateScalarFunction.java 75.00% 6 Missing ⚠️
...etic/PolymorphicUnaryArithmeticScalarFunction.java 55.55% 2 Missing and 2 partials ⚠️
... and 3 more
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     
Flag Coverage Δ
custom-integration1 100.00% <ø> (?)
integration 100.00% <ø> (+100.00%) ⬆️
integration1 100.00% <ø> (?)
integration2 0.00% <ø> (ø)
java-11 63.09% <64.59%> (-0.02%) ⬇️
java-21 63.15% <64.59%> (+0.05%) ⬆️
temurin 63.16% <64.59%> (+0.02%) ⬆️
unittests 63.16% <64.59%> (+0.02%) ⬆️
unittests1 55.38% <64.59%> (+0.01%) ⬆️
unittests2 34.81% <46.30%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Related to scalar or aggregation functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants