Repository: tajo Updated Branches: refs/heads/master 513aff422 -> 1e149127d
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/1e149127 Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/1e149127 Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/1e149127 Branch: refs/heads/master Commit: 1e149127d814b2d3f60b126238d702ca500a0c61 Parents: 513aff4 Author: Hyunsik Choi <[email protected]> Authored: Tue Oct 6 21:40:26 2015 -0700 Committer: Hyunsik Choi <[email protected]> Committed: Tue Oct 6 21:40:26 2015 -0700 ---------------------------------------------------------------------- CHANGES | 2 + .../org/apache/tajo/cli/tsql/TestTajoCli.java | 2 +- .../apache/tajo/engine/query/TestTimezone.java | 94 ++++++++++++++++++++ .../apache/tajo/engine/query/QueryContext.java | 2 - 4 files changed, 97 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tajo/blob/1e149127/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index a2f87a4..27fe2ce 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,8 @@ Release 0.12.0 - unreleased BUG FIXES + TAJO-1913: Timezone does not affect the constant folding. (hyunsik) + TAJO-1895: Add a maven profile to skip the unit tests of tajo-storage-pgsql. (hyunsik) http://git-wip-us.apache.org/repos/asf/tajo/blob/1e149127/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/1e149127/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/1e149127/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 20f4b40..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 @@ -45,8 +45,6 @@ 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<>(session.getAllVariables()); - // Among session variables, timezone must not be - copy.remove("TIMEZONE"); putAll(copy); }
