// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. #pragma once #include #include #include #include #include #include #include #include "arrow/array/data.h" #include "arrow/scalar.h" #include "arrow/type.h" #include "arrow/type_traits.h" #include "arrow/util/checked_cast.h" #include "arrow/util/macros.h" #include "arrow/util/visibility.h" namespace arrow { class Array; class ChunkedArray; class RecordBatch; class Table; /// \class Datum /// \brief Variant type for various Arrow C++ data structures struct ARROW_EXPORT Datum { /// \brief The kind of datum stored enum Kind { NONE, SCALAR, ARRAY, CHUNKED_ARRAY, RECORD_BATCH, TABLE }; /// \brief A placeholder type to represent empty datum struct Empty {}; /// \brief Datums variants may have a length. This special value indicate that the /// current variant does not have a length. static constexpr int64_t kUnknownLength = -1; /// \brief Storage of the actual datum. /// /// Note: For arrays, ArrayData is stored instead of Array for easier processing std::variant, std::shared_ptr, std::shared_ptr, std::shared_ptr, std::shared_ptr> value; /// \brief Empty datum, to be populated elsewhere Datum() = default; Datum(const Datum& other) = default; Datum& operator=(const Datum& other) = default; Datum(Datum&& other) = default; Datum& operator=(Datum&& other) = default; /// \brief Construct from a Scalar Datum(std::shared_ptr value) // NOLINT implicit conversion : value(std::move(value)) {} /// \brief Construct from an ArrayData Datum(std::shared_ptr value) // NOLINT implicit conversion : value(std::move(value)) {} /// \brief Construct from an ArrayData Datum(ArrayData arg) // NOLINT implicit conversion : value(std::make_shared(std::move(arg))) {} /// \brief Construct from an Array Datum(const Array& value); // NOLINT implicit conversion /// \brief Construct from an Array Datum(const std::shared_ptr& value); // NOLINT implicit conversion /// \brief Construct from a ChunkedArray Datum(std::shared_ptr value); // NOLINT implicit conversion /// \brief Construct from a RecordBatch Datum(std::shared_ptr value); // NOLINT implicit conversion /// \brief Construct from a Table Datum(std::shared_ptr
value); // NOLINT implicit conversion /// \brief Construct from a ChunkedArray. /// /// This can be expensive, prefer the shared_ptr constructor explicit Datum(const ChunkedArray& value); /// \brief Construct from a RecordBatch. /// /// This can be expensive, prefer the shared_ptr constructor explicit Datum(const RecordBatch& value); /// \brief Construct from a Table. /// /// This can be expensive, prefer the shared_ptr
constructor explicit Datum(const Table& value); /// \brief Cast from concrete subtypes of Array or Scalar to Datum template , bool IsScalar = std::is_base_of_v, typename = enable_if_t> Datum(std::shared_ptr value) // NOLINT implicit conversion : Datum(std::shared_ptr::type>( std::move(value))) {} /// \brief Cast from concrete subtypes of Array or Scalar to Datum template , bool IsArray = std::is_base_of_v, bool IsScalar = std::is_base_of_v, typename = enable_if_t> Datum(T&& value) // NOLINT implicit conversion : Datum(std::make_shared(std::forward(value))) {} /// \brief Copy from concrete subtypes of Scalar. /// /// The concrete scalar type must be copyable (not all of them are). template >> Datum(const T& value) // NOLINT implicit conversion : Datum(std::make_shared(value)) {} // Convenience constructors /// \brief Convenience constructor storing a bool scalar. explicit Datum(bool value); /// \brief Convenience constructor storing an int8 scalar. explicit Datum(int8_t value); /// \brief Convenience constructor storing a uint8 scalar. explicit Datum(uint8_t value); /// \brief Convenience constructor storing an int16 scalar. explicit Datum(int16_t value); /// \brief Convenience constructor storing a uint16 scalar. explicit Datum(uint16_t value); /// \brief Convenience constructor storing an int32 scalar. explicit Datum(int32_t value); /// \brief Convenience constructor storing a uint32 scalar. explicit Datum(uint32_t value); /// \brief Convenience constructor storing an int64 scalar. explicit Datum(int64_t value); /// \brief Convenience constructor storing a uint64 scalar. explicit Datum(uint64_t value); /// \brief Convenience constructor storing a float scalar. explicit Datum(float value); /// \brief Convenience constructor storing a double scalar. explicit Datum(double value); /// \brief Convenience constructor storing a string scalar. explicit Datum(std::string value); /// \brief Convenience constructor storing a string scalar. explicit Datum(const char* value); /// \brief Convenience constructor for a DurationScalar from std::chrono::duration template