Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Refer alias of select fields in group by field #205

Merged
merged 1 commit into from
Oct 8, 2019

Conversation

Jianfei-Li
Copy link
Contributor

*Issue #186

Description of changes:
This could partially solve the problems mentioned in #186

It works if the expression in select fields and group by fields are the same.

To solve the issue completely, we probably need to use scripted metrics aggregation.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@@ -103,8 +103,9 @@ public AggregationBuilder makeGroupAgg(Field field) throws SqlParseException {
}
return makeRangeGroup(methodField);
} else {
TermsAggregationBuilder termsBuilder = AggregationBuilders.terms(field.getName()).field(field.getName());
groupMap.put(field.getName(), new KVValue("KEY", termsBuilder));
String termName = (null != field.getAlias()) ? field.getAlias() : field.getName();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest to cover the empty string case by using Strings.isNullOrEmpty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I'll change to use that.

break;
}
}
}
}

if (lastAgg == null) {
if (shadowField == null) {
for (Field selectField: select.getFields()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possilbe to combine this forloop with the forloop on L241. For me, the if null check of shadowFiled is a little bit complex.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure whether it was two loops at the beginning, I prefer keep it as is to avoid breaking any logic.

@dai-chen
Copy link
Member

dai-chen commented Oct 7, 2019

Just a heads up, we have major code changes of several feature/bug fixes merged today. Please pull from master branch and make sure your changes can pass .gradlew build. Thanks!

@Jianfei-Li
Copy link
Contributor Author

Just a heads up, we have major code changes of several feature/bug fixes merged today. Please pull from master branch and make sure your changes can pass .gradlew build. Thanks!

Thanks for the head up. I just rebased, it could build successfully and passed all the tests.

Copy link
Contributor

@penghuo penghuo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@dai-chen dai-chen merged commit d736e91 into opendistro-for-elasticsearch:master Oct 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants