mapleFU commented on code in PR #42106: URL: https://github.com/apache/arrow/pull/42106#discussion_r1635369698
########## cpp/src/arrow/compute/special_forms/if_else_special_form.cc: ########## @@ -0,0 +1,62 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// NOTE: API is EXPERIMENTAL and will change without going through a +// deprecation cycle. + +#include "arrow/compute/special_forms/if_else_special_form.h" +#include "arrow/compute/exec.h" +#include "arrow/compute/expression.h" +#include "arrow/compute/expression_internal.h" + +namespace arrow { +namespace compute { + +Result<Datum> IfElseSpecialForm::Execute(const Expression::Call& call, + const ExecBatch& input, + ExecContext* exec_context) { + // The kernel (if_else) is not selection-vector-aware, so the input should not have a + // selection vector. + DCHECK(!call.kernel->selection_vector_aware && !input.selection_vector); + + std::vector<Datum> arguments(call.arguments.size()); + ARROW_ASSIGN_OR_RAISE(arguments[0], + ExecuteScalarExpression(call.arguments[0], input, exec_context)); + // Use cond as selection vector for IF branch. + // TODO: Consider chunked array for arguments[0]. Review Comment: Maybe applying check here? Or could it be scalar? ########## cpp/src/arrow/compute/special_form.h: ########## @@ -0,0 +1,62 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// NOTE: API is EXPERIMENTAL and will change without going through a +// deprecation cycle. + +#pragma once + +#include "arrow/compute/expression.h" +#include "arrow/util/visibility.h" + +#include <vector> + +namespace arrow { +namespace compute { + +/// The concept "special form" is borrowed from Lisp Review Comment: Aha, I didn't know that ########## cpp/src/arrow/compute/expression.cc: ########## @@ -716,6 +736,30 @@ Result<Datum> ExecuteScalarExpression(const Expression& expr, const Schema& full return ExecuteScalarExpression(expr, input, exec_context); } +namespace { + +// Execute a scalar expression that is not fully selection-vector-aware on a batch +// carrying a valid selection vector using the slow path: gathering the input and +// scattering the output. +Result<Datum> ExecuteScalarExpressionWithSelSlowPath(const Expression& expr, + const ExecBatch& input, + compute::ExecContext* exec_context) { + DCHECK(!expr.selection_vector_aware() && input.selection_vector); + auto values = input.values; + for (auto& value : values) { + if (value.is_scalar()) continue; + ARROW_ASSIGN_OR_RAISE( + value, Filter(value, input.selection_vector->data(), FilterOptions::Defaults())); + } Review Comment: Aha, this can be implemented like this, funny -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
