Repository: tajo Updated Branches: refs/heads/branch-0.11.1 70f6c1264 -> 20d850121
TAJO-1993: Table Timezone doesn't work when Timezone is not exactly same. Closes #888 Project: http://git-wip-us.apache.org/repos/asf/tajo/repo Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/20d85012 Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/20d85012 Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/20d85012 Branch: refs/heads/branch-0.11.1 Commit: 20d850121b2872290fcab633edd9dc0ad913a0aa Parents: 70f6c12 Author: charsyam <[email protected]> Authored: Sun Dec 6 01:56:06 2015 +0900 Committer: charsyam <[email protected]> Committed: Tue Dec 8 00:52:53 2015 +0900 ---------------------------------------------------------------------- CHANGES | 2 + .../org/apache/tajo/util/TestTimeZoneUtil.java | 46 ++++++++++++++ .../org/apache/tajo/parser/sql/SQLAnalyzer.java | 3 + .../java/org/apache/tajo/util/TimeZoneUtil.java | 63 ++++++++++++++++++++ 4 files changed, 114 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tajo/blob/20d85012/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 3c68bc5..a73eb69 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,8 @@ Release 0.11.1 - unreleased TAJO-2000: BSTIndex can cause OOM. (jinho) + TAJO-1993: Table Timezone doesn't work when Timezone is not exactly same.(DaeMyung) + TAJO-2010: Parquet can not read null value. (jinho) TAJO-2001: DirectRawFileScanner.getProgress occasionally fails. (jinho) http://git-wip-us.apache.org/repos/asf/tajo/blob/20d85012/tajo-core-tests/src/test/java/org/apache/tajo/util/TestTimeZoneUtil.java ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/util/TestTimeZoneUtil.java b/tajo-core-tests/src/test/java/org/apache/tajo/util/TestTimeZoneUtil.java new file mode 100644 index 0000000..ddee740 --- /dev/null +++ b/tajo-core-tests/src/test/java/org/apache/tajo/util/TestTimeZoneUtil.java @@ -0,0 +1,46 @@ +/** + * 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.apache.tajo.conf.TajoConf; +import org.apache.tajo.conf.TajoConf.ConfVars; +import org.apache.tajo.rpc.RpcConstants; +import org.junit.Test; + +import java.util.Properties; + +import static org.apache.tajo.rpc.RpcConstants.CLIENT_CONNECTION_TIMEOUT; +import static org.apache.tajo.rpc.RpcConstants.CLIENT_RETRY_NUM; +import static org.junit.Assert.*; + +public class TestTimeZoneUtil { + + @Test + public void testASIASeoul() throws Exception { + String timezone = TimeZoneUtil.getValidTimezone("ASIA/Seoul"); + assertEquals(timezone, "Asia/Seoul"); + } + + @Test + public void testGMT_PLUS_3() throws Exception { + String timezone = TimeZoneUtil.getValidTimezone("GMT+3"); + assertEquals(timezone, "GMT+3"); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tajo/blob/20d85012/tajo-core/src/main/java/org/apache/tajo/parser/sql/SQLAnalyzer.java ---------------------------------------------------------------------- diff --git a/tajo-core/src/main/java/org/apache/tajo/parser/sql/SQLAnalyzer.java b/tajo-core/src/main/java/org/apache/tajo/parser/sql/SQLAnalyzer.java index 12f1226..b8f2caf 100644 --- a/tajo-core/src/main/java/org/apache/tajo/parser/sql/SQLAnalyzer.java +++ b/tajo-core/src/main/java/org/apache/tajo/parser/sql/SQLAnalyzer.java @@ -40,6 +40,7 @@ import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.parser.sql.SQLParser.*; import org.apache.tajo.storage.StorageConstants; import org.apache.tajo.util.StringUtils; +import org.apache.tajo.util.TimeZoneUtil; import java.util.*; @@ -1703,6 +1704,8 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> { for (Map.Entry<String, String> entry : map.entrySet()) { if (entry.getKey().equals(StorageConstants.TEXT_DELIMITER)) { params.put(StorageConstants.TEXT_DELIMITER, StringUtils.unicodeEscapedDelimiter(entry.getValue())); + } else if (TimeZoneUtil.isTimezone(entry.getKey())) { + params.put(StorageConstants.TIMEZONE, TimeZoneUtil.getValidTimezone(entry.getValue())); } else { params.put(entry.getKey(), entry.getValue()); } http://git-wip-us.apache.org/repos/asf/tajo/blob/20d85012/tajo-core/src/main/java/org/apache/tajo/util/TimeZoneUtil.java ---------------------------------------------------------------------- diff --git a/tajo-core/src/main/java/org/apache/tajo/util/TimeZoneUtil.java b/tajo-core/src/main/java/org/apache/tajo/util/TimeZoneUtil.java new file mode 100644 index 0000000..2e6626c --- /dev/null +++ b/tajo-core/src/main/java/org/apache/tajo/util/TimeZoneUtil.java @@ -0,0 +1,63 @@ +/** + * 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 com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import org.apache.tajo.storage.StorageConstants; +import java.util.Map; + +public class TimeZoneUtil { + static ImmutableMap<String, String> timeZoneIdMap; + + static { + timeZoneIdMap = load(); + } + + private static ImmutableMap<String, String> load() { + ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder(); + String[] timezoneIds = java.util.TimeZone.getAvailableIDs(); + for (String timezoneId : timezoneIds) { + builder.put(timezoneId.toUpperCase(), timezoneId); + } + + return builder.build(); + } + + private static String find(String timezoneId) { + if (timezoneId == null) { + return null; + } + + return timeZoneIdMap.get(timezoneId.toUpperCase()); + } + + public static String getValidTimezone(String timeZoneId) { + String convertedTimezone = find(timeZoneId); + if (convertedTimezone != null) { + return convertedTimezone; + } + + return timeZoneId; + } + + public static boolean isTimezone(String key) { + return StorageConstants.TIMEZONE.equalsIgnoreCase(key); + } +}
