-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[C++][Gandiva] A question about Gandiva's GetResultType for DecimalType #40308
Comments
@pravindra Could you take a look at this? |
I think it's a problem and we should fix it. // Normal expression
TEST(DecimalTest, Divide) {
auto expr = arrow::compute::call("divide", {arrow::compute::field_ref("f1"),
arrow::compute::field_ref("f2")});
auto s = arrow::schema({arrow::field("f1", arrow::decimal128(11, 3)),
arrow::field("f2", arrow::decimal128(20, 9))});
ASSERT_OK_AND_ASSIGN(expr, expr.Bind(*s));
arrow::AssertTypeEqual(*expr.type(), *arrow::decimal128(32, 15));
auto b = arrow::RecordBatchFromJSON(s, R"([
["1.982", "1.000000001"]
])");
ASSERT_OK_AND_ASSIGN(auto input, arrow::compute::MakeExecBatch(*s, b));
ASSERT_OK_AND_ASSIGN(auto res,
arrow::compute::ExecuteScalarExpression(expr, input));
arrow::AssertArraysEqual(
*res.make_array(),
*arrow::ArrayFromJSON(arrow::decimal128(32, 15), R"(["1.981999998018000"])"));
}
// gandiva test
TEST_F(TestDecimalOps, TestDivide) {
DivideAndVerify(decimal_literal("1982", 11, 3),
decimal_literal("1000000001", 20, 9),
decimal_literal("1981999998018000001982", 38, 21));
} We will have different precision and scale for the same data. |
I'm not sure what is the important part in the codes. Could you explain it?
Could you show the URL that describes the rule?
Based on the arrow/cpp/src/gandiva/decimal_type_util.h Lines 54 to 58 in 6b1e254
|
The test codes are the decimal divide operation in compute expression and gandiva expression. For compute expression, divide result's decimal type is (32,15); but gandiva expression's result is (38, 21).
Below rules is our compute expression's rules:
And the compute doc: arrow/docs/source/cpp/compute.rst Lines 501 to 520 in 4fe364e
Yes, but maybe we should unify these rules between compute expression and gandiva expression. Or the results will be different when user do optimize expression with gandiva? |
Ah, I understand. You referred our compute module's behavior by "our Redshift’s decimal promotion rules". I thought that you refer Redshift's rules not our compute module's one. I don't object that Gandiva can also use the rules but it breaks backward compatibility. Can we support both rules and use the current rule by default for compatibility? |
Actually our compute module's decimal rules is the same with Redshift's rules. Compute module implement the rules by two step:
All these two steps are in expression
Agree. |
@kou Added the compatibility in the pr. PTAL? |
…motion rules (#40434) ### Rationale for this change Gandiva decimal divide rules are different with our compute module's rules. Some systems such as Redshift use the same rules as our compute module's rules. So it's useful that Gandiva support our compute module's rules too. ### What changes are included in this PR? Support an option argument in GetResultType for compatibilty with **compute module's decimal promotion rules**. ### Are these changes tested? Yes ### Are there any user-facing changes? No * GitHub Issue: #40308 Authored-by: ZhangHuiGui <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
Issue resolved by pull request 40434 |
Describe the bug, including details regarding any error messages, version, and platform.
Below codes calculate the decimal type's precision and scale.
arrow/cpp/src/gandiva/decimal_type_util.cc
Line 62 in 30e6d72
It seems different from our Redshift’s decimal promotion rules, is there any relevant background here?
It may cause the decimal divide results different from normal expression calculate.
Component(s)
C++ - Gandiva
The text was updated successfully, but these errors were encountered: