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

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

commit 03e9b63d166c402b1e5a2b55123bbcc84cb48ddc
Author: Surya Hebbar <[email protected]>
AuthorDate: Mon Jan 12 15:17:50 2026 +0530

    IMPALA-14563: Throw AnalysisException when aggregating complex type
    
    Before this change, when the user tries to aggregate by a complex type,
    we threw an IllegalStateException.
    
      SELECT complex_col, count(*) FROM table_example GROUP BY complex_col;
    
    Error:
    
      java.lang.IllegalStateException: null
    
    This does not provide appropriate context about the query's problem.
    
    Instead of throwing an IllegalStateException, we now throw the
    appropriate AnalysisException, which highlights the issue with the query.
    
      AnalysisException: GROUP BY expression cannot be used on complex types
                         without specifying a field
    
    This helps the user rewrite the query correctly by making them aware that
    specifying a field would fix the query.
    
      SELECT complex_col.val1, count(*) FROM table_example GROUP BY 
complex_col.val1;
    
    Testing:
      Added tests to TestsGroupBy() method in AnalyzeStmtsTest.java
    
    Change-Id: Ie431873efe7100e8150e93be2aa016381d687268
    Reviewed-on: http://gerrit.cloudera.org:8080/23855
    Tested-by: Impala Public Jenkins <[email protected]>
    Reviewed-by: Noemi Pap-Takacs <[email protected]>
---
 .../main/java/org/apache/impala/analysis/SelectStmt.java | 16 ++++++++++------
 .../org/apache/impala/analysis/AnalyzeStmtsTest.java     |  6 ++++++
 2 files changed, 16 insertions(+), 6 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 03c3f8e23..da7cef4a1 100644
--- a/fe/src/main/java/org/apache/impala/analysis/SelectStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/SelectStmt.java
@@ -1149,18 +1149,22 @@ public class SelectStmt extends QueryStmt {
       substituteOrdinalsAndAliases(groupingExprsCopy_, "GROUP BY", analyzer_);
 
       for (int i = 0; i < groupingExprsCopy_.size(); ++i) {
-        groupingExprsCopy_.get(i).analyze(analyzer_);
-        if (groupingExprsCopy_.get(i).contains(Expr.IS_AGGREGATE)) {
-          // reference the original expr in the error msg
+        Expr expr = groupingExprsCopy_.get(i);
+        expr.analyze(analyzer_);
+        if (expr.contains(Expr.IS_AGGREGATE)) {
           throw new AnalysisException(
               "GROUP BY expression must not contain aggregate functions: "
                   + groupingExprs_.get(i).toSql());
         }
-        if (groupingExprsCopy_.get(i).contains(AnalyticExpr.class)) {
-          // reference the original expr in the error msg
+        if (expr.contains(AnalyticExpr.class)) {
           throw new AnalysisException(
               "GROUP BY expression must not contain analytic expressions: "
-                  + groupingExprsCopy_.get(i).toSql());
+                  + expr.toSql());
+        }
+        if (expr.getType().isComplexType()) {
+          throw new AnalysisException(
+              "GROUP BY expression cannot be used on complex types without 
specifying a "
+              + "field: " + expr.toSql());
         }
       }
 
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 91e3cb2cd..961f90372 100644
--- a/fe/src/test/java/org/apache/impala/analysis/AnalyzeStmtsTest.java
+++ b/fe/src/test/java/org/apache/impala/analysis/AnalyzeStmtsTest.java
@@ -3001,6 +3001,12 @@ public class AnalyzeStmtsTest extends AnalyzerTest {
     AnalysisError("select zip, count(*) from functional.testtbl group by 2",
         "GROUP BY expression must not contain aggregate functions");
 
+    // can't group a complex type
+    AnalysisError("select int_struct_col, count(*) from "
+        + "functional_parquet.allcomplextypes" + " group by int_struct_col",
+        "GROUP BY expression cannot be used on complex types without 
specifying a field:"
+        + " int_struct_col");
+
     // multiple grouping cols
     AnalyzesOk("select int_col, string_col, bigint_col, count(*) " +
         "from functional.alltypes group by string_col, int_col, bigint_col");

Reply via email to