Skip to content
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 isOrderable and isComparable for Type #6770

Closed
wants to merge 2 commits into from

Conversation

duanmeng
Copy link
Collaborator

@duanmeng duanmeng commented Sep 27, 2023

In Presto, input to min/max/array_sort is restricted to orderable types. For example, MAP type is not orderable. Velox currently allows MAP inputs.
This PR extends the Velox Type class to add isOrderable() and isComparable() methods.

Part of #6718 and #6712

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 27, 2023
@netlify
Copy link

netlify bot commented Sep 27, 2023

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 4d02d8e
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/65156d0b81539a0008590b9d

@duanmeng duanmeng force-pushed the typeFiled branch 2 times, most recently from 2041291 to 3d968d5 Compare September 27, 2023 16:54
@duanmeng
Copy link
Collaborator Author

@mbasmanova Hi Masha, I've updated the PR with the logical type solution and added related tests, could you please help to take a look? Thanks a lot.

Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

velox/type/Type.cpp Outdated Show resolved Hide resolved
velox/type/Type.cpp Outdated Show resolved Hide resolved
velox/type/Type.h Outdated Show resolved Hide resolved
@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@pedroerp pedroerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a small bug above.

velox/type/Type.cpp Outdated Show resolved Hide resolved

rowType = ROW({INTEGER(), mapType});
EXPECT_FALSE(rowType->isOrderable());
EXPECT_FALSE(rowType->isComparable());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tests here don't catch the bug I pointed out above. Maybe re-design the test so that isOrderable != isComparable?

Copy link
Collaborator Author

@duanmeng duanmeng Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedroerp Yes, the test case in line 883 is wrong (it was intended to test isOrderable != isComparable), I've updated it, thanks.

auto mapType = MAP(INTEGER(), REAL());
...
rowType = ROW({INTEGER(), mapType});
EXPECT_FALSE(rowType->isOrderable());
- EXPECT_FALSE(rowType->isComparable());
+ EXPECT_TRUE(rowType->isComparable());

@@ -455,6 +455,10 @@ class Type : public Tree<const TypePtr>, public velox::ISerializable {

virtual bool isPrimitiveType() const = 0;

virtual bool isOrderable() const = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here would be the right place for a comment explaining what exactly these two methods should return, semantically.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

velox/type/Type.cpp Outdated Show resolved Hide resolved
@duanmeng duanmeng force-pushed the typeFiled branch 3 times, most recently from 9894314 to 8b4af07 Compare September 28, 2023 04:56
@duanmeng
Copy link
Collaborator Author

@mbasmanova @pedroerp @bikramSingh91 I've resolved all the comments added comments for the two APIs, and updated the test cases to guard the difference between the two APIs. Could you please help to take a look? Thanks.

Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duanmeng Thank you for iterating. Looks great % one comment.

@@ -455,6 +455,16 @@ class Type : public Tree<const TypePtr>, public velox::ISerializable {

virtual bool isPrimitiveType() const = 0;

/// Return true if the type is scalar type or unknown type. Return false if
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a virtual method and therefore it cannot say what its implementations will return. Instead in need to explain what the return value means. How about,

Returns true if equality relationship is defined for the values of this type, i.e. a == b is defined and returns true, false or null.

For example, scalar types are usually comparable and complex types are comparable if their nested types are.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, updated.

/// if all its children types are comparable.
virtual bool isComparable() const = 0;

/// Return true if the type is scalar type or unknown type. Return false if
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Returns true if less than relationship is defined for the values of this type, i.e. a <= b returns true or false.

For example, scalar types are usually orderable, arrays and structs are orderable if their nested types are, while map types are not orderable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mbasmanova merged this pull request in b661e8c.

facebook-github-bot pushed a commit that referenced this pull request Oct 5, 2023
…n signature (#6906)

Summary:
In Presto, input to min/max is restricted to orderable types.
For example, MAP type is not orderable. Velox currently allows MAP inputs.

This PR adds two APIs in `FunctionSignatureBuilder`: `orderableTypeVariable`
and `comparableTypeVariable`. Use type's `orderable` and `comparable` flag
added in #6770 to do the check
during type binding in `SignatureBinder.tryBind`.

Part of #6718

Pull Request resolved: #6906

Reviewed By: xiaoxmeng

Differential Revision: D49951511

Pulled By: mbasmanova

fbshipit-source-id: 17ee5fd75b25a7df636279d07e99773105349220
ericyuliu pushed a commit to ericyuliu/velox that referenced this pull request Oct 12, 2023
Summary:
In Presto, input to min/max/array_sort is restricted to orderable types. For example, MAP type is not orderable. Velox currently allows MAP inputs.
This PR extends the Velox Type class to add `isOrderable()` and `isComparable()` methods.

Part of facebookincubator#6718 and facebookincubator#6712

Pull Request resolved: facebookincubator#6770

Reviewed By: Yuhta

Differential Revision: D49693596

Pulled By: mbasmanova

fbshipit-source-id: 1386904dde45691368e759831b4bf24287b0de5d
ericyuliu pushed a commit to ericyuliu/velox that referenced this pull request Oct 12, 2023
…n signature (facebookincubator#6906)

Summary:
In Presto, input to min/max is restricted to orderable types.
For example, MAP type is not orderable. Velox currently allows MAP inputs.

This PR adds two APIs in `FunctionSignatureBuilder`: `orderableTypeVariable`
and `comparableTypeVariable`. Use type's `orderable` and `comparable` flag
added in facebookincubator#6770 to do the check
during type binding in `SignatureBinder.tryBind`.

Part of facebookincubator#6718

Pull Request resolved: facebookincubator#6906

Reviewed By: xiaoxmeng

Differential Revision: D49951511

Pulled By: mbasmanova

fbshipit-source-id: 17ee5fd75b25a7df636279d07e99773105349220
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants