Scalars

struct Scalar : public std::enable_shared_from_this<Scalar>, public arrow::util::EqualityComparable<Scalar>

Base class for scalar values.

A Scalar represents a single value with a specific DataType. Scalars are useful for passing single value inputs to compute functions, or for representing individual array elements (with a non-trivial wrapping cost, though).

Subclassed by arrow::BaseListScalar, arrow::ExtensionScalar, arrow::internal::PrimitiveScalarBase, arrow::NullScalar, arrow::RunEndEncodedScalar, arrow::StructScalar, arrow::UnionScalar

Public Functions

Status Validate() const

Perform cheap validation checks.

This is O(k) where k is the number of descendents.

Returns:

Status

Status ValidateFull() const

Perform extensive data validation checks.

This is potentially O(k*n) where k is the number of descendents and n is the length of descendents (if list scalars are involved).

Returns:

Status

Status Accept(ScalarVisitor *visitor) const

Apply the ScalarVisitor::Visit() method specialized to the scalar type.

inline std::shared_ptr<Scalar> GetSharedPtr() const

EXPERIMENTAL Enable obtaining shared_ptr<Scalar> from a const Scalar& context.

Public Members

std::shared_ptr<DataType> type

The type of the scalar value.

bool is_valid = false

Whether the value is valid (not null) or not.

struct Hash

Factory functions

std::shared_ptr<Scalar> MakeNullScalar(std::shared_ptr<DataType> type)

Scalar factory for null scalars.

template<typename Value>
Result<std::shared_ptr<Scalar>> MakeScalar(std::shared_ptr<DataType> type, Value &&value)

Scalar factory for non-null scalars.

template<typename Value, typename Traits = CTypeTraits<typename std::decay<Value>::type>, typename ScalarType = typename Traits::ScalarType, typename Enable = decltype(ScalarType(std::declval<Value>(), Traits::type_singleton()))>
std::shared_ptr<Scalar> MakeScalar(Value value)

Type-inferring scalar factory for non-null scalars.

Construct a Scalar instance with a DataType determined by the input C++ type. (for example Int8Scalar for a int8_t input). Only non-parametric primitive types and String are supported.

inline std::shared_ptr<Scalar> MakeScalar(std::string value)
inline std::shared_ptr<Scalar> MakeScalar(const std::shared_ptr<Scalar> &scalar)

Concrete scalar subclasses

struct NullScalar : public arrow::Scalar
#include <arrow/scalar.h>

A scalar value for NullType. Never valid.

Public Types

using TypeClass = NullType

Public Functions

inline NullScalar()
struct BooleanScalar : public arrow::internal::PrimitiveScalar<BooleanType, bool>
#include <arrow/scalar.h>

Public Types

using Base = internal::PrimitiveScalar<BooleanType, bool>

Public Functions

inline explicit BooleanScalar(bool value)
inline BooleanScalar()
template<typename T>
struct NumericScalar : public arrow::internal::PrimitiveScalar<T>
#include <arrow/scalar.h>

Public Types

using Base = typename internal::PrimitiveScalar<T>
using TypeClass = typename Base::TypeClass
using ValueType = typename Base::ValueType

Public Functions

inline explicit NumericScalar(ValueType value)
inline NumericScalar()
struct Int8Scalar : public arrow::NumericScalar<Int8Type>
#include <arrow/scalar.h>
struct Int16Scalar : public arrow::NumericScalar<Int16Type>
#include <arrow/scalar.h>
struct Int32Scalar : public arrow::NumericScalar<Int32Type>
#include <arrow/scalar.h>
struct Int64Scalar : public arrow::NumericScalar<Int64Type>
#include <arrow/scalar.h>
struct UInt8Scalar : public arrow::NumericScalar<UInt8Type>
#include <arrow/scalar.h>
struct UInt16Scalar : public arrow::NumericScalar<UInt16Type>
#include <arrow/scalar.h>
struct UInt32Scalar : public arrow::NumericScalar<UInt32Type>
#include <arrow/scalar.h>
struct UInt64Scalar : public arrow::NumericScalar<UInt64Type>
#include <arrow/scalar.h>
struct HalfFloatScalar : public arrow::NumericScalar<HalfFloatType>
#include <arrow/scalar.h>
struct FloatScalar : public arrow::NumericScalar<FloatType>
#include <arrow/scalar.h>
struct DoubleScalar : public arrow::NumericScalar<DoubleType>
#include <arrow/scalar.h>
struct BaseBinaryScalar : public arrow::internal::PrimitiveScalarBase
#include <arrow/scalar.h>

Subclassed by arrow::BinaryScalar, arrow::LargeBinaryScalar

Public Types

using ValueType = std::shared_ptr<Buffer>

Public Functions

inline const void *data() const override
inline void *mutable_data() override
inline std::string_view view() const override

Public Members

std::shared_ptr<Buffer> value
struct BinaryScalar : public arrow::BaseBinaryScalar
#include <arrow/scalar.h>

Subclassed by arrow::FixedSizeBinaryScalar, arrow::StringScalar

Public Types

using TypeClass = BinaryType

Public Functions

inline BinaryScalar(std::shared_ptr<Buffer> value, std::shared_ptr<DataType> type)
inline explicit BinaryScalar(std::shared_ptr<Buffer> value)
explicit BinaryScalar(std::string s)
inline BinaryScalar()
inline BaseBinaryScalar(std::shared_ptr<Buffer> value, std::shared_ptr<DataType> type)
struct StringScalar : public arrow::BinaryScalar
#include <arrow/scalar.h>

Public Types

using TypeClass = StringType

Public Functions

inline explicit StringScalar(std::shared_ptr<Buffer> value)
explicit StringScalar(std::string s)
inline StringScalar()
inline BinaryScalar(std::shared_ptr<Buffer> value, std::shared_ptr<DataType> type)
inline explicit BinaryScalar(std::shared_ptr<Buffer> value)
explicit BinaryScalar(std::string s)
inline BinaryScalar()
struct LargeBinaryScalar : public arrow::BaseBinaryScalar
#include <arrow/scalar.h>

Subclassed by arrow::LargeStringScalar

Public Types

using TypeClass = LargeBinaryType

Public Functions

inline LargeBinaryScalar(std::shared_ptr<Buffer> value, std::shared_ptr<DataType> type)
inline explicit LargeBinaryScalar(std::shared_ptr<Buffer> value)
explicit LargeBinaryScalar(std::string s)
inline LargeBinaryScalar()
inline BaseBinaryScalar(std::shared_ptr<Buffer> value, std::shared_ptr<DataType> type)
struct LargeStringScalar : public arrow::LargeBinaryScalar
#include <arrow/scalar.h>

Public Types

using TypeClass = LargeStringType

Public Functions

inline explicit LargeStringScalar(std::shared_ptr<Buffer> value)
explicit LargeStringScalar(std::string s)
inline LargeStringScalar()
inline LargeBinaryScalar(std::shared_ptr<Buffer> value, std::shared_ptr<DataType> type)
inline explicit LargeBinaryScalar(std::shared_ptr<Buffer> value)
explicit LargeBinaryScalar(std::string s)
inline LargeBinaryScalar()
struct FixedSizeBinaryScalar : public arrow::BinaryScalar
#include <arrow/scalar.h>

Public Types

using TypeClass = FixedSizeBinaryType

Public Functions

FixedSizeBinaryScalar(std::shared_ptr<Buffer> value, std::shared_ptr<DataType> type, bool is_valid = true)
explicit FixedSizeBinaryScalar(const std::shared_ptr<Buffer> &value, bool is_valid = true)
explicit FixedSizeBinaryScalar(std::string s, bool is_valid = true)
template<typename T>
struct TemporalScalar : public arrow::internal::PrimitiveScalar<T>
#include <arrow/scalar.h>

Subclassed by arrow::DateScalar< T >, arrow::IntervalScalar< T >, arrow::TimeScalar< T >

Public Types

using ValueType = typename internal::PrimitiveScalar<T>::ValueType

Public Functions

inline TemporalScalar(ValueType value, std::shared_ptr<DataType> type)
template<typename T>
struct DateScalar : public arrow::TemporalScalar<T>
#include <arrow/scalar.h>

Public Types

using ValueType = typename TemporalScalar<T>::ValueType

Public Functions

inline explicit DateScalar(ValueType value)
inline DateScalar()
struct Date32Scalar : public arrow::DateScalar<Date32Type>
#include <arrow/scalar.h>
struct Date64Scalar : public arrow::DateScalar<Date64Type>
#include <arrow/scalar.h>
template<typename T>
struct TimeScalar : public arrow::TemporalScalar<T>
#include <arrow/scalar.h>

Public Functions

inline TimeScalar(typename TemporalScalar<T>::ValueType value, TimeUnit::type unit)
struct Time32Scalar : public arrow::TimeScalar<Time32Type>
#include <arrow/scalar.h>
struct Time64Scalar : public arrow::TimeScalar<Time64Type>
#include <arrow/scalar.h>
struct TimestampScalar : public arrow::TemporalScalar<TimestampType>
#include <arrow/scalar.h>

Public Functions

inline TimestampScalar(typename TemporalScalar<TimestampType>::ValueType value, TimeUnit::type unit, std::string tz = "")

Public Static Functions

static Result<TimestampScalar> FromISO8601(std::string_view iso8601, TimeUnit::type unit)
template<typename T>
struct IntervalScalar : public arrow::TemporalScalar<T>
#include <arrow/scalar.h>

Public Types

using ValueType = typename TemporalScalar<T>::ValueType

Public Functions

inline explicit IntervalScalar(ValueType value)
inline IntervalScalar()
struct MonthIntervalScalar : public arrow::IntervalScalar<MonthIntervalType>
#include <arrow/scalar.h>
struct DayTimeIntervalScalar : public arrow::IntervalScalar<DayTimeIntervalType>
#include <arrow/scalar.h>
struct MonthDayNanoIntervalScalar : public arrow::IntervalScalar<MonthDayNanoIntervalType>
#include <arrow/scalar.h>
struct DurationScalar : public arrow::TemporalScalar<DurationType>
#include <arrow/scalar.h>

Public Functions

inline DurationScalar(typename TemporalScalar<DurationType>::ValueType value, TimeUnit::type unit)
template<template<typename, typename> class StdDuration, typename Rep>
inline explicit DurationScalar(StdDuration<Rep, std::nano> d)
template<template<typename, typename> class StdDuration, typename Rep>
inline explicit DurationScalar(StdDuration<Rep, std::micro> d)
template<template<typename, typename> class StdDuration, typename Rep>
inline explicit DurationScalar(StdDuration<Rep, std::milli> d)
template<template<typename, typename> class StdDuration, typename Rep, intmax_t Num>
inline explicit DurationScalar(StdDuration<Rep, std::ratio<Num, 1>> d)
template<typename TYPE_CLASS, typename VALUE_TYPE>
struct DecimalScalar : public arrow::internal::PrimitiveScalarBase
#include <arrow/scalar.h>

Public Types

using TypeClass = TYPE_CLASS
using ValueType = VALUE_TYPE

Public Functions

inline DecimalScalar(ValueType value, std::shared_ptr<DataType> type)
inline const void *data() const override
inline void *mutable_data() override
inline std::string_view view() const override

Public Members

ValueType value
struct Decimal128Scalar : public arrow::DecimalScalar<Decimal128Type, Decimal128>
#include <arrow/scalar.h>

Public Functions

inline DecimalScalar(ValueType value, std::shared_ptr<DataType> type)
struct Decimal256Scalar : public arrow::DecimalScalar<Decimal256Type, Decimal256>
#include <arrow/scalar.h>

Public Functions

inline DecimalScalar(ValueType value, std::shared_ptr<DataType> type)
struct BaseListScalar : public arrow::Scalar
#include <arrow/scalar.h>

Subclassed by arrow::FixedSizeListScalar, arrow::LargeListScalar, arrow::ListScalar, arrow::MapScalar

Public Types

using ValueType = std::shared_ptr<Array>

Public Functions

BaseListScalar(std::shared_ptr<Array> value, std::shared_ptr<DataType> type, bool is_valid = true)
inline Scalar(std::shared_ptr<DataType> type, bool is_valid)

Public Members

std::shared_ptr<Array> value
struct ListScalar : public arrow::BaseListScalar
#include <arrow/scalar.h>

Public Types

using TypeClass = ListType

Public Functions

explicit ListScalar(std::shared_ptr<Array> value, bool is_valid = true)
BaseListScalar(std::shared_ptr<Array> value, std::shared_ptr<DataType> type, bool is_valid = true)
struct LargeListScalar : public arrow::BaseListScalar
#include <arrow/scalar.h>

Public Types

using TypeClass = LargeListType

Public Functions

explicit LargeListScalar(std::shared_ptr<Array> value, bool is_valid = true)
BaseListScalar(std::shared_ptr<Array> value, std::shared_ptr<DataType> type, bool is_valid = true)
struct MapScalar : public arrow::BaseListScalar
#include <arrow/scalar.h>

Public Types

using TypeClass = MapType

Public Functions

explicit MapScalar(std::shared_ptr<Array> value, bool is_valid = true)
BaseListScalar(std::shared_ptr<Array> value, std::shared_ptr<DataType> type, bool is_valid = true)
struct FixedSizeListScalar : public arrow::BaseListScalar
#include <arrow/scalar.h>

Public Types

using TypeClass = FixedSizeListType

Public Functions

FixedSizeListScalar(std::shared_ptr<Array> value, std::shared_ptr<DataType> type, bool is_valid = true)
explicit FixedSizeListScalar(std::shared_ptr<Array> value, bool is_valid = true)
struct StructScalar : public arrow::Scalar
#include <arrow/scalar.h>

Public Types

using TypeClass = StructType
using ValueType = std::vector<std::shared_ptr<Scalar>>

Public Functions

Result<std::shared_ptr<Scalar>> field(FieldRef ref) const
inline StructScalar(ValueType value, std::shared_ptr<DataType> type, bool is_valid = true)

Public Members

ScalarVector value

Public Static Functions

static Result<std::shared_ptr<StructScalar>> Make(ValueType value, std::vector<std::string> field_names)
struct UnionScalar : public arrow::Scalar
#include <arrow/scalar.h>

Subclassed by arrow::DenseUnionScalar, arrow::SparseUnionScalar

Public Functions

virtual const std::shared_ptr<Scalar> &child_value() const = 0

Public Members

int8_t type_code
struct SparseUnionScalar : public arrow::UnionScalar
#include <arrow/scalar.h>

Public Types

using TypeClass = SparseUnionType
using ValueType = std::vector<std::shared_ptr<Scalar>>

Public Functions

SparseUnionScalar(ValueType value, int8_t type_code, std::shared_ptr<DataType> type)
inline virtual const std::shared_ptr<Scalar> &child_value() const override

Public Members

ValueType value
int child_id

Public Static Functions

static std::shared_ptr<Scalar> FromValue(std::shared_ptr<Scalar> value, int field_index, std::shared_ptr<DataType> type)

Construct a SparseUnionScalar from a single value, versus having to construct a vector of scalars.

struct DenseUnionScalar : public arrow::UnionScalar
#include <arrow/scalar.h>

Public Types

using TypeClass = DenseUnionType
using ValueType = std::shared_ptr<Scalar>

Public Functions

inline virtual const std::shared_ptr<Scalar> &child_value() const override
inline DenseUnionScalar(ValueType value, int8_t type_code, std::shared_ptr<DataType> type)

Public Members

ValueType value
struct RunEndEncodedScalar : public arrow::Scalar
#include <arrow/scalar.h>

Public Types

using TypeClass = RunEndEncodedType
using ValueType = std::shared_ptr<Scalar>

Public Functions

RunEndEncodedScalar(std::shared_ptr<Scalar> value, std::shared_ptr<DataType> type)
explicit RunEndEncodedScalar(const std::shared_ptr<DataType> &type)

Constructs a NULL RunEndEncodedScalar.

~RunEndEncodedScalar() override
inline const std::shared_ptr<DataType> &run_end_type() const
inline const std::shared_ptr<DataType> &value_type() const

Public Members

ValueType value
struct DictionaryScalar : public arrow::internal::PrimitiveScalarBase
#include <arrow/scalar.h>

A Scalar value for DictionaryType.

is_valid denotes the validity of the index, regardless of the corresponding value in the dictionary.

Public Types

using TypeClass = DictionaryType

Public Functions

explicit DictionaryScalar(std::shared_ptr<DataType> type)
inline DictionaryScalar(ValueType value, std::shared_ptr<DataType> type, bool is_valid = true)
Result<std::shared_ptr<Scalar>> GetEncodedValue() const
inline const void *data() const override
inline void *mutable_data() override
inline std::string_view view() const override

Public Members

struct arrow::DictionaryScalar::ValueType value

Public Static Functions

static std::shared_ptr<DictionaryScalar> Make(std::shared_ptr<Scalar> index, std::shared_ptr<Array> dict)
struct ValueType
#include <arrow/scalar.h>

Public Members

std::shared_ptr<Scalar> index
std::shared_ptr<Array> dictionary
struct ExtensionScalar : public arrow::Scalar
#include <arrow/scalar.h>

A Scalar value for ExtensionType.

The value is the underlying storage scalar. is_valid must only be true if value is non-null and value->is_valid is true

Public Types

using TypeClass = ExtensionType
using ValueType = std::shared_ptr<Scalar>

Public Functions

inline ExtensionScalar(std::shared_ptr<Scalar> storage, std::shared_ptr<DataType> type, bool is_valid = true)
template<typename Storage, typename = enable_if_t<std::is_base_of<Scalar, Storage>::value>>
inline ExtensionScalar(Storage &&storage, std::shared_ptr<DataType> type, bool is_valid = true)

Public Members

std::shared_ptr<Scalar> value

Utilities

class ScalarVisitor

Abstract scalar visitor class.

Subclass this to create a visitor that can be used with the Scalar::Accept() method.

Public Functions

virtual ~ScalarVisitor() = default
virtual Status Visit(const NullScalar &scalar)
virtual Status Visit(const BooleanScalar &scalar)
virtual Status Visit(const Int8Scalar &scalar)
virtual Status Visit(const Int16Scalar &scalar)
virtual Status Visit(const Int32Scalar &scalar)
virtual Status Visit(const Int64Scalar &scalar)
virtual Status Visit(const UInt8Scalar &scalar)
virtual Status Visit(const UInt16Scalar &scalar)
virtual Status Visit(const UInt32Scalar &scalar)
virtual Status Visit(const UInt64Scalar &scalar)
virtual Status Visit(const HalfFloatScalar &scalar)
virtual Status Visit(const FloatScalar &scalar)
virtual Status Visit(const DoubleScalar &scalar)
virtual Status Visit(const StringScalar &scalar)
virtual Status Visit(const BinaryScalar &scalar)
virtual Status Visit(const LargeStringScalar &scalar)
virtual Status Visit(const LargeBinaryScalar &scalar)
virtual Status Visit(const FixedSizeBinaryScalar &scalar)
virtual Status Visit(const Date64Scalar &scalar)
virtual Status Visit(const Date32Scalar &scalar)
virtual Status Visit(const Time32Scalar &scalar)
virtual Status Visit(const Time64Scalar &scalar)
virtual Status Visit(const TimestampScalar &scalar)
virtual Status Visit(const DayTimeIntervalScalar &scalar)
virtual Status Visit(const MonthDayNanoIntervalScalar &type)
virtual Status Visit(const MonthIntervalScalar &scalar)
virtual Status Visit(const DurationScalar &scalar)
virtual Status Visit(const Decimal128Scalar &scalar)
virtual Status Visit(const Decimal256Scalar &scalar)
virtual Status Visit(const ListScalar &scalar)
virtual Status Visit(const LargeListScalar &scalar)
virtual Status Visit(const MapScalar &scalar)
virtual Status Visit(const FixedSizeListScalar &scalar)
virtual Status Visit(const StructScalar &scalar)
virtual Status Visit(const DictionaryScalar &scalar)
virtual Status Visit(const SparseUnionScalar &scalar)
virtual Status Visit(const DenseUnionScalar &scalar)
virtual Status Visit(const RunEndEncodedScalar &scalar)
virtual Status Visit(const ExtensionScalar &scalar)