mapleFU commented on code in PR #45375:
URL: https://github.com/apache/arrow/pull/45375#discussion_r2015432177


##########
cpp/src/parquet/arrow/variant.cc:
##########
@@ -0,0 +1,89 @@
+// 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.
+
+#include "parquet/arrow/variant.h"
+
+#include <string>
+
+#include "arrow/extension_type.h"
+#include "arrow/result.h"
+#include "arrow/status.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/logging.h"
+
+namespace parquet::arrow {
+
+using ::arrow::Array;
+using ::arrow::ArrayData;
+using ::arrow::DataType;
+using ::arrow::ExtensionType;
+using ::arrow::Result;
+using ::arrow::Type;
+
+bool VariantExtensionType::ExtensionEquals(const ExtensionType& other) const {
+  return other.extension_name() == this->extension_name() &&
+         other.storage_type()->Equals(this->storage_type_);
+}
+
+Result<std::shared_ptr<DataType>> VariantExtensionType::Deserialize(
+    std::shared_ptr<DataType> storage_type, const std::string& serialized) 
const {
+  return VariantExtensionType::Make(std::move(storage_type));
+}
+
+std::string VariantExtensionType::Serialize() const { return ""; }
+
+std::shared_ptr<Array> VariantExtensionType::MakeArray(
+    std::shared_ptr<ArrayData> data) const {
+  DCHECK_EQ(data->type->id(), Type::EXTENSION);
+  DCHECK_EQ("parquet.variant",
+            ::arrow::internal::checked_cast<const ExtensionType&>(*data->type)
+                .extension_name());
+  return std::make_shared<::arrow::ExtensionArray>(data);
+}
+
+bool VariantExtensionType::IsSupportedStorageType(
+    const std::shared_ptr<DataType>& storage_type) {
+  // For now we only supported unshredded variants. Unshredded variant storage
+  // type should be a struct with a binary metadata and binary value.
+  //
+  // TODO(neilechao) In shredded variants, the binary value field can be 
replaced
+  // with one or more of the following: object, array, typed_value, and
+  // variant_value.
+  if (storage_type->id() == Type::STRUCT) {
+    if (storage_type->num_fields() == 2) {
+      return storage_type->field(0)->type()->storage_id() == Type::BINARY &&

Review Comment:
   unshredded variant should have "required"(which means not-nullable) metadata 
and value column, right



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to