Skip to content

Commit 39982cd

Browse files
committed
remove infer_type
1 parent 745ed58 commit 39982cd

File tree

6 files changed

+17
-45
lines changed

6 files changed

+17
-45
lines changed

cpp/src/arrow/array/builder_base.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ Status ArrayBuilder::Finish(std::shared_ptr<Array>* out) {
8484
return Status::OK();
8585
}
8686

87-
std::shared_ptr<DataType> ArrayBuilder::type() const {
88-
ARROW_CHECK(!infer_type_);
89-
return type_;
90-
}
91-
9287
void ArrayBuilder::Reset() {
9388
capacity_ = length_ = null_count_ = 0;
9489
null_bitmap_builder_.Reset();

cpp/src/arrow/array/builder_base.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class ARROW_EXPORT ArrayBuilder {
122122
/// \return Status
123123
Status Finish(std::shared_ptr<Array>* out);
124124

125-
std::shared_ptr<DataType> type() const;
125+
std::shared_ptr<DataType> type() const { return type_; }
126126

127127
protected:
128128
/// Append to null bitmap
@@ -187,11 +187,6 @@ class ARROW_EXPORT ArrayBuilder {
187187
// Child value array builders. These are owned by this class
188188
std::vector<std::shared_ptr<ArrayBuilder>> children_;
189189

190-
// Type of this builder is inferred in the Finish method. In this case,
191-
// the type() method cannot be used before Finish is called. Only used
192-
// for complex array builders (like nested builders). This is EXPERIMENTAL.
193-
bool infer_type_ = false;
194-
195190
private:
196191
ARROW_DISALLOW_COPY_AND_ASSIGN(ArrayBuilder);
197192
};

cpp/src/arrow/array/builder_nested.cc

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,13 @@ namespace arrow {
4141

4242
ListBuilder::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

5552
Status 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

133130
StructBuilder::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_);

cpp/src/arrow/array/builder_nested.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,8 @@ class ARROW_EXPORT ListBuilder : public ArrayBuilder {
4545
public:
4646
/// Use this constructor to incrementally build the value array along with offsets and
4747
/// null bitmap.
48-
///
49-
/// \param[in] pool the memory pool to use
50-
/// \param[in] value_builder array builder for the value array
51-
/// \param[in] type data type of the list that is being built
52-
/// \param[in] infer_type if true, will try to infer the data type in the Finish
53-
/// method. This is EXPERIMENTAL.
5448
ListBuilder(MemoryPool* pool, std::shared_ptr<ArrayBuilder> const& value_builder,
55-
const std::shared_ptr<DataType>& type = NULLPTR, bool infer_type = false);
49+
const std::shared_ptr<DataType>& type = NULLPTR);
5650

5751
Status Resize(int64_t capacity) override;
5852
void Reset() override;
@@ -93,11 +87,8 @@ class ARROW_EXPORT ListBuilder : public ArrayBuilder {
9387
/// called to maintain data-structure consistency.
9488
class ARROW_EXPORT StructBuilder : public ArrayBuilder {
9589
public:
96-
/// param[in] infer_type if true, will try to infer the data type in the Finish
97-
/// method. This is EXPERIMENTAL.
9890
StructBuilder(const std::shared_ptr<DataType>& type, MemoryPool* pool,
99-
std::vector<std::shared_ptr<ArrayBuilder>>&& field_builders,
100-
bool infer_type = false);
91+
std::vector<std::shared_ptr<ArrayBuilder>>&& field_builders);
10192

10293
Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
10394

cpp/src/arrow/array/builder_union.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ namespace arrow {
2525

2626
DenseUnionBuilder::DenseUnionBuilder(MemoryPool* pool,
2727
const std::shared_ptr<DataType>& type)
28-
: ArrayBuilder(type, pool), types_builder_(pool), offsets_builder_(pool) {
29-
infer_type_ = true;
30-
}
28+
: ArrayBuilder(type, pool), types_builder_(pool), offsets_builder_(pool) {}
3129

3230
Status DenseUnionBuilder::FinishInternal(std::shared_ptr<ArrayData>* out) {
3331
std::shared_ptr<Buffer> types;
@@ -50,9 +48,8 @@ Status DenseUnionBuilder::FinishInternal(std::shared_ptr<ArrayData>* out) {
5048
}
5149

5250
// If the type has not been specified in the constructor, infer it
53-
if (infer_type_) {
51+
if (!type_) {
5452
type_ = union_(fields, type_ids, UnionMode::DENSE);
55-
infer_type_ = false;
5653
}
5754

5855
*out = ArrayData::Make(type_, length(), {null_bitmap, types, offsets}, null_count_);

cpp/src/arrow/python/serialize.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class SequenceBuilder {
191191
}
192192
RETURN_NOT_OK(CreateAndUpdate(&target_sequence, tag, [this, &values]() {
193193
values.reset(new SequenceBuilder(pool_));
194-
return new ListBuilder(pool_, values->builder(), nullptr, true);
194+
return new ListBuilder(pool_, values->builder());
195195
}));
196196
RETURN_NOT_OK(target_sequence->Append());
197197
return internal::VisitIterable(
@@ -270,7 +270,7 @@ class DictBuilder {
270270
public:
271271
explicit DictBuilder(MemoryPool* pool = nullptr) : keys_(pool), vals_(pool) {
272272
builder_.reset(
273-
new StructBuilder(nullptr, pool, {keys_.builder(), vals_.builder()}, true));
273+
new StructBuilder(nullptr, pool, {keys_.builder(), vals_.builder()}));
274274
}
275275

276276
// Builder for the keys of the dictionary
@@ -300,7 +300,7 @@ Status SequenceBuilder::AppendDict(PyObject* context, PyObject* dict,
300300
}
301301
RETURN_NOT_OK(CreateAndUpdate(&dicts_, PythonType::DICT, [this]() {
302302
dict_values_.reset(new DictBuilder(pool_));
303-
return new ListBuilder(pool_, dict_values_->builder(), nullptr, true);
303+
return new ListBuilder(pool_, dict_values_->builder());
304304
}));
305305
RETURN_NOT_OK(dicts_->Append());
306306
PyObject* key;

0 commit comments

Comments
 (0)