You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by ch...@apache.org on 2015/12/05 18:10:57 UTC

tajo git commit: TAJO-1993: Table Timezone doesn't work when Timezone is not exactly same.

Repository: tajo
Updated Branches:
  refs/heads/master 158bf1df9 -> 4b53643d4


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/4b53643d
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/4b53643d
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/4b53643d

Branch: refs/heads/master
Commit: 4b53643d47f9afbd8ec52db9cb7d7fae8b03875d
Parents: 158bf1d
Author: charsyam <ch...@charsyamui-MacBook-Pro.local>
Authored: Sun Dec 6 01:56:06 2015 +0900
Committer: charsyam <ch...@charsyamui-MacBook-Pro.local>
Committed: Sun Dec 6 01:56:06 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/4b53643d/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 75ce90e..6ee903b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -57,6 +57,8 @@ Release 0.12.0 - unreleased
 
   BUG FIXES
 
+    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/4b53643d/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/4b53643d/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 3344e2d..c33fc09 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.TajoInternalError;
 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 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/4b53643d/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);
+  }
+}