-
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
Add 'equivalent' method to Type #1740
Conversation
velox/type/tests/TypeTest.cpp
Outdated
@@ -134,6 +134,9 @@ TEST(TypeTest, shortDecimal) { | |||
} catch (const VeloxRuntimeError& e) { | |||
EXPECT_EQ("(19 vs. 18)", e.message()); | |||
} | |||
EXPECT_TRUE(SHORT_DECIMAL(10, 5)->kindEquals(SHORT_DECIMAL(10, 5))); |
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.
Not related to this PR, but in the above tests we should try to construct a SHORT_DECIMAL with negative precision and scale and throw exception in those cases.
LGTM |
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.
@majetideepak Deepak, what's the motivation for this change? Type::kindEquals is expected to check only type kinds (recursively), not type parameters. For example, it doesn't check len parameter for the FixedSizeArrayType.
@mbasmanova I was exploring decimal signatures and felt this change was required. For example:
I would expect the following to fail since the argument types should not bind. But it doesn't since we use
|
@majetideepak Deepak, thank you for the context. Should we than rename the kindEquals method and change the comment to clarify that we are comparing everything (kind + parameters) except for the names? Also, should we fix the |
@mbasmanova Yes to all your suggestions including adding a virtual method to Type. I will make another pass. Thanks for the feedback. |
6cc1be5
to
1094dcf
Compare
@mbasmanova I renamed |
44c5c29
to
345fb3e
Compare
@majetideepak Look good to me. I wonder if equals is a bit too similar to == so users won't know the difference and assume these are exactly the same. Would it make sense to come up with a name that clearly says that "equals" ignores the names of the children. Also, would you update the PR title and write up a description? |
@mbasmanova for |
Why not use "equivalent" term you used in the PR description? |
db5c1cc
to
17aab6f
Compare
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@majetideepak Deepak, there are circle CI failures. Would you take a look? |
17aab6f
to
e00f9d3
Compare
@mbasmanova, CI is green. |
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@majetideepak Deepak, there are a lot of places that I need to change to accommodate this PR. As I'm changing these I'm having second thoughts. It feels like there is a clear use case for kindEquals method, e.g the function that operates on certain types can check if it got these. For example, a function that takes only decimals, can check if it got a short or long decimal. It wouldn't care what the precision and scales are. The use case for equivalence check is not as clear and I wonder if it actually makes sense to keep the kindEquals method that checks only the TypeKind recursively and add an equivalence method if there is a use case for it. What do you think? |
@mbasmanova Let's take
If the type is decimal, it is not enough to check if arrayVector type and searchVector type are both ShortDecimal. We must verify that the precision and scale are also the same, for the operation to be meaningful. I feel we must also ensure that the operation is meaningful somewhere. Does it make sense then only for the SignatureBinder to use an |
The SignatureBinder verifies the argument types. I also don't see why we need these checks in the functions. |
This is a good question. At this moment, I do not see any other use case. |
e00f9d3
to
96f501b
Compare
velox/type/Type.h
Outdated
@@ -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. |
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.
velox/type/Type.h
Outdated
@@ -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 comment
The 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.
@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Summary: The `kindEquals` method only checks if the `TypeKind` of two types matches recursively. However, certain types like DecimalType and FixedSizedArrayType require their parameters to match as well. This type of equivalence is needed by the SignatureBinder. A new `equivalent` method has been added to Type for this requirement. Example: Two FixedSizedArrayTypes are equivalent only if their lengths are equal. Two DecimalTypes are equivalent only if their precision/scale are the same. Pull Request resolved: facebookincubator#1740 Reviewed By: pedroerp Differential Revision: D36986040 Pulled By: mbasmanova fbshipit-source-id: 495cbe1c01aa87aea47c1c9d4f891e3cc784f4b2
Summary: The `kindEquals` method only checks if the `TypeKind` of two types matches recursively. However, certain types like DecimalType and FixedSizedArrayType require their parameters to match as well. This type of equivalence is needed by the SignatureBinder. A new `equivalent` method has been added to Type for this requirement. Example: Two FixedSizedArrayTypes are equivalent only if their lengths are equal. Two DecimalTypes are equivalent only if their precision/scale are the same. Pull Request resolved: facebookincubator#1740 Reviewed By: pedroerp Differential Revision: D36986040 Pulled By: mbasmanova fbshipit-source-id: 495cbe1c01aa87aea47c1c9d4f891e3cc784f4b2
…Clickhouse successfully (facebookincubator#1740) What changes were proposed in this pull request? (Fixes: facebookincubator#1738) How was this patch tested? manual tests, run ep/build-clickhouse/src/build_clickhouse.sh
The
kindEquals
method only checks if theTypeKind
of two types matches recursively.However, certain types like DecimalType and FixedSizedArrayType require their parameters
to match as well. This type of equivalence is needed by the SignatureBinder.
A new
equivalent
method has been added to Type for this requirement.Example: Two FixedSizedArrayTypes are equivalent only if their lengths are equal.
Two DecimalTypes are equivalent only if their precision/scale are the same.