Skip to content

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

@ZhangHuiGui

Description

@ZhangHuiGui

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++

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions