| 41 | // in the current directory |
| 42 | |
| 43 | arrow::Status RunMain(int argc, char** argv) { |
| 44 | ARROW_RETURN_NOT_OK(arrow::compute::Initialize()); |
| 45 | // Make Arrays |
| 46 | arrow::NumericBuilder<arrow::Int64Type> int64_builder; |
| 47 | arrow::BooleanBuilder boolean_builder; |
| 48 | |
| 49 | // Make place for 8 values in total |
| 50 | ARROW_RETURN_NOT_OK(int64_builder.Resize(8)); |
| 51 | ARROW_RETURN_NOT_OK(boolean_builder.Resize(8)); |
| 52 | |
| 53 | // Bulk append the given values |
| 54 | std::vector<int64_t> int64_values = {1, 2, 3, 4, 5, 6, 7, 8}; |
| 55 | ARROW_RETURN_NOT_OK(int64_builder.AppendValues(int64_values)); |
| 56 | std::shared_ptr<arrow::Array> array_a; |
| 57 | ARROW_RETURN_NOT_OK(int64_builder.Finish(&array_a)); |
| 58 | int64_builder.Reset(); |
| 59 | int64_values = {2, 5, 1, 3, 6, 2, 7, 4}; |
| 60 | std::shared_ptr<arrow::Array> array_b; |
| 61 | ARROW_RETURN_NOT_OK(int64_builder.AppendValues(int64_values)); |
| 62 | ARROW_RETURN_NOT_OK(int64_builder.Finish(&array_b)); |
| 63 | |
| 64 | // Cast the arrays to their actual types |
| 65 | auto int64_array_a = std::static_pointer_cast<arrow::Int64Array>(array_a); |
| 66 | auto int64_array_b = std::static_pointer_cast<arrow::Int64Array>(array_b); |
| 67 | // Explicit comparison of values using a loop |
| 68 | for (int64_t i = 0; i < 8; i++) { |
| 69 | if ((!int64_array_a->IsNull(i)) && (!int64_array_b->IsNull(i))) { |
| 70 | bool comparison_result = int64_array_a->Value(i) > int64_array_b->Value(i); |
| 71 | boolean_builder.UnsafeAppend(comparison_result); |
| 72 | } else { |
| 73 | boolean_builder.UnsafeAppendNull(); |
| 74 | } |
| 75 | } |
| 76 | std::shared_ptr<arrow::Array> array_a_gt_b_self; |
| 77 | ARROW_RETURN_NOT_OK(boolean_builder.Finish(&array_a_gt_b_self)); |
| 78 | std::cout << "Array explicitly compared" << std::endl; |
| 79 | |
| 80 | // Explicit comparison of values using a compute function |
| 81 | ARROW_ASSIGN_OR_RAISE(arrow::Datum compared_datum, |
| 82 | arrow::compute::CallFunction("greater", {array_a, array_b})); |
| 83 | auto array_a_gt_b_compute = compared_datum.make_array(); |
| 84 | std::cout << "Arrays compared using a compute function" << std::endl; |
| 85 |
no test coverage detected