-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'equivalent' method to Type #1740
Closed
majetideepak
wants to merge
3
commits into
facebookincubator:main
from
Ahana-Inc:support-decimal-equals
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -471,7 +471,19 @@ class Type : public Tree<const std::shared_ptr<const Type>>, | |
|
||
virtual std::string toString() const = 0; | ||
|
||
virtual bool operator==(const Type& other) const = 0; | ||
// Types are weakly matched. | ||
// Examples: Two RowTypes are equivalent if the children types are equivalent, | ||
// but the children names could be different. Two OpaqueTypes are equivalent | ||
// if the typeKind matches, but the typeIndex could be different. | ||
virtual bool equivalent(const Type& other) const = 0; | ||
|
||
// Types are strongly matched. | ||
// Examples: Two RowTypes are == if the children types and the children names | ||
// are same. Two OpaqueTypes are == if the typeKind and the typeIndex are | ||
// same. Same as equivalent for most types except for Row, Opaque types. | ||
virtual bool operator==(const Type& other) const { | ||
return this->equivalent(other); | ||
} | ||
|
||
inline bool operator!=(const Type& other) const { | ||
return !(*this == other); | ||
|
@@ -492,10 +504,10 @@ class Type : public Tree<const std::shared_ptr<const Type>>, | |
|
||
static std::shared_ptr<const Type> create(const folly::dynamic& obj); | ||
|
||
// recursive kind hashing (ignores names) | ||
// recursive kind hashing (uses only typeKind) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: perhaps, fix the comment to start with a capital letter and end with a period. Same below. |
||
size_t hashKind() const; | ||
|
||
// recursive kind match (ignores names) | ||
// recursive kind match (uses only typeKind) | ||
bool kindEquals(const std::shared_ptr<const Type>& other) const; | ||
|
||
template <TypeKind KIND, typename... CHILDREN> | ||
|
@@ -556,8 +568,49 @@ class TypeBase : public Type { | |
} | ||
}; | ||
|
||
using ShortDecimalType = DecimalType<TypeKind::SHORT_DECIMAL>; | ||
using LongDecimalType = DecimalType<TypeKind::LONG_DECIMAL>; | ||
template <TypeKind KIND> | ||
class ScalarType : public TypeBase<KIND> { | ||
public: | ||
uint32_t size() const override { | ||
return 0; | ||
} | ||
|
||
const std::shared_ptr<const Type>& childAt(uint32_t) const override { | ||
throw std::invalid_argument{"scalar type has no children"}; | ||
} | ||
|
||
std::string toString() const override { | ||
return TypeTraits<KIND>::name; | ||
} | ||
|
||
size_t cppSizeInBytes() const override { | ||
if (TypeTraits<KIND>::isFixedWidth) { | ||
return sizeof(typename TypeTraits<KIND>::NativeType); | ||
} | ||
// TODO: velox throws here for non fixed width types. | ||
return Type::cppSizeInBytes(); | ||
} | ||
|
||
FOLLY_NOINLINE static const std::shared_ptr<const ScalarType<KIND>> create(); | ||
|
||
bool equivalent(const Type& other) const override { | ||
return KIND == other.kind(); | ||
} | ||
|
||
// TODO: velox implementation is in cpp | ||
folly::dynamic serialize() const override { | ||
folly::dynamic obj = folly::dynamic::object; | ||
obj["name"] = "Type"; | ||
obj["type"] = TypeTraits<KIND>::name; | ||
return obj; | ||
} | ||
}; | ||
|
||
template <TypeKind KIND> | ||
const std::shared_ptr<const ScalarType<KIND>> ScalarType<KIND>::create() { | ||
static const auto instance = std::make_shared<const ScalarType<KIND>>(); | ||
return instance; | ||
} | ||
|
||
/// This class represents the fixed-point numbers. | ||
/// The parameter "precision" represents the number of digits the | ||
|
@@ -577,7 +630,7 @@ class DecimalType : public ScalarType<KIND> { | |
VELOX_CHECK_LE(precision, kMaxPrecision); | ||
} | ||
|
||
inline bool operator==(const Type& otherDecimal) const override { | ||
inline bool equivalent(const Type& otherDecimal) const override { | ||
if (this->kind() != otherDecimal.kind()) { | ||
return false; | ||
} | ||
|
@@ -611,49 +664,8 @@ class DecimalType : public ScalarType<KIND> { | |
const uint8_t scale_; | ||
}; | ||
|
||
template <TypeKind KIND> | ||
class ScalarType : public TypeBase<KIND> { | ||
public: | ||
uint32_t size() const override { | ||
return 0; | ||
} | ||
|
||
const std::shared_ptr<const Type>& childAt(uint32_t) const override { | ||
throw std::invalid_argument{"scalar type has no children"}; | ||
} | ||
|
||
std::string toString() const override { | ||
return TypeTraits<KIND>::name; | ||
} | ||
|
||
size_t cppSizeInBytes() const override { | ||
if (TypeTraits<KIND>::isFixedWidth) { | ||
return sizeof(typename TypeTraits<KIND>::NativeType); | ||
} | ||
// TODO: velox throws here for non fixed width types. | ||
return Type::cppSizeInBytes(); | ||
} | ||
|
||
FOLLY_NOINLINE static const std::shared_ptr<const ScalarType<KIND>> create(); | ||
|
||
bool operator==(const Type& other) const override { | ||
return KIND == other.kind(); | ||
} | ||
|
||
// TODO: velox implementation is in cpp | ||
folly::dynamic serialize() const override { | ||
folly::dynamic obj = folly::dynamic::object; | ||
obj["name"] = "Type"; | ||
obj["type"] = TypeTraits<KIND>::name; | ||
return obj; | ||
} | ||
}; | ||
|
||
template <TypeKind KIND> | ||
const std::shared_ptr<const ScalarType<KIND>> ScalarType<KIND>::create() { | ||
static const auto instance = std::make_shared<const ScalarType<KIND>>(); | ||
return instance; | ||
} | ||
using ShortDecimalType = DecimalType<TypeKind::SHORT_DECIMAL>; | ||
using LongDecimalType = DecimalType<TypeKind::LONG_DECIMAL>; | ||
|
||
class UnknownType : public TypeBase<TypeKind::UNKNOWN> { | ||
public: | ||
|
@@ -675,7 +687,7 @@ class UnknownType : public TypeBase<TypeKind::UNKNOWN> { | |
return 0; | ||
} | ||
|
||
bool operator==(const Type& other) const override { | ||
bool equivalent(const Type& other) const override { | ||
return TypeKind::UNKNOWN == other.kind(); | ||
} | ||
|
||
|
@@ -703,7 +715,7 @@ class ArrayType : public TypeBase<TypeKind::ARRAY> { | |
|
||
std::string toString() const override; | ||
|
||
bool operator==(const Type& other) const override; | ||
bool equivalent(const Type& other) const override; | ||
|
||
folly::dynamic serialize() const override; | ||
|
||
|
@@ -734,6 +746,8 @@ class FixedSizeArrayType : public ArrayType { | |
return "FIXED_SIZE_ARRAY"; | ||
} | ||
|
||
bool equivalent(const Type& other) const override; | ||
|
||
std::string toString() const override; | ||
|
||
private: | ||
|
@@ -762,7 +776,7 @@ class MapType : public TypeBase<TypeKind::MAP> { | |
|
||
const std::shared_ptr<const Type>& childAt(uint32_t idx) const override; | ||
|
||
bool operator==(const Type& other) const override; | ||
bool equivalent(const Type& other) const override; | ||
|
||
folly::dynamic serialize() const override; | ||
|
||
|
@@ -798,6 +812,8 @@ class RowType : public TypeBase<TypeKind::ROW> { | |
return names_.at(idx); | ||
} | ||
|
||
bool equivalent(const Type& other) const override; | ||
|
||
bool operator==(const Type& other) const override; | ||
|
||
std::string toString() const override; | ||
|
@@ -847,7 +863,7 @@ class FunctionType : public TypeBase<TypeKind::FUNCTION> { | |
return children_; | ||
} | ||
|
||
bool operator==(const Type& other) const override; | ||
bool equivalent(const Type& other) const override; | ||
|
||
std::string toString() const override; | ||
|
||
|
@@ -884,6 +900,8 @@ class OpaqueType : public TypeBase<TypeKind::OPAQUE> { | |
|
||
std::string toString() const override; | ||
|
||
bool equivalent(const Type& other) const override; | ||
|
||
bool operator==(const Type& other) const override; | ||
|
||
const std::type_index& typeIndex() const { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use /// for method and class-level comments.