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

lingmiao 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 7903e64  [Bug](partition pruning v2) Fix NPE when calling 
`Analyzer.getContext()` in partition pruning related logic. (#7542)
7903e64 is described below

commit 7903e6491ad17916530043e0f332a363433d750a
Author: Shuo Wang <wangshuo...@gmail.com>
AuthorDate: Thu Dec 30 17:03:14 2021 +0800

    [Bug](partition pruning v2) Fix NPE when calling `Analyzer.getContext()` in 
partition pruning related logic. (#7542)
    
    The partition pruning v2 use connection context in `OlapScanNode`.
    Before this PR, NPE would occur when running SQL without ConnectContext 
such as export, load.
    For example:
    ```
    EXPORT TABLE t TO "file:///home/data/export.txt"
    ```
---
 .../src/main/java/org/apache/doris/analysis/Analyzer.java     | 11 +++++++++++
 .../src/main/java/org/apache/doris/planner/OlapScanNode.java  |  4 ++--
 .../src/main/java/org/apache/doris/planner/ScanNode.java      |  2 +-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
index ba87c70..cd346eb 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
@@ -1757,6 +1757,8 @@ public class Analyzer {
         return schemaTable;
     }
 
+    // TODO: `globalState.context` could be null, refactor return value type to
+    // `Optional<ConnectContext>`.
     public ConnectContext getContext() {
         return globalState.context;
     }
@@ -1804,6 +1806,15 @@ public class Analyzer {
         return 
globalState.context.getSessionVariable().isEnableInferPredicate();
     }
 
+    // Use V2 version as default implementation.
+    public boolean partitionPruneV2Enabled() {
+        if (globalState.context == null) {
+            return true;
+        } else {
+            return 
globalState.context.getSessionVariable().getPartitionPruneAlgorithmVersion() == 
2;
+        }
+    }
+
     // The cost based join reorder is turned on
     // when 'enable_join_reorder_based_cost = true' and 'disable_join_reorder 
= false'
     // Load plan and query plan are the same framework
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
index 24c8bb6..9b36486 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
@@ -426,7 +426,7 @@ public class OlapScanNode extends ScanNode {
         }
 
         if (partitionInfo.getType() == PartitionType.RANGE) {
-            if 
(analyzer.getContext().getSessionVariable().getPartitionPruneAlgorithmVersion() 
== 2) {
+            if (analyzer.partitionPruneV2Enabled()) {
                 partitionPruner = new RangePartitionPrunerV2(keyItemMap,
                         partitionInfo.getPartitionColumns(), 
columnNameToRange);
             } else {
@@ -434,7 +434,7 @@ public class OlapScanNode extends ScanNode {
                         partitionInfo.getPartitionColumns(), columnFilters);
             }
         } else if (partitionInfo.getType() == PartitionType.LIST) {
-            if 
(analyzer.getContext().getSessionVariable().getPartitionPruneAlgorithmVersion() 
== 2) {
+            if (analyzer.partitionPruneV2Enabled()) {
                 partitionPruner = new ListPartitionPrunerV2(keyItemMap, 
partitionInfo.getPartitionColumns(),
                     columnNameToRange);
             } else {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java
index bf7d907..1deec6b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java
@@ -133,7 +133,7 @@ abstract public class ScanNode extends PlanNode {
                 columnFilters.put(column.getName(), keyFilter);
             }
 
-            if 
(analyzer.getContext().getSessionVariable().getPartitionPruneAlgorithmVersion() 
== 2) {
+            if (analyzer.partitionPruneV2Enabled()) {
                 ColumnRange columnRange = createColumnRange(slotDesc, 
conjuncts);
                 if (columnRange != null) {
                     columnNameToRange.put(column.getName(), columnRange);

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to