feat: add math functions SIGN/CBRT/TRUNC#813
Open
YinZiBenRun wants to merge 1 commit into
Open
Conversation
- sign(x): returns -1 for negative, 0 for zero, 1 for positive - cbrt(x): returns the cube root of a number - trunc(x, d): truncates x to d decimal places (not round) Add UDF classes (Sign.java, Cbrt.java, Trunc.java) and register them in BuildInSqlFunctionTable. Add cbrt/trunc static methods to GeaFlowBuiltinFunctions. Add unit tests covering negative, zero, and null edge cases. Resolves apache#790 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
1 similar comment
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & Why
The math folder
udf/table/math/currently has only E, Log2, and Round — noticeably thin. Adding SIGN (the sign of anumber), CBRT (cube root), and TRUNC (truncate to N decimals) is a quick win that meaningfully fills out the SQL
toolbox.
Resolves #790
Changes
New UDF classes
sign(x)returns -1 for negative, 0 for zero, 1 for positive. Supports Double/Long/Integer input.cbrt(x)returns the cube root of x. Supports Double input.trunc(x, d)truncates x to d decimal places (not round). Supports Double/Long/Integer input withoptional scale parameter.
Registration
BuildInSqlFunctionTable.javacbrt(Double)andtrunc(Double, Integer)static methods toGeaFlowBuiltinFunctions.java(sign alreadyexisted)
Tests
MathUdfTest.java— unit tests for Sign, Cbrt, Trunc UDF classestestCbrt()andtestTrunc()toInternalFunctionsTest.javaTRUNC vs ROUND — key distinction
truncusesRoundingMode.DOWNwhileroundusesRoundingMode.HALF_UP: