pitrou commented on a change in pull request #7898:
URL: https://github.com/apache/arrow/pull/7898#discussion_r469387808
##########
File path: cpp/src/arrow/array/array_test.cc
##########
@@ -2029,6 +2029,19 @@ TEST_F(TestAdaptiveIntBuilder, TestAppendNulls) {
}
}
+TEST(TestAdaptiveIntBuilderWithStartIntSize, TestReset) {
+ auto builder = std::make_shared<AdaptiveIntBuilder>(
+ static_cast<uint8_t>(sizeof(int16_t)), default_memory_pool());
+ ASSERT_TRUE(int16()->Equals(*builder->type()));
+
+ ASSERT_OK(
+
builder->Append(static_cast<int64_t>(std::numeric_limits<int16_t>::max()) + 1));
+ ASSERT_TRUE(int32()->Equals(*builder->type()));
Review comment:
Same here.
##########
File path: cpp/src/arrow/array/array_test.cc
##########
@@ -2029,6 +2029,19 @@ TEST_F(TestAdaptiveIntBuilder, TestAppendNulls) {
}
}
+TEST(TestAdaptiveIntBuilderWithStartIntSize, TestReset) {
+ auto builder = std::make_shared<AdaptiveIntBuilder>(
+ static_cast<uint8_t>(sizeof(int16_t)), default_memory_pool());
+ ASSERT_TRUE(int16()->Equals(*builder->type()));
Review comment:
`AssertTypeEqual`?
##########
File path: cpp/src/arrow/array/array_test.cc
##########
@@ -2029,6 +2029,19 @@ TEST_F(TestAdaptiveIntBuilder, TestAppendNulls) {
}
}
+TEST(TestAdaptiveIntBuilderWithStartIntSize, TestReset) {
+ auto builder = std::make_shared<AdaptiveIntBuilder>(
+ static_cast<uint8_t>(sizeof(int16_t)), default_memory_pool());
+ ASSERT_TRUE(int16()->Equals(*builder->type()));
+
+ ASSERT_OK(
+
builder->Append(static_cast<int64_t>(std::numeric_limits<int16_t>::max()) + 1));
+ ASSERT_TRUE(int32()->Equals(*builder->type()));
+
+ builder->Reset();
+ ASSERT_TRUE(int16()->Equals(*builder->type()));
Review comment:
Same here.
##########
File path: cpp/src/arrow/array/builder_dict.h
##########
@@ -105,18 +105,46 @@ class DictionaryBuilderBase : public ArrayBuilder {
// WARNING: the type given below is the value type, not the DictionaryType.
// The DictionaryType is instantiated on the Finish() call.
- template <typename T1 = T>
- DictionaryBuilderBase(enable_if_t<!std::is_base_of<FixedSizeBinaryType,
T1>::value,
+ template <typename B = BuilderType, typename T1 = T>
+ DictionaryBuilderBase(uint8_t start_int_size,
+ enable_if_t<std::is_base_of<AdaptiveIntBuilderBase,
B>::value &&
+ !is_fixed_size_binary_type<T1>::value,
const std::shared_ptr<DataType>&>
value_type,
MemoryPool* pool = default_memory_pool())
+ : ArrayBuilder(pool),
+ memo_table_(new internal::DictionaryMemoTable(pool, value_type)),
+ delta_offset_(0),
+ byte_width_(-1),
+ indices_builder_(start_int_size, pool),
+ value_type_(value_type) {}
+
+ template <typename T1 = T>
+ DictionaryBuilderBase(
Review comment:
Would the following work instead:
```c++
DictionaryBuilderBase(const std::shared_ptr<DataType>& value_type,
MemoryPool* pool = default_memory_pool())
: DictionaryBuilderBase(sizeof(int8_t), value_type, pool) {}
```
?
##########
File path: cpp/src/arrow/array/array_dict_test.cc
##########
@@ -904,6 +904,67 @@ TEST(TestDecimalDictionaryBuilder, DoubleTableSize) {
ASSERT_TRUE(expected.Equals(result));
}
+TEST(TestNullDictionaryBuilder, Basic) {
+ // MakeBuilder
+ auto dict_type = dictionary(int8(), null());
+ std::unique_ptr<ArrayBuilder> boxed_builder;
+ ASSERT_OK(MakeBuilder(default_memory_pool(), dict_type, &boxed_builder));
+ auto& builder = checked_cast<DictionaryBuilder<NullType>&>(*boxed_builder);
+
+ ASSERT_OK(builder.AppendNull());
+ ASSERT_OK(builder.AppendNull());
+ ASSERT_OK(builder.AppendNull());
+ ASSERT_EQ(3, builder.length());
+ ASSERT_EQ(3, builder.null_count());
+
+ ASSERT_OK(builder.AppendNulls(4));
+ ASSERT_EQ(7, builder.length());
+ ASSERT_EQ(7, builder.null_count());
+
+ auto int_array = ArrayFromJSON(int8(), "[0, 1, 0, null]");
+ ASSERT_OK(builder.AppendArray(*int_array));
+ ASSERT_EQ(11, builder.length());
+ ASSERT_EQ(11, builder.null_count());
+
+ std::shared_ptr<Array> result;
+ ASSERT_OK(builder.Finish(&result));
+ ASSERT_TRUE(dict_type->Equals(*result->type()));
Review comment:
`AssertTypeEquals`
##########
File path: cpp/src/arrow/array/array_dict_test.cc
##########
@@ -904,6 +904,67 @@ TEST(TestDecimalDictionaryBuilder, DoubleTableSize) {
ASSERT_TRUE(expected.Equals(result));
}
+TEST(TestNullDictionaryBuilder, Basic) {
+ // MakeBuilder
+ auto dict_type = dictionary(int8(), null());
+ std::unique_ptr<ArrayBuilder> boxed_builder;
+ ASSERT_OK(MakeBuilder(default_memory_pool(), dict_type, &boxed_builder));
+ auto& builder = checked_cast<DictionaryBuilder<NullType>&>(*boxed_builder);
+
+ ASSERT_OK(builder.AppendNull());
+ ASSERT_OK(builder.AppendNull());
+ ASSERT_OK(builder.AppendNull());
+ ASSERT_EQ(3, builder.length());
+ ASSERT_EQ(3, builder.null_count());
+
+ ASSERT_OK(builder.AppendNulls(4));
+ ASSERT_EQ(7, builder.length());
+ ASSERT_EQ(7, builder.null_count());
+
+ auto int_array = ArrayFromJSON(int8(), "[0, 1, 0, null]");
+ ASSERT_OK(builder.AppendArray(*int_array));
Review comment:
So one can append an array of ints to a null dictionary builder? What
does it mean?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]