Repository: incubator-hawq Updated Branches: refs/heads/master e5679ac4c -> a1ab4ab55
HAWQ-1144. Register to a multi-level partition table should fail. Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/a1ab4ab5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/a1ab4ab5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/a1ab4ab5 Branch: refs/heads/master Commit: a1ab4ab55d9c090b2c05983b9b86b51140a8f1c5 Parents: e5679ac Author: Wen Lin <[email protected]> Authored: Fri Nov 4 17:13:28 2016 +0800 Committer: Wen Lin <[email protected]> Committed: Fri Nov 4 17:13:28 2016 +0800 ---------------------------------------------------------------------- .../test_hawq_register_partition.cpp | 24 ++++++++++++++++++++ tools/bin/hawqregister | 15 ++++++++++++ 2 files changed, 39 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1ab4ab5/src/test/feature/ManagementTool/test_hawq_register_partition.cpp ---------------------------------------------------------------------- diff --git a/src/test/feature/ManagementTool/test_hawq_register_partition.cpp b/src/test/feature/ManagementTool/test_hawq_register_partition.cpp index 3decf6e..bb5e970 100644 --- a/src/test/feature/ManagementTool/test_hawq_register_partition.cpp +++ b/src/test/feature/ManagementTool/test_hawq_register_partition.cpp @@ -213,3 +213,27 @@ TEST_F(TestHawqRegister, TestPartitionTableExistsTableFileNotExists) { runYamlCaseTableExistsPartition("testpartitiontableexiststablefilenotexists", "partition/table_exists_table_file_not_exists"); } +TEST_F(TestHawqRegister, TestPartitionTableMultilevel) { + SQLUtility util; + util.execute("drop table if exists sales;"); + util.execute("drop table if exists nsales;"); + // create a partition table and extract it + util.execute("CREATE TABLE sales (trans_id int, date date, region text) DISTRIBUTED BY (trans_id) PARTITION BY RANGE (date) \ " + "(START (date '2011-01-01') INCLUSIVE END (date '2011-05-01') EXCLUSIVE EVERY (INTERVAL '1 month'), DEFAULT PARTITION outlying_dates );"); + util.execute("insert into sales values(1, '2011-1-15', 'usa');"); + + EXPECT_EQ(0, Command::getCommandStatus("hawq extract -d " + (string) HAWQ_DB + " -o sales.yml testhawqregister_testpartitiontablemultilevel.sales")); + + // create a two-level partition table + util.execute("CREATE TABLE nsales (trans_id int, date date, region text) DISTRIBUTED BY (trans_id) PARTITION BY RANGE (date) \ " + "SUBPARTITION BY LIST (region) SUBPARTITION TEMPLATE ( SUBPARTITION usa VALUES ('usa'), SUBPARTITION asia VALUES ('asia'),\ " + "SUBPARTITION europe VALUES ('europe'), DEFAULT SUBPARTITION other_regions) (START (date '2011-01-01') INCLUSIVE END (date '2011-06-01') EXCLUSIVE \ " + "EVERY (INTERVAL '1 month'), DEFAULT PARTITION outlying_dates );"); + + // should fail since multi-level partition is not supported + EXPECT_EQ(1, Command::getCommandStatus("hawq register -d " + (string) HAWQ_DB + " -c sales.yml testhawqregister_testpartitiontablemultilevel.nsales")); + + EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("rm -rf sales.yml"))); + util.execute("drop table nsales;"); + util.execute("drop table sales;"); +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1ab4ab5/tools/bin/hawqregister ---------------------------------------------------------------------- diff --git a/tools/bin/hawqregister b/tools/bin/hawqregister index 6ef21f2..6817983 100755 --- a/tools/bin/hawqregister +++ b/tools/bin/hawqregister @@ -294,6 +294,11 @@ class GpRegisterAccessor(object): query = "SELECT partitiontablename, partitionboundary FROM pg_partitions WHERE partitionschemaname = '%s' and tablename = '%s'" % (schemaname, tablename) return self.exec_query(query) + def get_partition_parent(self, tablename): + schemaname, tablename = tablename_handler(tablename) + query = "SELECT partitiontablename, parentpartitiontablename FROM pg_partitions WHERE partitionschemaname = '%s' and tablename = '%s'" % (schemaname, tablename) + return self.exec_query(query) + def get_partitionby(self, tablename): schemaname, tablename = tablename_handler(tablename) query = "SELECT partitionschemaname, partitiontablename, partitionname, partitiontype, parentpartitiontablename, partitionboundary FROM pg_partitions WHERE schemaname = '%s' and tablename='%s';" % (schemaname, tablename) @@ -966,6 +971,9 @@ class HawqRegisterPartition(HawqRegister): dic[ele['partitionboundary']] = ele['partitiontablename'] return dic + def _get_partition_parent(self): + return self.accessor.get_partition_parent(self.dst_table_name) + def _check_partitionby(self): def get_partitionby(): return self.accessor.get_partitionby(self.dst_table_name) @@ -1015,6 +1023,13 @@ class HawqRegisterPartition(HawqRegister): self._check_partitionby() self._check_partition_num() partitions = self._get_partition_info() + partitions_parents = self._get_partition_parent() + + # check if it is a multi-level partition table + if any(p['parentpartitiontablename'] for p in partitions_parents): + logger.error('Multi-level partition table is not supported!') + sys.exit(1) + self.queries = "set allow_system_table_mods='dml';" self.queries += "begin transaction;" self._check_duplicate_constraint()
