Skip to content

Commit

Permalink
trying to resolve literals.
Browse files Browse the repository at this point in the history
  • Loading branch information
codebird committed May 10, 2019
1 parent d07d396 commit 4a4137f
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.elasticsearch.xpack.sql.capabilities.Resolvables;
import org.elasticsearch.xpack.sql.expression.Alias;
import org.elasticsearch.xpack.sql.expression.Attribute;
import org.elasticsearch.xpack.sql.expression.Literal;
import org.elasticsearch.xpack.sql.expression.AttributeMap;
import org.elasticsearch.xpack.sql.expression.AttributeSet;
import org.elasticsearch.xpack.sql.expression.Expression;
Expand Down Expand Up @@ -69,6 +70,7 @@
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
import static org.elasticsearch.xpack.sql.util.CollectionUtils.combine;

public class Analyzer extends RuleExecutor<LogicalPlan> {
Expand Down Expand Up @@ -332,6 +334,11 @@ else if (plan instanceof Aggregate) {
List<Expression> groupings = a.groupings();
List<Expression> newGroupings = new ArrayList<>();
AttributeMap<Expression> resolved = Expressions.asAttributeMap(a.aggregates());
if(a.aggregates().stream().filter(s -> (s instanceof Literal) == false
&& (s instanceof Function) == false).collect(toSet()).isEmpty()){
resolved = Expressions.asAttributeMap(plan.inputSet().stream().map(NamedExpression.class::cast)
.collect(toList()));
}
boolean changed = false;
for (Expression grouping : groupings) {
if (grouping instanceof UnresolvedAttribute) {
Expand All @@ -344,7 +351,6 @@ else if (plan instanceof Aggregate) {
}
newGroupings.add(grouping);
}

return changed ? new Aggregate(a.source(), a.child(), newGroupings, a.aggregates()) : a;
}
}
Expand Down

0 comments on commit 4a4137f

Please sign in to comment.