Repository: hive Updated Branches: refs/heads/branch-1 8e8e39152 -> 012c99ff2
http://git-wip-us.apache.org/repos/asf/hive/blob/012c99ff/ql/src/test/org/apache/hadoop/hive/ql/parse/positive/TestTransactionStatement.java ---------------------------------------------------------------------- diff --git a/ql/src/test/org/apache/hadoop/hive/ql/parse/positive/TestTransactionStatement.java b/ql/src/test/org/apache/hadoop/hive/ql/parse/positive/TestTransactionStatement.java new file mode 100644 index 0000000..b7f8263 --- /dev/null +++ b/ql/src/test/org/apache/hadoop/hive/ql/parse/positive/TestTransactionStatement.java @@ -0,0 +1,102 @@ +/** + * 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.hadoop.hive.ql.parse.positive; + +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.ql.parse.ASTNode; +import org.apache.hadoop.hive.ql.parse.ParseDriver; +import org.apache.hadoop.hive.ql.parse.ParseException; +import org.apache.hadoop.hive.ql.parse.SemanticAnalyzer; +import org.apache.hadoop.hive.ql.parse.SemanticException; +import org.apache.hadoop.hive.ql.session.SessionState; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; + +/** + * Basic parser tests for multi-statement transactions + */ +public class TestTransactionStatement { + private static SessionState sessionState; + private ParseDriver pd; + + @BeforeClass + public static void initialize() { + HiveConf conf = new HiveConf(SemanticAnalyzer.class); + sessionState = SessionState.start(conf); + } + @AfterClass + public static void cleanUp() throws IOException { + if(sessionState != null) { + sessionState.close(); + } + } + + @Before + public void setup() throws SemanticException { + pd = new ParseDriver(); + } + + ASTNode parse(String query) throws ParseException { + ASTNode nd = pd.parse(query); + return (ASTNode) nd.getChild(0); + } + @Test + public void testTxnStart() throws ParseException { + ASTNode ast = parse("START TRANSACTION"); + Assert.assertEquals("AST doesn't match", + "TOK_START_TRANSACTION", ast.toStringTree()); + + ast = parse("START TRANSACTION ISOLATION LEVEL SNAPSHOT"); + Assert.assertEquals("AST doesn't match", + "(TOK_START_TRANSACTION (TOK_ISOLATION_LEVEL TOK_ISOLATION_SNAPSHOT))", ast.toStringTree()); + + ast = parse("START TRANSACTION READ ONLY"); + Assert.assertEquals("AST doesn't match", + "(TOK_START_TRANSACTION (TOK_TXN_ACCESS_MODE TOK_TXN_READ_ONLY))", ast.toStringTree()); + + ast = parse("START TRANSACTION READ WRITE, ISOLATION LEVEL SNAPSHOT"); + Assert.assertEquals("AST doesn't match", + "(TOK_START_TRANSACTION (TOK_TXN_ACCESS_MODE TOK_TXN_READ_WRITE) (TOK_ISOLATION_LEVEL TOK_ISOLATION_SNAPSHOT))", ast.toStringTree()); + + } + @Test + public void testTxnCommitRollback() throws ParseException { + ASTNode ast = parse("COMMIT"); + Assert.assertEquals("AST doesn't match", "TOK_COMMIT", ast.toStringTree()); + ast = parse("COMMIT WORK"); + Assert.assertEquals("AST doesn't match", "TOK_COMMIT", ast.toStringTree()); + ast = parse("ROLLBACK"); + Assert.assertEquals("AST doesn't match", "TOK_ROLLBACK", ast.toStringTree()); + ast = parse("ROLLBACK WORK"); + Assert.assertEquals("AST doesn't match", "TOK_ROLLBACK", ast.toStringTree()); + } + + @Test + public void testAutoCommit() throws ParseException { + ASTNode ast = parse("SET AUTOCOMMIT TRUE"); + Assert.assertEquals("AST doesn't match", "(TOK_SET_AUTOCOMMIT TOK_TRUE)", ast.toStringTree()); + ast = parse("SET AUTOCOMMIT FALSE"); + Assert.assertEquals("AST doesn't match", "(TOK_SET_AUTOCOMMIT TOK_FALSE)", ast.toStringTree()); + } +} http://git-wip-us.apache.org/repos/asf/hive/blob/012c99ff/ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java ---------------------------------------------------------------------- diff --git a/ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java b/ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java index 45ad22a..0bb8ebd 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java @@ -172,7 +172,7 @@ public class TestSessionState { // set state in current thread SessionState.start(ss1); SessionState ss2 = SessionState.get(); - ClassLoader loader2 = ss2.conf.getClassLoader(); + ClassLoader loader2 = ss2.getConf().getClassLoader(); System.out.println("Loader1:(Set in other thread) " + otherThread.loader); System.out.println("Loader2:(Set in SessionState.conf) " + loader2); http://git-wip-us.apache.org/repos/asf/hive/blob/012c99ff/ql/src/test/results/clientnegative/exchange_partition.q.out ---------------------------------------------------------------------- diff --git a/ql/src/test/results/clientnegative/exchange_partition.q.out b/ql/src/test/results/clientnegative/exchange_partition.q.out index b81fb99..8622615 100644 --- a/ql/src/test/results/clientnegative/exchange_partition.q.out +++ b/ql/src/test/results/clientnegative/exchange_partition.q.out @@ -50,5 +50,5 @@ POSTHOOK: type: SHOWPARTITIONS POSTHOOK: Input: default@ex_table2 part=part1 PREHOOK: query: ALTER TABLE ex_table1 EXCHANGE PARTITION (part='part1') WITH TABLE ex_table2 -PREHOOK: type: null +PREHOOK: type: ALTERTABLE_EXCHANGEPARTITION FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Got exception: java.io.IOException Cannot rename the source path. The destination path already exists.) http://git-wip-us.apache.org/repos/asf/hive/blob/012c99ff/ql/src/test/results/clientpositive/exchange_partition.q.out ---------------------------------------------------------------------- diff --git a/ql/src/test/results/clientpositive/exchange_partition.q.out b/ql/src/test/results/clientpositive/exchange_partition.q.out index 4ff1f6c..5b21eaf 100644 --- a/ql/src/test/results/clientpositive/exchange_partition.q.out +++ b/ql/src/test/results/clientpositive/exchange_partition.q.out @@ -59,9 +59,9 @@ POSTHOOK: type: SHOWPARTITIONS POSTHOOK: Input: ex2@exchange_part_test2 ds=2013-04-05 PREHOOK: query: ALTER TABLE ex1.exchange_part_test1 EXCHANGE PARTITION (ds='2013-04-05') WITH TABLE ex2.exchange_part_test2 -PREHOOK: type: null +PREHOOK: type: ALTERTABLE_EXCHANGEPARTITION POSTHOOK: query: ALTER TABLE ex1.exchange_part_test1 EXCHANGE PARTITION (ds='2013-04-05') WITH TABLE ex2.exchange_part_test2 -POSTHOOK: type: null +POSTHOOK: type: ALTERTABLE_EXCHANGEPARTITION PREHOOK: query: SHOW PARTITIONS ex1.exchange_part_test1 PREHOOK: type: SHOWPARTITIONS PREHOOK: Input: ex1@exchange_part_test1 http://git-wip-us.apache.org/repos/asf/hive/blob/012c99ff/ql/src/test/results/clientpositive/exchange_partition2.q.out ---------------------------------------------------------------------- diff --git a/ql/src/test/results/clientpositive/exchange_partition2.q.out b/ql/src/test/results/clientpositive/exchange_partition2.q.out index d47fb05..8c7c583 100644 --- a/ql/src/test/results/clientpositive/exchange_partition2.q.out +++ b/ql/src/test/results/clientpositive/exchange_partition2.q.out @@ -47,9 +47,9 @@ POSTHOOK: type: SHOWPARTITIONS POSTHOOK: Input: default@exchange_part_test2 ds=2013-04-05/hr=1 PREHOOK: query: ALTER TABLE exchange_part_test1 EXCHANGE PARTITION (ds='2013-04-05', hr='1') WITH TABLE exchange_part_test2 -PREHOOK: type: null +PREHOOK: type: ALTERTABLE_EXCHANGEPARTITION POSTHOOK: query: ALTER TABLE exchange_part_test1 EXCHANGE PARTITION (ds='2013-04-05', hr='1') WITH TABLE exchange_part_test2 -POSTHOOK: type: null +POSTHOOK: type: ALTERTABLE_EXCHANGEPARTITION PREHOOK: query: SHOW PARTITIONS exchange_part_test1 PREHOOK: type: SHOWPARTITIONS PREHOOK: Input: default@exchange_part_test1 http://git-wip-us.apache.org/repos/asf/hive/blob/012c99ff/ql/src/test/results/clientpositive/exchange_partition3.q.out ---------------------------------------------------------------------- diff --git a/ql/src/test/results/clientpositive/exchange_partition3.q.out b/ql/src/test/results/clientpositive/exchange_partition3.q.out index 3133ad7..3815861 100644 --- a/ql/src/test/results/clientpositive/exchange_partition3.q.out +++ b/ql/src/test/results/clientpositive/exchange_partition3.q.out @@ -64,10 +64,10 @@ ds=2013-04-05/hr=1 ds=2013-04-05/hr=2 PREHOOK: query: -- This will exchange both partitions hr=1 and hr=2 ALTER TABLE exchange_part_test1 EXCHANGE PARTITION (ds='2013-04-05') WITH TABLE exchange_part_test2 -PREHOOK: type: null +PREHOOK: type: ALTERTABLE_EXCHANGEPARTITION POSTHOOK: query: -- This will exchange both partitions hr=1 and hr=2 ALTER TABLE exchange_part_test1 EXCHANGE PARTITION (ds='2013-04-05') WITH TABLE exchange_part_test2 -POSTHOOK: type: null +POSTHOOK: type: ALTERTABLE_EXCHANGEPARTITION PREHOOK: query: SHOW PARTITIONS exchange_part_test1 PREHOOK: type: SHOWPARTITIONS PREHOOK: Input: default@exchange_part_test1