pitrou commented on code in PR #47835:
URL: https://github.com/apache/arrow/pull/47835#discussion_r2444034227


##########
cpp/src/parquet/types.h:
##########
@@ -178,6 +178,9 @@ class PARQUET_EXPORT LogicalType {
     KARNEY = 5
   };
 
+  /// \brief The latest supported Variant specification version by this library
+  static constexpr int8_t VARIANT_SPEC_VERSION = 1;

Review Comment:
   Let's use our naming convention for constants.
   ```suggestion
     static constexpr int8_t kVariantSpecVersion = 1;
   ```



##########
cpp/src/parquet/types.cc:
##########
@@ -1958,16 +1963,53 @@ class LogicalType::Impl::Variant final : public 
LogicalType::Impl::Incompatible,
  public:
   friend class VariantLogicalType;
 
-  OVERRIDE_TOSTRING(Variant)
-  OVERRIDE_TOTHRIFT(VariantType, VARIANT)
+  std::string ToString() const override;
+  std::string ToJSON() const override;
+  format::LogicalType ToThrift() const override;
+
+  int8_t spec_version() const { return specVersion_; }
 
  private:
-  Variant()
+  explicit Variant(const int8_t specVersion)
       : LogicalType::Impl(LogicalType::Type::VARIANT, SortOrder::UNKNOWN),
-        LogicalType::Impl::Inapplicable() {}
+        LogicalType::Impl::Inapplicable() {
+    this->specVersion_ = specVersion;
+  }
+
+  int8_t specVersion_;

Review Comment:
   Fix casing.
   ```suggestion
     int8_t spec_version_;
   ```



##########
cpp/src/parquet/types.cc:
##########
@@ -659,8 +664,8 @@ std::shared_ptr<const LogicalType> LogicalType::Geography(
   return GeographyLogicalType::Make(std::move(crs), algorithm);
 }
 
-std::shared_ptr<const LogicalType> LogicalType::Variant() {
-  return VariantLogicalType::Make();
+std::shared_ptr<const LogicalType> LogicalType::Variant(int8_t specVersion) {

Review Comment:
   ```suggestion
   std::shared_ptr<const LogicalType> LogicalType::Variant(int8_t spec_version) 
{
   ```



##########
cpp/src/parquet/types.cc:
##########
@@ -1958,16 +1963,53 @@ class LogicalType::Impl::Variant final : public 
LogicalType::Impl::Incompatible,
  public:
   friend class VariantLogicalType;
 
-  OVERRIDE_TOSTRING(Variant)
-  OVERRIDE_TOTHRIFT(VariantType, VARIANT)
+  std::string ToString() const override;
+  std::string ToJSON() const override;
+  format::LogicalType ToThrift() const override;
+
+  int8_t spec_version() const { return specVersion_; }
 
  private:
-  Variant()
+  explicit Variant(const int8_t specVersion)
       : LogicalType::Impl(LogicalType::Type::VARIANT, SortOrder::UNKNOWN),
-        LogicalType::Impl::Inapplicable() {}
+        LogicalType::Impl::Inapplicable() {
+    this->specVersion_ = specVersion;
+  }
+
+  int8_t specVersion_;
 };
 
-GENERATE_MAKE(Variant)
+int8_t VariantLogicalType::spec_version() const {
+  return (dynamic_cast<const 
LogicalType::Impl::Variant&>(*impl_)).spec_version();
+}
+
+std::string LogicalType::Impl::Variant::ToString() const {
+  std::stringstream type;
+  type << "Variant(" << static_cast<int>(specVersion_) << ")";
+  return type.str();
+}
+
+std::string LogicalType::Impl::Variant::ToJSON() const {
+  std::stringstream json;
+  json << R"({"Type": "Variant", "SpecVersion": )" << 
static_cast<int>(specVersion_)
+       << "}";
+
+  return json.str();
+}
+
+format::LogicalType LogicalType::Impl::Variant::ToThrift() const {
+  format::LogicalType type;
+  format::VariantType variant_type;
+  variant_type.__set_specification_version(specVersion_);
+  type.__set_VARIANT(variant_type);
+  return type;
+}
+
+std::shared_ptr<const LogicalType> VariantLogicalType::Make(const int8_t 
specVersion) {
+  auto logical_type = std::shared_ptr<VariantLogicalType>(new 
VariantLogicalType());

Review Comment:
   Can we use `std::make_shared`? It's more terse _and_ more efficient.



##########
cpp/src/parquet/types.cc:
##########
@@ -591,7 +591,12 @@ std::shared_ptr<const LogicalType> LogicalType::FromThrift(
 
     return GeographyLogicalType::Make(std::move(crs), algorithm);
   } else if (type.__isset.VARIANT) {
-    return VariantLogicalType::Make();
+    int8_t specVersion = VARIANT_SPEC_VERSION;

Review Comment:
   Let's please use `snake_case` for local variables: `spec_version`.



-- 
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