Skip to content

Commit

Permalink
Add the ListViewScalar class
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrv committed Apr 26, 2023
1 parent 855dddf commit 71cad47
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cpp/src/arrow/scalar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,17 @@ RunEndEncodedScalar::RunEndEncodedScalar(const std::shared_ptr<DataType>& type)

RunEndEncodedScalar::~RunEndEncodedScalar() = default;

ListViewScalar::ListViewScalar(std::shared_ptr<Array> value,
std::shared_ptr<DataType> type)
: Scalar{std::move(type), /*is_valid=*/value != NULLPTR}, value(std::move(value)) {
ARROW_CHECK(this->type->Equals(this->value->type()));
}

ListViewScalar::ListViewScalar(const std::shared_ptr<DataType>& type)
: ListViewScalar(NULLPTR, type) {}

ListViewScalar::~ListViewScalar() = default;

DictionaryScalar::DictionaryScalar(std::shared_ptr<DataType> type)
: internal::PrimitiveScalarBase(std::move(type)),
value{MakeNullScalar(checked_cast<const DictionaryType&>(*this->type).index_type()),
Expand Down
23 changes: 23 additions & 0 deletions cpp/src/arrow/scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,29 @@ struct ARROW_EXPORT RunEndEncodedScalar : public Scalar {
const TypeClass& ree_type() const { return internal::checked_cast<TypeClass&>(*type); }
};

struct ARROW_EXPORT ListViewScalar : public Scalar {
using TypeClass = ListViewType;
using ValueType = std::shared_ptr<Array>;

ValueType value;

ListViewScalar(std::shared_ptr<Array> value, std::shared_ptr<DataType> type);

/// \brief Constructs a NULL ListViewScalar
explicit ListViewScalar(const std::shared_ptr<DataType>& type);

~ListViewScalar() override;

const std::shared_ptr<DataType>& value_type() const {
return array_view_type().value_type();
}

private:
const TypeClass& array_view_type() const {
return internal::checked_cast<TypeClass&>(*type);
}
};

/// \brief A Scalar value for DictionaryType
///
/// `is_valid` denotes the validity of the `index`, regardless of
Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/type_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ struct RunEndEncodedScalar;

class ListViewType;
class ListViewArray;
struct ListViewScalar;

template <typename TypeClass>
class NumericArray;
Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ template <>
struct TypeTraits<ListViewType> {
using ArrayType = ListViewArray;
// TODO(felipecrv): Add BuilderType
using ScalarType = ListViewScalar;

constexpr static bool is_parameter_free = false;
};
Expand Down

0 comments on commit 71cad47

Please sign in to comment.