From 1fac21a2e453a46d25869744df14d38f1be4eb0e Mon Sep 17 00:00:00 2001 From: charsyam Date: Sat, 28 Nov 2015 13:33:07 +0900 Subject: [PATCH 1/3] converted case sensative timezone --- .../apache/tajo/util/TestTimeZoneUtil.java | 46 +++++++++++++ .../apache/tajo/parser/sql/SQLAnalyzer.java | 3 + .../org/apache/tajo/util/TimeZoneUtil.java | 64 +++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 tajo-core-tests/src/test/java/org/apache/tajo/util/TestTimeZoneUtil.java create mode 100644 tajo-core/src/main/java/org/apache/tajo/util/TimeZoneUtil.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 0000000000..ddee740d4a --- /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 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 3344e2db03..c33fc097d4 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 @@ -39,6 +39,7 @@ import org.apache.tajo.exception.TajoRuntimeException; import org.apache.tajo.storage.StorageConstants; import org.apache.tajo.util.StringUtils; +import org.apache.tajo.util.TimeZoneUtil; import java.util.*; import java.util.stream.Collectors; @@ -1712,6 +1713,8 @@ public Map escapeTableMeta(Map map) { for (Map.Entry 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()); } 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 0000000000..3736e01407 --- /dev/null +++ b/tajo-core/src/main/java/org/apache/tajo/util/TimeZoneUtil.java @@ -0,0 +1,64 @@ +/** + * 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.facebook.presto.hive.shaded.com.google.common.collect.Maps; +import org.apache.tajo.SessionVars; +import org.apache.tajo.storage.StorageConstants; + +import java.util.Map; + +public class TimeZoneUtil { + static Map timeZoneIdMap; + + static { + timeZoneIdMap = load(); + } + + private static Map load() { + Map timeZoneMap = Maps.newHashMap(); + String[] timezoneIds = java.util.TimeZone.getAvailableIDs(); + for (String timezoneId : timezoneIds) { + timeZoneMap.put(timezoneId.toUpperCase(), timezoneId); + } + + return timeZoneMap; + } + + 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); + } +} From f05bba545e736f670c3431c05c3ce9ef88eeacc7 Mon Sep 17 00:00:00 2001 From: charsyam Date: Wed, 2 Dec 2015 23:58:56 +0900 Subject: [PATCH 2/3] change invalid imports and using immuatbleMap --- .../main/java/org/apache/tajo/util/TimeZoneUtil.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 index 3736e01407..ce1f8484b4 100644 --- a/tajo-core/src/main/java/org/apache/tajo/util/TimeZoneUtil.java +++ b/tajo-core/src/main/java/org/apache/tajo/util/TimeZoneUtil.java @@ -18,27 +18,26 @@ package org.apache.tajo.util; -import com.facebook.presto.hive.shaded.com.google.common.collect.Maps; -import org.apache.tajo.SessionVars; +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 Map timeZoneIdMap; + static ImmutableMap timeZoneIdMap; static { timeZoneIdMap = load(); } - private static Map load() { + private static ImmutableMap load() { Map timeZoneMap = Maps.newHashMap(); String[] timezoneIds = java.util.TimeZone.getAvailableIDs(); for (String timezoneId : timezoneIds) { timeZoneMap.put(timezoneId.toUpperCase(), timezoneId); } - return timeZoneMap; + return ImmutableMap.builder().putAll(timeZoneMap).build(); } private static String find(String timezoneId) { From b437fa77f3995ec818025ea20debc17d11c04698 Mon Sep 17 00:00:00 2001 From: charsyam Date: Thu, 3 Dec 2015 23:48:48 +0900 Subject: [PATCH 3/3] refactoring build timezoneMap with ImmutableMap --- .../src/main/java/org/apache/tajo/util/TimeZoneUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 index ce1f8484b4..2e6626c5f0 100644 --- a/tajo-core/src/main/java/org/apache/tajo/util/TimeZoneUtil.java +++ b/tajo-core/src/main/java/org/apache/tajo/util/TimeZoneUtil.java @@ -31,13 +31,13 @@ public class TimeZoneUtil { } private static ImmutableMap load() { - Map timeZoneMap = Maps.newHashMap(); + ImmutableMap.Builder builder = ImmutableMap.builder(); String[] timezoneIds = java.util.TimeZone.getAvailableIDs(); for (String timezoneId : timezoneIds) { - timeZoneMap.put(timezoneId.toUpperCase(), timezoneId); + builder.put(timezoneId.toUpperCase(), timezoneId); } - return ImmutableMap.builder().putAll(timeZoneMap).build(); + return builder.build(); } private static String find(String timezoneId) {