(Doc section: RunMain)
| 26 | |
| 27 | // (Doc section: RunMain) |
| 28 | arrow::Status RunMain() { |
| 29 | // (Doc section: RunMain) |
| 30 | // (Doc section: Create Tables) |
| 31 | // Create a couple 32-bit integer arrays. |
| 32 | arrow::Int32Builder int32builder; |
| 33 | int32_t some_nums_raw[5] = {34, 624, 2223, 5654, 4356}; |
| 34 | ARROW_RETURN_NOT_OK(int32builder.AppendValues(some_nums_raw, 5)); |
| 35 | std::shared_ptr<arrow::Array> some_nums; |
| 36 | ARROW_ASSIGN_OR_RAISE(some_nums, int32builder.Finish()); |
| 37 | |
| 38 | int32_t more_nums_raw[5] = {75342, 23, 64, 17, 736}; |
| 39 | ARROW_RETURN_NOT_OK(int32builder.AppendValues(more_nums_raw, 5)); |
| 40 | std::shared_ptr<arrow::Array> more_nums; |
| 41 | ARROW_ASSIGN_OR_RAISE(more_nums, int32builder.Finish()); |
| 42 | |
| 43 | // Make a table out of our pair of arrays. |
| 44 | std::shared_ptr<arrow::Field> field_a, field_b; |
| 45 | std::shared_ptr<arrow::Schema> schema; |
| 46 | |
| 47 | field_a = arrow::field("A", arrow::int32()); |
| 48 | field_b = arrow::field("B", arrow::int32()); |
| 49 | |
| 50 | schema = arrow::schema({field_a, field_b}); |
| 51 | |
| 52 | // Initialize the compute module to register the required compute kernels. |
| 53 | ARROW_RETURN_NOT_OK(arrow::compute::Initialize()); |
| 54 | |
| 55 | std::shared_ptr<arrow::Table> table; |
| 56 | table = arrow::Table::Make(schema, {some_nums, more_nums}, 5); |
| 57 | // (Doc section: Create Tables) |
| 58 | |
| 59 | // (Doc section: Sum Datum Declaration) |
| 60 | // The Datum class is what all compute functions output to, and they can take Datums |
| 61 | // as inputs, as well. |
| 62 | arrow::Datum sum; |
| 63 | // (Doc section: Sum Datum Declaration) |
| 64 | // (Doc section: Sum Call) |
| 65 | // Here, we can use arrow::compute::Sum. This is a convenience function, and the next |
| 66 | // computation won't be so simple. However, using these where possible helps |
| 67 | // readability. |
| 68 | ARROW_ASSIGN_OR_RAISE(sum, arrow::compute::Sum({table->GetColumnByName("A")})); |
| 69 | // (Doc section: Sum Call) |
| 70 | // (Doc section: Sum Datum Type) |
| 71 | // Get the kind of Datum and what it holds -- this is a Scalar, with int64. |
| 72 | std::cout << "Datum kind: " << sum.ToString() |
| 73 | << " content type: " << sum.type()->ToString() << std::endl; |
| 74 | // (Doc section: Sum Datum Type) |
| 75 | // (Doc section: Sum Contents) |
| 76 | // Note that we explicitly request a scalar -- the Datum cannot simply give what it is, |
| 77 | // you must ask for the correct type. |
| 78 | std::cout << sum.scalar_as<arrow::Int64Scalar>().value << std::endl; |
| 79 | // (Doc section: Sum Contents) |
| 80 | |
| 81 | // (Doc section: Add Datum Declaration) |
| 82 | arrow::Datum element_wise_sum; |
| 83 | // (Doc section: Add Datum Declaration) |
| 84 | // (Doc section: Add Call) |
| 85 | // Get element-wise sum of both columns A and B in our Table. Note that here we use |
no test coverage detected