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 2014/04/19 06:47:02 UTC

git commit: TAJO-763: Out of range problem in utc_usec_to(). (Ilhyun Suh via hyunsik)

Repository: tajo
Updated Branches:
  refs/heads/branch-0.8.0 026368be0 -> cce655ab5


TAJO-763: Out of range problem in utc_usec_to(). (Ilhyun Suh via hyunsik)


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

Branch: refs/heads/branch-0.8.0
Commit: cce655ab5c6c12a90068e530288bb4ef1a4268b6
Parents: 026368b
Author: Hyunsik Choi <hy...@apache.org>
Authored: Sat Apr 19 13:40:02 2014 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Sat Apr 19 13:44:54 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../org/apache/tajo/util/TimeStampUtil.java     | 11 +--
 .../org/apache/tajo/util/TestTimeStampUtil.java | 75 ++++++++++++++++++++
 3 files changed, 84 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/cce655ab/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 4afe79b..488234c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -325,6 +325,8 @@ Release 0.8.0 - unreleased
 
   BUG FIXES
 
+    TAJO-763: Out of range problem in utc_usec_to(). (Ilhyun Suh via hyunsik)
+
     TAJO-741: GreedyHeuristicJoinOrderAlgorithm removes some join pairs. (jaehwa)
 
     TAJO-772: TajoDump cannot dump upper/lower mixed case database names.

http://git-wip-us.apache.org/repos/asf/tajo/blob/cce655ab/tajo-common/src/main/java/org/apache/tajo/util/TimeStampUtil.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/util/TimeStampUtil.java b/tajo-common/src/main/java/org/apache/tajo/util/TimeStampUtil.java
index 31c5b90..830c4aa 100644
--- a/tajo-common/src/main/java/org/apache/tajo/util/TimeStampUtil.java
+++ b/tajo-common/src/main/java/org/apache/tajo/util/TimeStampUtil.java
@@ -30,19 +30,22 @@ public class TimeStampUtil {
     }
 
     public static long getHour(DateTime dateTime) {
-        return convertToMicroSeconds(dateTime.withTime(dateTime.get(DateTimeFieldType.clockhourOfDay()), 0, 0, 0));
+        return convertToMicroSeconds(dateTime.withTime(dateTime.get(DateTimeFieldType.hourOfDay()), 0, 0, 0));
     }
 
     public static long getMinute(DateTime dateTime) {
-        return convertToMicroSeconds(dateTime.withTime(dateTime.get(DateTimeFieldType.clockhourOfDay()), dateTime.get(DateTimeFieldType.minuteOfHour()), 0, 0));
+        return convertToMicroSeconds(dateTime.withTime(dateTime.get(DateTimeFieldType.hourOfDay()),
+            dateTime.get(DateTimeFieldType.minuteOfHour()), 0, 0));
     }
 
     public static long getSecond(DateTime dateTime) {
-        return convertToMicroSeconds(dateTime.withTime(dateTime.get(DateTimeFieldType.clockhourOfDay()), dateTime.get(DateTimeFieldType.minuteOfHour()), dateTime.get(DateTimeFieldType.secondOfMinute()), 0));
+        return convertToMicroSeconds(dateTime.withTime(dateTime.get(DateTimeFieldType.hourOfDay()),
+            dateTime.get(DateTimeFieldType.minuteOfHour()), dateTime.get(DateTimeFieldType.secondOfMinute()), 0));
     }
 
     public static long getMonth(DateTime dateTime) {
-        return convertToMicroSeconds(dateTime.withTimeAtStartOfDay().withDate(dateTime.getYear(),dateTime.getMonthOfYear(),1));
+        return convertToMicroSeconds(dateTime.withTimeAtStartOfDay().withDate(dateTime.getYear(),
+            dateTime.getMonthOfYear(),1));
     }
 
     public static long getDayOfWeek(DateTime dateTime,int week) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/cce655ab/tajo-common/src/test/java/org/apache/tajo/util/TestTimeStampUtil.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/test/java/org/apache/tajo/util/TestTimeStampUtil.java b/tajo-common/src/test/java/org/apache/tajo/util/TestTimeStampUtil.java
new file mode 100644
index 0000000..353063d
--- /dev/null
+++ b/tajo-common/src/test/java/org/apache/tajo/util/TestTimeStampUtil.java
@@ -0,0 +1,75 @@
+/**
+ * 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.util;
+
+import org.joda.time.DateTimeZone;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.DateTime;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestTimeStampUtil {
+  private static final int TEST_YEAR = 2014;
+  private static final int TEST_MONTH_OF_YEAR = 4;
+  private static final int TEST_DAY_OF_MONTH = 18;
+  private static final int TEST_HOUR_OF_DAY = 0;
+  private static final int TEST_MINUTE_OF_HOUR = 15;
+  private static final int TEST_SECOND_OF_MINUTE = 25;
+  private static final DateTime TEST_DATETIME = new DateTime(TEST_YEAR, TEST_MONTH_OF_YEAR, TEST_DAY_OF_MONTH,
+      TEST_HOUR_OF_DAY, TEST_MINUTE_OF_HOUR, TEST_SECOND_OF_MINUTE, DateTimeZone.UTC);
+  private static final DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
+
+  @Test
+  public void testGetYear() {
+    assertEquals(DateTime.parse("2014-01-01 00:00:00", fmt.withZoneUTC()).getMillis() * 1000,
+        TimeStampUtil.getYear(TEST_DATETIME));
+  }
+
+  @Test
+  public void testGetMonth() {
+    assertEquals(DateTime.parse("2014-04-01 00:00:00", fmt.withZoneUTC()).getMillis() * 1000,
+        TimeStampUtil.getMonth(TEST_DATETIME));
+  }
+
+  @Test
+  public void testGetDay() {
+    assertEquals(DateTime.parse("2014-04-18 00:00:00", fmt.withZoneUTC()).getMillis() * 1000,
+        TimeStampUtil.getDay(TEST_DATETIME));
+  }
+
+  @Test
+  public void testGetHour() {
+    assertEquals(DateTime.parse("2014-04-18 00:00:00",fmt.withZoneUTC()).getMillis() * 1000,
+        TimeStampUtil.getHour(TEST_DATETIME));
+  }
+
+  @Test
+  public void testGetMinute() {
+    assertEquals(DateTime.parse("2014-04-18 00:15:00",fmt.withZoneUTC()).getMillis() * 1000,
+        TimeStampUtil.getMinute(TEST_DATETIME));
+  }
+
+  @Test
+  public void testGetSecond() {
+    assertEquals(DateTime.parse("2014-04-18 00:15:25",fmt.withZoneUTC()).getMillis() * 1000,
+        TimeStampUtil.getSecond(TEST_DATETIME));
+  }
+}