Skip to content
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

[fix](Nereids) result type of add precision is 1 more than expected #27136

Merged
merged 1 commit into from
Nov 17, 2023
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 @@ -50,7 +50,7 @@ public Expression withChildren(List<Expression> children) {
@Override
public DecimalV3Type getDataTypeForDecimalV3(DecimalV3Type t1, DecimalV3Type t2) {
DecimalV3Type decimalV3Type = (DecimalV3Type) DecimalV3Type.widerDecimalV3Type(t1, t2, false);
return (DecimalV3Type) DecimalV3Type.createDecimalV3Type(decimalV3Type.getPrecision() + 1,
return DecimalV3Type.createDecimalV3Type(decimalV3Type.getPrecision() + 1,
decimalV3Type.getScale());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public DataType getDataType() throws UnboundException {
return getDataTypeForDecimalV2((DecimalV2Type) t1, (DecimalV2Type) t2);
}
if (t1.isDecimalV3Type() && t2.isDecimalV3Type()) {
return getDataTypeForDecimalV3((DecimalV3Type) t1, (DecimalV3Type) t2);
if (this instanceof Add || this instanceof Subtract || this instanceof Mod) {
return t1;
} else {
return getDataTypeForDecimalV3((DecimalV3Type) t1, (DecimalV3Type) t2);
}
}
return getDataTypeForOthers(t1, t2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Expression withChildren(List<Expression> children) {
@Override
public DecimalV3Type getDataTypeForDecimalV3(DecimalV3Type t1, DecimalV3Type t2) {
DecimalV3Type decimalV3Type = (DecimalV3Type) DecimalV3Type.widerDecimalV3Type(t1, t2, false);
return (DecimalV3Type) DecimalV3Type.createDecimalV3Type(decimalV3Type.getPrecision() + 1,
return DecimalV3Type.createDecimalV3Type(decimalV3Type.getPrecision() + 1,
decimalV3Type.getScale());
}

Expand Down
12 changes: 12 additions & 0 deletions regression-test/suites/nereids_arith_p0/decimal.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2299,4 +2299,16 @@ suite('nereids_arith_p0_decimal') {
// select id, BITAND(kdcml128v3, kbool), BITOR(kdcml128v3, kbool), BITXOR(kdcml128v3, kbool) from expr_test order by id"""
// qt_sql_test_Decimal128V3_Boolean_notn_4 """
// select id, BITAND(kdcml128v3, kbool), BITOR(kdcml128v3, kbool), BITXOR(kdcml128v3, kbool) from expr_test_not_nullable order by id"""


// decimal add precision
sql """drop table if exists test_arithmetic_expressions"""
sql """
CREATE TABLE IF NOT EXISTS test_arithmetic_expressions (
`a` DECIMALV3(9, 3) NOT NULL,
`b` DECIMALV3(9, 3) NOT NULL
) DISTRIBUTED BY HASH(a) PROPERTIES("replication_num" = "1");
"""
sql "select a + b from test_arithmetic_expressions"
sql """drop table if exists test_arithmetic_expressions"""
}
Loading