Skip to content

Commit

Permalink
Variant LogicalType class
Browse files Browse the repository at this point in the history
  • Loading branch information
neilechao committed Jan 28, 2025
1 parent ee627e3 commit 30c3a40
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cpp/src/parquet/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ std::shared_ptr<const LogicalType> LogicalType::FromThrift(
return UUIDLogicalType::Make();
} else if (type.__isset.FLOAT16) {
return Float16LogicalType::Make();
} else if (type.__isset.VARIANT) {
return VariantLogicalType::Make();
} else {
throw ParquetException("Metadata contains Thrift LogicalType that is not recognized");
}
Expand Down Expand Up @@ -536,6 +538,10 @@ std::shared_ptr<const LogicalType> LogicalType::Float16() {
return Float16LogicalType::Make();
}

std::shared_ptr<const LogicalType> LogicalType::Variant() {
return VariantLogicalType::Make();
}

std::shared_ptr<const LogicalType> LogicalType::None() { return NoLogicalType::Make(); }

/*
Expand Down Expand Up @@ -618,6 +624,7 @@ class LogicalType::Impl {
class BSON;
class UUID;
class Float16;
class Variant;
class No;
class Undefined;

Expand Down Expand Up @@ -690,6 +697,9 @@ bool LogicalType::is_UUID() const { return impl_->type() == LogicalType::Type::U
bool LogicalType::is_float16() const {
return impl_->type() == LogicalType::Type::FLOAT16;
}
bool LogicalType::is_variant() const {
return impl_->type() == LogicalType::Type::VARIANT;
}
bool LogicalType::is_none() const { return impl_->type() == LogicalType::Type::NONE; }
bool LogicalType::is_valid() const {
return impl_->type() != LogicalType::Type::UNDEFINED;
Expand Down Expand Up @@ -1619,6 +1629,22 @@ class LogicalType::Impl::Float16 final : public LogicalType::Impl::Incompatible,

GENERATE_MAKE(Float16)

class LogicalType::Impl::Variant final : public LogicalType::Impl::Incompatible,
public LogicalType::Impl::SimpleApplicable {
public:
friend class VariantLogicalType;

OVERRIDE_TOSTRING(Variant)
OVERRIDE_TOTHRIFT(VariantType, VARIANT)

private:
Variant()
: LogicalType::Impl(LogicalType::Type::VARIANT, SortOrder::UNKNOWN),
LogicalType::Impl::SimpleApplicable(parquet::Type::BYTE_ARRAY) {}
};

GENERATE_MAKE(Variant)

class LogicalType::Impl::No final : public LogicalType::Impl::SimpleCompatible,
public LogicalType::Impl::UniversalApplicable {
public:
Expand Down
12 changes: 12 additions & 0 deletions cpp/src/parquet/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class PARQUET_EXPORT LogicalType {
BSON,
UUID,
FLOAT16,
VARIANT,
NONE // Not a real logical type; should always be last element
};
};
Expand Down Expand Up @@ -212,6 +213,7 @@ class PARQUET_EXPORT LogicalType {
static std::shared_ptr<const LogicalType> BSON();
static std::shared_ptr<const LogicalType> UUID();
static std::shared_ptr<const LogicalType> Float16();
static std::shared_ptr<const LogicalType> Variant();

/// \brief Create a placeholder for when no logical type is specified
static std::shared_ptr<const LogicalType> None();
Expand Down Expand Up @@ -266,6 +268,7 @@ class PARQUET_EXPORT LogicalType {
bool is_BSON() const;
bool is_UUID() const;
bool is_float16() const;
bool is_variant() const;
bool is_none() const;
/// \brief Return true if this logical type is of a known type.
bool is_valid() const;
Expand Down Expand Up @@ -446,6 +449,15 @@ class PARQUET_EXPORT Float16LogicalType : public LogicalType {
Float16LogicalType() = default;
};

/// \brief Allowed for physical type BYTE_ARRAY.
class PARQUET_EXPORT VariantLogicalType : public LogicalType {
public:
static std::shared_ptr<const LogicalType> Make();

private:
VariantLogicalType() = default;
};

/// \brief Allowed for any physical type.
class PARQUET_EXPORT NoLogicalType : public LogicalType {
public:
Expand Down

0 comments on commit 30c3a40

Please sign in to comment.