Repository: incubator-impala Updated Branches: refs/heads/master 025fd3bd7 -> 6c992f97f
IMPALA-3491: Use unique_database fixture in test_last_ddl_time_update.py. Testing: Ran the test locally in a loop 10 times, and did an exhaustive private test run on HDFS. Change-Id: I97e96217301078d48584c51218345dc96f6853a6 Reviewed-on: http://gerrit.cloudera.org:8080/3104 Reviewed-by: Alex Behm <[email protected]> Tested-by: Alex Behm <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/6c992f97 Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/6c992f97 Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/6c992f97 Branch: refs/heads/master Commit: 6c992f97f2f314a7837ac0c8b4fd7d8de0414806 Parents: 025fd3b Author: Alex Behm <[email protected]> Authored: Fri May 13 13:11:37 2016 -0700 Committer: Tim Armstrong <[email protected]> Committed: Tue Jun 7 22:30:08 2016 -0700 ---------------------------------------------------------------------- tests/metadata/test_last_ddl_time_update.py | 85 +++++++++++------------- 1 file changed, 37 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/6c992f97/tests/metadata/test_last_ddl_time_update.py ---------------------------------------------------------------------- diff --git a/tests/metadata/test_last_ddl_time_update.py b/tests/metadata/test_last_ddl_time_update.py index cbcb105..8de7fe5 100644 --- a/tests/metadata/test_last_ddl_time_update.py +++ b/tests/metadata/test_last_ddl_time_update.py @@ -1,22 +1,11 @@ # Copyright (c) 2012 Cloudera, Inc. All rights reserved. # Impala tests for DDL statements -import logging -import pytest -import sys import time -from subprocess import call from tests.common.skip import SkipIfS3 from tests.common.test_vector import * from tests.common.impala_test_suite import * from tests.util.filesystem_utils import WAREHOUSE, IS_S3 -DB_NAME = "metastore_update" -TABLE_NAME = "ddltime_test" -FULL_NAME = "%s.%s" % (DB_NAME, TABLE_NAME) -HIVE_LAST_DDL_TIME_PARAM_KEY = "transient_lastDdlTime" -TBL_LOC = "%s/t_part_tmp" % WAREHOUSE -DB_LOC = "%s/%s" % (WAREHOUSE, DB_NAME) - # Checks that ALTER and INSERT statements update the last DDL time of the modified table. class TestLastDdlTimeUpdate(ImpalaTestSuite): @@ -37,57 +26,56 @@ class TestLastDdlTimeUpdate(ImpalaTestSuite): # to regress here. cls.TestMatrix.add_constraint(lambda v: False) - def __cleanup(self): - self.execute_query("drop table if exists %s" % FULL_NAME) - self.execute_query("drop database if exists %s" % DB_NAME) - call(["hadoop", "fs", "-rm", "-r", "-f", TBL_LOC], shell=False) - - def setup_method(self, method): - self.__cleanup() - self.execute_query("create database if not exists %s LOCATION '%s'" % (DB_NAME, - DB_LOC)) - self.execute_query("create external table if not exists %s " - "(i int) partitioned by (j int, s string)" - % FULL_NAME) - - def teardown_method(self, method): - self.__cleanup() + def test_alter(self, vector, unique_database): + TBL_NAME = "alter_test_tbl" + FQ_TBL_NAME = unique_database + "." + TBL_NAME + self.execute_query("create external table %s (i int) " + "partitioned by (j int, s string)" % FQ_TBL_NAME) - @pytest.mark.execute_serially - def test_alter(self, vector): # add/drop partitions - self.run_test("alter table %s add partition (j=1, s='2012')" % FULL_NAME, True) + self.run_test("alter table %s add partition (j=1, s='2012')" % FQ_TBL_NAME, + unique_database, TBL_NAME, True) self.run_test("alter table %s add if not exists " - "partition (j=1, s='2012')" % FULL_NAME, False) - self.run_test("alter table %s drop partition (j=1, s='2012')" % FULL_NAME, True) + "partition (j=1, s='2012')" % FQ_TBL_NAME, + unique_database, TBL_NAME, False) + self.run_test("alter table %s drop partition (j=1, s='2012')" % FQ_TBL_NAME, + unique_database, TBL_NAME, True) self.run_test("alter table %s drop if exists " - "partition (j=2, s='2012')" % FULL_NAME, False) + "partition (j=2, s='2012')" % FQ_TBL_NAME, + unique_database, TBL_NAME, False) # rename columns - self.run_test("alter table %s change column i k int" % FULL_NAME, True) - self.run_test("alter table %s change column k i int" % FULL_NAME, True) + self.run_test("alter table %s change column i k int" % FQ_TBL_NAME, + unique_database, TBL_NAME, True) + self.run_test("alter table %s change column k i int" % FQ_TBL_NAME, + unique_database, TBL_NAME, True) # change location of table self.run_test("alter table %s set location " - "'%s'" % (FULL_NAME, TBL_LOC), True) + "'%s'" % (FQ_TBL_NAME, WAREHOUSE), + unique_database, TBL_NAME, True) # change format of table - self.run_test("alter table %s set fileformat textfile" % FULL_NAME, True) - - @pytest.mark.execute_serially - def test_insert(self, vector): + self.run_test("alter table %s set fileformat textfile" % FQ_TBL_NAME, + unique_database, TBL_NAME, True) + + def test_insert(self, vector, unique_database): + TBL_NAME = "insert_test_tbl" + FQ_TBL_NAME = unique_database + "." + TBL_NAME + self.execute_query("create external table %s (i int) " + "partitioned by (j int, s string)" % FQ_TBL_NAME) # static partition insert self.run_test("insert into %s partition(j=1, s='2012') " - "select 10" % FULL_NAME, True) + "select 10" % FQ_TBL_NAME, unique_database, TBL_NAME, True) # dynamic partition insert self.run_test("insert into %s partition(j, s) " - "select 10, 2, '2013'" % FULL_NAME, True) + "select 10, 2, '2013'" % FQ_TBL_NAME, unique_database, TBL_NAME, True) # dynamic partition insert changing no partitions (empty input) self.run_test("insert into %s partition(j, s) " "select * from (select 10 as i, 2 as j, '2013' as s) as t " - "where t.i < 10" % FULL_NAME, False) + "where t.i < 10" % FQ_TBL_NAME, unique_database, TBL_NAME, False) # dynamic partition insert modifying an existing partition self.run_test("insert into %s partition(j, s) " - "select 20, 1, '2012'" % FULL_NAME, False) + "select 20, 1, '2012'" % FQ_TBL_NAME, unique_database, TBL_NAME, False) - def run_test(self, query, expect_changed): + def run_test(self, query, db_name, table_name, expect_changed): """ Runs the given query (expected to be an ALTER or INSERT statement) and compares the last ddl time before and after executing the query. @@ -95,8 +83,10 @@ class TestLastDdlTimeUpdate(ImpalaTestSuite): otherwise we expect no change. """ + HIVE_LAST_DDL_TIME_PARAM_KEY = "transient_lastDdlTime" + # Get last DDL time before executing query. - table = self.hive_client.get_table(DB_NAME, TABLE_NAME) + table = self.hive_client.get_table(db_name, table_name) assert table is not None beforeDdlTime = table.parameters[HIVE_LAST_DDL_TIME_PARAM_KEY] @@ -104,10 +94,10 @@ class TestLastDdlTimeUpdate(ImpalaTestSuite): # Hive uses a seconds granularity on the last ddl time. time.sleep (2) - result = self.execute_query(query) + self.execute_query(query) # Get last ddl time after executing query . - table = self.hive_client.get_table(DB_NAME, TABLE_NAME) + table = self.hive_client.get_table(db_name, table_name) afterDdlTime = table.parameters[HIVE_LAST_DDL_TIME_PARAM_KEY] if expect_changed: @@ -115,4 +105,3 @@ class TestLastDdlTimeUpdate(ImpalaTestSuite): assert long(afterDdlTime) - long(beforeDdlTime) <= 20 else: assert long(afterDdlTime) == long(beforeDdlTime) -
