Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:27:00

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #pragma once
0019 
0020 #include <memory>
0021 #include <string>
0022 #include <vector>
0023 
0024 #include "arrow/extension_type.h"
0025 #include "arrow/testing/visibility.h"
0026 #include "arrow/util/macros.h"
0027 
0028 namespace arrow {
0029 
0030 class ARROW_TESTING_EXPORT ExampleUuidArray : public ExtensionArray {
0031  public:
0032   using ExtensionArray::ExtensionArray;
0033 };
0034 
0035 class ARROW_TESTING_EXPORT ExampleUuidType : public ExtensionType {
0036  public:
0037   ExampleUuidType() : ExtensionType(fixed_size_binary(16)) {}
0038 
0039   std::string extension_name() const override { return "uuid"; }
0040 
0041   bool ExtensionEquals(const ExtensionType& other) const override;
0042 
0043   std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override;
0044 
0045   Result<std::shared_ptr<DataType>> Deserialize(
0046       std::shared_ptr<DataType> storage_type,
0047       const std::string& serialized) const override;
0048 
0049   std::string Serialize() const override { return "uuid-serialized"; }
0050 };
0051 
0052 class ARROW_TESTING_EXPORT SmallintArray : public ExtensionArray {
0053  public:
0054   using ExtensionArray::ExtensionArray;
0055 };
0056 
0057 class ARROW_TESTING_EXPORT TinyintArray : public ExtensionArray {
0058  public:
0059   using ExtensionArray::ExtensionArray;
0060 };
0061 
0062 class ARROW_TESTING_EXPORT ListExtensionArray : public ExtensionArray {
0063  public:
0064   using ExtensionArray::ExtensionArray;
0065 };
0066 
0067 class ARROW_TESTING_EXPORT SmallintType : public ExtensionType {
0068  public:
0069   SmallintType() : ExtensionType(int16()) {}
0070 
0071   std::string extension_name() const override { return "smallint"; }
0072 
0073   bool ExtensionEquals(const ExtensionType& other) const override;
0074 
0075   std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override;
0076 
0077   Result<std::shared_ptr<DataType>> Deserialize(
0078       std::shared_ptr<DataType> storage_type,
0079       const std::string& serialized) const override;
0080 
0081   std::string Serialize() const override { return "smallint"; }
0082 };
0083 
0084 class ARROW_TESTING_EXPORT TinyintType : public ExtensionType {
0085  public:
0086   TinyintType() : ExtensionType(int8()) {}
0087 
0088   std::string extension_name() const override { return "tinyint"; }
0089 
0090   bool ExtensionEquals(const ExtensionType& other) const override;
0091 
0092   std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override;
0093 
0094   Result<std::shared_ptr<DataType>> Deserialize(
0095       std::shared_ptr<DataType> storage_type,
0096       const std::string& serialized) const override;
0097 
0098   std::string Serialize() const override { return "tinyint"; }
0099 };
0100 
0101 class ARROW_TESTING_EXPORT ListExtensionType : public ExtensionType {
0102  public:
0103   ListExtensionType() : ExtensionType(list(int32())) {}
0104 
0105   std::string extension_name() const override { return "list-ext"; }
0106 
0107   bool ExtensionEquals(const ExtensionType& other) const override;
0108 
0109   std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override;
0110 
0111   Result<std::shared_ptr<DataType>> Deserialize(
0112       std::shared_ptr<DataType> storage_type,
0113       const std::string& serialized) const override;
0114 
0115   std::string Serialize() const override { return "list-ext"; }
0116 };
0117 
0118 class ARROW_TESTING_EXPORT DictExtensionType : public ExtensionType {
0119  public:
0120   DictExtensionType() : ExtensionType(dictionary(int8(), utf8())) {}
0121 
0122   std::string extension_name() const override { return "dict-extension"; }
0123 
0124   bool ExtensionEquals(const ExtensionType& other) const override;
0125 
0126   std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override;
0127 
0128   Result<std::shared_ptr<DataType>> Deserialize(
0129       std::shared_ptr<DataType> storage_type,
0130       const std::string& serialized) const override;
0131 
0132   std::string Serialize() const override { return "dict-extension-serialized"; }
0133 };
0134 
0135 // A minimal extension type that does not error when passed blank extension information
0136 class ARROW_TESTING_EXPORT MetadataOptionalExtensionType : public ExtensionType {
0137  public:
0138   MetadataOptionalExtensionType() : ExtensionType(null()) {}
0139   std::string extension_name() const override { return "metadata.optional"; }
0140   std::string Serialize() const override { return ""; }
0141   std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override {
0142     return nullptr;
0143   }
0144   bool ExtensionEquals(const ExtensionType& other) const override {
0145     return other.extension_name() == extension_name();
0146   }
0147   Result<std::shared_ptr<DataType>> Deserialize(
0148       std::shared_ptr<DataType> storage_type,
0149       const std::string& serialized_data) const override {
0150     return std::make_shared<MetadataOptionalExtensionType>();
0151   }
0152 };
0153 
0154 class ARROW_TESTING_EXPORT Complex128Array : public ExtensionArray {
0155  public:
0156   using ExtensionArray::ExtensionArray;
0157 };
0158 
0159 class ARROW_TESTING_EXPORT Complex128Type : public ExtensionType {
0160  public:
0161   Complex128Type()
0162       : ExtensionType(struct_({::arrow::field("real", float64(), /*nullable=*/false),
0163                                ::arrow::field("imag", float64(), /*nullable=*/false)})) {}
0164 
0165   std::string extension_name() const override { return "complex128"; }
0166 
0167   bool ExtensionEquals(const ExtensionType& other) const override;
0168 
0169   std::shared_ptr<Array> MakeArray(std::shared_ptr<ArrayData> data) const override;
0170 
0171   Result<std::shared_ptr<DataType>> Deserialize(
0172       std::shared_ptr<DataType> storage_type,
0173       const std::string& serialized) const override;
0174 
0175   std::string Serialize() const override { return "complex128-serialized"; }
0176 };
0177 
0178 ARROW_TESTING_EXPORT
0179 std::shared_ptr<DataType> uuid();
0180 
0181 ARROW_TESTING_EXPORT
0182 std::shared_ptr<DataType> smallint();
0183 
0184 ARROW_TESTING_EXPORT
0185 std::shared_ptr<DataType> tinyint();
0186 
0187 ARROW_TESTING_EXPORT
0188 std::shared_ptr<DataType> list_extension_type();
0189 
0190 ARROW_TESTING_EXPORT
0191 std::shared_ptr<DataType> dict_extension_type();
0192 
0193 ARROW_TESTING_EXPORT
0194 std::shared_ptr<DataType> complex128();
0195 
0196 ARROW_TESTING_EXPORT
0197 std::shared_ptr<Array> ExampleUuid();
0198 
0199 ARROW_TESTING_EXPORT
0200 std::shared_ptr<Array> ExampleSmallint();
0201 
0202 ARROW_TESTING_EXPORT
0203 std::shared_ptr<Array> ExampleTinyint();
0204 
0205 ARROW_TESTING_EXPORT
0206 std::shared_ptr<Array> ExampleDictExtension();
0207 
0208 ARROW_TESTING_EXPORT
0209 std::shared_ptr<Array> ExampleComplex128();
0210 
0211 ARROW_TESTING_EXPORT
0212 std::shared_ptr<Array> MakeComplex128(const std::shared_ptr<Array>& real,
0213                                       const std::shared_ptr<Array>& imag);
0214 
0215 // A RAII class that registers an extension type on construction
0216 // and unregisters it on destruction.
0217 class ARROW_TESTING_EXPORT ExtensionTypeGuard {
0218  public:
0219   explicit ExtensionTypeGuard(const std::shared_ptr<DataType>& type);
0220   explicit ExtensionTypeGuard(const DataTypeVector& types);
0221   ~ExtensionTypeGuard();
0222   ARROW_DEFAULT_MOVE_AND_ASSIGN(ExtensionTypeGuard);
0223 
0224  protected:
0225   ARROW_DISALLOW_COPY_AND_ASSIGN(ExtensionTypeGuard);
0226 
0227   std::vector<std::string> extension_names_;
0228 };
0229 
0230 }  // namespace arrow