-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat](Nereids) add numeric functions #40744
Conversation
Thank you for your contribution to Apache Doris. Since 2024-03-18, the Document has been moved to doris-website. |
run buildall |
fa2f58a
to
76a098e
Compare
run buildall |
TPC-H: Total hot run time: 43005 ms
|
TPC-DS: Total hot run time: 195717 ms
|
ClickBench: Total hot run time: 31.02 s
|
37061e4
to
4d76abb
Compare
run buildall |
TPC-H: Total hot run time: 43027 ms
|
4d76abb
to
5d90267
Compare
run buildall |
TPC-H: Total hot run time: 42953 ms
|
run buildall |
TPC-H: Total hot run time: 41212 ms
|
run performance |
run p0 |
TPC-H: Total hot run time: 41979 ms
|
TPC-DS: Total hot run time: 199206 ms
|
ClickBench: Total hot run time: 32.1 s
|
309ada3
to
a9d0c39
Compare
run buildall |
run feut |
run performance |
@@ -84,6 +84,12 @@ public DecimalV3Literal roundFloor(int newScale) { | |||
value.setScale(newScale, RoundingMode.FLOOR)); | |||
} | |||
|
|||
public DecimalV3Literal round(int newScale) { | |||
return new DecimalV3Literal(DecimalV3Type | |||
.createDecimalV3Type(((DecimalV3Type) dataType).getPrecision(), newScale), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what scale should be set if newScale bigger than old scale?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when new scale is larger than original one, it would throw an Invocationexception when calling create Decimal Type in java with message: precision should not smaller than scale and ExpressionEvaluator would catch this exception and go back to original expression. But actually when new scalar bigger than old one, we can return original one when folding constant. Same as be calculation logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when new scale is larger than original one, it would throw an Invocationexception when calling create Decimal Type in java with message: precision should not smaller than scale and ExpressionEvaluator would catch this exception and go back to original expression. But actually when new scalar bigger than old one, we can return original one when folding constant. Same as be calculation logic
we should not rely on exception, exception is very expensive, so we should process it without use exception
*/ | ||
@ExecFunction(name = "ceil") | ||
public static Expression ceil(DecimalV3Literal first, IntegerLiteral second) { | ||
return first.roundCeiling(second.getValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as round, if second > old scale, the result is wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move if into roundCeiling
*/ | ||
@ExecFunction(name = "floor") | ||
public static Expression floor(DecimalV3Literal first, IntegerLiteral second) { | ||
return first.roundFloor(second.getValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as ceil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
*/ | ||
@ExecFunction(name = "exp") | ||
public static Expression exp(DoubleLiteral first) { | ||
return new DoubleLiteral(Math.exp(first.getValue())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what will happen if result of Math.exp is infinity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should return null literal, in java it would return infinite value when it is infinity, would return NaN when the input is Invalid like acos(-2) which input should between [-1, 1]. In sql behavior, it should return NULL, when it is NaN or infinity(positive, negative is same logic). Let me add some boundary check in some functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong about Infinity, actually it should return "inf" in sql and " ∞" in explain string. NaN is right to show by NULL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
.../java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java
Show resolved
Hide resolved
run buildall |
TPC-H: Total hot run time: 41728 ms
|
TPC-DS: Total hot run time: 194806 ms
|
ClickBench: Total hot run time: 33.38 s
|
…recision problem (#43422) - Problem function like ```select floor(300.343, 2)``` precision should be 5 and scale should be 2, but now is (6, 2) after compute precision, but after folding const on fe, it changed to (5, 2) but upper level of plan still expect the output of child to be (6, 2). So it would rise an exception when executing. - How it was fixed fix folding constant precision of floor/round/ceil/truncate functions from (5, 2) to (6, 2) in upper case - Notion when second value is negative and it absolute value >= precision - value, it can not be expressed in fe which result is zero with decimal type (3, 0). like 000. So just let it go back and no using folding constant by fe. - Related PR: #40744 - Release note Fix floor/round/ceil functions precision problem in folding constant
…recision problem (#43422) - Problem function like ```select floor(300.343, 2)``` precision should be 5 and scale should be 2, but now is (6, 2) after compute precision, but after folding const on fe, it changed to (5, 2) but upper level of plan still expect the output of child to be (6, 2). So it would rise an exception when executing. - How it was fixed fix folding constant precision of floor/round/ceil/truncate functions from (5, 2) to (6, 2) in upper case - Notion when second value is negative and it absolute value >= precision - value, it can not be expressed in fe which result is zero with decimal type (3, 0). like 000. So just let it go back and no using folding constant by fe. - Related PR: #40744 - Release note Fix floor/round/ceil functions precision problem in folding constant
…recision problem (#43422) - Problem function like ```select floor(300.343, 2)``` precision should be 5 and scale should be 2, but now is (6, 2) after compute precision, but after folding const on fe, it changed to (5, 2) but upper level of plan still expect the output of child to be (6, 2). So it would rise an exception when executing. - How it was fixed fix folding constant precision of floor/round/ceil/truncate functions from (5, 2) to (6, 2) in upper case - Notion when second value is negative and it absolute value >= precision - value, it can not be expressed in fe which result is zero with decimal type (3, 0). like 000. So just let it go back and no using folding constant by fe. - Related PR: #40744 - Release note Fix floor/round/ceil functions precision problem in folding constant
…recision problem (apache#43422) - Problem function like ```select floor(300.343, 2)``` precision should be 5 and scale should be 2, but now is (6, 2) after compute precision, but after folding const on fe, it changed to (5, 2) but upper level of plan still expect the output of child to be (6, 2). So it would rise an exception when executing. - How it was fixed fix folding constant precision of floor/round/ceil/truncate functions from (5, 2) to (6, 2) in upper case - Notion when second value is negative and it absolute value >= precision - value, it can not be expressed in fe which result is zero with decimal type (3, 0). like 000. So just let it go back and no using folding constant by fe. - Related PR: apache#40744 - Release note Fix floor/round/ceil functions precision problem in folding constant
…recision problem (apache#43422) - Problem function like ```select floor(300.343, 2)``` precision should be 5 and scale should be 2, but now is (6, 2) after compute precision, but after folding const on fe, it changed to (5, 2) but upper level of plan still expect the output of child to be (6, 2). So it would rise an exception when executing. - How it was fixed fix folding constant precision of floor/round/ceil/truncate functions from (5, 2) to (6, 2) in upper case - Notion when second value is negative and it absolute value >= precision - value, it can not be expressed in fe which result is zero with decimal type (3, 0). like 000. So just let it go back and no using folding constant by fe. - Related PR: apache#40744 - Release note Fix floor/round/ceil functions precision problem in folding constant
…recision problem (apache#43422) - Problem function like ```select floor(300.343, 2)``` precision should be 5 and scale should be 2, but now is (6, 2) after compute precision, but after folding const on fe, it changed to (5, 2) but upper level of plan still expect the output of child to be (6, 2). So it would rise an exception when executing. - How it was fixed fix folding constant precision of floor/round/ceil/truncate functions from (5, 2) to (6, 2) in upper case - Notion when second value is negative and it absolute value >= precision - value, it can not be expressed in fe which result is zero with decimal type (3, 0). like 000. So just let it go back and no using folding constant by fe. - Related PR: apache#40744 - Release note Fix floor/round/ceil functions precision problem in folding constant
…cion (#44022) Related PR: #40744 when executing floor(1) it would castTo decimalV3(3,0) because it need (3,0) to contain it's message. But after fold const, it lost precision(3) because decimalV3 literal class does not have mechanism to save precision Solved: after folding constant, we need to change result type to the type we wanted
…cion (#44022) Related PR: #40744 when executing floor(1) it would castTo decimalV3(3,0) because it need (3,0) to contain it's message. But after fold const, it lost precision(3) because decimalV3 literal class does not have mechanism to save precision Solved: after folding constant, we need to change result type to the type we wanted
…cion (#44022) Related PR: #40744 when executing floor(1) it would castTo decimalV3(3,0) because it need (3,0) to contain it's message. But after fold const, it lost precision(3) because decimalV3 literal class does not have mechanism to save precision Solved: after folding constant, we need to change result type to the type we wanted
…o match with be execution behavior (#47966) ### What problem does this PR solve? Related PR: #40744, #47228 Problem Summary: When numeric function input or output out of boundary when fe folding constant, it would throw an exception before. Now we change it to match with be execution result, which is NullLiteral
…o match with be execution behavior (#47966) ### What problem does this PR solve? Related PR: #40744, #47228 Problem Summary: When numeric function input or output out of boundary when fe folding constant, it would throw an exception before. Now we change it to match with be execution result, which is NullLiteral
…o match with be execution behavior (apache#47966) ### What problem does this PR solve? Related PR: apache#40744, apache#47228 Problem Summary: When numeric function input or output out of boundary when fe folding constant, it would throw an exception before. Now we change it to match with be execution result, which is NullLiteral
…o match with be execution behavior (apache#47966) Related PR: apache#40744, apache#47228 Problem Summary: When numeric function input or output out of boundary when fe folding constant, it would throw an exception before. Now we change it to match with be execution result, which is NullLiteral
…o match with be execution behavior (apache#47966) ### What problem does this PR solve? Related PR: apache#40744, apache#47228 Problem Summary: When numeric function input or output out of boundary when fe folding constant, it would throw an exception before. Now we change it to match with be execution result, which is NullLiteral
…y behavior to match with be execution behavior #47966 (#48237) pick:#47966 Related PR: #40744, #47228 Problem Summary: When numeric function input or output out of boundary when fe folding constant, it would throw an exception before. Now we change it to match with be execution result, which is NullLiteral ### What problem does this PR solve? Issue Number: close #xxx Related PR: #xxx Problem Summary: ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
…y behavior to match with be execution behavior (#47966) (#48281) pick:#47966 ### What problem does this PR solve? Related PR: #40744, #47228 Problem Summary: When numeric function input or output out of boundary when fe folding constant, it would throw an exception before. Now we change it to match with be execution result, which is NullLiteral
add fold constant on fe of numeric functions:
Coalesce, Round, Ceil, Floor, Exp, Ln, Log, Log10, Log2, Sqrt, Power, Sin, Cos, Tan, Acos, Asin, Atan, Atan2, Sign, Bin, BitCount, BitLength, Cbrt, Cosh, Tanh, Dexp, Dlog10, Dlog1, Dpow, Dsqrt, Fmod, Fpow, Radians, Degrees, Xor, Pi, E, Conv, Truncate, CountEqual, Pmod.