Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cpp/src/arrow/compute/expression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,15 @@ Result<Datum> ExecuteScalarExpression(const Expression& expr, const ExecBatch& i
}
}

int64_t input_length;
if (!arguments.empty() && all_scalar) {
// all inputs are scalar, so use a 1-long batch to avoid
// computing input.length equivalent outputs
input_length = 1;
} else {
input_length = input.length;
}

auto executor = compute::detail::KernelExecutor::MakeScalar();

compute::KernelContext kernel_context(exec_context, call->kernel);
Expand All @@ -772,8 +781,8 @@ Result<Datum> ExecuteScalarExpression(const Expression& expr, const ExecBatch& i
RETURN_NOT_OK(executor->Init(&kernel_context, {kernel, types, options}));

compute::detail::DatumAccumulator listener;
RETURN_NOT_OK(executor->Execute(
ExecBatch(std::move(arguments), all_scalar ? 1 : input.length), &listener));
RETURN_NOT_OK(
executor->Execute(ExecBatch(std::move(arguments), input_length), &listener));
const auto out = executor->WrapResults(arguments, listener.values());
#ifndef NDEBUG
DCHECK_OK(executor->CheckResultType(out, call->function_name.c_str()));
Expand Down
19 changes: 19 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,25 @@ 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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check the output length == 10 explicit?


EXPECT_EQ(actual.length(), kCount);
}

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