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

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

commit adeb7fc0580d2e04235f2b58f0a4a97820a1c477
Author: Peter Rozsa <[email protected]>
AuthorDate: Mon Nov 21 08:33:22 2022 +0100

    IMPALA-11722: Wrong error message when unsupported complex type comes from 
* expression
    
    Adds the missing check for unsupported struct fields when SlotRef
    is created from an expanded path from star expression. For example:
    'select * from functional_orc_def.complextypestbl;' reports
    NullPointerException instead of reporting an AnalysisException: 'Struct
    containing a collection type is not allowed in the select list.'
    Now the struct condition checks are placed at every callsite.
    
    Analyze tests added for erroneous queries.
    
    Change-Id: I43ffe5d56740b36c93cf4401be871377d3168a4c
    Reviewed-on: http://gerrit.cloudera.org:8080/19261
    Reviewed-by: Impala Public Jenkins <[email protected]>
    Tested-by: Impala Public Jenkins <[email protected]>
---
 .../org/apache/impala/analysis/SelectStmt.java     |  3 ++
 .../java/org/apache/impala/analysis/SlotRef.java   | 44 ++++++++++++----------
 .../apache/impala/analysis/AnalyzeStmtsTest.java   |  6 +++
 3 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/fe/src/main/java/org/apache/impala/analysis/SelectStmt.java 
b/fe/src/main/java/org/apache/impala/analysis/SelectStmt.java
index 19db3caa0..b6a5ee2ab 100644
--- a/fe/src/main/java/org/apache/impala/analysis/SelectStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/SelectStmt.java
@@ -912,6 +912,9 @@ public class SelectStmt extends QueryStmt {
       SlotDescriptor slotDesc = analyzer_.registerSlotRef(
           starExpandedPathInfo.getExpandedPath(), false);
       SlotRef slotRef = new SlotRef(slotDesc);
+      if (slotRef.getType().isStructType()) {
+        slotRef.checkForUnsupportedStructFeatures();
+      }
       Preconditions.checkState(slotRef.isAnalyzed(),
           "Analysis should be done in constructor");
 
diff --git a/fe/src/main/java/org/apache/impala/analysis/SlotRef.java 
b/fe/src/main/java/org/apache/impala/analysis/SlotRef.java
index 7297fa8d9..e9fa5d5ed 100644
--- a/fe/src/main/java/org/apache/impala/analysis/SlotRef.java
+++ b/fe/src/main/java/org/apache/impala/analysis/SlotRef.java
@@ -25,7 +25,6 @@ import org.apache.impala.analysis.Path.PathType;
 import org.apache.impala.catalog.FeFsTable;
 import org.apache.impala.catalog.FeTable;
 import org.apache.impala.catalog.HdfsFileFormat;
-import org.apache.impala.catalog.StructField;
 import org.apache.impala.catalog.StructType;
 import org.apache.impala.catalog.TableLoadingException;
 import org.apache.impala.catalog.Type;
@@ -180,23 +179,10 @@ public class SlotRef extends Expr {
       // The NDV cannot exceed the #rows in the table.
       numDistinctValues_ = Math.min(numDistinctValues_, 
rootTable.getNumRows());
     }
-    if (type_.isStructType() && rootTable != null) {
-      if (!(rootTable instanceof FeFsTable)) {
-        throw new AnalysisException(String.format(
-            "%s is not supported when querying STRUCT type %s",
-            rootTable, type_.toSql()));
-      }
-      FeFsTable feTable = (FeFsTable)rootTable;
-      for (HdfsFileFormat format : feTable.getFileFormats()) {
-        if (format != HdfsFileFormat.ORC && format != HdfsFileFormat.PARQUET) {
-          throw new AnalysisException("Querying STRUCT is only supported for 
ORC and " +
-              "Parquet file formats.");
-        }
-      }
-    }
+
     if (type_.isStructType()) {
       addStructChildrenAsSlotRefs();
-      checkForUnsupportedStructFields();
+      checkForUnsupportedStructFeatures();
     }
   }
 
@@ -212,12 +198,13 @@ public class SlotRef extends Expr {
 
     analyzer.createStructTuplesAndSlotDescs(desc_);
     addStructChildrenAsSlotRefs();
-    checkForUnsupportedStructFields();
+    checkForUnsupportedStructFeatures();
   }
 
   // Throws an AnalysisException if any of the struct fields, recursively, of 
this SlotRef
-  // is a collection or unsupported type. Should only be used if this is a 
struct.
-  private void checkForUnsupportedStructFields() throws AnalysisException {
+  // is a collection or unsupported type or has any other unsupported feature.
+  // Should only be used if this is a struct.
+  public void checkForUnsupportedStructFeatures() throws AnalysisException {
     Preconditions.checkState(type_ instanceof StructType);
     for (Expr child : getChildren()) {
       final Type fieldType = child.getType();
@@ -236,7 +223,24 @@ public class SlotRef extends Expr {
 
       if (fieldType.isStructType()) {
         Preconditions.checkState(child instanceof SlotRef);
-        ((SlotRef) child).checkForUnsupportedStructFields();
+        ((SlotRef) child).checkForUnsupportedStructFeatures();
+      }
+    }
+    if (resolvedPath_ != null) {
+      FeTable rootTable = resolvedPath_.getRootTable();
+      if (rootTable != null) {
+        if (!(rootTable instanceof FeFsTable)) {
+          throw new AnalysisException(
+              String.format("%s is not supported when querying STRUCT type 
%s", rootTable,
+                  type_.toSql()));
+        }
+        FeFsTable feTable = (FeFsTable) rootTable;
+        for (HdfsFileFormat format : feTable.getFileFormats()) {
+          if (format != HdfsFileFormat.ORC && format != 
HdfsFileFormat.PARQUET) {
+            throw new AnalysisException("Querying STRUCT is only supported for 
ORC and "
+                + "Parquet file formats.");
+          }
+        }
       }
     }
   }
diff --git a/fe/src/test/java/org/apache/impala/analysis/AnalyzeStmtsTest.java 
b/fe/src/test/java/org/apache/impala/analysis/AnalyzeStmtsTest.java
index 833726784..7c83f5c19 100644
--- a/fe/src/test/java/org/apache/impala/analysis/AnalyzeStmtsTest.java
+++ b/fe/src/test/java/org/apache/impala/analysis/AnalyzeStmtsTest.java
@@ -1098,6 +1098,12 @@ public class AnalyzeStmtsTest extends AnalyzerTest {
 
     AnalysisError("select * from functional.allcomplextypes",
             ctx,"STRUCT type inside collection types is not supported.");
+
+    AnalysisError("select * from functional_orc_def.complextypestbl", ctx,
+        "Struct containing a collection type is not allowed in the select 
list.");
+
+    AnalysisError("select * from functional_parquet.binary_in_complex_types", 
ctx,
+        "Binary type inside collection types is not supported 
(IMPALA-11491).");
   }
 
   @Test

Reply via email to