Repository: tajo Updated Branches: refs/heads/window_function 1b3ec373c -> 39d4f2d7b
TAJO-763: Out of range problem in utc_usec_to(). (hyunsik) Project: http://git-wip-us.apache.org/repos/asf/tajo/repo Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/92e9a667 Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/92e9a667 Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/92e9a667 Branch: refs/heads/window_function Commit: 92e9a667379b99df1e9160ac207246ac65b0cfac Parents: f8ba4db Author: Hyunsik Choi <[email protected]> Authored: Sat Apr 19 13:40:02 2014 +0900 Committer: Hyunsik Choi <[email protected]> Committed: Sat Apr 19 13:40:02 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/92e9a667/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 1bc79c9..46f78c0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -334,6 +334,8 @@ Release 0.8.0 - unreleased BUG FIXES + TAJO-763: Out of range problem in utc_usec_to(). (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/92e9a667/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/92e9a667/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)); + } +}
