Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
张回归 authored and 张回归 committed Feb 2, 2024
1 parent 796b0cc commit 1f3471e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
22 changes: 15 additions & 7 deletions cpp/src/arrow/compute/expression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -750,15 +750,23 @@ Result<Datum> ExecuteScalarExpression(const Expression& expr, const ExecBatch& i

auto call = CallNotNull(expr);

std::vector<Datum> arguments(call->arguments.size());

size_t num_args = call->arguments.size();
std::vector<Datum> arguments(num_args);
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;

if (num_args) {
for (size_t i = 0; i < num_args; ++i) {
ARROW_ASSIGN_OR_RAISE(
arguments[i], ExecuteScalarExpression(call->arguments[i], input, exec_context));
if (arguments[i].is_array()) {
all_scalar = false;
}
}
} else {
// See ARROW-39860. When num_args == 0, there is no problem in continuing to execute
// subsequent logic, because we have already found the kernel that the current
// expression can execute during Bind.
all_scalar = false;
}

auto executor = compute::detail::KernelExecutor::MakeScalar();
Expand Down
17 changes: 17 additions & 0 deletions cpp/src/arrow/compute/expression_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,23 @@ TEST(Expression, ExecuteCall) {
])"));
}

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

Expression random_expr = call("random", {}, random_options);
ASSERT_OK_AND_ASSIGN(random_expr, random_expr.Bind(float64()));

ASSERT_OK_AND_ASSIGN(Datum actual, ExecuteScalarExpression(random_expr, input));
compute::ExecContext* exec_context = default_exec_context();
ASSERT_OK_AND_ASSIGN(auto function,
exec_context->func_registry()->GetFunction("random"));
ASSERT_OK_AND_ASSIGN(Datum expected,
function->Execute(input, &random_options, exec_context));
AssertDatumsEqual(actual, expected, /*verbose=*/true);
}

TEST(Expression, ExecuteDictionaryTransparent) {
ExpectExecute(
equal(field_ref("a"), field_ref("b")),
Expand Down

0 comments on commit 1f3471e

Please sign in to comment.