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

[C++] SimplifyWithGuarantee evaluate a wrong result for a function call which has no arguments #40395

Closed
ZhangHuiGui opened this issue Mar 7, 2024 · 1 comment
Assignees
Milestone

Comments

@ZhangHuiGui
Copy link
Collaborator

ZhangHuiGui commented Mar 7, 2024

Describe the bug, including details regarding any error messages, version, and platform.

Test codes like below:

  const int kCount = 10;
  auto random_options = RandomOptions::FromSeed(/*seed=*/0);
  ExecBatch input({}, kCount);
  ExecBatch input({}, kCount);

  Expression random_expr = call("random", {}, random_options);
  ASSERT_OK_AND_ASSIGN(random_expr, random_expr.Bind(float64()));
  ASSERT_OK_AND_ASSIGN(auto simplify_expr, SimplifyWithGuarantee(random_expr, input.guarantee));

  ASSERT_OK_AND_ASSIGN(Datum actual, ExecuteScalarExpression(simplify_expr, input)); // failed

Failed with Invalid: ExecuteScalarExpression cannot Execute non-scalar expression Array[int64].

It's caused by below codes in FoldConstans:
https://github.com/apache/arrow/blob/49cdb0fe4e98fda19031c864a18e6156c6edbf3c/cpp/src/arrow/compute/expression.cc#L848C1-L856C10

We should not go into the all_of branch for the call has no arguments, but the all_of will return true for this situation.

Component(s)

C++

bkietz pushed a commit that referenced this issue Mar 13, 2024
…ions (#40396)

### Rationale for this change
Fix a problem when we call `SimplifyWithGuarantee` evaluate a function call which has no arguments.

### What changes are included in this PR?
Check empty for call.arguments before we evaluate arguments as literal in FoldConstants.

### Are these changes tested?
Yes.

### Are there any user-facing changes?
No.

* GitHub Issue: #40395

Lead-authored-by: hugo.zhang <hugo.zhang@openpie.com>
Co-authored-by: ZhangHuiGui <hugo.zhang@openpie.com>
Signed-off-by: Benjamin Kietzman <bengilgit@gmail.com>
@bkietz bkietz added this to the 16.0.0 milestone Mar 13, 2024
@bkietz
Copy link
Member

bkietz commented Mar 13, 2024

Issue resolved by pull request 40396
#40396

@bkietz bkietz closed this as completed Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants