-
Notifications
You must be signed in to change notification settings - Fork 25k
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
SQL: Fix ORDER BY YEAR() function #51562
Changes from 4 commits
34d31f3
94251c9
2aa1aee
1875e76
801ca3e
e50c2fd
88553db
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 |
---|---|---|
|
@@ -253,7 +253,7 @@ Collection<Failure> verify(LogicalPlan plan) { | |
} | ||
|
||
checkForScoreInsideFunctions(p, localFailures); | ||
checkNestedUsedInGroupByOrHaving(p, localFailures); | ||
checkNestedUsedInGroupByOrHavingOrOrderBy(p, localFailures, attributeRefs); | ||
checkForGeoFunctionsOnDocValues(p, localFailures); | ||
checkPivot(p, localFailures, attributeRefs); | ||
|
||
|
@@ -722,16 +722,19 @@ private static void checkForScoreInsideFunctions(LogicalPlan p, Set<Failure> loc | |
Function.class)); | ||
} | ||
|
||
private static void checkNestedUsedInGroupByOrHaving(LogicalPlan p, Set<Failure> localFailures) { | ||
private static void checkNestedUsedInGroupByOrHavingOrOrderBy(LogicalPlan p, Set<Failure> localFailures, | ||
AttributeMap<Expression> attributeRefs) { | ||
List<FieldAttribute> nested = new ArrayList<>(); | ||
Consumer<FieldAttribute> match = fa -> { | ||
Consumer<FieldAttribute> match = (fa) -> { | ||
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. why |
||
if (fa.isNested()) { | ||
nested.add(fa); | ||
} | ||
}; | ||
|
||
// nested fields shouldn't be used in aggregates or having (yet) | ||
p.forEachDown(a -> a.groupings().forEach(agg -> agg.forEachUp(match, FieldAttribute.class)), Aggregate.class); | ||
p.forEachDown(a -> a.groupings().forEach(agg -> agg.forEachUp(e -> | ||
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. Small nit - this type of call seems to be used 3 times (last time twice) - maybe could be extracted into a small method to avoid repetition. |
||
attributeRefs.getOrDefault(e, e).forEachUp(match, FieldAttribute.class) | ||
)), Aggregate.class); | ||
|
||
if (!nested.isEmpty()) { | ||
localFailures.add( | ||
|
@@ -740,15 +743,26 @@ private static void checkNestedUsedInGroupByOrHaving(LogicalPlan p, Set<Failure> | |
} | ||
|
||
// check in having | ||
p.forEachDown(f -> { | ||
if (f.child() instanceof Aggregate) { | ||
f.condition().forEachUp(match, FieldAttribute.class); | ||
} | ||
}, Filter.class); | ||
p.forEachDown(f -> f.forEachDown(a -> f.condition().forEachUp(e -> | ||
attributeRefs.getOrDefault(e, e).forEachUp(match, FieldAttribute.class)), | ||
Aggregate.class), Filter.class); | ||
|
||
if (!nested.isEmpty()) { | ||
localFailures.add( | ||
fail(nested.get(0), "HAVING isn't (yet) compatible with nested fields " + new AttributeSet(nested).names())); | ||
nested.clear(); | ||
} | ||
|
||
// check in order by (scalars not allowed) | ||
p.forEachDown(ob -> ob.order().forEach(o -> o.forEachUp(e -> | ||
attributeRefs.getOrDefault(e, e).forEachUp(f -> f.arguments().forEach( | ||
arg -> arg.forEachUp(match, FieldAttribute.class)), ScalarFunction.class) | ||
)), OrderBy.class); | ||
|
||
if (!nested.isEmpty()) { | ||
localFailures.add( | ||
fail(nested.get(0), "ORDER BY isn't (yet) compatible with scalar functions on nested fields " + | ||
new AttributeSet(nested).names())); | ||
} | ||
} | ||
|
||
|
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.
I think the method can be removed entirely - is it used anywhere else?