-
Notifications
You must be signed in to change notification settings - Fork 4.1k
There is an error in the usage example of the Compute Function on the official website? #38847
Copy link
Copy link
Closed
Labels
Milestone
Description
Describe the usage question you have. Please include as many useful details as possible.
I use Compute Function according to the example on the official website, and can compile successfully, but in the execution is an error: "Key error: No function registered with name: sum"
Here's my code:
#include
#include <arrow/api.h>
#include <arrow/compute/api.h>
using namespace std;
arrow::Status RunMain() {
// Create a couple 32-bit integer arrays.
arrow::Int32Builder int32builder;
int32_t some_nums_raw[5] = {34, 624, 2223, 5654, 4356};
ARROW_RETURN_NOT_OK(int32builder.AppendValues(some_nums_raw, 5));
std::shared_ptrarrow::Array some_nums;
ARROW_ASSIGN_OR_RAISE(some_nums, int32builder.Finish());
int32_t more_nums_raw[5] = {75342, 23, 64, 17, 736};
ARROW_RETURN_NOT_OK(int32builder.AppendValues(more_nums_raw, 5));
std::shared_ptr<arrow::Array> more_nums;
ARROW_ASSIGN_OR_RAISE(more_nums, int32builder.Finish());
// Make a table out of our pair of arrays.
std::shared_ptr<arrow::Field> field_a, field_b;
std::shared_ptr<arrow::Schema> schema;
field_a = arrow::field("A", arrow::int32());
field_b = arrow::field("B", arrow::int32());
schema = arrow::schema({field_a, field_b});
std::shared_ptr<arrow::Table> table;
table = arrow::Table::Make(schema, {some_nums, more_nums}, 5);
arrow::Datum tmp;
ARROW_ASSIGN_OR_RAISE(tmp, arrow::compute::Sum({table->GetColumnByName("A")}));
// Get the kind of Datum and what it holds -- this is a Scalar, with int64.
std::cout << "Datum kind: " << tmp.ToString() << " content type: " << tmp.type()->ToString() << std::endl;
std::cout << tmp.scalar_as<arrow::Int64Scalar>().value << std::endl;
return arrow::Status::OK();
}
int main() {
arrow::Status st = RunMain();
if (!st.ok()) {
std::cerr << st << std::endl;
return 1;
}
return 0;
}
Component(s)
C++
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Fields
Give feedbackNo fields configured for issues without a type.