// 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 { enum Kind { NONE, SCALAR, ARRAY, CHUNKED_ARRAY, RECORD_BATCH, TABLE }; struct Empty {}; // 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; 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; Datum(std::shared_ptr value) // NOLINT implicit conversion : value(std::move(value)) {} Datum(std::shared_ptr value) // NOLINT implicit conversion : value(std::move(value)) {} Datum(ArrayData arg) // NOLINT implicit conversion : value(std::make_shared(std::move(arg))) {} Datum(const Array& value); // NOLINT implicit conversion Datum(const std::shared_ptr& value); // NOLINT implicit conversion Datum(std::shared_ptr value); // NOLINT implicit conversion Datum(std::shared_ptr value); // NOLINT implicit conversion Datum(std::shared_ptr
value); // NOLINT implicit conversion // Explicit constructors from const-refs. Can be expensive, prefer the // shared_ptr constructors explicit Datum(const ChunkedArray& value); explicit Datum(const RecordBatch& value); explicit Datum(const Table& value); // Cast from 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))) {} // Cast from 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))) {} // Many Scalars are copyable, let that happen template >> Datum(const T& value) // NOLINT implicit conversion : Datum(std::make_shared(value)) {} // Convenience constructors explicit Datum(bool value); explicit Datum(int8_t value); explicit Datum(uint8_t value); explicit Datum(int16_t value); explicit Datum(uint16_t value); explicit Datum(int32_t value); explicit Datum(uint32_t value); explicit Datum(int64_t value); explicit Datum(uint64_t value); explicit Datum(float value); explicit Datum(double value); explicit Datum(std::string value); explicit Datum(const char* value); // Forward to convenience constructors for a DurationScalar from std::chrono::duration template