Skip to content

Commit

Permalink
Implement LogicalType class
Browse files Browse the repository at this point in the history
  • Loading branch information
benibus committed Jun 14, 2023
1 parent 30abe53 commit 6522ab1
Show file tree
Hide file tree
Showing 2 changed files with 39 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 @@ -435,6 +435,8 @@ std::shared_ptr<const LogicalType> LogicalType::FromThrift(
return BSONLogicalType::Make();
} else if (type.__isset.UUID) {
return UUIDLogicalType::Make();
} else if (type.__isset.FLOAT16) {
return Float16LogicalType::Make();
} else {
throw ParquetException("Metadata contains Thrift LogicalType that is not recognized");
}
Expand Down Expand Up @@ -488,6 +490,10 @@ std::shared_ptr<const LogicalType> LogicalType::BSON() { return BSONLogicalType:

std::shared_ptr<const LogicalType> LogicalType::UUID() { return UUIDLogicalType::Make(); }

std::shared_ptr<const LogicalType> LogicalType::Float16() {
return Float16LogicalType::Make();
}

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

/*
Expand Down Expand Up @@ -569,6 +575,7 @@ class LogicalType::Impl {
class JSON;
class BSON;
class UUID;
class Float16;
class No;
class Undefined;

Expand Down Expand Up @@ -638,6 +645,9 @@ bool LogicalType::is_null() const { return impl_->type() == LogicalType::Type::N
bool LogicalType::is_JSON() const { return impl_->type() == LogicalType::Type::JSON; }
bool LogicalType::is_BSON() const { return impl_->type() == LogicalType::Type::BSON; }
bool LogicalType::is_UUID() const { return impl_->type() == LogicalType::Type::UUID; }
bool LogicalType::is_float16() const {
return impl_->type() == LogicalType::Type::FLOAT16;
}
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 @@ -1551,6 +1561,22 @@ class LogicalType::Impl::UUID final : public LogicalType::Impl::Incompatible,

GENERATE_MAKE(UUID)

class LogicalType::Impl::Float16 final : public LogicalType::Impl::Incompatible,
public LogicalType::Impl::TypeLengthApplicable {
public:
friend class Float16LogicalType;

OVERRIDE_TOSTRING(Float16)
OVERRIDE_TOTHRIFT(Float16Type, FLOAT16)

private:
Float16()
: LogicalType::Impl(LogicalType::Type::FLOAT16, SortOrder::SIGNED),
LogicalType::Impl::TypeLengthApplicable(parquet::Type::FIXED_LEN_BYTE_ARRAY, 2) {}
};

GENERATE_MAKE(Float16)

class LogicalType::Impl::No final : public LogicalType::Impl::SimpleCompatible,
public LogicalType::Impl::UniversalApplicable {
public:
Expand Down
13 changes: 13 additions & 0 deletions cpp/src/parquet/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class PARQUET_EXPORT LogicalType {
JSON,
BSON,
UUID,
FLOAT16,
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> JSON();
static std::shared_ptr<const LogicalType> BSON();
static std::shared_ptr<const LogicalType> UUID();
static std::shared_ptr<const LogicalType> Float16();

/// \brief Create a placeholder for when no logical type is specified
static std::shared_ptr<const LogicalType> None();
Expand Down Expand Up @@ -265,6 +267,7 @@ class PARQUET_EXPORT LogicalType {
bool is_JSON() const;
bool is_BSON() const;
bool is_UUID() const;
bool is_float16() 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 @@ -435,6 +438,16 @@ class PARQUET_EXPORT UUIDLogicalType : public LogicalType {
UUIDLogicalType() = default;
};

/// \brief Allowed for physical type FIXED_LEN_BYTE_ARRAY with length 2,
/// must encode raw FLOAT16 bytes.
class PARQUET_EXPORT Float16LogicalType : public LogicalType {
public:
static std::shared_ptr<const LogicalType> Make();

private:
Float16LogicalType() = default;
};

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

0 comments on commit 6522ab1

Please sign in to comment.