tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blrun...@apache.org
Subject git commit: TAJO-218: HiveQLAnalyzer has to support cast expression. (jaehwa)
Date Tue, 25 Feb 2014 03:12:29 GMT
Repository: incubator-tajo
Updated Branches:
  refs/heads/branch-0.8.0 5eafede2f -> a33b83665


TAJO-218: HiveQLAnalyzer has to support cast expression. (jaehwa)


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

Branch: refs/heads/branch-0.8.0
Commit: a33b836659fe1236db8d9ea3883b3bddefe131a1
Parents: 5eafede
Author: blrunner <jhjung@gruter.com>
Authored: Tue Feb 25 12:11:42 2014 +0900
Committer: blrunner <jhjung@gruter.com>
Committed: Tue Feb 25 12:11:42 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../tajo/engine/parser/HiveQLAnalyzer.java      | 66 +++++++++++---------
 .../tajo/engine/parser/TestHiveQLAnalyzer.java  |  5 ++
 .../resources/queries/default/select_15.hiveql  |  1 +
 .../resources/queries/default/select_15.sql     |  1 +
 5 files changed, 47 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/a33b8366/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 31d8942..6d08c67 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -475,6 +475,8 @@ Release 0.8.0 - unreleased
 
   TASKS
 
+    TAJO-218: HiveQLAnalyzer has to support cast expression. (jaehwa)
+
     TAJO-621: Add DOAP file for Tajo. (hyunsik)
 
     TAJO-622: Add TM mark and navigation links required for TLP project.

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/a33b8366/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/HiveQLAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/HiveQLAnalyzer.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/HiveQLAnalyzer.java
index dd8c405..6d95fe1 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/HiveQLAnalyzer.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/HiveQLAnalyzer.java
@@ -1188,7 +1188,10 @@ public class HiveQLAnalyzer extends HiveQLParserBaseVisitor<Expr>
{
    */
   @Override
   public Expr visitCastExpression(HiveQLParser.CastExpressionContext ctx) {
-    return visitExpression(ctx.expression());
+    DataTypeExpr castTarget = getDataTypeExpr(ctx.primitiveType());
+    Expr expr = visitExpression(ctx.expression());
+    Expr current = new CastExpr(expr, castTarget);
+    return current;
   }
 
   @Override
@@ -1455,33 +1458,7 @@ public class HiveQLAnalyzer extends HiveQLParserBaseVisitor<Expr>
{
           if (eachColumn.colType().type() != null) {
             if (eachColumn.colType().type().primitiveType() != null) {
               HiveQLParser.PrimitiveTypeContext primitiveType = eachColumn.colType().type().primitiveType();
-
-              if (primitiveType.KW_STRING() != null) {
-                type = TajoDataTypes.Type.TEXT.name();
-              } else if (primitiveType.KW_TINYINT() != null) {
-                type = TajoDataTypes.Type.INT1.name();
-              } else if (primitiveType.KW_SMALLINT() != null) {
-                type = TajoDataTypes.Type.INT2.name();
-              } else if (primitiveType.KW_INT() != null) {
-                type = TajoDataTypes.Type.INT4.name();
-              } else if (primitiveType.KW_BIGINT() != null) {
-                type = TajoDataTypes.Type.INT8.name();
-              } else if (primitiveType.KW_FLOAT() != null) {
-                type = TajoDataTypes.Type.FLOAT4.name();
-              } else if (primitiveType.KW_DOUBLE() != null) {
-                type = TajoDataTypes.Type.FLOAT8.name();
-              } else if (primitiveType.KW_DECIMAL() != null) {
-                type = TajoDataTypes.Type.DECIMAL.name();
-              } else if (primitiveType.KW_BOOLEAN() != null) {
-                type = TajoDataTypes.Type.BOOLEAN.name();
-              } else if (primitiveType.KW_DATE() != null) {
-                type = TajoDataTypes.Type.DATE.name();
-              } else if (primitiveType.KW_DATETIME() != null) {
-                //TODO
-              } else if (primitiveType.KW_TIMESTAMP() != null) {
-                type = TajoDataTypes.Type.TIMESTAMP.name();
-              }
-
+              type = getDataTypeExpr(primitiveType).getTypeName();
               columns[i] = new CreateTable.ColumnDefinition(eachColumn.colName.Identifier().getText(),
type);
             }
           }
@@ -1499,6 +1476,39 @@ public class HiveQLAnalyzer extends HiveQLParserBaseVisitor<Expr>
{
     return createTable;
   }
 
+
+  private DataTypeExpr getDataTypeExpr(HiveQLParser.PrimitiveTypeContext primitiveType) {
+    DataTypeExpr typeDefinition = null;
+
+    if (primitiveType.KW_STRING() != null) {
+      typeDefinition = new DataTypeExpr(TajoDataTypes.Type.TEXT.name());
+    } else if (primitiveType.KW_TINYINT() != null) {
+      typeDefinition = new DataTypeExpr(TajoDataTypes.Type.INT1.name());
+    } else if (primitiveType.KW_SMALLINT() != null) {
+      typeDefinition = new DataTypeExpr(TajoDataTypes.Type.INT2.name());
+    } else if (primitiveType.KW_INT() != null) {
+      typeDefinition = new DataTypeExpr(TajoDataTypes.Type.INT4.name());
+    } else if (primitiveType.KW_BIGINT() != null) {
+      typeDefinition = new DataTypeExpr(TajoDataTypes.Type.INT8.name());
+    } else if (primitiveType.KW_FLOAT() != null) {
+      typeDefinition = new DataTypeExpr(TajoDataTypes.Type.FLOAT4.name());
+    } else if (primitiveType.KW_DOUBLE() != null) {
+      typeDefinition = new DataTypeExpr(TajoDataTypes.Type.FLOAT8.name());
+    } else if (primitiveType.KW_DECIMAL() != null) {
+      typeDefinition = new DataTypeExpr(TajoDataTypes.Type.DECIMAL.name());
+    } else if (primitiveType.KW_BOOLEAN() != null) {
+      typeDefinition = new DataTypeExpr(TajoDataTypes.Type.BOOLEAN.name());
+    } else if (primitiveType.KW_DATE() != null) {
+    } else if (primitiveType.KW_DATETIME() != null) {
+      //TODO
+    } else if (primitiveType.KW_TIMESTAMP() != null) {
+      typeDefinition = new DataTypeExpr(TajoDataTypes.Type.TIMESTAMP.name());
+    }
+
+    return typeDefinition;
+  }
+
+
   @Override
   public Expr visitDropTableStatement(HiveQLParser.DropTableStatementContext ctx) {
     DropTable dropTable = new DropTable(ctx.tableName().getText(), false);

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/a33b8366/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 240f082..ef21dc3 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
@@ -134,6 +134,11 @@ public class TestHiveQLAnalyzer {
   }
 
   @Test
+  public void testSelect15() throws IOException {
+    compareJsonResult("select_15.sql", "select_15.hiveql");
+  }
+
+  @Test
   public void testAsterisk1() throws IOException {
     compareJsonResult("asterisk_1.sql");
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/a33b8366/tajo-core/tajo-core-backend/src/test/resources/queries/default/select_15.hiveql
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/resources/queries/default/select_15.hiveql
b/tajo-core/tajo-core-backend/src/test/resources/queries/default/select_15.hiveql
new file mode 100644
index 0000000..37c1c83
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/test/resources/queries/default/select_15.hiveql
@@ -0,0 +1 @@
+select id,  cast(point as string) as point, cast(score as int) as score from table1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/a33b8366/tajo-core/tajo-core-backend/src/test/resources/queries/default/select_15.sql
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/resources/queries/default/select_15.sql
b/tajo-core/tajo-core-backend/src/test/resources/queries/default/select_15.sql
new file mode 100644
index 0000000..7c942b1
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/test/resources/queries/default/select_15.sql
@@ -0,0 +1 @@
+select id,  point::text as point, score::INT4 as score from table1
\ No newline at end of file


Mime
View raw message