File indexing completed on 2025-08-27 08:47:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #pragma once
0022
0023 #include <memory>
0024 #include <string>
0025
0026 #include "arrow/array/array_base.h"
0027 #include "arrow/array/data.h"
0028 #include "arrow/result.h"
0029 #include "arrow/status.h"
0030 #include "arrow/type.h"
0031 #include "arrow/type_fwd.h"
0032 #include "arrow/util/checked_cast.h"
0033 #include "arrow/util/macros.h"
0034 #include "arrow/util/visibility.h"
0035
0036 namespace arrow {
0037
0038
0039 class ARROW_EXPORT ExtensionType : public DataType {
0040 public:
0041 static constexpr Type::type type_id = Type::EXTENSION;
0042
0043 static constexpr const char* type_name() { return "extension"; }
0044
0045
0046 const std::shared_ptr<DataType>& storage_type() const { return storage_type_; }
0047
0048
0049 Type::type storage_id() const override { return storage_type_->id(); }
0050
0051 DataTypeLayout layout() const override;
0052
0053 std::string ToString(bool show_metadata = false) const override;
0054
0055 std::string name() const override { return "extension"; }
0056
0057 int32_t byte_width() const override { return storage_type_->byte_width(); }
0058 int bit_width() const override { return storage_type_->bit_width(); }
0059
0060
0061
0062
0063 virtual std::string extension_name() const = 0;
0064
0065
0066
0067
0068
0069 virtual bool ExtensionEquals(const ExtensionType& other) const = 0;
0070
0071
0072
0073 virtual std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const = 0;
0074
0075
0076
0077
0078
0079
0080 virtual Result<std::shared_ptr<DataType>> Deserialize(
0081 std::shared_ptr<DataType> storage_type,
0082 const std::string& serialized_data) const = 0;
0083
0084
0085
0086
0087
0088 virtual std::string Serialize() const = 0;
0089
0090
0091 static std::shared_ptr<Array> WrapArray(const std::shared_ptr<DataType>& ext_type,
0092 const std::shared_ptr<Array>& storage);
0093
0094
0095 static std::shared_ptr<ChunkedArray> WrapArray(
0096 const std::shared_ptr<DataType>& ext_type,
0097 const std::shared_ptr<ChunkedArray>& storage);
0098
0099 protected:
0100 explicit ExtensionType(std::shared_ptr<DataType> storage_type)
0101 : DataType(Type::EXTENSION), storage_type_(std::move(storage_type)) {}
0102
0103 std::shared_ptr<DataType> storage_type_;
0104 };
0105
0106
0107 class ARROW_EXPORT ExtensionArray : public Array {
0108 public:
0109 using TypeClass = ExtensionType;
0110
0111
0112
0113 explicit ExtensionArray(const std::shared_ptr<ArrayData>& data);
0114
0115
0116 ExtensionArray(const std::shared_ptr<DataType>& type,
0117 const std::shared_ptr<Array>& storage);
0118
0119 const ExtensionType* extension_type() const {
0120 return internal::checked_cast<const ExtensionType*>(data_->type.get());
0121 }
0122
0123
0124 const std::shared_ptr<Array>& storage() const { return storage_; }
0125
0126 protected:
0127 void SetData(const std::shared_ptr<ArrayData>& data);
0128 std::shared_ptr<Array> storage_;
0129 };
0130
0131 class ARROW_EXPORT ExtensionTypeRegistry {
0132 public:
0133
0134
0135
0136 static std::shared_ptr<ExtensionTypeRegistry> GetGlobalRegistry();
0137
0138 virtual ~ExtensionTypeRegistry() = default;
0139
0140 virtual Status RegisterType(std::shared_ptr<ExtensionType> type) = 0;
0141 virtual Status UnregisterType(const std::string& type_name) = 0;
0142 virtual std::shared_ptr<ExtensionType> GetType(const std::string& type_name) = 0;
0143 };
0144
0145
0146
0147
0148
0149 ARROW_EXPORT
0150 Status RegisterExtensionType(std::shared_ptr<ExtensionType> type);
0151
0152
0153
0154
0155
0156 ARROW_EXPORT
0157 Status UnregisterExtensionType(const std::string& type_name);
0158
0159
0160
0161
0162 ARROW_EXPORT
0163 std::shared_ptr<ExtensionType> GetExtensionType(const std::string& type_name);
0164
0165 ARROW_EXPORT extern const char kExtensionTypeKeyName[];
0166 ARROW_EXPORT extern const char kExtensionMetadataKeyName[];
0167
0168 }