tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject git commit: TAJO-438: Date literal support. (Jae Young Lee via jihoon)
Date Wed, 08 Jan 2014 10:16:22 GMT
Updated Branches:
  refs/heads/master 285c4a485 -> 7d85f3ae9


TAJO-438: Date literal support. (Jae Young Lee via jihoon)


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

Branch: refs/heads/master
Commit: 7d85f3ae9b26a2f096f793b93a21f5606873a0b3
Parents: 285c4a4
Author: Jihoon Son <jihoonson@apache.org>
Authored: Wed Jan 8 19:15:54 2014 +0900
Committer: Jihoon Son <jihoonson@apache.org>
Committed: Wed Jan 8 19:15:54 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../org/apache/tajo/algebra/DateLiteral.java    | 51 ++++++++++++++++++++
 .../java/org/apache/tajo/algebra/OpType.java    |  1 +
 .../java/org/apache/tajo/datum/DateDatum.java   |  5 ++
 .../org/apache/tajo/datum/DatumFactory.java     |  4 +-
 .../org/apache/tajo/engine/parser/SQLParser.g4  |  5 ++
 .../apache/tajo/engine/parser/SQLAnalyzer.java  | 10 +++-
 .../tajo/engine/planner/AlgebraVisitor.java     |  2 +
 .../tajo/engine/planner/BaseAlgebraVisitor.java |  5 ++
 .../tajo/engine/planner/LogicalPlanner.java     | 13 +++++
 .../tajo/engine/eval/TestSQLDateTimeTypes.java  |  7 +++
 11 files changed, 103 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/7d85f3ae/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5016ef1..3c71e57 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@ Release 0.8.0 - unreleased
 
   NEW FEATURES
 
+    TAJO-438: Date literal support. (Jae Young Lee via jihoon)
+
     TAJO-474: Add query admin utility. (DaeMyung Kang via hyunsik)
 
     TAJO-460: CTAS statement should support partitioned table.

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/7d85f3ae/tajo-algebra/src/main/java/org/apache/tajo/algebra/DateLiteral.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/DateLiteral.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/DateLiteral.java
new file mode 100644
index 0000000..54b2b20
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/DateLiteral.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.algebra;
+
+import com.google.common.base.Objects;
+
+public class DateLiteral extends Expr {
+  private DateValue date;
+
+  public DateLiteral(DateValue date) {
+    super(OpType.DateLiteral);
+    this.date = date;
+  }
+
+  public DateValue getDate() {
+    return date;
+  }
+
+  public String toString() {
+    return date.toString();
+  }
+
+  public int hashCode() {
+    return Objects.hashCode(date);
+  }
+
+  @Override
+  boolean equalsTo(Expr expr) {
+    if (expr instanceof DateLiteral) {
+      DateLiteral another = (DateLiteral) expr;
+      return date.equals(another.date);
+    }
+    return false;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/7d85f3ae/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
index 3022ea1..ec6be1c 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
@@ -98,6 +98,7 @@ public enum OpType {
   Literal(LiteralValue.class),
   NullLiteral(NullLiteral.class),
   TimeLiteral(TimeLiteral.class),
+  DateLiteral(DateLiteral.class),
   TimestampLiteral(TimestampLiteral.class);
 
   private Class baseClass;

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/7d85f3ae/tajo-common/src/main/java/org/apache/tajo/datum/DateDatum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/DateDatum.java b/tajo-common/src/main/java/org/apache/tajo/datum/DateDatum.java
index 7029b97..a7f3072 100644
--- a/tajo-common/src/main/java/org/apache/tajo/datum/DateDatum.java
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/DateDatum.java
@@ -38,6 +38,11 @@ public class DateDatum extends Datum {
     date = decode(value);
   }
 
+  public DateDatum(int year, int month, int day) {
+    super(TajoDataTypes.Type.DATE);
+    date = new LocalDate(year, month, day);
+  }
+
   public DateDatum(String dateStr) {
     super(TajoDataTypes.Type.DATE);
     this.date = LocalDate.parse(dateStr, DEFAULT_FORMATTER);

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/7d85f3ae/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java b/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java
index 7520423..784c039 100644
--- a/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java
@@ -290,8 +290,10 @@ public class DatumFactory {
       return new DateDatum(datum.asInt4());
     case TEXT:
       return new DateDatum(datum.asChars());
+    case DATE:
+      return (DateDatum) datum;
     default:
-      throw new InvalidCastException(datum.type() + " cannot be casted to TIMESTAMP type");
+      throw new InvalidCastException(datum.type() + " cannot be casted to DATE type");
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/7d85f3ae/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 fbae175..4b5eea4 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
@@ -191,6 +191,7 @@ general_literal
 datetime_literal
   : timestamp_literal
   | time_literal
+  | date_literal
   ;
 
 time_literal
@@ -201,6 +202,10 @@ timestamp_literal
   : TIMESTAMP timestamp_string=Character_String_Literal
   ;
 
+date_literal
+  : DATE date_string=Character_String_Literal
+  ;
+
 boolean_literal
   : TRUE | FALSE | UNKNOWN
   ;

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/7d85f3ae/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 a096e7d..2555b9c 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
@@ -1265,7 +1265,9 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> {
   public Expr visitDatetime_literal(@NotNull SQLParser.Datetime_literalContext ctx) {
     if (checkIfExist(ctx.time_literal())) {
       return visitTime_literal(ctx.time_literal());
-    } else { 
+    } else if(checkIfExist(ctx.date_literal())) {
+      return visitDate_literal(ctx.date_literal());
+    } else {
       return visitTimestamp_literal(ctx.timestamp_literal());
     }
   }
@@ -1277,6 +1279,12 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> {
   }
 
   @Override
+  public Expr visitDate_literal(SQLParser.Date_literalContext ctx) {
+    String datePart = stripQuote(ctx.date_string.getText());
+    return new DateLiteral(parseDate(datePart));
+  }
+
+  @Override
   public Expr visitTimestamp_literal(SQLParser.Timestamp_literalContext ctx) {
     String timestampStr = stripQuote(ctx.timestamp_string.getText());
     String [] parts = timestampStr.split(" ");

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/7d85f3ae/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlgebraVisitor.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlgebraVisitor.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlgebraVisitor.java
index dcfc6fc..26a1ba4 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlgebraVisitor.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlgebraVisitor.java
@@ -100,5 +100,7 @@ public interface AlgebraVisitor<CONTEXT, RESULT> {
   RESULT visitNullLiteral(CONTEXT ctx, Stack<OpType> stack, NullLiteral expr) throws
PlanningException;
   RESULT visitTimestampLiteral(CONTEXT ctx, Stack<OpType> stack, TimestampLiteral expr)
throws PlanningException;
   RESULT visitTimeLiteral(CONTEXT ctx, Stack<OpType> stack, TimeLiteral expr) throws
PlanningException;
+  RESULT visitDateLiteral(CONTEXT ctx, Stack<OpType> stack, DateLiteral expr) throws
PlanningException;
+
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/7d85f3ae/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
index 8b13194..880a874 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
@@ -645,4 +645,9 @@ public class BaseAlgebraVisitor<CONTEXT, RESULT> implements AlgebraVisitor<CONTE
   public RESULT visitTimeLiteral(CONTEXT ctx, Stack<OpType> stack, TimeLiteral expr)
throws PlanningException {
     return null;
   }
+
+  @Override
+  public RESULT visitDateLiteral(CONTEXT ctx, Stack<OpType> stack, DateLiteral expr)
throws PlanningException {
+    return null;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/7d85f3ae/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
index 7349c0d..be24112 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
@@ -40,6 +40,7 @@ import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.datum.NullDatum;
 import org.apache.tajo.datum.TimestampDatum;
 import org.apache.tajo.datum.TimeDatum;
+import org.apache.tajo.datum.DateDatum;
 import org.apache.tajo.engine.eval.*;
 import org.apache.tajo.engine.exception.InvalidQueryException;
 import org.apache.tajo.engine.exception.UndefinedFunctionException;
@@ -1185,6 +1186,18 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
         return new ConstEval(datum);
       }
 
+      case DateLiteral: {
+        DateLiteral dateLiteral = (DateLiteral) expr;
+        DateValue dateValue = dateLiteral.getDate();
+        int [] dates = LogicalPlanner.dateToIntArray(dateValue.getYears(),
+            dateValue.getMonths(),
+            dateValue.getDays());
+
+        DateDatum datum;
+        datum = new DateDatum(dates[0], dates[1], dates[2]);
+        return new ConstEval(datum);
+      }
+
       case TimestampLiteral: {
         TimestampLiteral timestampLiteral = (TimestampLiteral) expr;
         DateValue dateValue = timestampLiteral.getDate();

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/7d85f3ae/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
index cc38dea..6567b52 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
@@ -43,4 +43,11 @@ public class TestSQLDateTimeTypes extends ExprTestBase {
     testSimpleEval("select TIME '10:09:37';",
         new String[]{"10:09:37"});
   }
+
+  @Test
+  public void testDateLiteral() throws IOException {
+    testSimpleEval("select DATE '1970-01-17';",
+        new String[]{"1970-01-17"});
+  }
+
 }


Mime
View raw message