Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cpp/src/arrow/array/builder_adaptive.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class ARROW_EXPORT AdaptiveIntBuilderBase : public ArrayBuilder {
return Status::OK();
}

Type::type type_id() const final {
// This could be more optimal, but it requires minor modifications
// to AdaptiveIntBuilder and AdaptiveUIntBuilder.
return type()->id();
}

void Reset() override;
Status Resize(int64_t capacity) override;

Expand Down
6 changes: 6 additions & 0 deletions cpp/src/arrow/array/builder_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ class ARROW_EXPORT ArrayBuilder {
/// \brief Return the type of the built Array
virtual std::shared_ptr<DataType> type() const = 0;

/// \brief Return the type ID of the built Array.
///
/// Use this method when only the type ID is needed, instead of calling
/// type()->id(), to avoid unnecessary allocation and deallocation.
virtual Type::type type_id() const = 0;

protected:
/// Set the next length bits to not null (i.e. valid).
Status SetNotNull(int64_t length);
Expand Down
7 changes: 7 additions & 0 deletions cpp/src/arrow/array/builder_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ class BaseBinaryBuilder
return std::numeric_limits<offset_type>::max() - 1;
}

Type::type type_id() const override { return TypeClass::type_id; }

protected:
TypedBufferBuilder<offset_type> offsets_builder_;
TypedBufferBuilder<uint8_t> value_data_builder_;
Expand Down Expand Up @@ -711,6 +713,8 @@ class ARROW_EXPORT BinaryViewBuilder : public ArrayBuilder {

std::shared_ptr<DataType> type() const override { return binary_view(); }

Type::type type_id() const override { return Type::BINARY_VIEW; }

protected:
TypedBufferBuilder<BinaryViewType::c_type> data_builder_;

Expand All @@ -723,6 +727,7 @@ class ARROW_EXPORT StringViewBuilder : public BinaryViewBuilder {
public:
using BinaryViewBuilder::BinaryViewBuilder;
std::shared_ptr<DataType> type() const override { return utf8_view(); }
Type::type type_id() const override { return Type::STRING_VIEW; }
};

// ----------------------------------------------------------------------
Expand Down Expand Up @@ -900,6 +905,8 @@ class ARROW_EXPORT FixedSizeBinaryBuilder : public ArrayBuilder {
return fixed_size_binary(byte_width_);
}

Type::type type_id() const override { return Type::FIXED_SIZE_BINARY; }

protected:
int32_t byte_width_;
BufferBuilder byte_builder_;
Expand Down
6 changes: 6 additions & 0 deletions cpp/src/arrow/array/builder_decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class ARROW_EXPORT Decimal32Builder : public FixedSizeBinaryBuilder {

std::shared_ptr<DataType> type() const override { return decimal_type_; }

Type::type type_id() const override { return Type::DECIMAL32; }

protected:
std::shared_ptr<Decimal32Type> decimal_type_;
};
Expand Down Expand Up @@ -91,6 +93,8 @@ class ARROW_EXPORT Decimal64Builder : public FixedSizeBinaryBuilder {

std::shared_ptr<DataType> type() const override { return decimal_type_; }

Type::type type_id() const override { return Type::DECIMAL64; }

protected:
std::shared_ptr<Decimal64Type> decimal_type_;
};
Expand Down Expand Up @@ -122,6 +126,8 @@ class ARROW_EXPORT Decimal128Builder : public FixedSizeBinaryBuilder {

std::shared_ptr<DataType> type() const override { return decimal_type_; }

Type::type type_id() const override { return Type::DECIMAL128; }

protected:
std::shared_ptr<Decimal128Type> decimal_type_;
};
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/array/builder_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ class DictionaryBuilderBase : public ArrayBuilder {
ordered_);
}

Type::type type_id() const override { return Type::DICTIONARY; }

protected:
template <typename c_type>
Status AppendArraySliceImpl(const typename TypeTraits<T>::ArrayType& dict,
Expand Down Expand Up @@ -714,6 +716,8 @@ class DictionaryBuilderBase<BuilderType, NullType> : public ArrayBuilder {
ordered_);
}

Type::type type_id() const override { return Type::DICTIONARY; }

protected:
BuilderType indices_builder_;
bool ordered_ = false;
Expand Down
8 changes: 8 additions & 0 deletions cpp/src/arrow/array/builder_nested.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ class VarLengthListLikeBuilder : public ArrayBuilder {
return std::make_shared<TYPE>(value_field_->WithType(value_builder_->type()));
}

Type::type type_id() const override { return TypeClass::type_id; }

private:
static constexpr const char* type_name() {
if constexpr (is_list_view(TYPE::type_id)) {
Expand Down Expand Up @@ -617,6 +619,8 @@ class ARROW_EXPORT MapBuilder : public ArrayBuilder {
keys_sorted_);
}

Type::type type_id() const override { return Type::MAP; }

Status ValidateOverflow(int64_t new_elements) {
return list_builder_->ValidateOverflow(new_elements);
}
Expand Down Expand Up @@ -720,6 +724,8 @@ class ARROW_EXPORT FixedSizeListBuilder : public ArrayBuilder {
return fixed_size_list(value_field_->WithType(value_builder_->type()), list_size_);
}

Type::type type_id() const override { return Type::FIXED_SIZE_LIST; }

// Cannot make this a static attribute because of linking issues
static constexpr int64_t maximum_elements() {
return std::numeric_limits<FixedSizeListType::offset_type>::max() - 1;
Expand Down Expand Up @@ -827,6 +833,8 @@ class ARROW_EXPORT StructBuilder : public ArrayBuilder {

std::shared_ptr<DataType> type() const override;

Type::type type_id() const override { return Type::STRUCT; }

private:
std::shared_ptr<DataType> type_;
};
Expand Down
6 changes: 6 additions & 0 deletions cpp/src/arrow/array/builder_primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class ARROW_EXPORT NullBuilder : public ArrayBuilder {

std::shared_ptr<DataType> type() const override { return null(); }

Type::type type_id() const override { return Type::NA; }

Status Finish(std::shared_ptr<NullArray>* out) { return FinishTyped(out); }
};

Expand Down Expand Up @@ -348,6 +350,8 @@ class NumericBuilder

std::shared_ptr<DataType> type() const override { return type_; }

Type::type type_id() const override { return TypeClass::type_id; }

protected:
std::shared_ptr<DataType> type_;
TypedBufferBuilder<value_type> data_builder_;
Expand Down Expand Up @@ -682,6 +686,8 @@ class ARROW_EXPORT BooleanBuilder

std::shared_ptr<DataType> type() const override { return boolean(); }

Type::type type_id() const override { return Type::BOOL; }

protected:
TypedBufferBuilder<bool> data_builder_;
};
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/array/builder_run_end.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class RunCompressorBuilder : public ArrayBuilder {

std::shared_ptr<DataType> type() const override { return inner_builder_->type(); }

Type::type type_id() const override { return inner_builder_->type_id(); }

bool has_open_run() const { return current_run_length_ > 0; }
int64_t open_run_length() const { return current_run_length_; }

Expand Down Expand Up @@ -258,6 +260,8 @@ class ARROW_EXPORT RunEndEncodedBuilder : public ArrayBuilder {

std::shared_ptr<DataType> type() const override;

Type::type type_id() const override { return Type::RUN_END_ENCODED; }

private:
/// \brief Update physical capacity and logical length
///
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/array/builder_union.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class ARROW_EXPORT BasicUnionBuilder : public ArrayBuilder {

std::shared_ptr<DataType> type() const override;

Type::type type_id() const override {
return mode_ == UnionMode::SPARSE ? Type::SPARSE_UNION : Type::DENSE_UNION;
}

int64_t length() const override { return types_builder_.length(); }

protected:
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/arrow/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class ARROW_EXPORT TypeErasedIntBuilder : public ArrayBuilder {

std::shared_ptr<DataType> type() const override { return builder_->type(); }

Type::type type_id() const override { return builder_->type_id(); }

private:
std::unique_ptr<ArrayBuilder> builder_;
Type::type type_id_;
Expand Down
Loading