tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject tajo git commit: TAJO-1241: Change documentaiton url of devel and current versions.
Date Fri, 12 Dec 2014 00:33:11 GMT
Repository: tajo
Updated Branches:
  refs/heads/master 3c273b52d -> 758927e5a


TAJO-1241: Change documentaiton url of devel and current versions.

Closes #295


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

Branch: refs/heads/master
Commit: 758927e5aed12d390b02198525b812b838cd2ba3
Parents: 3c273b5
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Fri Dec 12 09:31:46 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Fri Dec 12 09:31:46 2014 +0900

----------------------------------------------------------------------
 CHANGES                                         |   2 +
 .../org/apache/tajo/catalog/CatalogUtil.java    |   6 +
 .../org/apache/tajo/client/QueryClientImpl.java |   8 +-
 .../apache/tajo/client/SessionConnection.java   |  65 +++-------
 .../org/apache/tajo/client/TajoClientUtil.java  |   4 +-
 .../org/apache/tajo/jdbc/TajoResultSetBase.java |   7 +-
 tajo-client/src/main/proto/ClientProtos.proto   |  11 +-
 .../main/java/org/apache/tajo/SessionVars.java  |   2 +-
 .../java/org/apache/tajo/conf/TajoConf.java     |  74 ++++-------
 .../engine/function/datetime/CurrentDate.java   |   2 +-
 .../function/datetime/DatePartFromTime.java     |   2 +-
 .../datetime/DatePartFromTimestamp.java         |   2 +-
 .../function/datetime/ToCharTimestamp.java      |   2 +-
 .../function/datetime/ToTimestampText.java      |   2 +-
 .../apache/tajo/engine/parser/SQLAnalyzer.java  |   2 +-
 .../engine/planner/physical/SeqScanExec.java    |  16 ++-
 .../org/apache/tajo/master/GlobalEngine.java    |   4 +-
 .../tajo/master/TajoMasterClientService.java    |   6 +-
 .../java/org/apache/tajo/QueryTestCaseBase.java |   8 +-
 .../org/apache/tajo/TajoTestingCluster.java     |   4 +-
 .../apache/tajo/engine/eval/ExprTestBase.java   |   2 +-
 .../tajo/engine/eval/TestSQLExpression.java     |   5 +-
 .../engine/function/TestDateTimeFunctions.java  |   5 +-
 .../tajo/engine/query/TestSelectQuery.java      |  47 ++++++-
 .../tajo/engine/query/TestSetSessionQuery.java  |   4 +-
 .../TestSelectQuery/testTimezonedTable2.sql     |   1 +
 .../TestSelectQuery/testTimezonedTable4.sql     |   2 +
 .../TestSelectQuery/testTimezonedTable5.sql     |   2 +
 .../results/TestSQLAnalyzer/settimezone1.result |   2 +-
 .../results/TestSQLAnalyzer/settimezone2.result |   2 +-
 .../results/TestSQLAnalyzer/settimezone3.result |   2 +-
 .../TestTajoCli/testHelpSessionVars.result      |   2 +-
 .../results/TestTajoCli/testSetTimezone1.result |   4 +
 tajo-docs/src/main/sphinx/configuration.rst     |   4 +-
 .../sphinx/configuration/catalog-site-xml.rst   |   3 +
 .../configuration/configuration_defaults.rst    |  28 ----
 .../configuration/service_config_defaults.rst   |  28 ++++
 .../main/sphinx/configuration/tajo-site-xml.rst |  24 ++++
 tajo-docs/src/main/sphinx/index.rst             |   1 +
 .../sphinx/table_management/table_overview.rst  |  67 +++-------
 tajo-docs/src/main/sphinx/time_zone.rst         | 129 +++++++++++++++++++
 .../org/apache/tajo/plan/ExprAnnotator.java     |  12 +-
 .../org/apache/tajo/plan/LogicalPlanner.java    |   4 +-
 .../org/apache/tajo/plan/expr/CastEval.java     |   5 +-
 .../org/apache/tajo/plan/util/PlannerUtil.java  |  24 +++-
 .../org/apache/tajo/storage/StorageUtil.java    |   1 +
 .../storage/TextSerializerDeserializer.java     |   6 +-
 47 files changed, 410 insertions(+), 235 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index e039f97..ac13ec5 100644
--- a/CHANGES
+++ b/CHANGES
@@ -20,6 +20,8 @@ Release 0.9.1 - unreleased
 
   IMPROVEMENT
 
+    TAJO-1241: Change default client and table time zone behavior. (hyunsik)
+
     TAJO-1243: *-site.xml.template should have default configs commented out.
     (hyunsik)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
index 8e8314c..df2112e 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
@@ -823,6 +823,12 @@ public class CatalogUtil {
   public static final String ENABLE_DICTIONARY    = "parquet.enable.dictionary";
   public static final String VALIDATION           = "parquet.validation";
 
+  /**
+   * Create new table property with default configs. It is used to make TableMeta to be stored in Catalog.
+   *
+   * @param type StoreType
+   * @return Table properties
+   */
   public static KeyValueSet newPhysicalProperties(StoreType type) {
     KeyValueSet options = new KeyValueSet();
     if (StoreType.CSV == type || StoreType.TEXTFILE == type) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
index 6809fda..dc35968 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
@@ -37,6 +37,7 @@ import org.apache.tajo.jdbc.TajoResultSet;
 import org.apache.tajo.rpc.NettyClientBase;
 import org.apache.tajo.rpc.ServerCallable;
 import org.apache.tajo.util.NetUtils;
+import org.apache.tajo.util.ProtoUtil;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
@@ -181,7 +182,11 @@ public class QueryClientImpl implements QueryClient {
         TajoMasterClientProtocolService.BlockingInterface tajoMasterService = client.getStub();
 
 
-        return tajoMasterService.submitQuery(null, builder.build());
+        SubmitQueryResponse response = tajoMasterService.submitQuery(null, builder.build());
+        if (response.getResultCode() == ResultCode.OK) {
+          connection.updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars()));
+        }
+        return response;
       }
     }.withRetries();
   }
@@ -489,6 +494,7 @@ public class QueryClientImpl implements QueryClient {
         ClientProtos.UpdateQueryResponse response = tajoMasterService.updateQuery(null, builder.build());
 
         if (response.getResultCode() == ClientProtos.ResultCode.OK) {
+          connection.updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars()));
           return true;
         } else {
           if (response.hasErrorMessage()) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java b/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java
index dcec1a3..44b772b 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java
@@ -23,12 +23,12 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.tajo.QueryId;
-import org.apache.tajo.SessionVars;
 import org.apache.tajo.TajoIdProtos;
 import org.apache.tajo.annotation.Nullable;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.ipc.ClientProtos.ResultCode;
+import org.apache.tajo.ipc.ClientProtos.SessionUpdateResponse;
 import org.apache.tajo.ipc.TajoMasterClientProtocol;
 import org.apache.tajo.rpc.NettyClientBase;
 import org.apache.tajo.rpc.RpcConnectionPool;
@@ -190,32 +190,17 @@ public class SessionConnection implements Closeable {
       public Map<String, String> call(NettyClientBase client) throws ServiceException {
         checkSessionAndGet(client);
 
-        // keep client-side session variables
-        for (Map.Entry<String, String> entry : variables.entrySet()) {
-          String key = entry.getKey();
-          if (SessionVars.exists(entry.getKey())) {
-            SessionVars configKey = SessionVars.get(key);
-            if (configKey.getMode() == SessionVars.VariableMode.CLI_SIDE_VAR) {
-              sessionVarsCache.put(key, entry.getValue());
-            }
-          }
-        }
-
         TajoMasterClientProtocolService.BlockingInterface tajoMasterService = client.getStub();
         KeyValueSet keyValueSet = new KeyValueSet();
         keyValueSet.putAll(variables);
         ClientProtos.UpdateSessionVariableRequest request = ClientProtos.UpdateSessionVariableRequest.newBuilder()
             .setSessionId(sessionId)
-            .setSetVariables(keyValueSet.getProto()).build();
+            .setSessionVars(keyValueSet.getProto()).build();
 
-        ClientProtos.SessionUpdateResponse response = tajoMasterService.updateSessionVariables(null, request);
-        if (response.getResultCode() == ResultCode.OK) {
-          Map<String, String> updated = ProtoUtil.convertToMap(response.getVariables());
+        SessionUpdateResponse response = tajoMasterService.updateSessionVariables(null, request);
 
-          synchronized (sessionVarsCache) {
-            sessionVarsCache.clear();
-            sessionVarsCache.putAll(updated);
-          }
+        if (response.getResultCode() == ResultCode.OK) {
+          updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars()));
           return Collections.unmodifiableMap(sessionVarsCache);
         } else {
           throw new ServiceException(response.getMessage());
@@ -230,26 +215,15 @@ public class SessionConnection implements Closeable {
       public Map<String, String> call(NettyClientBase client) throws ServiceException {
         checkSessionAndGet(client);
 
-        // Remove matched session vars
-        for (String key : variables) {
-          if (sessionVarsCache.containsKey(key)) {
-            sessionVarsCache.remove(key);
-          }
-        }
-
         TajoMasterClientProtocolService.BlockingInterface tajoMasterService = client.getStub();
         ClientProtos.UpdateSessionVariableRequest request = ClientProtos.UpdateSessionVariableRequest.newBuilder()
             .setSessionId(sessionId)
             .addAllUnsetVariables(variables).build();
 
-        ClientProtos.SessionUpdateResponse response = tajoMasterService.updateSessionVariables(null, request);
-        if (response.getResultCode() == ResultCode.OK) {
-          Map<String, String> updated = ProtoUtil.convertToMap(response.getVariables());
+        SessionUpdateResponse response = tajoMasterService.updateSessionVariables(null, request);
 
-          synchronized (sessionVarsCache) {
-            sessionVarsCache.clear();
-            sessionVarsCache.putAll(updated);
-          }
+        if (response.getResultCode() == ResultCode.OK) {
+          updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars()));
           return Collections.unmodifiableMap(sessionVarsCache);
         } else {
           throw new ServiceException(response.getMessage());
@@ -258,11 +232,10 @@ public class SessionConnection implements Closeable {
     }.withRetries();
   }
 
-  public String getCachedSessionVariable(final String varname) {
-    if (sessionVarsCache.containsKey(varname)) {
-      return sessionVarsCache.get(varname);
-    } else {
-      throw new RuntimeException("No such session variable" + varname);
+  void updateSessionVarsCache(Map<String, String> variables) {
+    synchronized (sessionVarsCache) {
+      this.sessionVarsCache.clear();
+      this.sessionVarsCache.putAll(variables);
     }
   }
 
@@ -271,9 +244,11 @@ public class SessionConnection implements Closeable {
 
       public String call(NettyClientBase client) throws ServiceException {
 
-        // If a desired variable is client side one and exists in the cache, immediately return the variable.
-        if (sessionVarsCache.containsKey(varname)) {
-          return sessionVarsCache.get(varname);
+        synchronized (sessionVarsCache) {
+          // If a desired variable is client side one and exists in the cache, immediately return the variable.
+          if (sessionVarsCache.containsKey(varname)) {
+            return sessionVarsCache.get(varname);
+          }
         }
 
         checkSessionAndGet(client);
@@ -297,7 +272,9 @@ public class SessionConnection implements Closeable {
   }
 
   public Map<String, String> getCachedAllSessionVariables() {
-    return Collections.unmodifiableMap(sessionVarsCache);
+    synchronized (sessionVarsCache) {
+      return Collections.unmodifiableMap(sessionVarsCache);
+    }
   }
 
   public Map<String, String> getAllSessionVariables() throws ServiceException {
@@ -377,7 +354,7 @@ public class SessionConnection implements Closeable {
       if (response.getResultCode() == ResultCode.OK) {
 
         sessionId = response.getSessionId();
-        sessionVarsCache.putAll(ProtoUtil.convertToMap(response.getVariables()));
+        updateSessionVarsCache(ProtoUtil.convertToMap(response.getSessionVars()));
         if (LOG.isDebugEnabled()) {
           LOG.debug(String.format("Got session %s as a user '%s'.", sessionId.getId(), userInfo.getUserName()));
         }

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java
index bf9d111..744ba1d 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientUtil.java
@@ -72,8 +72,8 @@ public class TajoClientUtil {
       // non-forward query
       // select * from table1 [limit 10]
       int fetchRowNum = conf.getIntVar(TajoConf.ConfVars.$RESULT_SET_FETCH_ROWNUM);
-      if (response.hasSessionVariables()) {
-        for (PrimitiveProtos.KeyValueProto eachKeyValue: response.getSessionVariables().getKeyvalList()) {
+      if (response.hasSessionVars()) {
+        for (PrimitiveProtos.KeyValueProto eachKeyValue: response.getSessionVars().getKeyvalList()) {
           if (eachKeyValue.getKey().equals(SessionVars.FETCH_ROWNUM.keyname())) {
             fetchRowNum = Integer.parseInt(eachKeyValue.getValue());
           }

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-client/src/main/java/org/apache/tajo/jdbc/TajoResultSetBase.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/jdbc/TajoResultSetBase.java b/tajo-client/src/main/java/org/apache/tajo/jdbc/TajoResultSetBase.java
index 051ea75..77cbbf2 100644
--- a/tajo-client/src/main/java/org/apache/tajo/jdbc/TajoResultSetBase.java
+++ b/tajo-client/src/main/java/org/apache/tajo/jdbc/TajoResultSetBase.java
@@ -19,7 +19,6 @@
 package org.apache.tajo.jdbc;
 
 import org.apache.tajo.SessionVars;
-import org.apache.tajo.TajoConstants;
 import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.datum.*;
@@ -53,11 +52,11 @@ public abstract class TajoResultSetBase implements ResultSet {
 
     if (clientSideSessionVars != null) {
 
-      if (clientSideSessionVars.containsKey(SessionVars.TZ.name())) {
-        String timezoneId = clientSideSessionVars.get(SessionVars.TZ.name());
+      if (clientSideSessionVars.containsKey(SessionVars.TIMEZONE.name())) {
+        String timezoneId = clientSideSessionVars.get(SessionVars.TIMEZONE.name());
         this.timezone = TimeZone.getTimeZone(timezoneId);
       } else {
-        this.timezone = TimeZone.getTimeZone(TajoConstants.DEFAULT_SYSTEM_TIMEZONE);
+        this.timezone = TimeZone.getDefault();
       }
 
     }

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-client/src/main/proto/ClientProtos.proto
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/proto/ClientProtos.proto b/tajo-client/src/main/proto/ClientProtos.proto
index fa12ab2..51db763 100644
--- a/tajo-client/src/main/proto/ClientProtos.proto
+++ b/tajo-client/src/main/proto/ClientProtos.proto
@@ -39,19 +39,19 @@ message CreateSessionRequest {
 message CreateSessionResponse {
   required ResultCode resultCode = 1;
   optional SessionIdProto sessionId = 2;
-  optional KeyValueSetProto variables = 3;
+  optional KeyValueSetProto sessionVars = 3;
   optional string message = 4;
 }
 
 message UpdateSessionVariableRequest {
   optional SessionIdProto sessionId = 1;
-  optional KeyValueSetProto setVariables = 2;
+  optional KeyValueSetProto sessionVars = 2;
   repeated string unsetVariables = 3;
 }
 
 message SessionUpdateResponse {
   required ResultCode resultCode = 1;
-  optional KeyValueSetProto variables = 2;
+  optional KeyValueSetProto sessionVars = 2;
   optional string message = 3;
 }
 
@@ -69,13 +69,14 @@ message ExplainQueryResponse {
 message QueryRequest {
   optional SessionIdProto sessionId = 1;
   required string query = 2;
-  repeated KeyValueProto setVariables = 3;
+  repeated KeyValueProto sessionVars = 3;
   required bool isJson = 4;
 }
 
 message UpdateQueryResponse {
   required ResultCode resultCode = 1;
   optional string errorMessage = 2;
+  optional KeyValueSetProto sessionVars = 3;
 }
 
 message GetQueryResultRequest {
@@ -140,7 +141,7 @@ message SubmitQueryResponse {
   optional string errorMessage = 10;
   optional string errorTrace = 11;
 
-  optional KeyValueSetProto sessionVariables = 12;
+  optional KeyValueSetProto sessionVars = 12;
 }
 
 message GetQueryStatusResponse {

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-common/src/main/java/org/apache/tajo/SessionVars.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/SessionVars.java b/tajo-common/src/main/java/org/apache/tajo/SessionVars.java
index fa717d1..d87bbef 100644
--- a/tajo-common/src/main/java/org/apache/tajo/SessionVars.java
+++ b/tajo-common/src/main/java/org/apache/tajo/SessionVars.java
@@ -71,7 +71,7 @@ public enum SessionVars implements ConfigKey {
   ON_ERROR_STOP(ConfVars.$CLI_ERROR_STOP, "tsql will exist if an error occurs.", CLI_SIDE_VAR),
 
   // Timezone & Date ----------------------------------------------------------
-  TZ(ConfVars.$TIMEZONE, "Sets timezone", CLI_SIDE_VAR),
+  TIMEZONE(ConfVars.$TIMEZONE, "Sets timezone", CLI_SIDE_VAR),
   DATE_ORDER(ConfVars.$DATE_ORDER, "date order (default is YMD)", CLI_SIDE_VAR),
 
   // Locales and Character set ------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
index 252b8f0..ed38cdc 100644
--- a/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
+++ b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
@@ -18,8 +18,8 @@
 
 package org.apache.tajo.conf;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
-
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -39,16 +39,10 @@ import java.io.PrintStream;
 import java.net.InetSocketAddress;
 import java.util.Map;
 import java.util.TimeZone;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 public class TajoConf extends Configuration {
-
   private static TimeZone SYSTEM_TIMEZONE;
   private static int DATE_ORDER = -1;
-  private static final ReentrantReadWriteLock confLock = new ReentrantReadWriteLock();
-  private static final Lock writeLock = confLock.writeLock();
-  private static final Lock readLock = confLock.readLock();
   
   private static final Map<String, ConfVars> vars = TUtil.newHashMap();
 
@@ -59,8 +53,6 @@ public class TajoConf extends Configuration {
     Configuration.addDefaultResource("storage-site.xml");
     Configuration.addDefaultResource("tajo-default.xml");
     Configuration.addDefaultResource("tajo-site.xml");
-
-    confStaticInit();
     
     for (ConfVars confVars: ConfVars.values()) {
       vars.put(confVars.keyname(), confVars);
@@ -82,55 +74,37 @@ public class TajoConf extends Configuration {
     addResource(path);
   }
 
-  private static void confStaticInit() {
-    TimeZone.setDefault(getSystemTimezone());
-    getDateOrder();
+  @SuppressWarnings("unused")
+  public TimeZone getSystemTimezone() {
+    return TimeZone.getTimeZone(getVar(ConfVars.$TIMEZONE));
   }
 
-  public static TimeZone getSystemTimezone() {
-    writeLock.lock();
-    try {
-      if (SYSTEM_TIMEZONE == null) {
-        TajoConf tajoConf = new TajoConf();
-        SYSTEM_TIMEZONE = TimeZone.getTimeZone(tajoConf.getVar(ConfVars.$TIMEZONE));
-      }
-      return SYSTEM_TIMEZONE;
-    } finally {
-      writeLock.unlock();
-    }
+  public void setSystemTimezone(TimeZone timezone) {
+    setVar(ConfVars.$TIMEZONE, timezone.getID());
   }
 
   public static int getDateOrder() {
-    writeLock.lock();
-    try {
-      if (DATE_ORDER < 0) {
-        TajoConf tajoConf = new TajoConf();
-        String dateOrder = tajoConf.getVar(ConfVars.$DATE_ORDER);
-        if ("YMD".equals(dateOrder)) {
-          DATE_ORDER = DateTimeConstants.DATEORDER_YMD;
-        } else if ("DMY".equals(dateOrder)) {
-          DATE_ORDER = DateTimeConstants.DATEORDER_DMY;
-        } else if ("MDY".equals(dateOrder)) {
-          DATE_ORDER = DateTimeConstants.DATEORDER_MDY;
-        } else {
-          DATE_ORDER = DateTimeConstants.DATEORDER_YMD;
-        }
+    if (DATE_ORDER < 0) {
+      TajoConf tajoConf = new TajoConf();
+      String dateOrder = tajoConf.getVar(ConfVars.$DATE_ORDER);
+      if ("YMD".equals(dateOrder)) {
+        DATE_ORDER = DateTimeConstants.DATEORDER_YMD;
+      } else if ("DMY".equals(dateOrder)) {
+        DATE_ORDER = DateTimeConstants.DATEORDER_DMY;
+      } else if ("MDY".equals(dateOrder)) {
+        DATE_ORDER = DateTimeConstants.DATEORDER_MDY;
+      } else {
+        DATE_ORDER = DateTimeConstants.DATEORDER_YMD;
       }
-      return DATE_ORDER;
-    } finally {
-      writeLock.unlock();
     }
+    return DATE_ORDER;
   }
 
+  @VisibleForTesting
   public static int setDateOrder(int dateOrder) {
-    writeLock.lock();
-    try {
-      int oldDateOrder = DATE_ORDER;
-      DATE_ORDER = dateOrder;
-      return oldDateOrder;
-    } finally {
-    	writeLock.unlock();
-    }
+    int oldDateOrder = DATE_ORDER;
+    DATE_ORDER = dateOrder;
+    return oldDateOrder;
   }
 
   public static enum ConfVars implements ConfigKey {
@@ -347,8 +321,8 @@ public class TajoConf extends Configuration {
     $CLI_ERROR_STOP("tajo.cli.error.stop", false),
 
     // Timezone & Date ----------------------------------------------------------
-    $TIMEZONE("tajo.timezone", TajoConstants.DEFAULT_SYSTEM_TIMEZONE),
-    $DATE_ORDER("tajo.date.order", "YMD"),
+    $TIMEZONE("tajo.timezone", TimeZone.getDefault().getID()),
+    $DATE_ORDER("tajo.datetime.date-order", "YMD"),
 
     // FILE FORMAT
     $TEXT_NULL("tajo.text.null", "\\\\N"),

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/CurrentDate.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/CurrentDate.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/CurrentDate.java
index ccfbd84..d57ac02 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/CurrentDate.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/CurrentDate.java
@@ -53,7 +53,7 @@ public class CurrentDate extends GeneralFunction {
 
   @Override
   public void init(OverridableConf context, FunctionEval.ParamType[] types) {
-    String timezoneId = context.get(SessionVars.TZ, TajoConstants.DEFAULT_SYSTEM_TIMEZONE);
+    String timezoneId = context.get(SessionVars.TIMEZONE, TajoConstants.DEFAULT_SYSTEM_TIMEZONE);
     timezone = TimeZone.getTimeZone(timezoneId);
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/DatePartFromTime.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/DatePartFromTime.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/DatePartFromTime.java
index ae09197..85c76a2 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/DatePartFromTime.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/DatePartFromTime.java
@@ -63,7 +63,7 @@ public class DatePartFromTime extends GeneralFunction {
 
   @Override
   public void init(OverridableConf context, FunctionEval.ParamType [] types) {
-    String timezoneId = context.get(SessionVars.TZ, TajoConstants.DEFAULT_SYSTEM_TIMEZONE);
+    String timezoneId = context.get(SessionVars.TIMEZONE, TajoConstants.DEFAULT_SYSTEM_TIMEZONE);
     timezone = TimeZone.getTimeZone(timezoneId);
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/DatePartFromTimestamp.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/DatePartFromTimestamp.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/DatePartFromTimestamp.java
index cd195fb..57b3900 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/DatePartFromTimestamp.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/DatePartFromTimestamp.java
@@ -59,7 +59,7 @@ public class DatePartFromTimestamp extends GeneralFunction {
 
   @Override
   public void init(OverridableConf context, FunctionEval.ParamType [] types) {
-    String timezoneId = context.get(SessionVars.TZ, TajoConstants.DEFAULT_SYSTEM_TIMEZONE);
+    String timezoneId = context.get(SessionVars.TIMEZONE, TajoConstants.DEFAULT_SYSTEM_TIMEZONE);
     timezone = TimeZone.getTimeZone(timezoneId);
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/ToCharTimestamp.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/ToCharTimestamp.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/ToCharTimestamp.java
index 9e76677..1053ecb 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/ToCharTimestamp.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/ToCharTimestamp.java
@@ -62,7 +62,7 @@ public class ToCharTimestamp extends GeneralFunction {
 
   @Override
   public void init(OverridableConf context, FunctionEval.ParamType[] paramTypes) {
-    String timezoneId = context.get(SessionVars.TZ, TajoConstants.DEFAULT_SYSTEM_TIMEZONE);
+    String timezoneId = context.get(SessionVars.TIMEZONE, TajoConstants.DEFAULT_SYSTEM_TIMEZONE);
     timezone = TimeZone.getTimeZone(timezoneId);
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/ToTimestampText.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/ToTimestampText.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/ToTimestampText.java
index e9beefb..6b199f6 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/ToTimestampText.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/datetime/ToTimestampText.java
@@ -54,7 +54,7 @@ public class ToTimestampText extends GeneralFunction {
   }
 
   public void init(OverridableConf queryContext, FunctionEval.ParamType [] paramTypes) {
-    String timezoneId = queryContext.get(SessionVars.TZ, TajoConstants.DEFAULT_SYSTEM_TIMEZONE);
+    String timezoneId = queryContext.get(SessionVars.TIMEZONE, TajoConstants.DEFAULT_SYSTEM_TIMEZONE);
     timezone = TimeZone.getTimeZone(timezoneId);
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java b/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
index ca04301..7d6c951 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
@@ -113,7 +113,7 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> {
       } else {
         value = null;
       }
-      return new SetSession(SessionVars.TZ.name(), value);
+      return new SetSession(SessionVars.TIMEZONE.name(), value);
 
     } else {
       throw new SQLSyntaxError("Unsupported session statement");

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/SeqScanExec.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/SeqScanExec.java b/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/SeqScanExec.java
index 759b19c..1ed25d8 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/SeqScanExec.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/SeqScanExec.java
@@ -21,6 +21,7 @@ package org.apache.tajo.engine.planner.physical;
 import org.apache.hadoop.io.IOUtils;
 import org.apache.tajo.catalog.Column;
 import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.catalog.TableMeta;
 import org.apache.tajo.catalog.partition.PartitionMethodDesc;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.catalog.proto.CatalogProtos.FragmentProto;
@@ -38,6 +39,7 @@ import org.apache.tajo.plan.expr.EvalTreeUtil;
 import org.apache.tajo.plan.expr.FieldEval;
 import org.apache.tajo.plan.logical.ScanNode;
 import org.apache.tajo.plan.rewrite.rules.PartitionedTableRewriter;
+import org.apache.tajo.plan.util.PlannerUtil;
 import org.apache.tajo.storage.*;
 import org.apache.tajo.storage.fragment.FileFragment;
 import org.apache.tajo.storage.fragment.FragmentConvertor;
@@ -212,15 +214,25 @@ public class SeqScanExec extends PhysicalExec {
 
   private void initScanner(Schema projected) throws IOException {
     this.projector = new Projector(context, inSchema, outSchema, plan.getTargets());
+    TableMeta meta = null;
+    try {
+      meta = (TableMeta) plan.getTableDesc().getMeta().clone();
+    } catch (CloneNotSupportedException e) {
+      throw new RuntimeException(e);
+    }
+
+    // set system default properties
+    PlannerUtil.applySystemDefaultToTableProperties(context.getQueryContext(), meta);
+
     if (fragments != null) {
       if (fragments.length > 1) {
-        this.scanner = new MergeScanner(context.getConf(), plan.getPhysicalSchema(), plan.getTableDesc().getMeta(),
+        this.scanner = new MergeScanner(context.getConf(), plan.getPhysicalSchema(), meta,
             FragmentConvertor.<FileFragment>convert(context.getConf(), plan.getTableDesc().getMeta().getStoreType(),
                 fragments), projected
         );
       } else {
         this.scanner = StorageManager.getStorageManager(
-            context.getConf()).getScanner(plan.getTableDesc().getMeta(), plan.getPhysicalSchema(), fragments[0],
+            context.getConf()).getScanner(meta, plan.getPhysicalSchema(), fragments[0],
             projected);
       }
       scanner.init();

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java b/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
index f23a8d3..399644c 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
@@ -65,6 +65,7 @@ import org.apache.tajo.plan.verifier.VerificationState;
 import org.apache.tajo.plan.verifier.VerifyException;
 import org.apache.tajo.storage.*;
 import org.apache.tajo.util.CommonTestingUtil;
+import org.apache.tajo.util.ProtoUtil;
 import org.apache.tajo.worker.TaskAttemptContext;
 
 import java.io.IOException;
@@ -303,7 +304,6 @@ public class GlobalEngine extends AbstractService {
       responseBuilder.setQueryId(queryId.getProto());
       responseBuilder.setMaxRowNum(maxRow);
       responseBuilder.setTableDesc(desc.getProto());
-      responseBuilder.setSessionVariables(session.getProto().getVariables());
       responseBuilder.setResultCode(ClientProtos.ResultCode.OK);
 
       // NonFromQuery indicates a form of 'select a, x+y;'
@@ -359,6 +359,8 @@ public class GlobalEngine extends AbstractService {
         LOG.info("Query is forwarded to " + queryInfo.getQueryMasterHost() + ":" + queryInfo.getQueryMasterPort());
       }
     }
+
+    responseBuilder.setSessionVars(ProtoUtil.convertFromMap(session.getAllVariables()));
     SubmitQueryResponse response = responseBuilder.build();
     return response;
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/main/java/org/apache/tajo/master/TajoMasterClientService.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/TajoMasterClientService.java b/tajo-core/src/main/java/org/apache/tajo/master/TajoMasterClientService.java
index a4f0259..b420a65 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/TajoMasterClientService.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/TajoMasterClientService.java
@@ -145,7 +145,7 @@ public class TajoMasterClientService extends AbstractService {
         CreateSessionResponse.Builder builder = CreateSessionResponse.newBuilder();
         builder.setResultCode(ResultCode.OK);
         builder.setSessionId(TajoIdProtos.SessionIdProto.newBuilder().setId(sessionId).build());
-        builder.setVariables(ProtoUtil.convertFromMap(context.getSessionManager().getAllVariables(sessionId)));
+        builder.setSessionVars(ProtoUtil.convertFromMap(context.getSessionManager().getAllVariables(sessionId)));
         return builder.build();
       } catch (NoSuchDatabaseException nsde) {
         CreateSessionResponse.Builder builder = CreateSessionResponse.newBuilder();
@@ -174,7 +174,7 @@ public class TajoMasterClientService extends AbstractService {
     public SessionUpdateResponse buildSessionUpdateOnSuccess(Map<String, String> variables) {
       SessionUpdateResponse.Builder builder = SessionUpdateResponse.newBuilder();
       builder.setResultCode(ResultCode.OK);
-      builder.setVariables(new KeyValueSet(variables).getProto());
+      builder.setSessionVars(new KeyValueSet(variables).getProto());
       return builder.build();
     }
 
@@ -190,7 +190,7 @@ public class TajoMasterClientService extends AbstractService {
         throws ServiceException {
       try {
         String sessionId = request.getSessionId().getId();
-        for (KeyValueProto kv : request.getSetVariables().getKeyvalList()) {
+        for (KeyValueProto kv : request.getSessionVars().getKeyvalList()) {
           context.getSessionManager().setVariable(sessionId, kv.getKey(), kv.getValue());
         }
         for (String unsetVariable : request.getUnsetVariablesList()) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
index efcc691..ecfb9f5 100644
--- a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
+++ b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
@@ -330,7 +330,13 @@ public class QueryTestCaseBase {
     if (parsedResults.size() > 1) {
       assertNotNull("This script \"" + queryFileName + "\" includes two or more queries");
     }
-    ResultSet result = client.executeQueryAndGetResult(parsedResults.get(0).getHistoryStatement());
+
+    int idx = 0;
+    for (; idx < parsedResults.size() - 1; idx++) {
+      client.executeQueryAndGetResult(parsedResults.get(idx).getHistoryStatement()).close();
+    }
+
+    ResultSet result = client.executeQueryAndGetResult(parsedResults.get(idx).getHistoryStatement());
     assertNotNull("Query succeeded test", result);
     return result;
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java b/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java
index e5dfb7a..757ba0f 100644
--- a/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java
+++ b/tajo-core/src/test/java/org/apache/tajo/TajoTestingCluster.java
@@ -118,7 +118,9 @@ public class TajoTestingCluster {
   }
 
   void initPropertiesAndConfigs() {
-    TimeZone.setDefault(TimeZone.getTimeZone(TajoConstants.DEFAULT_SYSTEM_TIMEZONE));
+    TimeZone testDefaultTZ = TimeZone.getTimeZone(TajoConstants.DEFAULT_SYSTEM_TIMEZONE);
+    conf.setSystemTimezone(testDefaultTZ);
+    TimeZone.setDefault(testDefaultTZ);
 
     if (System.getProperty(ConfVars.RESOURCE_MANAGER_CLASS.varname) != null) {
       String testResourceManager = System.getProperty(ConfVars.RESOURCE_MANAGER_CLASS.varname);

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
index 8cd87a8..e286b92 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/ExprTestBase.java
@@ -218,7 +218,7 @@ public class ExprTestBase {
       queryContext.putAll(context);
     }
 
-    String timezoneId = queryContext.get(SessionVars.TZ);
+    String timezoneId = queryContext.get(SessionVars.TIMEZONE);
     TimeZone timeZone = TimeZone.getTimeZone(timezoneId);
 
     LazyTuple lazyTuple;

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
index 4a9e42c..52982c0 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
@@ -23,7 +23,6 @@ import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.catalog.exception.NoSuchFunctionException;
 import org.apache.tajo.common.TajoDataTypes;
-import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.datum.TimestampDatum;
 import org.apache.tajo.engine.query.QueryContext;
@@ -856,7 +855,7 @@ public class TestSQLExpression extends ExprTestBase {
   @Test
   public void testCastWithNestedFunction() throws IOException {
     QueryContext context = new QueryContext(getConf());
-    context.put(SessionVars.TZ, "GMT-6");
+    context.put(SessionVars.TIMEZONE, "GMT-6");
     TimeZone tz = TimeZone.getTimeZone("GMT-6");
 
     int unixtime = 1389071574; // (int) (System.currentTimeMillis() / 1000);
@@ -868,7 +867,7 @@ public class TestSQLExpression extends ExprTestBase {
   @Test
   public void testCastFromTable() throws IOException {
     QueryContext queryContext = new QueryContext(getConf());
-    queryContext.put(SessionVars.TZ, "GMT-6");
+    queryContext.put(SessionVars.TIMEZONE, "GMT-6");
     TimeZone tz = TimeZone.getTimeZone("GMT-6");
 
     Schema schema = new Schema();

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java
index cb7856b..6c708fb 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java
@@ -21,7 +21,6 @@ package org.apache.tajo.engine.function;
 
 import org.apache.tajo.SessionVars;
 import org.apache.tajo.catalog.Schema;
-import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.datum.TimestampDatum;
 import org.apache.tajo.engine.eval.ExprTestBase;
@@ -431,7 +430,7 @@ public class TestDateTimeFunctions extends ExprTestBase {
     TimeZone.setDefault(TimeZone.getTimeZone("GMT-6"));
 
     QueryContext context = new QueryContext(getConf());
-    context.put(SessionVars.TZ, "GMT-6");
+    context.put(SessionVars.TIMEZONE, "GMT-6");
 
     try {
       Date expectedDate = new Date(System.currentTimeMillis());
@@ -455,7 +454,7 @@ public class TestDateTimeFunctions extends ExprTestBase {
     TimeZone.setDefault(TimeZone.getTimeZone("GMT-6"));
 
     QueryContext context = new QueryContext(getConf());
-    context.put(SessionVars.TZ, "GMT-6");
+    context.put(SessionVars.TIMEZONE, "GMT-6");
 
     try {
       Date expectedDate = new Date(System.currentTimeMillis());

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
index 5b7641a..2d9b1f8 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
@@ -37,6 +37,7 @@ import org.junit.experimental.categories.Category;
 import java.sql.ResultSet;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.TimeZone;
 
 import static org.apache.tajo.TajoConstants.DEFAULT_DATABASE_NAME;
 import static org.junit.Assert.*;
@@ -541,6 +542,8 @@ public class TestSelectQuery extends QueryTestCaseBase {
 
   @Test
   public void testTimezonedTable1() throws Exception {
+    // Table - GMT (No table property or no system timezone)
+    // Client - GMT (default client time zone is used if no TIME ZONE session variable is given.)
     try {
       executeDDL("datetime_table_ddl.sql", "timezoned", new String[]{"timezoned1"});
       ResultSet res = executeQuery();
@@ -553,6 +556,8 @@ public class TestSelectQuery extends QueryTestCaseBase {
 
   @Test
   public void testTimezonedTable2() throws Exception {
+    // Table - timezone = GMT+9
+    // Client - GMT (SET TIME ZONE 'GMT';)
     try {
       executeDDL("datetime_table_timezoned_ddl.sql", "timezoned", new String[]{"timezoned2"});
       ResultSet res = executeQuery();
@@ -565,8 +570,11 @@ public class TestSelectQuery extends QueryTestCaseBase {
 
   @Test
   public void testTimezonedTable3() throws Exception {
+    // Table - timezone = GMT+9
+    // Client - GMT+9 through TajoClient API
+
     Map<String,String> sessionVars = new HashMap<String, String>();
-    sessionVars.put(SessionVars.TZ.name(), "GMT+9");
+    sessionVars.put(SessionVars.TIMEZONE.name(), "GMT+9");
     getClient().updateSessionVariables(sessionVars);
 
     try {
@@ -578,6 +586,41 @@ public class TestSelectQuery extends QueryTestCaseBase {
       executeString("DROP TABLE IF EXISTS timezoned3");
     }
 
-    getClient().unsetSessionVariables(Lists.newArrayList("TZ"));
+    getClient().unsetSessionVariables(Lists.newArrayList("TIMEZONE"));
+  }
+
+  @Test
+  public void testTimezonedTable4() throws Exception {
+    // Table - timezone = GMT+9
+    // Client - GMT+9 (SET TIME ZONE 'GMT+9';)
+
+    try {
+      executeDDL("datetime_table_timezoned_ddl.sql", "timezoned", new String[]{"timezoned4"});
+      ResultSet res = executeQuery();
+      assertResultSet(res, "testTimezonedTable3.result");
+      cleanupQuery(res);
+    } finally {
+      executeString("DROP TABLE IF EXISTS timezoned4");
+    }
+  }
+
+  @Test
+  public void testTimezonedTable5() throws Exception {
+    // Table - timezone = GMT+9 (by a specified system timezone)
+    // TajoClient uses JVM default timezone (GMT+9)
+
+    try {
+      testingCluster.getConfiguration().setSystemTimezone(TimeZone.getTimeZone("GMT+9"));
+
+      executeDDL("datetime_table_ddl.sql", "timezoned", new String[]{"timezoned5"});
+      ResultSet res = executeQuery();
+      assertResultSet(res, "testTimezonedTable3.result");
+      cleanupQuery(res);
+    } finally {
+      executeString("DROP TABLE IF EXISTS timezoned5");
+
+      // restore the config
+      testingCluster.getConfiguration().setSystemTimezone(TimeZone.getTimeZone("GMT"));
+    }
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSetSessionQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSetSessionQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSetSessionQuery.java
index 5d463c4..c9c7339 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSetSessionQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSetSessionQuery.java
@@ -58,9 +58,9 @@ public class TestSetSessionQuery extends QueryTestCaseBase {
 
   @Test
   public final void testSetTimezone() throws Exception {
-    assertFalse(getClient().existSessionVariable("TZ"));
+    assertFalse(getClient().existSessionVariable("TIMEZONE"));
     executeString("SET TIME ZONE 'GMT+9'").close();
-    assertTrue(getClient().existSessionVariable("TZ"));
+    assertTrue(getClient().existSessionVariable("TIMEZONE"));
     executeString("SET TIME ZONE to DEFAULT").close();
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable2.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable2.sql b/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable2.sql
index 722fc65..1fd9e36 100644
--- a/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable2.sql
+++ b/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable2.sql
@@ -1 +1,2 @@
+SET TIME ZONE 'GMT';
 SELECT * FROM timezoned2;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable4.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable4.sql b/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable4.sql
new file mode 100644
index 0000000..acd096b
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable4.sql
@@ -0,0 +1,2 @@
+SET TIME ZONE 'GMT+9';
+SELECT * FROM timezoned4;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable5.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable5.sql b/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable5.sql
new file mode 100644
index 0000000..13894ce
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestSelectQuery/testTimezonedTable5.sql
@@ -0,0 +1,2 @@
+SET SESSION TIMEZONE = 'GMT+9';
+SELECT * FROM timezoned5;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone1.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone1.result b/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone1.result
index 366e447..b7dda46 100644
--- a/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone1.result
+++ b/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone1.result
@@ -1,5 +1,5 @@
 {
-  "name": "TZ",
+  "name": "TIMEZONE",
   "value": "PDT",
   "OpType": "SetSession"
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone2.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone2.result b/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone2.result
index 7653373..10e4bfa 100644
--- a/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone2.result
+++ b/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone2.result
@@ -1,5 +1,5 @@
 {
-  "name": "TZ",
+  "name": "TIMEZONE",
   "value": "-7",
   "OpType": "SetSession"
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone3.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone3.result b/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone3.result
index 8bb188e..31f78e1 100644
--- a/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone3.result
+++ b/tajo-core/src/test/resources/results/TestSQLAnalyzer/settimezone3.result
@@ -1,4 +1,4 @@
 {
-  "name": "TZ",
+  "name": "TIMEZONE",
   "OpType": "SetSession"
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/resources/results/TestTajoCli/testHelpSessionVars.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestTajoCli/testHelpSessionVars.result b/tajo-core/src/test/resources/results/TestTajoCli/testHelpSessionVars.result
index 25f1ae7..b5b7c22 100644
--- a/tajo-core/src/test/resources/results/TestTajoCli/testHelpSessionVars.result
+++ b/tajo-core/src/test/resources/results/TestTajoCli/testHelpSessionVars.result
@@ -8,7 +8,7 @@ Available Session Variables:
 \set CLI_PAGING_ENABLED [true or false] - Enable paging of result display
 \set CLI_DISPLAY_ERROR_TRACE [true or false] - Enable display of error trace
 \set ON_ERROR_STOP [true or false] - tsql will exist if an error occurs.
-\set TZ [text value] - Sets timezone
+\set TIMEZONE [text value] - Sets timezone
 \set DATE_ORDER [text value] - date order (default is YMD)
 \set LANG [text value] - Language
 \set LC_ALL [text value] - String sort order

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-core/src/test/resources/results/TestTajoCli/testSetTimezone1.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestTajoCli/testSetTimezone1.result b/tajo-core/src/test/resources/results/TestTajoCli/testSetTimezone1.result
new file mode 100644
index 0000000..fdb2a2d
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestTajoCli/testSetTimezone1.result
@@ -0,0 +1,4 @@
+?timestamp
+-------------------------------
+2014-10-01 08:09:01
+(1 rows, , 0 B selected)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-docs/src/main/sphinx/configuration.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/configuration.rst b/tajo-docs/src/main/sphinx/configuration.rst
index f898969..5214ea8 100644
--- a/tajo-docs/src/main/sphinx/configuration.rst
+++ b/tajo-docs/src/main/sphinx/configuration.rst
@@ -10,5 +10,7 @@ Configuration
     configuration/tajo_master_configuration
     configuration/worker_configuration
     configuration/catalog_configuration
-    configuration/configuration_defaults
     configuration/ha_configuration
+    configuration/service_config_defaults
+    configuration/tajo-site-xml
+    configuration/catalog-site-xml
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-docs/src/main/sphinx/configuration/catalog-site-xml.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/configuration/catalog-site-xml.rst b/tajo-docs/src/main/sphinx/configuration/catalog-site-xml.rst
new file mode 100644
index 0000000..96273b2
--- /dev/null
+++ b/tajo-docs/src/main/sphinx/configuration/catalog-site-xml.rst
@@ -0,0 +1,3 @@
+*************************
+The catalog-site.xml File
+*************************
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-docs/src/main/sphinx/configuration/configuration_defaults.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/configuration/configuration_defaults.rst b/tajo-docs/src/main/sphinx/configuration/configuration_defaults.rst
deleted file mode 100644
index e3967b1..0000000
--- a/tajo-docs/src/main/sphinx/configuration/configuration_defaults.rst
+++ /dev/null
@@ -1,28 +0,0 @@
-**********************
-Configuration Defaults
-**********************
-
-Tajo Master Configuration Defaults
-====================================
-
-============================  ==============================================================  ===========   ===============  
-  Service Name                Config Property Name                                            Description   default address 
-============================  ==============================================================  ===========   ===============  
-Tajo Master Umbilical Rpc     tajo.master.umbilical-rpc.address                                             localhost:26001 
-Tajo Master Client Rpc        tajo.master.client-rpc.address                                                localhost:26002 
-Tajo Master Info Http         tajo.master.info-http.address                                                 0.0.0.0:26080
-Tajo Resource Tracker Rpc     tajo.resource-tracker.rpc.address                                             localhost:26003
-Tajo Catalog Client Rpc       tajo.catalog.client-rpc.address                                               localhost:26005
-============================  ==============================================================  ===========   ===============  
-
-====================================
-Tajo Worker Configuration Defaults
-====================================
-
-============================  ==============================================================  ===========   ===============  
-  Service Name                Config Property Name                                            Description   default address 
-============================  ==============================================================  ===========   ===============  
-Tajo Worker Peer Rpc          tajo.worker.peer-rpc.address                                                  0.0.0.0:28091   
-Tajo Worker Client Rpc        tajo.worker.client-rpc.address                                                0.0.0.0:28092   
-Tajo Worker Info Http         tajo.worker.info-http.address                                                 0.0.0.0:28080   
-============================  ==============================================================  ===========   ===============  
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-docs/src/main/sphinx/configuration/service_config_defaults.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/configuration/service_config_defaults.rst b/tajo-docs/src/main/sphinx/configuration/service_config_defaults.rst
new file mode 100644
index 0000000..aaaf34e
--- /dev/null
+++ b/tajo-docs/src/main/sphinx/configuration/service_config_defaults.rst
@@ -0,0 +1,28 @@
+**************************************
+Cluster Service Configuration Defaults 
+**************************************
+
+Tajo Master Configuration Defaults
+====================================
+
+============================  ==============================================================  ===========   ===============  
+  Service Name                Config Property Name                                            Description   default address 
+============================  ==============================================================  ===========   ===============  
+Tajo Master Umbilical Rpc     tajo.master.umbilical-rpc.address                                             localhost:26001 
+Tajo Master Client Rpc        tajo.master.client-rpc.address                                                localhost:26002 
+Tajo Master Info Http         tajo.master.info-http.address                                                 0.0.0.0:26080
+Tajo Resource Tracker Rpc     tajo.resource-tracker.rpc.address                                             localhost:26003
+Tajo Catalog Client Rpc       tajo.catalog.client-rpc.address                                               localhost:26005
+============================  ==============================================================  ===========   ===============  
+
+====================================
+Tajo Worker Configuration Defaults
+====================================
+
+============================  ==============================================================  ===========   ===============  
+  Service Name                Config Property Name                                            Description   default address 
+============================  ==============================================================  ===========   ===============  
+Tajo Worker Peer Rpc          tajo.worker.peer-rpc.address                                                  0.0.0.0:28091   
+Tajo Worker Client Rpc        tajo.worker.client-rpc.address                                                0.0.0.0:28092   
+Tajo Worker Info Http         tajo.worker.info-http.address                                                 0.0.0.0:28080   
+============================  ==============================================================  ===========   ===============  
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-docs/src/main/sphinx/configuration/tajo-site-xml.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/configuration/tajo-site-xml.rst b/tajo-docs/src/main/sphinx/configuration/tajo-site-xml.rst
new file mode 100644
index 0000000..d0c3597
--- /dev/null
+++ b/tajo-docs/src/main/sphinx/configuration/tajo-site-xml.rst
@@ -0,0 +1,24 @@
+**********************
+The tajo-site.xml File
+**********************
+
+To the ``core-site.xml`` file on every host in your cluster, you must add the following information:
+
+======================
+System Config
+======================
+
+
+
+======================
+Date/Time Settings
+======================
+
++--------------------------+----------------+--------------------------------------------------------+
+| Property Name            | Property Value | Descriptions                                           |
++==========================+================+========================================================+
+| tajo.timezone            | Time zone id   | Refer to :doc:`/time_zone`                             |
++--------------------------+----------------+--------------------------------------------------------+
+| tajo.datetime.date-order | Date order     | Determine date order. It should be one of YMD, DMY, MDY|
++--------------------------+----------------+--------------------------------------------------------+
+

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-docs/src/main/sphinx/index.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/index.rst b/tajo-docs/src/main/sphinx/index.rst
index bca4053..80cd842 100644
--- a/tajo-docs/src/main/sphinx/index.rst
+++ b/tajo-docs/src/main/sphinx/index.rst
@@ -33,6 +33,7 @@ Table of Contents:
    configuration
    tsql
    sql_language
+   time_zone
    functions
    table_management
    table_partitioning

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-docs/src/main/sphinx/table_management/table_overview.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/table_management/table_overview.rst b/tajo-docs/src/main/sphinx/table_management/table_overview.rst
index bb4b827..704d6aa 100644
--- a/tajo-docs/src/main/sphinx/table_management/table_overview.rst
+++ b/tajo-docs/src/main/sphinx/table_management/table_overview.rst
@@ -5,6 +5,14 @@ Overview of Tajo Tables
 Overview
 ========
 
+Managed Table
+================
+
+.. todo::
+
+External Table
+================
+
 .. todo::
 
 Table Properties
@@ -39,60 +47,17 @@ Compression
 
 Time zone
 ---------
-In Tajo, a table property ``timezone`` allows users to specify a time zone that the table uses for reading or writing. 
-When each table row are read or written, ```timestamp``` and ```time``` column values are adjusted by a given time zone if it is set. Time zone can be an abbreviation form like 'PST' or 'DST'. Also, it accepts an offset-based form like 'GMT+9' or UTC+9' or a location-based form like 'Asia/Seoul'. 
-
-Each table has one time zone, and many tables can have different time zones. Internally, Tajo translates all tables data to offset-based values. So, complex queries like join with multiple time zones work well.
-
-.. note::
-
-  In many cases, offset-based forms or locaion-based forms are recommanded. In order to know the list of time zones, please refer to `List of tz database time zones <http://en.wikipedia.org/wiki/List_of_tz_database_time_zones>`_
-
-.. note::
-
-  Java 6 does not recognize many location-based time zones and an offset-based timezone using the prefix 'UTC'. We highly recommanded using the offset-based time zone using the prefix 'GMT'. In other words, you should use 'GMT-7' instead of 'UTC-7' in Java 6.
-
-How time zone works in Tajo
-^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-For example, consider that there is a list of delimited text lines where each rows are written with ``Asia/Seoul`` time zone (i.e., GMT + 9).
-
-.. code-block:: text
-
-  1980-4-1 01:50:30.010|1980-04-01
-  80/4/1 1:50:30 AM|80/4/1
-  1980 April 1 1:50:30|1980-04-01
-
-
-In order to register the table, we should put a table property ``'timezone'='Asia/Seoul'`` in ``CREATE TABLE`` statement as follows:
-
-.. code-block:: sql
-
- CREATE EXTERNAL TABLE table1 (
-  t_timestamp  TIMESTAMP,
-  t_date    DATE
- ) USING TEXTFILE WITH('text.delimiter'='|', 'timezone'='ASIA/Seoul') LOCATION '/path-to-table/'
 
+In Tajo, a table property ``timezone`` allows users to specify a time zone that the table uses for reading or writing. 
 
-By default, ``tsql`` and ``TajoClient`` API use UTC time zone. So, timestamp values in the result are adjusted by the time zone offset. But, date is not adjusted because date type does not consider time zone.
+You can specify a table time zone as follows:
 
 .. code-block:: sql
 
-  default> SELECT * FROM table1
-  t_timestamp,            t_date
-  ----------------------------------
-  1980-03-31 16:50:30.01, 1980-04-01
-  1980-03-31 16:50:30   , 1980-04-01
-  1980-03-31 16:50:30   , 1980-04-01
-
-In addition, users can set client-side time zone by setting a session variable 'TZ'. It enables a client to translate timestamp or time values to user's time zoned ones.
-
-.. code-block:: sql
+   CREATE EXTERNAL TABLE table1 (
+    t_timestamp  TIMESTAMP,
+    t_date    DATE
+   ) USING TEXTFILE WITH('timezone'='ASIA/Seoul') LOCATION '/path-to-table/'
+ 
 
-  default> \set TZ 'Asia/Seoul'  
-  default> SELECT * FROM table1
-  t_timestamp,            t_date
-  ----------------------------------
-  1980-04-01 01:50:30.01, 1980-04-01
-  1980-04-01 01:50:30   , 1980-04-01
-  1980-04-01 01:50:30   , 1980-04-01
\ No newline at end of file
+In order to learn time zone, please refer to :doc:`/time_zone`.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-docs/src/main/sphinx/time_zone.rst
----------------------------------------------------------------------
diff --git a/tajo-docs/src/main/sphinx/time_zone.rst b/tajo-docs/src/main/sphinx/time_zone.rst
new file mode 100644
index 0000000..8225dee
--- /dev/null
+++ b/tajo-docs/src/main/sphinx/time_zone.rst
@@ -0,0 +1,129 @@
+******************
+Time Zone
+******************
+
+Time zone affects some data types (e.g., ``Timestamp`` and ``Time``) and operations (e.g., ``to_char``). Tables can have different time zones. Internally, Tajo translates all table rows to UTC values and processes them. It becomes easier for Tajo to handle multiple different time zones.
+
+In Tajo, there are some time zong settings.
+
+========================
+Server Cluster Time Zone
+========================
+
+One Tajo cluster has a system time zone which globally affects all tables in which the table property 'time zone' are not specified.
+
+You can set the system time zone in *conf/tajo-site.xml* file as follows:
+
+**tajo-site.xml**
+
+.. code-block:: xml  
+
+  <name>tajo.timezone</name>
+  <property>GMT+9</property>
+
+
+==================
+Table Time Zone
+==================
+
+In Tajo, a table property ``timezone`` allows users to specify a time zone that the table uses for reading or writing. 
+When each table row are read or written, ```timestamp``` and ```time``` column values are adjusted by a given time zone if it is set.
+
+You can specify a table time zone as follows:
+
+.. code-block:: sql
+
+   CREATE EXTERNAL TABLE table1 (
+    t_timestamp  TIMESTAMP,
+    t_date    DATE
+   ) USING TEXTFILE WITH('timezone'='ASIA/Seoul') LOCATION '/path-to-table/'
+ 
+
+In order to learn table properties, please refer to :doc:`/table_management/table_overview`.
+
+==================
+Client Time Zone
+==================
+
+Each client has its own time zone setting. It translates retrieved timestamp and time values by time zone. In order to set client time zone, you should set the session variable ``TIMEZONE``. There are some ways to set this session variable.
+
+In ``tsql``, you can use ``\set timezone`` meta command as follows:
+
+**tsql**
+
+.. code-block:: sh
+
+  default> \set timezone GMT+9
+
+
+The following ways use SQL statements. So, this way is available in ``tsql``, JDBC, and Tajo Java API.
+
+**SQL**
+
+.. code-block:: sql
+
+  SET TIME ZONE 'GMT+9';
+
+  or
+
+  SET SESSION TIMEZONE TO 'GMT+9';
+
+============
+Time Zone ID
+============
+
+Time zone can be an abbreviation form like 'PST' or 'DST'. Also, it accepts an offset-based form like 'GMT+9' or UTC+9' or a location-based form like 'Asia/Seoul'. 
+
+.. note::
+
+  In many cases, offset-based forms or locaion-based forms are recommanded. In order to know the list of time zones, please refer to `List of tz database time zones <http://en.wikipedia.org/wiki/List_of_tz_database_time_zones>`_
+
+.. note::
+
+  Java 6 does not recognize many location-based time zones and an offset-based timezone using the prefix 'UTC'. We highly recommanded using the offset-based time zone using the prefix 'GMT'. In other words, you should use 'GMT-7' instead of 'UTC-7' in Java 6.
+
+=====================
+Examples of Time Zone
+=====================
+
+For example, consider that there is a list of delimited text lines where each rows are written with ``Asia/Seoul`` time zone (i.e., GMT + 9).
+
+.. code-block:: text
+
+  1980-4-1 01:50:30.010|1980-04-01
+  80/4/1 1:50:30 AM|80/4/1
+  1980 April 1 1:50:30|1980-04-01
+
+
+In order to register the table, we should put a table property ``'timezone'='Asia/Seoul'`` in ``CREATE TABLE`` statement as follows:
+
+.. code-block:: sql
+
+ CREATE EXTERNAL TABLE table1 (
+  t_timestamp  TIMESTAMP,
+  t_date    DATE
+ ) USING TEXTFILE WITH('text.delimiter'='|', 'timezone'='ASIA/Seoul') LOCATION '/path-to-table/'
+
+
+By default, ``tsql`` and ``TajoClient`` API use UTC time zone. So, timestamp values in the result are adjusted by the time zone offset. But, date is not adjusted because date type does not consider time zone.
+
+.. code-block:: sql
+
+  default> SELECT * FROM table1
+  t_timestamp,            t_date
+  ----------------------------------
+  1980-03-31 16:50:30.01, 1980-04-01
+  1980-03-31 16:50:30   , 1980-04-01
+  1980-03-31 16:50:30   , 1980-04-01
+
+In addition, users can set client-side time zone by setting a session variable 'TZ'. It enables a client to translate timestamp or time values to user's time zoned ones.
+
+.. code-block:: sql
+
+  default> SET TIME ZONE 'Asia/Seoul'
+  default> SELECT * FROM table1
+  t_timestamp,            t_date
+  ----------------------------------
+  1980-04-01 01:50:30.01, 1980-04-01
+  1980-04-01 01:50:30   , 1980-04-01
+  1980-04-01 01:50:30   , 1980-04-01
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-plan/src/main/java/org/apache/tajo/plan/ExprAnnotator.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/ExprAnnotator.java b/tajo-plan/src/main/java/org/apache/tajo/plan/ExprAnnotator.java
index 62ba33c..fcbbb21 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/ExprAnnotator.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/ExprAnnotator.java
@@ -783,8 +783,8 @@ public class ExprAnnotator extends BaseAlgebraVisitor<ExprAnnotator.Context, Eva
 
       // some cast operation may require earlier evaluation with timezone.
       TimeZone tz = null;
-      if (ctx.queryContext.containsKey(SessionVars.TZ)) {
-        String tzId = ctx.queryContext.get(SessionVars.TZ);
+      if (ctx.queryContext.containsKey(SessionVars.TIMEZONE)) {
+        String tzId = ctx.queryContext.get(SessionVars.TIMEZONE);
         tz = TimeZone.getTimeZone(tzId);
       }
 
@@ -859,8 +859,8 @@ public class ExprAnnotator extends BaseAlgebraVisitor<ExprAnnotator.Context, Eva
     TimeMeta tm = new TimeMeta();
     DateTimeUtil.toJulianTimeMeta(timestamp, tm);
 
-    if (ctx.queryContext.containsKey(SessionVars.TZ)) {
-      TimeZone tz = TimeZone.getTimeZone(ctx.queryContext.get(SessionVars.TZ));
+    if (ctx.queryContext.containsKey(SessionVars.TIMEZONE)) {
+      TimeZone tz = TimeZone.getTimeZone(ctx.queryContext.get(SessionVars.TIMEZONE));
       DateTimeUtil.toUTCTimezone(tm, tz);
     }
 
@@ -889,8 +889,8 @@ public class ExprAnnotator extends BaseAlgebraVisitor<ExprAnnotator.Context, Eva
     TimeDatum timeDatum = new TimeDatum(time);
     TimeMeta tm = timeDatum.toTimeMeta();
 
-    if (ctx.queryContext.containsKey(SessionVars.TZ)) {
-      TimeZone tz = TimeZone.getTimeZone(ctx.queryContext.get(SessionVars.TZ));
+    if (ctx.queryContext.containsKey(SessionVars.TIMEZONE)) {
+      TimeZone tz = TimeZone.getTimeZone(ctx.queryContext.get(SessionVars.TIMEZONE));
       DateTimeUtil.toUTCTimezone(tm, tz);
     }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java b/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
index d153971..df45c3a 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/LogicalPlanner.java
@@ -95,8 +95,8 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
       this.evalOptimizer = evalOptimizer;
 
       // session's time zone
-      if (context.containsKey(SessionVars.TZ)) {
-        String timezoneId = context.get(SessionVars.TZ);
+      if (context.containsKey(SessionVars.TIMEZONE)) {
+        String timezoneId = context.get(SessionVars.TIMEZONE);
         timeZone = TimeZone.getTimeZone(timezoneId);
       }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CastEval.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CastEval.java b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CastEval.java
index 700913e..3cad842 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CastEval.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/expr/CastEval.java
@@ -21,7 +21,6 @@ package org.apache.tajo.plan.expr;
 import com.google.gson.annotations.Expose;
 import org.apache.tajo.OverridableConf;
 import org.apache.tajo.SessionVars;
-import org.apache.tajo.TajoConstants;
 import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.datum.Datum;
 import org.apache.tajo.datum.DatumFactory;
@@ -40,8 +39,8 @@ public class CastEval extends UnaryEval {
     super(EvalType.CAST, operand);
     this.target = target;
 
-    if (context.containsKey(SessionVars.TZ)) {
-      String timezoneId = context.get(SessionVars.TZ);
+    if (context.containsKey(SessionVars.TIMEZONE)) {
+      String timezoneId = context.get(SessionVars.TIMEZONE);
       timezone = TimeZone.getTimeZone(timezoneId);
     }
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-plan/src/main/java/org/apache/tajo/plan/util/PlannerUtil.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/util/PlannerUtil.java b/tajo-plan/src/main/java/org/apache/tajo/plan/util/PlannerUtil.java
index e6fa8de..abcef7a 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/util/PlannerUtil.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/util/PlannerUtil.java
@@ -25,12 +25,10 @@ import org.apache.tajo.OverridableConf;
 import org.apache.tajo.SessionVars;
 import org.apache.tajo.algebra.*;
 import org.apache.tajo.annotation.Nullable;
-import org.apache.tajo.catalog.Column;
-import org.apache.tajo.catalog.Schema;
-import org.apache.tajo.catalog.SchemaUtil;
-import org.apache.tajo.catalog.SortSpec;
+import org.apache.tajo.catalog.*;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.plan.*;
 import org.apache.tajo.plan.expr.*;
 import org.apache.tajo.plan.logical.*;
@@ -802,9 +800,23 @@ public class PlannerUtil {
         tableProperties.set(StorageConstants.TEXT_NULL, sessionVars.get(SessionVars.NULL_CHAR));
       }
 
-      if (sessionVars.containsKey(SessionVars.TZ)) {
-        tableProperties.set(StorageConstants.TIMEZONE, sessionVars.get(SessionVars.TZ));
+      if (sessionVars.containsKey(SessionVars.TIMEZONE)) {
+        tableProperties.set(StorageConstants.TIMEZONE, sessionVars.get(SessionVars.TIMEZONE));
       }
     }
   }
+
+  /**
+   * This method sets a set of table properties by System default configs.
+   * These properties are implicitly used to read or write rows in Table.
+   * Don't use this method for TableMeta to be stored in Catalog.
+   *
+   * @param systemConf System configuration
+   * @param meta TableMeta to be set
+   */
+  public static void applySystemDefaultToTableProperties(OverridableConf systemConf, TableMeta meta) {
+    if (!meta.containsOption(StorageConstants.TIMEZONE)) {
+      meta.putOption(StorageConstants.TIMEZONE, systemConf.get(SessionVars.TIMEZONE));
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-storage/src/main/java/org/apache/tajo/storage/StorageUtil.java
----------------------------------------------------------------------
diff --git a/tajo-storage/src/main/java/org/apache/tajo/storage/StorageUtil.java b/tajo-storage/src/main/java/org/apache/tajo/storage/StorageUtil.java
index 1789cc9..f998ebf 100644
--- a/tajo-storage/src/main/java/org/apache/tajo/storage/StorageUtil.java
+++ b/tajo-storage/src/main/java/org/apache/tajo/storage/StorageUtil.java
@@ -27,6 +27,7 @@ import org.apache.tajo.catalog.Column;
 import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.catalog.TableMeta;
 import org.apache.tajo.catalog.proto.CatalogProtos;
+import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.util.FileUtil;
 import org.apache.tajo.util.KeyValueSet;
 import parquet.hadoop.ParquetOutputFormat;

http://git-wip-us.apache.org/repos/asf/tajo/blob/758927e5/tajo-storage/src/main/java/org/apache/tajo/storage/TextSerializerDeserializer.java
----------------------------------------------------------------------
diff --git a/tajo-storage/src/main/java/org/apache/tajo/storage/TextSerializerDeserializer.java b/tajo-storage/src/main/java/org/apache/tajo/storage/TextSerializerDeserializer.java
index ce7b11d..ab8816b 100644
--- a/tajo-storage/src/main/java/org/apache/tajo/storage/TextSerializerDeserializer.java
+++ b/tajo-storage/src/main/java/org/apache/tajo/storage/TextSerializerDeserializer.java
@@ -20,6 +20,7 @@ package org.apache.tajo.storage;
 
 import com.google.protobuf.Message;
 import org.apache.commons.codec.binary.Base64;
+import org.apache.tajo.TajoConstants;
 import org.apache.tajo.catalog.Column;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.conf.TajoConf;
@@ -30,6 +31,7 @@ import org.apache.tajo.util.NumberUtil;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.TimeZone;
 
 // Compatibility with Apache Hive
 @Deprecated
@@ -85,12 +87,12 @@ public class TextSerializerDeserializer implements SerializerDeserializer {
         out.write(bytes);
         break;
       case TIME:
-        bytes = ((TimeDatum)datum).asChars(TajoConf.getSystemTimezone(), true).getBytes();
+        bytes = ((TimeDatum)datum).asChars(TimeZone.getDefault(), true).getBytes();
         length = bytes.length;
         out.write(bytes);
         break;
       case TIMESTAMP:
-        bytes = ((TimestampDatum)datum).asChars(TajoConf.getSystemTimezone(), true).getBytes();
+        bytes = ((TimestampDatum)datum).asChars(TimeZone.getDefault(), true).getBytes();
         length = bytes.length;
         out.write(bytes);
         break;


Mime
View raw message