Repository: tajo Updated Branches: refs/heads/branch-0.11.0 00953fd01 -> c54d27568
TAJO-1913: Timezone does not affect the constant folding. Closes #810 Project: http://git-wip-us.apache.org/repos/asf/tajo/repo Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/c54d2756 Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/c54d2756 Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/c54d2756 Branch: refs/heads/branch-0.11.0 Commit: c54d27568c529b60f6bf9ddc5ff50b8d54a048f2 Parents: 00953fd Author: Hyunsik Choi <[email protected]> Authored: Tue Oct 6 21:40:26 2015 -0700 Committer: Hyunsik Choi <[email protected]> Committed: Tue Oct 6 21:49:06 2015 -0700 ---------------------------------------------------------------------- CHANGES | 4 +- .../org/apache/tajo/cli/tsql/TestTajoCli.java | 2 +- .../apache/tajo/engine/query/TestTimezone.java | 94 ++++++++++++++++++++ .../apache/tajo/engine/query/QueryContext.java | 4 +- 4 files changed, 99 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tajo/blob/c54d2756/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 9629c78..0355cc9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,6 @@ Tajo Change Log -Release 0.11.0 - Released +Release 0.11.0 - unreleased NEW FEATURES @@ -284,6 +284,8 @@ Release 0.11.0 - Released (Contributed by navis, Committed by hyunsik) BUG FIXES + + TAJO-1913: Timezone does not affect the constant folding. (hyunsik) TAJO-1901: Repair partition throws ArrayIndexOutOfBoundsException occasionally. (Contributed by jaehwa, committed by hyunsik) http://git-wip-us.apache.org/repos/asf/tajo/blob/c54d2756/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java index f265e55..0503d5d 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java @@ -446,7 +446,7 @@ public class TestTajoCli { tajoCli.executeScript("select * from " + tableName); String consoleResult = new String(out.toByteArray()); tajoCli.executeScript("DROP TABLE " + tableName + " PURGE"); - assertTrue(consoleResult.contains("1970-01-01 01:00:00")); + assertTrue(consoleResult.contains("1970-01-01 00:00:00")); } @Test(timeout = 3000) http://git-wip-us.apache.org/repos/asf/tajo/blob/c54d2756/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestTimezone.java ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestTimezone.java b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestTimezone.java new file mode 100644 index 0000000..1167c16 --- /dev/null +++ b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestTimezone.java @@ -0,0 +1,94 @@ +/* + * 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.engine.query; + +import org.apache.tajo.QueryTestCaseBase; +import org.apache.tajo.client.ResultSetUtil; +import org.apache.tajo.exception.TajoException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.Collection; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + +@RunWith(Parameterized.class) +public class TestTimezone extends QueryTestCaseBase { + private String timezone; + + public TestTimezone(String timezone) { + this.timezone = timezone; + } + + @Test + public void testToTimestamp() throws TajoException, SQLException, IOException { + executeString(String.format("SET TIME ZONE TO '%s'", timezone)).close(); + + try (ResultSet res = + executeString("select to_timestamp('2015/08/12 14:00:00', 'FMYYYY/FMMM/FMDD HH24:FMMI:FMSS');")) { + assertTrue(res.next()); + assertEquals("2015-08-12 14:00:00", res.getString(1)); + } + } + + @Test + public void testCastWithTimezone() throws TajoException, SQLException, IOException { + executeString(String.format("SET TIME ZONE TO '%s'", timezone)).close(); + + try (ResultSet res = executeString("select CAST('2015-08-12 14:00:00' AS timestamp);")) { + assertTrue(res.next()); + assertEquals("2015-08-12 14:00:00", res.getString(1)); + } + } + + @Test + public void testCastWithTimezone2() throws TajoException, SQLException, IOException { + executeString(String.format("SET TIME ZONE TO '%s'", timezone)).close(); + + try (ResultSet res = executeString("select '2015-08-12 14:00:00'::TIMESTAMP;")) { + assertTrue(res.next()); + assertEquals("2015-08-12 14:00:00", res.getString(1)); + } + } + + @Test + public void testToChar() throws TajoException, SQLException, IOException { + executeString(String.format("SET TIME ZONE TO '%s'", timezone)).close(); + + try (ResultSet res = executeString("select to_char('2015-08-12 14:00:00'::TIMESTAMP, 'yyyy-mm-dd hh24:mi:ss')")) { + assertTrue(res.next()); + assertEquals("2015-08-12 14:00:00", res.getString(1)); + } + } + + @Parameterized.Parameters + public static Collection<Object []> getParameters() { + return Arrays.asList(new Object[][]{ + {"GMT"}, + {"GMT+9"} + }); + } +} http://git-wip-us.apache.org/repos/asf/tajo/blob/c54d2756/tajo-core/src/main/java/org/apache/tajo/engine/query/QueryContext.java ---------------------------------------------------------------------- diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/query/QueryContext.java b/tajo-core/src/main/java/org/apache/tajo/engine/query/QueryContext.java index 7279e8e..f35249e 100644 --- a/tajo-core/src/main/java/org/apache/tajo/engine/query/QueryContext.java +++ b/tajo-core/src/main/java/org/apache/tajo/engine/query/QueryContext.java @@ -44,9 +44,7 @@ public class QueryContext extends OverridableConf { public QueryContext(TajoConf conf, Session session) { super(conf, ConfigKey.ConfigType.QUERY, ConfigKey.ConfigType.SESSION); - Map<String, String> copy = new HashMap<String, String>(session.getAllVariables()); - // Among session variables, timezone must not be - copy.remove("TIMEZONE"); + Map<String, String> copy = new HashMap<>(session.getAllVariables()); putAll(copy); }
