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

Fixes #45, strip sorts from weight check queries #46

Closed

Conversation

cdeszaq
Copy link
Collaborator

@cdeszaq cdeszaq commented Sep 22, 2016

Note: Based on other PRs. Once those merge, this PR will be repointed to master.

}

public LimitSpec withLimit(OptionalInt limit) {
return new LimitSpec(this.columns, limit);
Copy link
Contributor

@archolewa archolewa Sep 22, 2016

Choose a reason for hiding this comment

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

this is unnecessary in both withers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

((GroupByQuery) innerQuery).getLimitSpec()
((GroupByQuery) innerQuery).getLimitSpec() == null ?
null :
((GroupByQuery) innerQuery).getLimitSpec().withColumns(new LinkedHashSet<>())
Copy link
Contributor

Choose a reason for hiding this comment

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

Seeing as how we're doing this twice, and all the casting makes for a fairly complex statement, I would suggest extracting this into a helper method:

private LimitSpec extractLimitSpec(GroupByQuery query) {
   return query.getLimitSpec() == null ? null : query.getLimitSpec().withColumns(new LinkedHashSet());
} 

This will simplify the constructor call to:

   ...
   query.getQueryType() == QueryType.GROUP_BY ? extractLimitSpec((GroupByQuery) query) : null

and this code to:

...
extractLimitSpec((GroupByQuery) innerQuery)

It also means that we can have a positive condition, which is always nice.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could also have it take a Query instead, and do the type checking and casting inside the method. Either approach is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

GroupByQuery groupByQuery = builder.buildQuery(apiRequest, merger.merge(apiRequest))

expect: "The groupBy query has a sort, as a pre-condition"
!groupByQuery.limitSpec.columns.empty
Copy link
Contributor

Choose a reason for hiding this comment

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

Since columns is a collection, you can simplify this using groovy truthiness:

groupByQuery.limitSpec.columns

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done


and: "The weight-check query doesn't have a sort at either level"
new WeightEvaluationQuery(groupByQuery, 1).limitSpec.columns.empty
new WeightEvaluationQuery(groupByQuery, 1).innermostQuery.limitSpec.columns.empty
Copy link
Contributor

Choose a reason for hiding this comment

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

You can do something similar here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@will-lauer
Copy link
Contributor

👍

}

public LimitSpec withLimit(OptionalInt limit) {
return new LimitSpec(this.columns, limit);
Copy link
Contributor

Choose a reason for hiding this comment

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

It can underline which parameters are pulled from local instance.

@michael-mclawhorn
Copy link
Contributor

I'm warm to andrew's requests. Otherwise 👍 for me.

@cdeszaq cdeszaq force-pushed the fixSortingOnWeightCheckQueries branch from b2141c1 to ef3c0eb Compare September 23, 2016 21:38
@cdeszaq
Copy link
Collaborator Author

cdeszaq commented Sep 23, 2016

Merged

@cdeszaq cdeszaq closed this Sep 23, 2016
@cdeszaq cdeszaq deleted the fixSortingOnWeightCheckQueries branch September 27, 2016 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants