Skip to content

[CALCITE-2591] EnumerableDefaults#mergeJoin should throw error and not return incorrect results when inputs are not ordered#859

Closed
eolivelli wants to merge 5 commits intoapache:masterfrom
eolivelli:fix/CALCITE-2591-no-assert
Closed

[CALCITE-2591] EnumerableDefaults#mergeJoin should throw error and not return incorrect results when inputs are not ordered#859
eolivelli wants to merge 5 commits intoapache:masterfrom
eolivelli:fix/CALCITE-2591-no-assert

Conversation

@eolivelli
Copy link
Contributor

No description provided.

@eolivelli eolivelli changed the title CALCITE-2591 EnumerableDefaults#mergeJoin should throw error and not return incorrect results when inputs are not ordered [CALCITE-2591] EnumerableDefaults#mergeJoin should throw error and not return incorrect results when inputs are not ordered Sep 23, 2018
…t return incorrect results when inputs are not ordered
@eolivelli eolivelli force-pushed the fix/CALCITE-2591-no-assert branch from e5420ce to 14f8b5c Compare September 23, 2018 13:21
assert !generateNullsOnLeft : "not implemented";
assert !generateNullsOnRight : "not implemented";
if (generateNullsOnLeft) {
throw new UnsupportedOperationException("not implemented");
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use meaningful exception messages.

Do you really want to see UnsupportedOperationException("not implemented") in production logs? I bet you don't

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@eolivelli
Copy link
Contributor Author

@vlsi fixed the message, please take another look

int c = leftKey.compareTo(leftKey2);
if (c != 0) {
assert c < 0 : "not sorted";
if (c < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The condition should be c > 0.
Original assertion was c<0==true, and assertion is violated in c>0 case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, yes, sorry, trivial error !!!
So it should be "c >= 0" strictly speaking

Copy link
Contributor

@vlsi vlsi Sep 23, 2018

Choose a reason for hiding this comment

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

c==0 is acceptable (merge join allows to have duplicate values in the input)

assert c < 0 : "not sorted";
if (c < 0) {
throw new IllegalStateException(
"not sorted, " + leftKey + " is less than " + leftKey2);
Copy link
Contributor

Choose a reason for hiding this comment

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

The message should be updated to account c>0.
A bit more verbose message won't hurt.

For instance: "mergeJoin assumes sorted in ascending order input, however ... "

if (c > 0) {
throw new IllegalStateException(
"mergeJoin assumes sorted in ascending order input, "
+ "however " + leftKey + " is less than " + leftKey2);
Copy link
Contributor

Choose a reason for hiding this comment

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

leftKey + " is less than " + leftKey2 seems to be wrong.

c = leftKey.compareTo(leftKey2).
c > 0 ==> leftKey > leftKey2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, sure, I wrote the comment when the assertion was wrong :-)
sorry

@eolivelli
Copy link
Contributor Author

Thank you @vlsi for your quick review

I have applied your suggestions

@vlsi
Copy link
Contributor

vlsi commented Sep 23, 2018

LGTM.

Will commit if no-one objects in a day or two.

@eolivelli
Copy link
Contributor Author

Thank you very much.
If you have time please take a look to my real problem on the mailing list

@asfgit asfgit closed this in b9da74e Sep 24, 2018
F21 pushed a commit to F21/calcite that referenced this pull request Jan 3, 2019
…t return incorrect results when inputs are not ordered (Enrico Olivelli)

fixes apache#859
wangxlong pushed a commit to wangxlong/calcite that referenced this pull request Feb 13, 2020
…t return incorrect results when inputs are not ordered (Enrico Olivelli)

fixes apache#859
jamesstarr pushed a commit to jamesstarr/calcite that referenced this pull request Aug 28, 2025
…t return incorrect results when inputs are not ordered (Enrico Olivelli)

fixes apache#859

Change-Id: Iab1f286779b0fda255d84ff5111d327cb55cbdd8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants