-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[FLINK-39677][table] Fix ARRAY_SORT comparator contract violation #28155
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,8 +109,14 @@ public ArraySortComparator(boolean isAscending) { | |
| @Override | ||
| public int compare(Object o1, Object o2) { | ||
| try { | ||
| boolean isGreater = (boolean) greaterHandle.invoke(o1, o2); | ||
| return isAscending ? (isGreater ? 1 : -1) : (isGreater ? -1 : 1); | ||
| // Two probes so equal elements return 0 (Comparator contract). | ||
| if ((boolean) greaterHandle.invoke(o1, o2)) { | ||
| return isAscending ? 1 : -1; | ||
| } | ||
| if ((boolean) greaterHandle.invoke(o2, o1)) { | ||
| return isAscending ? -1 : 1; | ||
| } | ||
|
Comment on lines
+113
to
+118
Contributor
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. instead of having 2 invocations we could have 2 evaluators
WDYT?
Contributor
Author
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. What would this get us? It seems like it would only add more MethodHandles in this class?
Contributor
Author
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. I mean, I could see adding a builtin COMPARE(a, b) → -1/0/+1 function in BuiltInFunctionDefinitions. Would that be better?
Contributor
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. we don't have such function right? From existing we could use
Contributor
Author
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. I thinking of an internal-only function like How would Are either of these ideas worth it? Or should we just go with the current approach?
Contributor
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. I think the An internal compare function/expression could be a good long-term direction for unifying ordering semantics, but it probably needs broader discussion.
Contributor
Author
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. I opened an alternative version of this change over here: #28159. Notably, there is already code generation for "compare" since it is needed for various operators. We just need an internal function to reference. |
||
| return 0; | ||
| } catch (Throwable e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
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 one:
maybe we can extract this into a variable and re-use it