[fix](grouping)fix grouping function bug (#11861)

This commit is contained in:
starocean999
2022-08-24 15:05:25 +08:00
committed by GitHub
parent f875684345
commit 8b4f693ad5
4 changed files with 142 additions and 19 deletions

View File

@ -29,9 +29,7 @@ import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Wraps all information of group by clause. support normal GROUP BY clause and extended GROUP BY clause like
@ -285,8 +283,12 @@ public class GroupByClause implements ParseNode {
Analyzer analyzer) {
groupingExprs = Expr.substituteList(groupingExprs, smap, analyzer, true);
for (VirtualSlotRef vs : groupingSlots) {
vs.setRealSlots(Optional.ofNullable(Expr.substituteList(vs.getRealSlots(), smap, analyzer, true)).orElse(
new ArrayList<>()).stream().map(e -> (SlotRef) e).collect(Collectors.toList()));
ArrayList<Expr> exprs = Expr.substituteList(vs.getRealSlots(), smap, analyzer, true);
if (exprs != null) {
vs.setRealSlots(exprs);
} else {
vs.setRealSlots(new ArrayList<Expr>());
}
}
}

View File

@ -17,7 +17,6 @@
package org.apache.doris.analysis;
import org.apache.doris.catalog.Table;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
@ -270,20 +269,6 @@ public class GroupingInfo {
public void substituteGroupingFn(Expr expr, Analyzer analyzer) throws AnalysisException {
if (expr instanceof GroupingFunctionCallExpr) {
// TODO(yangzhengguo) support expression in grouping functions
for (Expr child : expr.getChildren()) {
if (!(child instanceof SlotRef)) {
throw new AnalysisException("grouping functions only support column in current version.");
// expr from inline view
} else if (((SlotRef) child).getDesc().getParent().getTable().getType()
== Table.TableType.INLINE_VIEW) {
InlineViewRef ref = (InlineViewRef) ((SlotRef) child).getDesc().getParent().getRef();
int colIndex = ref.getColLabels().indexOf(((SlotRef) child).getColumnName());
if (colIndex != -1 && !(ref.getViewStmt().getResultExprs().get(colIndex) instanceof SlotRef)) {
throw new AnalysisException("grouping functions only support column in current version.");
}
}
}
// if is substituted skip
if (expr.getChildren().size() == 1 && expr.getChild(0) instanceof VirtualSlotRef) {
return;