Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zanmato1984 committed Sep 29, 2024
1 parent 96d61c7 commit 1e141d7
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ if(ARROW_COMPUTE)
compute/kernels/scalar_validity.cc
compute/kernels/vector_array_sort.cc
compute/kernels/vector_cumulative_ops.cc
compute/kernels/vector_gather.cc
compute/kernels/vector_pairwise.cc
compute/kernels/vector_nested.cc
compute/kernels/vector_rank.cc
Expand Down
49 changes: 49 additions & 0 deletions cpp/src/arrow/compute/kernels/vector_gather.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// #include "arrow/compute/kernels/vector_gather_internal.h"
#include "arrow/compute/function.h"
#include "arrow/compute/kernels/codegen_internal.h"
#include "arrow/compute/registry.h"
#include "arrow/util/logging.h"

namespace arrow::compute::internal {

namespace {

struct GatherKernelSignature {
InputType indices_type;
InputType value_type;
ArrayKernelExec exec;
};

std::unique_ptr<Function> MakeGatherFunction(
std::string name, int min_args, std::vector<GatherKernelSignature>&& signatures,
FunctionDoc doc) {
auto func = std::make_unique<VectorFunction>(std::move(name), Arity::VarArgs(min_args),
std::move(doc));
for (auto& signature : signatures) {
auto kernel = VectorKernel{};
kernel.signature = KernelSignature::Make(
{std::move(signature.indices_type), std::move(signature.value_type)},
OutputType(LastType), /*is_varargs=*/true);
kernel.exec = signature.exec;
kernel.can_execute_chunkwise = false;
DCHECK_OK(func->AddKernel(std::move(kernel)));
}
return func;
}

const FunctionDoc gather_doc(
"Gather values from a list of inputs with an indices vector",
"The output is populated with values selected from the inputs, where each value is "
"chosen based on the corresponding index from the indices that specifies which input "
"in the list to use",
{"indices", "*inputs"});

} // namespace

void RegisterVectorGather(FunctionRegistry* registry) {
std::vector<GatherKernelSignature> signatures = {};
DCHECK_OK(registry->AddFunction(
MakeGatherFunction("gather", /*min_args=*/2, std::move(signatures), gather_doc)));
}

} // namespace arrow::compute::internal
39 changes: 39 additions & 0 deletions cpp/src/arrow/compute/kernels/vector_gather_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include "arrow/compute/function.h"

namespace arrow::compute::internal {

// class GatherMetaFunction : public MetaFunction {
// public:
// GatherMetaFunction() : MetaFunction("gather", Arity::VarArgs(3), gather_doc) {}

// Result<Datum> ExecuteImpl(const std::vector<Datum>& args,
// const FunctionOptions* options,
// ExecContext* ctx) const override {
// for (const auto& arg : args) {
// if (arg.kind() != Datum::ARRAY && arg.kind() != Datum::CHUNKED_ARRAY) {
// return Status::TypeError("Gather arguments should be array-like");
// }
// }

// if (!is_integer(*args[0].type())) {
// return Status::NotImplemented("Indices to gather must be integer type");
// }

// if (args[0].kind() == Datum::RECORD_BATCH) {
// ARROW_ASSIGN_OR_RAISE(
// std::shared_ptr<RecordBatch> out_batch,
// FilterRecordBatch(*args[0].record_batch(), args[1], options, ctx));
// return Datum(out_batch);
// } else if (args[0].kind() == Datum::TABLE) {
// ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Table> out_table,
// FilterTable(*args[0].table(), args[1], options, ctx));
// return Datum(out_table);
// } else {
// return CallFunction("array_filter", args, options, ctx);
// }
// }
// };

} // namespace arrow::compute::internal

0 comments on commit 1e141d7

Please sign in to comment.