Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,12 @@ public static Expression divideDecimal(DecimalLiteral first, DecimalLiteral seco
*/
@ExecFunction(name = "divide")
public static Expression divideDecimalV3(DecimalV3Literal first, DecimalV3Literal second) {
if (second.getValue().compareTo(BigDecimal.ZERO) == 0) {
return new NullLiteral(first.getDataType());
}
DecimalV3Type t1 = (DecimalV3Type) first.getDataType();
DecimalV3Type t2 = (DecimalV3Type) second.getDataType();
if (second.getValue().compareTo(BigDecimal.ZERO) == 0) {
return new NullLiteral(DecimalV3Type.createDecimalV3TypeLooseCheck(
t1.getPrecision(), t1.getScale() - t2.getScale()));
}
BigDecimal result = first.getValue().divide(second.getValue());
return new DecimalV3Literal(DecimalV3Type.createDecimalV3TypeLooseCheck(
t1.getPrecision(), t1.getScale() - t2.getScale()), result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,7 @@ suite("fold_constant_numeric_arithmatic") {
testFoldConst("SELECT 0 ^ 1 AS xor_case_2") //0 XOR 1 = 1
testFoldConst("SELECT 255 ^ 128 AS xor_case_3") //255 XOR 128

// ensure divide for decimal v3 could return correct type when divider is 0
sql """ select if(random() > 0.5, cast(random() as decimal(38,10)), cast(0 as decimal(30, 10)) / cast(0 as decimal(30,10)))"""

}
Loading