HAWQ-1044. Add normal path testcase for hawq register --repair
Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/04441128 Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/04441128 Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/04441128 Branch: refs/heads/master Commit: 0444112857c1e23a744c555f4d7b3353187fa749 Parents: f87c234 Author: Chunling Wang <[email protected]> Authored: Mon Sep 19 13:20:22 2016 +0800 Committer: Chunling Wang <[email protected]> Committed: Mon Sep 19 13:20:22 2016 +0800 ---------------------------------------------------------------------- .../test_hawq_register_usage2_case1.cpp | 3 +- .../test_hawq_register_usage2_case2.cpp | 7 +- .../test_hawq_register_usage2_case3.cpp | 68 ++++++++++++++++++++ .../ManagementTool/usage2case3/t_tpl_old_1.yml | 31 +++++++++ .../ManagementTool/usage2case3/t_tpl_old_2.yml | 33 ++++++++++ .../ManagementTool/usage2case3/t_tpl_old_3.yml | 21 ++++++ .../ManagementTool/usage2case3/t_tpl_old_4.yml | 23 +++++++ 7 files changed, 183 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04441128/src/test/feature/ManagementTool/test_hawq_register_usage2_case1.cpp ---------------------------------------------------------------------- diff --git a/src/test/feature/ManagementTool/test_hawq_register_usage2_case1.cpp b/src/test/feature/ManagementTool/test_hawq_register_usage2_case1.cpp index fa0d00d..c967bb0 100644 --- a/src/test/feature/ManagementTool/test_hawq_register_usage2_case1.cpp +++ b/src/test/feature/ManagementTool/test_hawq_register_usage2_case1.cpp @@ -42,7 +42,8 @@ TEST_F(TestHawqRegister, TestUsage2Case1Expected) { EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq extract -d %s -o t_%s.yml testhawqregister_testusage2case1expected.%s", HAWQ_DB, std::to_string(suffix).c_str(), t.c_str()))); EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq register -d %s -c t_%s.yml testhawqregister_testusage2case1expected.%s", HAWQ_DB, std::to_string(suffix).c_str(), nt.c_str()))); util.query(hawq::test::stringFormat("select * from %s;", nt.c_str()), 150); - EXPECT_EQ(0, Command::getCommandStatus("rm -rf t.yml")); + + EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("rm -rf t_%s.yml", std::to_string(suffix).c_str()))); util.execute(hawq::test::stringFormat("drop table %s;", t.c_str())); util.execute(hawq::test::stringFormat("drop table %s;", nt.c_str())); } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04441128/src/test/feature/ManagementTool/test_hawq_register_usage2_case2.cpp ---------------------------------------------------------------------- diff --git a/src/test/feature/ManagementTool/test_hawq_register_usage2_case2.cpp b/src/test/feature/ManagementTool/test_hawq_register_usage2_case2.cpp index 43fd837..ab0e101 100644 --- a/src/test/feature/ManagementTool/test_hawq_register_usage2_case2.cpp +++ b/src/test/feature/ManagementTool/test_hawq_register_usage2_case2.cpp @@ -43,7 +43,6 @@ TEST_F(TestHawqRegister, TestUsage2Case2Expected) { strs_src_dst["@DATABASE_OID@"]= getDatabaseOid(); strs_src_dst["@TABLE_OID@"]= getTableOid(t); frep.replace(t_yml_tpl, t_yml, strs_src_dst); - auto tmp = hawq::test::stringFormat("hawq register -d %s -c %s testhawqregister_testusage2case2expected.%s", HAWQ_DB, t_yml.c_str(), nt.c_str()); EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq register -d %s -c %s testhawqregister_testusage2case2expected.%s", HAWQ_DB, t_yml.c_str(), nt.c_str()))); util.query(hawq::test::stringFormat("select * from %s;", nt.c_str()), 200); @@ -56,9 +55,13 @@ TEST_F(TestHawqRegister, TestUsage2Case2Expected) { strs_src_dst["@TABLE_OID_OLD@"]= getTableOid(nt); strs_src_dst["@TABLE_OID_NEW@"]= getTableOid(t); frep.replace(t_yml_tpl_new, t_yml_new, strs_src_dst); - tmp = hawq::test::stringFormat("hawq register --force -d %s -c %s testhawqregister_testusage2case2expected.%s", HAWQ_DB, t_yml_new.c_str(), nt.c_str()); EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq register --force -d %s -c %s testhawqregister_testusage2case2expected.%s", HAWQ_DB, t_yml_new.c_str(), nt.c_str()))); util.query(hawq::test::stringFormat("select * from %s;", nt.c_str()), 150); + + EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("rm -rf %s", t_yml.c_str()))); + EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("rm -rf %s", t_yml_new.c_str()))); + util.execute(hawq::test::stringFormat("drop table %s;", t.c_str())); + util.execute(hawq::test::stringFormat("drop table %s;", nt.c_str())); } } } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04441128/src/test/feature/ManagementTool/test_hawq_register_usage2_case3.cpp ---------------------------------------------------------------------- diff --git a/src/test/feature/ManagementTool/test_hawq_register_usage2_case3.cpp b/src/test/feature/ManagementTool/test_hawq_register_usage2_case3.cpp new file mode 100644 index 0000000..e2dc613 --- /dev/null +++ b/src/test/feature/ManagementTool/test_hawq_register_usage2_case3.cpp @@ -0,0 +1,68 @@ +#include <string> + +#include "lib/command.h" +#include "lib/sql_util.h" +#include "lib/string_util.h" +#include "lib/hdfs_config.h" +#include "lib/file_replace.h" +#include "test_hawq_register.h" + +#include "gtest/gtest.h" + +using std::string; +using hawq::test::SQLUtility; +using hawq::test::Command; +using hawq::test::HdfsConfig; + +TEST_F(TestHawqRegister, TestUsage2Case3Expected) { + SQLUtility util; + string test_root(util.getTestRootPath()); + std::vector<string> create_table_matrix = {"distributed by (i)", "distributed randomly"}; + std::vector<string> fmt_matrix = {"row", "parquet"}; + int suffix=0; + + for (auto & ddl : create_table_matrix) { + for (auto & fmt : fmt_matrix) { + suffix++; + string t_yml_tpl_old(hawq::test::stringFormat("%s/ManagementTool/usage2case3/t_tpl_old_%s.yml", test_root.c_str(), std::to_string(suffix).c_str())); + string t_yml_old(hawq::test::stringFormat("%s/ManagementTool/usage2case3/t_old_%s.yml", test_root.c_str(), std::to_string(suffix).c_str())); + auto t = hawq::test::stringFormat("t_usage2_case3_%s", std::to_string(suffix).c_str()); + auto nt = hawq::test::stringFormat("nt_usage2_case3_%s", std::to_string(suffix).c_str()); + util.execute(hawq::test::stringFormat("drop table if exists %s;", t.c_str())); + util.execute(hawq::test::stringFormat("drop table if exists %s;", nt.c_str())); + + // hawq register -d hawq_feature_test -c t_usage2_case3_#.yml nt_usage2_case3_#, where nt_usage2_case3_# does not exist + util.execute(hawq::test::stringFormat("create table %s(i int) with (appendonly=true, orientation=%s) %s;", t.c_str(), fmt.c_str(), ddl.c_str())); + util.execute(hawq::test::stringFormat("insert into %s select generate_series(1, 100);", t.c_str())); + util.execute(hawq::test::stringFormat("insert into %s select generate_series(101, 200);", t.c_str())); + util.query(hawq::test::stringFormat("select * from %s;", t.c_str()), 200); + EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq extract -d %s -o t_%s.yml testhawqregister_testusage2case3expected.%s", HAWQ_DB, std::to_string(suffix).c_str(), t.c_str()))); + EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq register -d %s -c t_%s.yml testhawqregister_testusage2case3expected.%s", HAWQ_DB, std::to_string(suffix).c_str(), nt.c_str()))); + util.query(hawq::test::stringFormat("select * from %s;", nt.c_str()), 200); + + // hawq register -d hawq_feature_test -c t_usage2_case3_#.yml nt_usage2_case3_#, where nt_usage2_case3_# exists + util.execute(hawq::test::stringFormat("drop table if exists %s;", t.c_str())); + util.execute(hawq::test::stringFormat("create table %s(i int) with (appendonly=true, orientation=%s) %s;", t.c_str(), fmt.c_str(), ddl.c_str())); + util.execute(hawq::test::stringFormat("insert into %s select generate_series(101, 150);", t.c_str())); + util.query(hawq::test::stringFormat("select * from %s;", t.c_str()), 50); + EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq extract -d %s -o t_%s.yml testhawqregister_testusage2case3expected.%s", HAWQ_DB, std::to_string(suffix).c_str(), t.c_str()))); + EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq register -d %s -c t_%s.yml testhawqregister_testusage2case3expected.%s", HAWQ_DB, std::to_string(suffix).c_str(), nt.c_str()))); + util.query(hawq::test::stringFormat("select * from %s;", nt.c_str()), 250); + + // hawq register --repair -d hawq_feature_test -c t_old_#.yml nt_usage2_case3_# + hawq::test::FileReplace frep; + std::unordered_map<std::string, std::string> strs_src_dst; + strs_src_dst["@DATABASE_OID@"]= getDatabaseOid(); + strs_src_dst["@TABLE_OID@"]= getTableOid(nt); + frep.replace(t_yml_tpl_old, t_yml_old, strs_src_dst); + EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("hawq register --repair -d %s -c %s testhawqregister_testusage2case3expected.%s", HAWQ_DB, t_yml_old.c_str(), nt.c_str()))); + util.query(hawq::test::stringFormat("select * from %s;", nt.c_str()), 100); + + EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("rm -rf t_%s.yml", std::to_string(suffix).c_str()))); + EXPECT_EQ(0, Command::getCommandStatus(hawq::test::stringFormat("rm -rf %s", t_yml_old.c_str()))); + util.execute(hawq::test::stringFormat("drop table %s;", t.c_str())); + util.execute(hawq::test::stringFormat("drop table %s;", nt.c_str())); + } + } +} + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04441128/src/test/feature/ManagementTool/usage2case3/t_tpl_old_1.yml ---------------------------------------------------------------------- diff --git a/src/test/feature/ManagementTool/usage2case3/t_tpl_old_1.yml b/src/test/feature/ManagementTool/usage2case3/t_tpl_old_1.yml new file mode 100644 index 0000000..573c66e --- /dev/null +++ b/src/test/feature/ManagementTool/usage2case3/t_tpl_old_1.yml @@ -0,0 +1,31 @@ +AO_FileLocations: + Blocksize: 32768 + Checksum: false + CompressionLevel: 0 + CompressionType: null + Files: + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/1 + size: 176 + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/2 + size: 168 + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/3 + size: 192 + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/4 + size: 168 + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/5 + size: 192 + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/6 + size: 216 +AO_Schema: +- name: i + type: int4 +Bucketnum: 6 +DBVersion: PostgreSQL 8.2.15 (Greenplum Database 4.2.0 build 1) (HAWQ 2.0.1.0 build + dev) on x86_64-apple-darwin14.5.0, compiled by GCC Apple LLVM version 6.1.0 (clang-602.0.53) + (based on LLVM 3.6.0svn) compiled on Jul 6 2016 10:22:33 +DFS_URL: hdfs://localhost:8020 +Distribution_Policy: DISTRIBUTED BY (i) +Encoding: UTF8 +FileFormat: AO +TableName: public.t_1 +Version: 1.0.0 http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04441128/src/test/feature/ManagementTool/usage2case3/t_tpl_old_2.yml ---------------------------------------------------------------------- diff --git a/src/test/feature/ManagementTool/usage2case3/t_tpl_old_2.yml b/src/test/feature/ManagementTool/usage2case3/t_tpl_old_2.yml new file mode 100644 index 0000000..d3388a0 --- /dev/null +++ b/src/test/feature/ManagementTool/usage2case3/t_tpl_old_2.yml @@ -0,0 +1,33 @@ +Bucketnum: 6 +DBVersion: PostgreSQL 8.2.15 (Greenplum Database 4.2.0 build 1) (HAWQ 2.0.1.0 build + dev) on x86_64-apple-darwin14.5.0, compiled by GCC Apple LLVM version 6.1.0 (clang-602.0.53) + (based on LLVM 3.6.0svn) compiled on Jul 6 2016 10:22:33 +DFS_URL: hdfs://localhost:8020 +Distribution_Policy: DISTRIBUTED BY (i) +Encoding: UTF8 +FileFormat: Parquet +Parquet_FileLocations: + Checksum: false + CompressionLevel: 0 + CompressionType: null + EnableDictionary: false + Files: + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/1 + size: 254 + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/2 + size: 250 + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/3 + size: 258 + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/4 + size: 250 + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/5 + size: 258 + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/6 + size: 270 + PageSize: 1048576 + RowGroupSize: 8388608 +Parquet_Schema: +- name: i + type: int4 +TableName: public.t_2 +Version: 1.0.0 http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04441128/src/test/feature/ManagementTool/usage2case3/t_tpl_old_3.yml ---------------------------------------------------------------------- diff --git a/src/test/feature/ManagementTool/usage2case3/t_tpl_old_3.yml b/src/test/feature/ManagementTool/usage2case3/t_tpl_old_3.yml new file mode 100644 index 0000000..b1eb162 --- /dev/null +++ b/src/test/feature/ManagementTool/usage2case3/t_tpl_old_3.yml @@ -0,0 +1,21 @@ +AO_FileLocations: + Blocksize: 32768 + Checksum: false + CompressionLevel: 0 + CompressionType: null + Files: + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/1 + size: 1016 +AO_Schema: +- name: i + type: int4 +Bucketnum: 6 +DBVersion: PostgreSQL 8.2.15 (Greenplum Database 4.2.0 build 1) (HAWQ 2.0.1.0 build + dev) on x86_64-apple-darwin14.5.0, compiled by GCC Apple LLVM version 6.1.0 (clang-602.0.53) + (based on LLVM 3.6.0svn) compiled on Jul 6 2016 10:22:33 +DFS_URL: hdfs://localhost:8020 +Distribution_Policy: DISTRIBUTED RANDOMLY +Encoding: UTF8 +FileFormat: AO +TableName: public.t_3 +Version: 1.0.0 http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/04441128/src/test/feature/ManagementTool/usage2case3/t_tpl_old_4.yml ---------------------------------------------------------------------- diff --git a/src/test/feature/ManagementTool/usage2case3/t_tpl_old_4.yml b/src/test/feature/ManagementTool/usage2case3/t_tpl_old_4.yml new file mode 100644 index 0000000..39dee63 --- /dev/null +++ b/src/test/feature/ManagementTool/usage2case3/t_tpl_old_4.yml @@ -0,0 +1,23 @@ +Bucketnum: 6 +DBVersion: PostgreSQL 8.2.15 (Greenplum Database 4.2.0 build 1) (HAWQ 2.0.1.0 build + dev) on x86_64-apple-darwin14.5.0, compiled by GCC Apple LLVM version 6.1.0 (clang-602.0.53) + (based on LLVM 3.6.0svn) compiled on Jul 6 2016 10:22:33 +DFS_URL: hdfs://localhost:8020 +Distribution_Policy: DISTRIBUTED RANDOMLY +Encoding: UTF8 +FileFormat: Parquet +Parquet_FileLocations: + Checksum: false + CompressionLevel: 0 + CompressionType: null + EnableDictionary: false + Files: + - path: /hawq_default/16385/@DATABASE_OID@/@TABLE_OID@/1 + size: 596 + PageSize: 1048576 + RowGroupSize: 8388608 +Parquet_Schema: +- name: i + type: int4 +TableName: public.t_4 +Version: 1.0.0
