hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject incubator-hawq git commit: HAWQ-1011. Check whether the table to be registered is existed
Date Fri, 26 Aug 2016 02:53:12 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/master 532671a9d -> 9c7920cbf


HAWQ-1011. Check whether the table to be registered is existed


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/9c7920cb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/9c7920cb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/9c7920cb

Branch: refs/heads/master
Commit: 9c7920cbf9fda6002f3493b808d88957c7ea083e
Parents: 532671a
Author: xunzhang <xunzhangthu@gmail.com>
Authored: Thu Aug 25 11:35:28 2016 +0800
Committer: rlei <rlei@pivotal.io>
Committed: Fri Aug 26 10:52:45 2016 +0800

----------------------------------------------------------------------
 .../ManagementTool/test_hawq_register.cpp       | 22 +++++++++++++++-----
 tools/bin/hawqregister                          | 13 +++++++++++-
 2 files changed, 29 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9c7920cb/src/test/feature/ManagementTool/test_hawq_register.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/ManagementTool/test_hawq_register.cpp b/src/test/feature/ManagementTool/test_hawq_register.cpp
index 434f817..f7f67c0 100644
--- a/src/test/feature/ManagementTool/test_hawq_register.cpp
+++ b/src/test/feature/ManagementTool/test_hawq_register.cpp
@@ -240,6 +240,7 @@ TEST_F(TestHawqRegister, TestUsage1ParquetRandomly2) {
 TEST_F(TestHawqRegister, TestUsage2ParquetRandomly) {
   SQLUtility util;
   util.execute("drop table if exists t;");
+  util.execute("drop table if exists nt;");
   util.execute("create table t(i int) with (appendonly=true, orientation=parquet) distributed
randomly;");
   util.execute("insert into t values(1), (2), (3);");
   util.query("select * from t;", 3);
@@ -334,10 +335,21 @@ TEST_F(TestHawqRegister, TestEmptyTable) {
 TEST_F(TestHawqRegister, TestIncorrectYaml) {
   SQLUtility util;
   string filePath = util.getTestRootPath() + "/ManagementTool/";
-  EXPECT_EQ(0, hawq::test::endsWith(Command::getCommandOutput("hawq register -d " + (string)
HAWQ_DB + " -c " + filePath + "incorrect1.yml xx"), "attribute does not exist."));
-  EXPECT_EQ(0, hawq::test::endsWith(Command::getCommandOutput("hawq register -d " + (string)
HAWQ_DB + " -c " + filePath + "incorrect2.yml xx"), "attribute does not exist."));
-  EXPECT_EQ(0, hawq::test::endsWith(Command::getCommandOutput("hawq register -d " + (string)
HAWQ_DB + " -c " + filePath + "incorrect3.yml xx"), "attribute does not exist."));
-  EXPECT_EQ(0, hawq::test::endsWith(Command::getCommandOutput("hawq register -d " + (string)
HAWQ_DB + " -c " + filePath + "incorrect4.yml xx"), "attribute does not exist."));
-  EXPECT_EQ(0, hawq::test::endsWith(Command::getCommandOutput("hawq register -d " + (string)
HAWQ_DB + " -c " + filePath + "incorrect5.yml xx"), "attribute does not exist."));
+  EXPECT_EQ(1, Command::getCommandStatus("hawq register -d " + (string) HAWQ_DB + " -c "
+ filePath + "incorrect1.yml xx"));
+  EXPECT_EQ(1, Command::getCommandStatus("hawq register -d " + (string) HAWQ_DB + " -c "
+ filePath + "incorrect2.yml xx"));
+  EXPECT_EQ(1, Command::getCommandStatus("hawq register -d " + (string) HAWQ_DB + " -c "
+ filePath + "incorrect3.yml xx"));
+  EXPECT_EQ(1, Command::getCommandStatus("hawq register -d " + (string) HAWQ_DB + " -c "
+ filePath + "incorrect4.yml xx"));
+  EXPECT_EQ(1, Command::getCommandStatus("hawq register -d " + (string) HAWQ_DB + " -c "
+ filePath + "incorrect5.yml xx"));
   EXPECT_EQ(1, Command::getCommandStatus("hawq register -d " + (string) HAWQ_DB + " -c "
+ filePath + "incorrect6.yml xx"));
 }
+
+TEST_F(TestHawqRegister, TestCreateExistedTable) {
+  SQLUtility util;
+  util.execute("drop table if exists t10;");
+  util.execute("create table t10(i int) with (appendonly=true, orientation=row) distributed
by (i);");
+  util.execute("insert into t10 values(1), (2), (3);");
+  EXPECT_EQ(0, Command::getCommandStatus("hawq extract -d " + (string) HAWQ_DB + " -o t10.yml
testhawqregister_testcreateexistedtable.t10"));
+  auto tmp = Command::getCommandOutput("hawq register -d " + (string) HAWQ_DB + " -c t10.yml
testhawqregister_testcreateexistedtable.t10");
+  auto out = hawq::test::trim(hawq::test::trimNewLine(tmp));
+  EXPECT_EQ(1, hawq::test::endsWith(out, "has already existed."));
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9c7920cb/tools/bin/hawqregister
----------------------------------------------------------------------
diff --git a/tools/bin/hawqregister b/tools/bin/hawqregister
index 26284a8..96b932d 100755
--- a/tools/bin/hawqregister
+++ b/tools/bin/hawqregister
@@ -106,7 +106,6 @@ def register_yaml_dict_check(D):
                 sys.exit(1)
 
 
-
 def option_parser_yml(yml_file):
     import yaml
     with open(yml_file, 'r') as f:
@@ -131,6 +130,18 @@ def option_parser_yml(yml_file):
 
 def create_table(dburl, tablename, schema_info, fmt, distrbution_policy, file_locations):
     try:
+        query = "select count(*) from pg_class where relname = '%s'" % tablename.split('.')[-1].lower()
+        conn = dbconn.connect(dburl, False)
+        rows = dbconn.execSQL(conn, query)
+        conn.commit()
+        for row in rows:
+            if row[0] != 0:
+                logger.error("Register failed: table %s has already existed." % tablename)
+                sys.exit(1)
+    except DatabaseError, ex:
+        logger.error('Failed to execute query "%s"' % query)
+        sys.exit(1)
+    try:
         schema = ','.join([k['name'] + ' ' + k['type'] for k in schema_info])
         fmt = 'ROW' if fmt == 'AO' else fmt
         if fmt == 'ROW':


Mime
View raw message