Ensure Parameters are in proper order for queries having WITH clause#1529
Ensure Parameters are in proper order for queries having WITH clause#1529martint merged 2 commits intotrinodb:masterfrom
Conversation
0af4123 to
b18148a
Compare
There was a problem hiding this comment.
This will produce an ordering based on traversal order. We need to:
- Collect all the Parameter nodes
- Sort them based on their lexical order (
Parameter.getLocation())
b18148a to
6fc3b0a
Compare
martint
left a comment
There was a problem hiding this comment.
Instead of passing parameters and parameterPositionMap everywhere, why not compose them into a single mapping of parameter -> expression (i.e., Map<NodeRef<Parameter>, Expression>) in Analysis and pass that around?
There was a problem hiding this comment.
Instead of assembling these into a long, compare based on line first and then based on column number.
There was a problem hiding this comment.
There's already a class that does this: ParameterExtractor.
This could all be replaced with:
List<Parameter> parameters = getParameters(...).stream()
.sorted(Comparator.comparing(
parameter -> parameter.getLocation().get(),
Comparator.comparing(NodeLocation::getLineNumber)
.thenComparing(NodeLocation::getColumnNumber)))
.collect(Collectors.toList());There was a problem hiding this comment.
The type of this should be Map<NodeRef<Parameter>, Integer>
There was a problem hiding this comment.
Make this a Map<NodeRef<Parameter>, Integer> and rename the variable to parameterOrdinals
|
Can you add an end-to-end test that involves WITH to make sure parameters are being interpreted correctly? |
6fc3b0a to
d2b5a01
Compare
92f1af5 to
79f9e7d
Compare
79f9e7d to
8efe78c
Compare
99325d3 to
8efe78c
Compare
Cherry-pick of trinodb/trino#1529 Fixes prestodb#17012 Co-authored-by: praveenkrishna <praveenkrishna@tutanota.com>
Cherry-pick of trinodb/trino#1529 Fixes #17012 Co-authored-by: praveenkrishna <praveenkrishna@tutanota.com>
Fixes #1191