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

Function TestStringDictionaryAppendIndices

cpp/src/arrow/array/array_dict_test.cc:429–460  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

427
428template <typename BuilderType, typename IndexType, typename AppendCType>
429void 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
462TEST(TestStringDictionaryBuilder, AppendIndices) {
463 // Currently AdaptiveIntBuilder only accepts int64_t in bulk appends

Callers

nothing calls this directly

Calls 10

ArrayFromJSONFunction · 0.85
InsertMemoValuesMethod · 0.80
type_singletonFunction · 0.50
dictionaryFunction · 0.50
AppendIndicesMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
lengthMethod · 0.45
FinishMethod · 0.45
EqualsMethod · 0.45

Tested by

no test coverage detected