-
Notifications
You must be signed in to change notification settings - Fork 94
fix(isthmus): correct strpos parameter order #676
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: main
Are you sure you want to change the base?
Conversation
benbellick
left a comment
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.
Just two minor comments but otherwise LGTM! Thanks for doing that 🚀
| } | ||
|
|
||
| List<RexNode> operands = new ArrayList<>(call.getOperands()); | ||
| Collections.swap(operands, 0, 1); |
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.
Probably not a bad idea to put a comment here just because we have some naked numbers used to reference parameters.
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.
Is the class Javadoc not sufficient?
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.
It's probably fine, just my opinion if we wanted to make it extra clear. Feel free to ignore if you disagree.
| } | ||
|
|
||
| String query = String.format("SELECT STRPOS(%s, %s) > 0 FROM strings", left, right); | ||
| @Test |
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.
| @Test | |
| @Test | |
| // Verifies POSITION→strpos parameter swap (#662). | |
| // SQL POSITION(substring IN input) must become Substrait strpos(input, substring). |
Just so someone has a reference for the future :)
55dd3b9 to
7b8542b
Compare
|
@benbellick I changed the comments in both PositionFunctionMapper and StringFunctionTest to (hopefully) make things clearer, along the lines of your suggestions. |
Both SQL STRPOS and POSITION functions are modelled by Calcite as Position. Parameters are substring followed by the input to be searched. This maps to the Substrait strpos function, which has the parameters of input to be searched followed by substring. The default mapping retains the argument order, which results in SQL being translated to incorrect Substrait, and correct Substrait translated to incorrect SQL. Round-trip between Substrait and SQL still works since the parameter order is reversed in both directions, resulting in the correct order again. This change adds a custom function mapper to reverse the order of the first two parameters when converting between Calcite Position and Substrait strpos functions. Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
7b8542b to
d6cd9db
Compare
Both SQL STRPOS and POSITION functions are modelled by Calcite as Position. Parameters are substring followed by the input to be searched. This maps to the Substrait strpos function, which has the parameters of input to be searched followed by substring. The default mapping retains the argument order, which results in SQL being translated to incorrect Substrait, and correct Substrait translated to incorrect SQL. Round-trip between Substrait and SQL still works since the parameter order is reversed in both directions, resulting in the correct order again.
This change adds a custom function mapper to reverse the order of the first two parameters when converting between Calcite Position and Substrait strpos functions.
Closes #662