Skip to content

Commit

Permalink
KYLIN-4658 Fix union all issue with regarding to windows function & a…
Browse files Browse the repository at this point in the history
…ggregation on
  • Loading branch information
kyotoYaho authored and zhangayqian committed Nov 5, 2021
1 parent 44e7008 commit 3f4c3d8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,27 @@ ColumnRowType buildColumnRowType() {

// add window aggregate calls column
for (Group group : groups) {
List<TupleExpression> sourceColOuter = Lists.newArrayList();
group.keys.asSet().stream().map(inputColumnRowType::getTupleExpressionByIndex).forEach(sourceColOuter::add);
group.orderKeys.getFieldCollations().stream().map(RelFieldCollation::getFieldIndex)
.map(inputColumnRowType::getTupleExpressionByIndex).forEach(sourceColOuter::add);
for (AggregateCall aggrCall : group.getAggregateCalls(this)) {
TblColRef aggrCallCol = TblColRef.newInnerColumn(aggrCall.getName(),
TblColRef.InnerDataTypeEnum.LITERAL);
List<TupleExpression> sourceColInner = Lists.newArrayList(sourceColOuter.iterator());
aggrCall.getArgList().stream().filter(i -> i < inputColumnRowType.size())
.map(inputColumnRowType::getTupleExpressionByIndex).forEach(sourceColInner::add);
aggrCallCol.setSubTupleExps(sourceColInner);
columns.add(aggrCallCol);
if (olapChild instanceof OLAPUnionRel) {
for (AggregateCall aggrCall : group.getAggregateCalls(this)) {
TblColRef aggrCallCol = TblColRef.newInnerColumn(aggrCall.getName(),
TblColRef.InnerDataTypeEnum.LITERAL);
columns.add(aggrCallCol);
}
} else {
List<TupleExpression> sourceColOuter = Lists.newArrayList();
group.keys.asSet().stream().map(inputColumnRowType::getTupleExpressionByIndex)
.forEach(sourceColOuter::add);
group.orderKeys.getFieldCollations().stream().map(RelFieldCollation::getFieldIndex)
.map(inputColumnRowType::getTupleExpressionByIndex).forEach(sourceColOuter::add);
for (AggregateCall aggrCall : group.getAggregateCalls(this)) {
TblColRef aggrCallCol = TblColRef.newInnerColumn(aggrCall.getName(),
TblColRef.InnerDataTypeEnum.LITERAL);
List<TupleExpression> sourceColInner = Lists.newArrayList(sourceColOuter.iterator());
aggrCall.getArgList().stream().filter(i -> i < inputColumnRowType.size())
.map(inputColumnRowType::getTupleExpressionByIndex).forEach(sourceColInner::add);
aggrCallCol.setSubTupleExps(sourceColInner);
columns.add(aggrCallCol);
}
}
}
return new ColumnRowType(columns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,14 @@ public TupleExpression visitInputRef(RexInputRef inputRef) {
// check it for rewrite count
if (index < inputRowType.size()) {
TblColRef column = inputRowType.getColumnByIndex(index);
TupleExpression tuple = new ColumnTupleExpression(column);
TupleExpression tuple;
if (column.getSubTupleExps() != null) {
DataType dataType = DataType
.getType(OLAPTable.DATATYPE_MAPPING.get(inputRef.getType().getSqlTypeName()));
tuple = new RexCallTupleExpression(dataType, column.getSubTupleExps());
} else {
tuple = new ColumnTupleExpression(column);
}
tuple.setDigest(inputRef.toString());
return tuple;
} else {
Expand Down

0 comments on commit 3f4c3d8

Please sign in to comment.