You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by hy...@apache.org on 2013/09/04 06:30:41 UTC

git commit: TAJO-141: Multiple union queries within a table subquery causes NPE. (hyunsik)

Updated Branches:
  refs/heads/master 3703a7c36 -> fb37ff33c


TAJO-141: Multiple union queries within a table subquery causes NPE. (hyunsik)


Project: http://git-wip-us.apache.org/repos/asf/incubator-tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tajo/commit/fb37ff33
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/fb37ff33
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/fb37ff33

Branch: refs/heads/master
Commit: fb37ff33cfaac9d46d2aaa62a9ad64abfc01ee2a
Parents: 3703a7c
Author: Hyunsik Choi <hy...@apache.org>
Authored: Wed Sep 4 11:11:01 2013 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Wed Sep 4 11:11:01 2013 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 ++
 .../tajo/algebra/ColumnReferenceExpr.java       |  6 +++
 .../org/apache/tajo/engine/parser/SQLParser.g4  |  7 ++-
 .../apache/tajo/engine/parser/SQLAnalyzer.java  | 55 ++++++++++++++++----
 .../tajo/engine/parser/TestSQLAnalyzer.java     |  6 +++
 .../src/test/queries/table_subquery1.sql        | 19 +++++++
 6 files changed, 85 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/fb37ff33/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 62c2a1f..3f87a23 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -124,6 +124,9 @@ Release 0.2.0 - unreleased
 
   BUG FIXES
 
+    TAJO-151: Multiple union queries within a table subquery causes NPE.
+    (hyunsik)
+
     TAJO-137: Unreleased resources and wrong allocation requests in
     TajoWorkerResourceManager. (hyoungjunkim via hyunsik)
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/fb37ff33/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java
index dfc2584..aa94275 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java
@@ -29,6 +29,12 @@ public class ColumnReferenceExpr extends Expr {
     this.name = columnName;
   }
 
+  public ColumnReferenceExpr(String tableName, String columnName) {
+    super(OpType.Column);
+    this.tableName = tableName;
+    this.name = columnName;
+  }
+
   public void setTableName(String tableName) {
     this.tableName = tableName;
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/fb37ff33/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4 b/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
index 765f3d6..5955da7 100644
--- a/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
+++ b/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
@@ -282,7 +282,12 @@ query_specification
 
 select_list
   : MULTIPLY
-  | derived_column (COMMA derived_column)*
+  | select_sublist (COMMA select_sublist)*
+  ;
+
+select_sublist
+  : derived_column
+  | asterisked_qualifier=Identifier DOT MULTIPLY
   ;
 
 set_qualifier

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/fb37ff33/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
index cc762f0..82b1295 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
@@ -184,29 +184,64 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> {
       }
     }
 
-    Projection projection = new Projection();
+    Projection projection = visitSelect_list(ctx.select_list());
 
     if (ctx.set_qualifier() != null && ctx.set_qualifier().DISTINCT() != null) {
       projection.setDistinct();
     }
 
-    if (ctx.select_list().MULTIPLY() != null) {
+    if (current != null) {
+      projection.setChild(current);
+    }
+
+    current = projection;
+
+    return current;
+  }
+
+  /**
+   * <pre>
+   *   select_list
+   *   : MULTIPLY
+   *   | select_sublist (COMMA select_sublist)*
+   *   ;
+   * </pre>
+   * @param ctx
+   * @return
+   */
+  @Override
+  public Projection visitSelect_list(SQLParser.Select_listContext ctx) {
+    Projection projection = new Projection();
+    if (ctx.MULTIPLY() != null) {
       projection.setAll();
     } else {
-      Target targets [] = new Target[ctx.select_list().derived_column().size()];
+      Target [] targets = new Target[ctx.select_sublist().size()];
       for (int i = 0; i < targets.length; i++) {
-        targets[i] = visitDerived_column(ctx.select_list().derived_column(i));
+        targets[i] = visitSelect_sublist(ctx.select_sublist(i));
       }
       projection.setTargets(targets);
     }
 
-    if (current != null) {
-      projection.setChild(current);
-    }
-
-    current = projection;
+    return projection;
+  }
 
-    return current;
+  /**
+   * <pre>
+   *   select_sublist
+   *   : derived_column
+   *   | asterisked_qualifier=Identifier DOT MULTIPLY
+   *   ;
+   * </pre>
+   * @param ctx
+   * @return
+   */
+  @Override
+  public Target visitSelect_sublist(SQLParser.Select_sublistContext ctx) {
+    if (ctx.asterisked_qualifier != null) {
+      return new Target(new ColumnReferenceExpr(ctx.asterisked_qualifier.getText(), "*"));
+    } else {
+      return visitDerived_column(ctx.derived_column());
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/fb37ff33/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java
index 549cd1e..5ba26f8 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java
@@ -245,6 +245,12 @@ public class TestSQLAnalyzer {
     parseQuery(sql);
   }
 
+  @Test
+  public void testTableSubQuery1() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/table_subquery1.sql"));
+    parseQuery(sql);
+  }
+
   static String[] exprs = {
       "1 + 2", // 0
       "3 - 4", // 1

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/fb37ff33/tajo-core/tajo-core-backend/src/test/queries/table_subquery1.sql
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/queries/table_subquery1.sql b/tajo-core/tajo-core-backend/src/test/queries/table_subquery1.sql
new file mode 100644
index 0000000..3181e43
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/test/queries/table_subquery1.sql
@@ -0,0 +1,19 @@
+SELECT unioninput.*
+FROM (
+  select
+    table1.key,
+    table1.value
+  FROM
+    table1
+  WHERE
+    table1.key < 100
+
+  UNION ALL
+
+  SELECT
+    table2.*
+  FROM
+    table2
+  WHERE
+    table2.key > 100
+) unioninput
\ No newline at end of file