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

nic pushed a commit to branch 3.0.x
in repository https://gitbox.apache.org/repos/asf/kylin.git

commit a233418d45bc459e865ed89f69177ac27e183cf9
Author: yaqian.zhang <[email protected]>
AuthorDate: Mon Oct 21 11:36:09 2019 +0800

    KYLIN-4166 Case when return null when SQL no GROUP BY
---
 .../apache/kylin/query/relnode/OLAPProjectRel.java | 32 ++++++++++++----------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git 
a/query/src/main/java/org/apache/kylin/query/relnode/OLAPProjectRel.java 
b/query/src/main/java/org/apache/kylin/query/relnode/OLAPProjectRel.java
index 59d2c38..8be7249 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPProjectRel.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPProjectRel.java
@@ -306,21 +306,23 @@ public class OLAPProjectRel extends Project implements 
OLAPRel {
         }
 
         // replace projects with dynamic fields
-        Map<TblColRef, RelDataType> dynFields = this.context.dynamicFields;
-        for (TblColRef dynFieldCol : dynFields.keySet()) {
-            String replaceFieldName = dynFieldCol.getName();
-            int rowIndex = this.columnRowType.getIndexByName(replaceFieldName);
-            if (rowIndex >= 0) {
-                int inputIndex = 
inputColumnRowType.getIndexByName(replaceFieldName);
-                if (inputIndex >= 0) {
-                    // field to be replaced
-                    RelDataType fieldType = dynFields.get(dynFieldCol);
-                    RelDataTypeField newField = new 
RelDataTypeFieldImpl(replaceFieldName, rowIndex, fieldType);
-                    // project to be replaced
-                    RelDataTypeField inputField = 
getInput().getRowType().getFieldList().get(inputIndex);
-                    RexInputRef newFieldRef = new 
RexInputRef(inputField.getIndex(), inputField.getType());
-
-                    replaceFieldMap.put(rowIndex, new Pair<RelDataTypeField, 
RexNode>(newField, newFieldRef));
+        if (this.context.afterAggregate) {
+            Map<TblColRef, RelDataType> dynFields = this.context.dynamicFields;
+            for (TblColRef dynFieldCol : dynFields.keySet()) {
+                String replaceFieldName = dynFieldCol.getName();
+                int rowIndex = 
this.columnRowType.getIndexByName(replaceFieldName);
+                if (rowIndex >= 0) {
+                    int inputIndex = 
inputColumnRowType.getIndexByName(replaceFieldName);
+                    if (inputIndex >= 0) {
+                        // field to be replaced
+                        RelDataType fieldType = dynFields.get(dynFieldCol);
+                        RelDataTypeField newField = new 
RelDataTypeFieldImpl(replaceFieldName, rowIndex, fieldType);
+                        // project to be replaced
+                        RelDataTypeField inputField = 
getInput().getRowType().getFieldList().get(inputIndex);
+                        RexInputRef newFieldRef = new 
RexInputRef(inputField.getIndex(), inputField.getType());
+
+                        replaceFieldMap.put(rowIndex, new 
Pair<RelDataTypeField, RexNode>(newField, newFieldRef));
+                    }
                 }
             }
         }

Reply via email to