| 235 | |
| 236 | template <typename OffsetType> |
| 237 | void 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 | |
| 263 | TEST(KeyColumnArray, SliceBinaryTest) { |
| 264 | const char* json_test_strings = R"(["Hello", "World", "Slice", "Binary", "Test"])"; |
nothing calls this directly
no test coverage detected