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

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 7771233  [BUG] GROUPING func and ORDER BY are used at the same time to 
report NullPointerException (#6266)
7771233 is described below

commit 7771233f3062eb47db321d977b6f3ea7f44227e7
Author: Xinyi Zou <[email protected]>
AuthorDate: Wed Jul 21 12:31:20 2021 +0800

    [BUG] GROUPING func and ORDER BY are used at the same time to report 
NullPointerException (#6266)
    
    fix #6265
    
    The reason for the error is that the `Grouping Func Exprs` is substituted 
twice. In the first substitution, `VirtualSlotRef` is used to replace the 
original `SlotRef`, and in the second substitution, `VirtualSlotRef` is 
reported in the `getTable()` Times Null pointer. IN
    ```
    } else if (((SlotRef) child).getDesc().getParent().getTable().getType()
    ```
    For the first substitution, the List of executable exprs in select clause 
has been substituted.
    ```
    groupingInfo = new GroupingInfo(analyzer, groupByClause.getGroupingType());
                groupingInfo.substituteGroupingFn(resultExprs, analyzer);
    ```
    In the second substitution, actually only need to substitute the unique 
expr in Ordering exprs.
    ```
    createSortInfo(analyzer);
            if (sortInfo != null && 
CollectionUtils.isNotEmpty(sortInfo.getOrderingExprs())) {
                if (groupingInfo != null) {
                    
groupingInfo.substituteGroupingFn(sortInfo.getOrderingExprs(), analyzer);
                }
            }
    ```
    change into:
    ```
    createSortInfo(analyzer);
            if (sortInfo != null && 
CollectionUtils.isNotEmpty(sortInfo.getOrderingExprs())) {
                if (groupingInfo != null) {
                    List<Expr> orderingExprNotInSelect = 
sortInfo.getOrderingExprs().stream()
                            .filter(item -> 
!resultExprs.contains(item)).collect(Collectors.toList());
                    groupingInfo.substituteGroupingFn(orderingExprNotInSelect, 
analyzer);
                }
            }
    ```
---
 .../src/main/java/org/apache/doris/analysis/SelectStmt.java       | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
index 6a60dde..9219489 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
@@ -61,6 +61,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 /**
  * Representation of a single select block, including GROUP BY, ORDER BY and 
HAVING
@@ -508,7 +509,12 @@ public class SelectStmt extends QueryStmt {
         createSortInfo(analyzer);
         if (sortInfo != null && 
CollectionUtils.isNotEmpty(sortInfo.getOrderingExprs())) {
             if (groupingInfo != null) {
-                groupingInfo.substituteGroupingFn(sortInfo.getOrderingExprs(), 
analyzer);
+                // List of executable exprs in select clause has been 
substituted, only the unique expr in Ordering
+                // exprs needs to be substituted.
+                // Otherwise, if substitute twice for `Grouping Func Expr`, a 
null pointer will be reported.
+                List<Expr> orderingExprNotInSelect = 
sortInfo.getOrderingExprs().stream()
+                        .filter(item -> 
!resultExprs.contains(item)).collect(Collectors.toList());
+                groupingInfo.substituteGroupingFn(orderingExprNotInSelect, 
analyzer);
             }
         }
         analyzeAggregation(analyzer);

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to