MCPcopy Create free account
hub / github.com/apache/arrow / MakeBatchesFromNumString

Function MakeBatchesFromNumString

cpp/src/arrow/acero/asof_join_node_test.cc:92–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92Result<BatchesWithSchema> MakeBatchesFromNumString(
93 const std::shared_ptr<Schema>& schema,
94 const std::vector<std::string_view>& json_strings, int multiplicity = 1) {
95 FieldVector num_fields;
96 for (auto field : schema->fields()) {
97 auto id = field->type()->id();
98 bool adjust = id == Type::BOOL || is_base_binary_like(id);
99 num_fields.push_back(adjust ? field->WithType(int64()) : field);
100 }
101 auto num_schema =
102 std::make_shared<Schema>(num_fields, schema->endianness(), schema->metadata());
103 BatchesWithSchema num_batches =
104 MakeBatchesFromString(num_schema, json_strings, multiplicity);
105 BatchesWithSchema batches;
106 batches.schema = schema;
107 int n_fields = schema->num_fields();
108 size_t batch_index = 0;
109 for (auto num_batch : num_batches.batches) {
110 Datum two(Int32Scalar(2));
111 std::vector<Datum> values;
112 for (int i = 0; i < n_fields; i++) {
113 auto type = schema->field(i)->type();
114 if (is_base_binary_like(type->id())) {
115 // casting to string first enables casting to binary
116 ARROW_ASSIGN_OR_RAISE(Datum as_string, Cast(num_batch.values[i], utf8()));
117 ARROW_ASSIGN_OR_RAISE(Datum as_type, Cast(as_string, type));
118 values.push_back(as_type);
119 } else if (Type::BOOL == type->id()) {
120 // the next 4 lines compute `as_bool` as `(bool)(x - 2*(x/2))`, i.e., the low bit
121 // of `x`. Here, `x` stands for `num_batch.values[i]`, which is an `int64` value.
122 // Taking the low bit is a somewhat arbitrary way of obtaining both `true` and
123 // `false` values from the `int64` values in the test data, in order to get good
124 // testing coverage. A simple cast to a Boolean value would not get good coverage
125 // because all positive values would be cast to `true`.
126 ARROW_ASSIGN_OR_RAISE(Datum div_two, Divide(num_batch.values[i], two));
127 ARROW_ASSIGN_OR_RAISE(Datum rounded, Multiply(div_two, two));
128 ARROW_ASSIGN_OR_RAISE(Datum low_bit, Subtract(num_batch.values[i], rounded));
129 ARROW_ASSIGN_OR_RAISE(Datum as_bool, Cast(low_bit, type));
130 values.push_back(as_bool);
131 } else {
132 values.push_back(num_batch.values[i]);
133 }
134 }
135 ExecBatch batch(values, num_batch.length);
136 batch.index = batch_index++;
137 batches.batches.push_back(batch);
138 }
139 return batches;
140}
141
142void BuildNullArray(std::shared_ptr<Array>& empty, const std::shared_ptr<DataType>& type,
143 int64_t length) {

Callers

nothing calls this directly

Calls 11

is_base_binary_likeFunction · 0.85
MakeBatchesFromStringFunction · 0.85
push_backMethod · 0.80
WithTypeMethod · 0.80
fieldsMethod · 0.45
idMethod · 0.45
typeMethod · 0.45
endiannessMethod · 0.45
metadataMethod · 0.45
num_fieldsMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected