Skip to content
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

Fix exception during plan duplicate columns in order by clause #3018

Closed
wants to merge 4 commits into from

Conversation

yuananf
Copy link
Contributor

@yuananf yuananf commented Jun 3, 2015

fix #1621
@martint any suggestion?

@@ -629,8 +630,15 @@ private PlanBuilder sort(PlanBuilder subPlan, List<SortItem> orderBy, Optional<S

ImmutableList.Builder<Symbol> orderBySymbols = ImmutableList.builder();
ImmutableMap.Builder<Symbol, SortOrder> orderings = ImmutableMap.builder();
Set<Symbol> orderBySymbolSet = new HashSet<Symbol>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of keeping track of the symbols, I'd change the code to build a HashMap for orderings instead of Guava's ImmutableMap.builder.

One thing to be careful with is that if the sort order for a given column is different, the first one should win. For instance, in:

SELECT a, a FROM t ORDER BY a ASC, a DESC

DESC for the second occurrence is effectively a no-op.

I'd add a test for this while you're at it.

@yuananf
Copy link
Contributor Author

yuananf commented Jun 5, 2015

@martint comments addressed.

for (FieldOrExpression fieldOrExpression : orderByExpressions) {
Symbol symbol = subPlan.translate(fieldOrExpression);
orderBySymbols.add(symbol);
if (orderings.containsKey(symbol)) {
sortItems.next();
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of calling next() in the two branches (which makes the code a little more error prone), assign sortItems.next() to a variable before the if block and use it below.

Also, invert the if condition. I think the code will read more natural:

for (...) {
    ...
    if (!orderings.contains(...)) {
       ... add to map, etc
    }
}

@yuananf
Copy link
Contributor Author

yuananf commented Jun 8, 2015

@martint thanks, comments addressed.

@martint
Copy link
Contributor

martint commented Jun 8, 2015

Merged, thanks!

@martint martint closed this Jun 8, 2015
@martint martint added this to the 0.107 milestone Jun 8, 2015
@yuananf yuananf deleted the orderby-fix branch June 9, 2015 00:37
@martint martint modified the milestones: 0.108, 0.107 Jun 9, 2015
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.

Exception during planning with duplicate columns in order by clause
3 participants