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

Function GenericTestSlice

cpp/src/arrow/compute/light_array_test.cc:237–261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235
236template <typename OffsetType>
237void GenericTestSlice(const std::shared_ptr<DataType>& type, const char* json_data,
238 const std::vector<SliceTestCase>& testCases) {
239 auto array = ArrayFromJSON(type, json_data);
240 KeyColumnArray kc_array =
241 ColumnArrayFromArrayData(array->data(), 0, array->length()).ValueOrDie();
242
243 for (const auto& testCase : testCases) {
244 ARROW_SCOPED_TRACE("Offset: ", testCase.offset, " Length: ", testCase.length);
245 KeyColumnArray sliced = kc_array.Slice(testCase.offset, testCase.length);
246
247 // Extract binary data from the sliced KeyColumnArray
248 std::vector<std::string> sliced_data;
249 const auto* offset_data = reinterpret_cast<const OffsetType*>(sliced.data(1));
250 const auto* string_data = reinterpret_cast<const char*>(sliced.data(2));
251
252 for (auto i = 0; i < testCase.length; ++i) {
253 auto start = offset_data[i];
254 auto end = offset_data[i + 1];
255 sliced_data.push_back(std::string(string_data + start, string_data + end));
256 }
257
258 // Compare the sliced values to the expected string
259 ASSERT_EQ(testCase.expected, sliced_data);
260 }
261}
262
263TEST(KeyColumnArray, SliceBinaryTest) {
264 const char* json_test_strings = R"(["Hello", "World", "Slice", "Binary", "Test"])";

Callers

nothing calls this directly

Calls 7

ArrayFromJSONFunction · 0.85
ColumnArrayFromArrayDataFunction · 0.85
ValueOrDieMethod · 0.80
push_backMethod · 0.80
dataMethod · 0.45
lengthMethod · 0.45
SliceMethod · 0.45

Tested by

no test coverage detected