You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by xx...@apache.org on 2020/12/31 11:11:12 UTC

[kylin] branch master updated: KYLIN-4658 Fix union all issue with regarding to windows function & aggregation on

This is an automated email from the ASF dual-hosted git repository.

xxyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git


The following commit(s) were added to refs/heads/master by this push:
     new c962a23  KYLIN-4658 Fix union all issue with regarding to windows function & aggregation on
c962a23 is described below

commit c962a233672245c92db8ea29ee2f2540adbcc708
Author: Zhong, Yanghong <nj...@apache.org>
AuthorDate: Wed Dec 30 22:17:00 2020 +0800

    KYLIN-4658 Fix union all issue with regarding to windows function & aggregation on
---
 .../apache/kylin/query/relnode/OLAPWindowRel.java  | 33 ++++++++++++++--------
 .../relnode/visitor/TupleExpressionVisitor.java    |  9 +++++-
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPWindowRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPWindowRel.java
index 7c9721a..6fab922 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPWindowRel.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPWindowRel.java
@@ -96,18 +96,27 @@ public class OLAPWindowRel extends Window implements OLAPRel {
 
         // 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);
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/visitor/TupleExpressionVisitor.java b/query/src/main/java/org/apache/kylin/query/relnode/visitor/TupleExpressionVisitor.java
index 67793d5..587d710 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/visitor/TupleExpressionVisitor.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/visitor/TupleExpressionVisitor.java
@@ -164,7 +164,14 @@ public class TupleExpressionVisitor extends RexVisitorImpl<TupleExpression> {
         // 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 {