You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by bl...@apache.org on 2014/02/24 11:04:21 UTC

git commit: TAJO-403: HiveQLAnalyzer should supports standard function in the GROUP BY Clause. (Adding missed class)

Repository: incubator-tajo
Updated Branches:
  refs/heads/master 7a05b2158 -> dbe617cfc


TAJO-403: HiveQLAnalyzer should supports standard function in the GROUP BY Clause. (Adding missed class)


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

Branch: refs/heads/master
Commit: dbe617cfc73222db3a001021d8526b186e56c49f
Parents: 7a05b21
Author: blrunner <jh...@gruter.com>
Authored: Mon Feb 24 19:04:00 2014 +0900
Committer: blrunner <jh...@gruter.com>
Committed: Mon Feb 24 19:04:00 2014 +0900

----------------------------------------------------------------------
 .../tajo/engine/parser/TestHiveQLAnalyzer.java  | 240 +++++--------------
 1 file changed, 60 insertions(+), 180 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/dbe617cf/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestHiveQLAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestHiveQLAnalyzer.java b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestHiveQLAnalyzer.java
index 5d5ad4d..240f082 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestHiveQLAnalyzer.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestHiveQLAnalyzer.java
@@ -18,6 +18,7 @@
 
 package org.apache.tajo.engine.parser;
 
+import com.google.common.base.Preconditions;
 import org.antlr.v4.runtime.ANTLRInputStream;
 import org.antlr.v4.runtime.CommonTokenStream;
 import org.apache.commons.logging.Log;
@@ -34,6 +35,7 @@ import static org.junit.Assert.assertEquals;
 
 public class TestHiveQLAnalyzer {
   private static final Log LOG = LogFactory.getLog(TestHiveQLAnalyzer.class.getName());
+  protected static final String BASE_PATH = "src/test/resources/queries/default/";
 
   public static Expr parseQuery(String sql) {
     ANTLRInputStream input = new ANTLRInputStream(sql);
@@ -56,331 +58,209 @@ public class TestHiveQLAnalyzer {
     return ste[depth].getMethodName();
   }
 
-  public static void compareJsonResult(Expr expr, Expr hiveExpr) throws IOException {
-    if (expr != null && hiveExpr != null) {
-      if (!expr.toJson().equals(hiveExpr.toJson())) {
-        LOG.info("### Tajo Parse Result ### \n" + expr.toJson());
-        LOG.info("### Hive Parse Result ### \n" + hiveExpr.toJson());
-        throw new IOException(getMethodName(3));
-      }
-    } else {
-      LOG.info("### Tajo Parse Result ### \n" + expr.toJson());
-      LOG.info("### Hive Parse Result ### \n" + hiveExpr.toJson());
-      throw new IOException(getMethodName(3));
-    }
+  public static void compareJsonResult(String sqlPath) throws IOException {
+      Preconditions.checkNotNull(sqlPath);
+      compareJsonResult(sqlPath, sqlPath);
+  }
+
+  public static void compareJsonResult(String sqlPath, String hiveqlPath) throws IOException {
+    Preconditions.checkNotNull(sqlPath, hiveqlPath);
+    String sql = FileUtil.readTextFile(new File(BASE_PATH + sqlPath));
+    String hiveQL = FileUtil.readTextFile(new File(BASE_PATH + hiveqlPath));
+    Expr expr = parseQuery(sql);
+    Expr hiveExpr = parseHiveQL(hiveQL);
+    assertEquals(expr.toJson(), hiveExpr.toJson());
   }
 
   @Test
   public void testSelect1() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_1.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("select_1.sql");
   }
 
   @Test
   public void testSelect3() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_3.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("select_3.sql");
   }
 
   @Test
   public void testSelect4() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_4.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("select_4.sql");
   }
 
   @Test
   public void testSelect5() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_5.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("select_5.sql");
   }
 
   @Test
   public void testSelect7() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_7.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("select_7.sql");
   }
 
   @Test
   public void testSelect8() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_8.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("select_8.sql");
   }
 
   @Test
   public void testSelect9() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_9.sql"));
-    Expr expr = parseQuery(sql);
-    sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_9.hiveql"));
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("select_9.sql", "select_9.hiveql");
   }
 
   @Test
   public void testSelect10() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_10.sql"));
-    Expr expr = parseQuery(sql);
-    sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_10.hiveql"));
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("select_10.sql", "select_10.hiveql");
   }
 
+  //TODO: support beween condition
   //@Test
-  public void testSelect11() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_11.sql"));
-    Expr expr = parseQuery(sql);
-    sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_11.hiveql"));
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
-  }
+//  public void testSelect11() throws IOException {
+//    compareJsonResult("select_11.sql", "select_11.hiveql");
+//  }
 
   @Test
   public void testSelect12() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_12.hiveql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("select_12.hiveql");
   }
 
   @Test
   public void testSelect13() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_13.sql"));
-    Expr expr = parseQuery(sql);
-    sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_13.hiveql"));
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("select_13.sql", "select_13.hiveql");
   }
 
   @Test
   public void testSelect14() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/select_14.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("select_14.sql");
   }
 
   @Test
   public void testAsterisk1() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/asterisk_1.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("asterisk_1.sql");
   }
 
   @Test
   public void testAsterisk2() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/asterisk_2.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("asterisk_2.sql");
   }
 
   @Test
   public void testAsterisk3() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/asterisk_3.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("asterisk_3.sql");
   }
 
   @Test
   public void testAsterisk4() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/asterisk_4.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("asterisk_4.sql");
   }
 
   @Test
   public void testGroupby1() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/groupby_1.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("groupby_1.sql");
   }
 
   @Test
   public void testGroupby2() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/groupby_2.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("groupby_2.sql");
   }
 
   @Test
   public void testGroupby3() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/groupby_3.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("groupby_3.sql");
   }
 
   @Test
   public void testGroupby4() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/groupby_4.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("groupby_4.sql");
   }
 
   @Test
   public void testGroupby5() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/groupby_5.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("groupby_5.sql");
   }
+
   @Test
   public void testJoin2() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/join_2.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("join_2.sql");
   }
 
   @Test
   public void testJoin5() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/join_5.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("join_5.sql");
   }
 
   @Test
   public void testJoin6() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/join_6.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("join_6.sql");
   }
 
   @Test
   public void testJoin7() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/join_7.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("join_7.sql");
   }
 
-  //@Test
-  public void testJoin9() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/join_9.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    assertEquals(expr, hiveExpr);
-  }
+    //TODO: support complex join conditions
+    //@Test
+//  public void testJoin9() throws IOException {
+//    compareJsonResult("join_9.sql");
+//  }
 
   @Test
   public void testJoin12() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/join_12.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    assertEquals(expr, hiveExpr);
+    compareJsonResult("join_12.sql");
   }
 
   @Test
   public void testJoin13() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/join_13.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("join_13.sql");
   }
 
   @Test
   public void testJoin14() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/join_14.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("join_14.sql");
   }
 
   @Test
   public void testJoin15() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/join_15.sql"));
-    Expr expr = parseQuery(sql);
-    sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/join_15.hiveql"));
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("join_15.sql", "join_15.hiveql");
   }
 
   @Test
   public void testUnion1() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/union_1.hiveql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("union_1.hiveql");
   }
 
   @Test
   public void testInsert1() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/insert_into_select_1.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
-
+    compareJsonResult("insert_into_select_1.sql");
   }
 
   @Test
   public void testInsert2() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/insert_overwrite_into_select_2.sql"));
-    Expr expr = parseQuery(sql);
-    sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/insert_overwrite_into_select_2.hiveql"));
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("insert_overwrite_into_select_2.sql", "insert_overwrite_into_select_2.hiveql");
   }
 
   @Test
   public void testCreate1() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_1.sql"));
-    Expr expr = parseQuery(sql);
-    sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_1.hiveql"));
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("create_table_1.sql", "create_table_1.hiveql");
   }
 
   @Test
   public void testCreate2() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_2.sql"));
-    Expr expr = parseQuery(sql);
-    sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_2.hiveql"));
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("create_table_2.sql", "create_table_2.hiveql");
   }
 
   @Test
   public void testCreate11() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_11.sql"));
-    Expr expr = parseQuery(sql);
-    sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_11.hiveql"));
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("create_table_11.sql", "create_table_11.hiveql");
   }
 
   @Test
   public void testCreate12() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_12.sql"));
-    Expr expr = parseQuery(sql);
-    sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/create_table_12.hiveql"));
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("create_table_12.sql", "create_table_12.hiveql");
   }
 
   @Test
   public void testDrop() throws IOException {
-    String sql = FileUtil.readTextFile(new File("src/test/resources/queries/default/drop_table.sql"));
-    Expr expr = parseQuery(sql);
-    Expr hiveExpr = parseHiveQL(sql);
-    compareJsonResult(expr, hiveExpr);
+    compareJsonResult("drop_table.sql");
   }
 }