Skip to content

[C++] Expression ExecuteScalarExpression execute empty args function with a wrong result #39860

Closed

Description

@ZhangHuiGui

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

Problem

We have some arrow-builtin functions with no arguments support, like random/count_all/hash_count_all.

When we use call("random", {}, opts) and execute the expression with ExecuteScalarExpression(random_expr, cp::ExecBatch({}, 10)), the result only output one row. What we expected is 10 rows array.

 [
  0.5353881964857193
]

Reproduce

TEST(Expression, ExprWithNoArguments) {
   auto random_options = RandomOptions::FromSeed(/*seed=*/0);
   auto expr = call("random", {}, random_opts);
   ASSERT_OK_AND_ASSIGN(expr, expr.Bind(arrow::float64()));
  ASSERT_OK_AND_ASSIGN(auto out, ExecuteScalarExpression(
                                        expr, ExecBatch({}, 10)));
   std::cout << out.make_array()->ToString() << std::endl; // expect 10 rows but only get 1 row
}

Reason

The ExecuteScalarExpression internal code do some checks like below:

  bool all_scalar = true;
  for (size_t i = 0; i < arguments.size(); ++i) {
    ARROW_ASSIGN_OR_RAISE(
        arguments[i], ExecuteScalarExpression(call->arguments[i], input, exec_context));
    if (arguments[i].is_array()) {
      all_scalar = false;
    }
  }

The all_scalar will decide the output rows, if all_scalar is true, only output 1 row.
So we should consider the empty function arguments here? Or i missed some background here?

Component(s)

C++

Activity

  1. added a commit that references this issue on Feb 2, 2024
    1f3471e
  2. added a commit that references this issue on Feb 5, 2024
  3. added this to the 16.0.0 milestone on Feb 5, 2024
  4. modified the milestones: 16.0.0, 15.0.1 on Feb 14, 2024
  5. added a commit that references this issue on Feb 19, 2024
  6. added a commit that references this issue on Feb 20, 2024
  7. added a commit that references this issue on Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions