tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject git commit: TAJO-452: Timstamp literal with fractional seconds results in java.lang.ArrayIndexOutOfBoundsException. (Keuntae Park via hyunsik).
Date Fri, 27 Dec 2013 00:22:06 GMT
Updated Branches:
  refs/heads/master 7306ba324 -> 319a37725


TAJO-452: Timstamp literal with fractional seconds results in java.lang.ArrayIndexOutOfBoundsException.
(Keuntae Park via 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/319a3772
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/319a3772
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/319a3772

Branch: refs/heads/master
Commit: 319a37725feb5fe4fa04280da4fd11fd24406960
Parents: 7306ba3
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Fri Dec 27 09:21:13 2013 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Fri Dec 27 09:21:13 2013 +0900

----------------------------------------------------------------------
 CHANGES.txt                                                  | 5 ++++-
 .../src/main/java/org/apache/tajo/algebra/TimeValue.java     | 3 ++-
 .../src/main/java/org/apache/tajo/datum/TimestampDatum.java  | 8 +++++++-
 .../src/main/java/org/apache/tajo/json/DatumAdapter.java     | 5 +++--
 .../main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java | 2 +-
 .../org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java    | 8 ++++++++
 6 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/319a3772/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index e1c460e..858b185 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -172,7 +172,10 @@ Release 0.8.0 - unreleased
 
   BUG FIXES
 
-    TAJO-452: pass invalid argument to DateTime constructor in LogicalPlanner.
+    TAJO-452: Timstamp literal with fractional seconds results in 
+    java.lang.ArrayIndexOutOfBoundsException. (Keuntae Park via hyunsik)
+
+    TAJO-454: pass invalid argument to DateTime constructor in LogicalPlanner.
     (DaeMyung Kang via hyunsik)
 
     TAJO-451: Update documentation and version constant for Tajo 0.8.

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/319a3772/tajo-algebra/src/main/java/org/apache/tajo/algebra/TimeValue.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/TimeValue.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/TimeValue.java
index 916c3d2..b41b644 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/TimeValue.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/TimeValue.java
@@ -19,6 +19,7 @@
 package org.apache.tajo.algebra;
 
 import com.google.common.base.Objects;
+import org.apache.commons.lang.StringUtils;
 
 public class TimeValue {
   private String hours;
@@ -49,7 +50,7 @@ public class TimeValue {
   }
 
   public void setSecondsFraction(String secondsFraction) {
-    this.secondsFraction = secondsFraction;
+    this.secondsFraction = StringUtils.rightPad(secondsFraction, 3, '0');
   }
 
   public String getSecondsFraction() {

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/319a3772/tajo-common/src/main/java/org/apache/tajo/datum/TimestampDatum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/TimestampDatum.java b/tajo-common/src/main/java/org/apache/tajo/datum/TimestampDatum.java
index 4799964..ff3cc3b 100644
--- a/tajo-common/src/main/java/org/apache/tajo/datum/TimestampDatum.java
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/TimestampDatum.java
@@ -29,7 +29,9 @@ public class TimestampDatum extends Datum {
   public static final int SIZE = 8;
   /** ISO 8601/SQL standard format - ex) 1997-12-17 07:37:16-08 */
   public static final String DEFAULT_FORMAT_STRING = "yyyy-MM-dd HH:mm:ss";
+  public static final String FRACTION_FORMAT_STRING = "yyyy-MM-dd HH:mm:ss.SSS";
   private static final DateTimeFormatter DEFAULT_FORMATTER = DateTimeFormat.forPattern(DEFAULT_FORMAT_STRING);
+  private static final DateTimeFormatter FRACTION_FORMATTER = DateTimeFormat.forPattern(FRACTION_FORMAT_STRING);
   private DateTime dateTime;
 
   public TimestampDatum(int timestamp) {
@@ -106,7 +108,11 @@ public class TimestampDatum extends Datum {
 
   @Override
   public String asChars() {
-    return dateTime.toString(DEFAULT_FORMATTER);
+    if (getMillisOfSecond() > 0) {
+      return dateTime.toString(FRACTION_FORMATTER);
+    } else {
+      return dateTime.toString(DEFAULT_FORMATTER);
+    }
   }
 
   public String toChars(DateTimeFormatter format) {

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/319a3772/tajo-common/src/main/java/org/apache/tajo/json/DatumAdapter.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/json/DatumAdapter.java b/tajo-common/src/main/java/org/apache/tajo/json/DatumAdapter.java
index daece65..f24d213 100644
--- a/tajo-common/src/main/java/org/apache/tajo/json/DatumAdapter.java
+++ b/tajo-common/src/main/java/org/apache/tajo/json/DatumAdapter.java
@@ -21,6 +21,7 @@ package org.apache.tajo.json;
 import com.google.gson.*;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.datum.*;
+import org.joda.time.DateTime;
 
 import java.lang.reflect.Type;
 
@@ -38,7 +39,7 @@ public class DatumAdapter implements GsonSerDerAdapter<Datum> {
     case TIME:
       return new TimeDatum(jsonObject.get("value").getAsLong());
     case TIMESTAMP:
-      return new TimestampDatum(jsonObject.get("value").getAsString());
+      return new TimestampDatum(new DateTime(jsonObject.get("value").getAsLong()));
     default:
       return context.deserialize(jsonObject.get("body"),
           DatumFactory.getDatumClass(TajoDataTypes.Type.valueOf(typeName)));
@@ -57,7 +58,7 @@ public class DatumAdapter implements GsonSerDerAdapter<Datum> {
       jsonObj.addProperty("value", src.asInt8());
       break;
     case TIMESTAMP:
-      jsonObj.addProperty("value", src.asChars());
+      jsonObj.addProperty("value", ((TimestampDatum)src).getMillis());
       break;
     default:
       jsonObj.add("body", context.serialize(src));

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/319a3772/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 54a90da..a096e7d 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
@@ -1298,7 +1298,7 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> {
     TimeValue time;
     boolean hasFractionOfSeconds = parts[2].indexOf('.') > 0;
     if (hasFractionOfSeconds) {
-      String [] secondsParts = parts[2].split(".");
+      String [] secondsParts = parts[2].split("\\.");
       time = new TimeValue(parts[0], parts[1], secondsParts[0]);
       if (secondsParts.length == 2) {
         time.setSecondsFraction(secondsParts[1]);

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/319a3772/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 9eb4d1d..cc38dea 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
@@ -25,6 +25,14 @@ import java.io.IOException;
 public class TestSQLDateTimeTypes extends ExprTestBase {
 
   @Test
+  public void testTimestamp() throws IOException {
+    testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37';", new String[]{"1970-01-17 10:09:37"});
+    testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.5';", new String[]{"1970-01-17
10:09:37.500"});
+    testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.01';", new String[]{"1970-01-17
10:09:37.010"});
+    testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.003';", new String[]{"1970-01-17
10:09:37.003"});
+  }
+
+  @Test
   public void testToTimestamp() throws IOException {
     testSimpleEval("select to_char(TIMESTAMP '1970-01-17 10:09:37', 'yyyy-MM-dd HH:mm:ss');",
         new String[]{"1970-01-17 10:09:37"});


Mime
View raw message