| 427 | |
| 428 | template <typename BuilderType, typename IndexType, typename AppendCType> |
| 429 | void TestStringDictionaryAppendIndices() { |
| 430 | auto index_type = TypeTraits<IndexType>::type_singleton(); |
| 431 | |
| 432 | auto ex_dict = ArrayFromJSON(utf8(), R"(["c", "a", "b", "d"])"); |
| 433 | auto invalid_dict = ArrayFromJSON(binary(), R"(["e", "f"])"); |
| 434 | |
| 435 | BuilderType builder; |
| 436 | ASSERT_OK(builder.InsertMemoValues(*ex_dict)); |
| 437 | |
| 438 | // Inserting again should have no effect |
| 439 | ASSERT_OK(builder.InsertMemoValues(*ex_dict)); |
| 440 | |
| 441 | // Type mismatch |
| 442 | ASSERT_RAISES(Invalid, builder.InsertMemoValues(*invalid_dict)); |
| 443 | |
| 444 | std::vector<AppendCType> raw_indices = {0, 1, 2, -1, 3}; |
| 445 | std::vector<uint8_t> is_valid = {1, 1, 1, 0, 1}; |
| 446 | for (int i = 0; i < 2; ++i) { |
| 447 | ASSERT_OK(builder.AppendIndices( |
| 448 | raw_indices.data(), static_cast<int64_t>(raw_indices.size()), is_valid.data())); |
| 449 | } |
| 450 | |
| 451 | ASSERT_EQ(10, builder.length()); |
| 452 | |
| 453 | std::shared_ptr<Array> result; |
| 454 | ASSERT_OK(builder.Finish(&result)); |
| 455 | |
| 456 | auto ex_indices = ArrayFromJSON(index_type, R"([0, 1, 2, null, 3, 0, 1, 2, null, 3])"); |
| 457 | auto dtype = dictionary(index_type, utf8()); |
| 458 | DictionaryArray expected(dtype, ex_indices, ex_dict); |
| 459 | ASSERT_TRUE(expected.Equals(result)); |
| 460 | } |
| 461 | |
| 462 | TEST(TestStringDictionaryBuilder, AppendIndices) { |
| 463 | // Currently AdaptiveIntBuilder only accepts int64_t in bulk appends |
nothing calls this directly
no test coverage detected