@@ -41,16 +41,13 @@ namespace arrow {
4141
4242ListBuilder::ListBuilder (MemoryPool* pool,
4343 std::shared_ptr<ArrayBuilder> const & value_builder,
44- const std::shared_ptr<DataType>& type, bool infer_type)
45- : ArrayBuilder(type || infer_type
46- ? type
47- : std::static_pointer_cast<DataType>(
48- std::make_shared<ListType>(value_builder->type ())),
44+ const std::shared_ptr<DataType>& type)
45+ : ArrayBuilder(type ? type
46+ : std::static_pointer_cast<DataType>(
47+ std::make_shared<ListType>(value_builder->type ())),
4948 pool),
5049 offsets_builder_(pool),
51- value_builder_(value_builder) {
52- infer_type_ = infer_type;
53- }
50+ value_builder_(value_builder) {}
5451
5552Status ListBuilder::AppendValues (const int32_t * offsets, int64_t length,
5653 const uint8_t * valid_bytes) {
@@ -102,10 +99,10 @@ Status ListBuilder::FinishInternal(std::shared_ptr<ArrayData>* out) {
10299 RETURN_NOT_OK (value_builder_->FinishInternal (&items));
103100 }
104101
105- if (infer_type_) {
102+ // If the type has not been specified in the constructor, infer it
103+ if (!arrow::internal::checked_cast<ListType&>(*type_).value_type ()) {
106104 type_ = std::static_pointer_cast<DataType>(
107105 std::make_shared<ListType>(value_builder_->type ()));
108- infer_type_ = false ;
109106 }
110107 std::shared_ptr<Buffer> null_bitmap;
111108 RETURN_NOT_OK (null_bitmap_builder_.Finish (&null_bitmap));
@@ -131,10 +128,8 @@ ArrayBuilder* ListBuilder::value_builder() const {
131128// Struct
132129
133130StructBuilder::StructBuilder (const std::shared_ptr<DataType>& type, MemoryPool* pool,
134- std::vector<std::shared_ptr<ArrayBuilder>>&& field_builders,
135- bool infer_type)
131+ std::vector<std::shared_ptr<ArrayBuilder>>&& field_builders)
136132 : ArrayBuilder(type, pool) {
137- infer_type_ = infer_type;
138133 children_ = std::move (field_builders);
139134}
140135
@@ -159,13 +154,12 @@ Status StructBuilder::FinishInternal(std::shared_ptr<ArrayData>* out) {
159154 }
160155
161156 // If the type has not been specified in the constructor, infer it
162- if (infer_type_ ) {
157+ if (!type_ ) {
163158 std::vector<std::shared_ptr<Field>> fields;
164159 for (const auto & field_builder : children_) {
165160 fields.push_back (field (" " , field_builder->type ()));
166161 }
167162 type_ = struct_ (fields);
168- infer_type_ = false ;
169163 }
170164
171165 *out = ArrayData::Make (type_, length_, {null_bitmap}, null_count_);
0 commit comments