Repository: incubator-hawq
Updated Branches:
  refs/heads/master 27147c570 -> b38fb124a


HAWQ-758. Refactor insert checkinstall cases using new test framework


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

Branch: refs/heads/master
Commit: b38fb124affbb2a6fe73c8f6661fc6243513e017
Parents: 27147c5
Author: YI JIN <[email protected]>
Authored: Thu Jun 2 14:55:20 2016 +1000
Committer: YI JIN <[email protected]>
Committed: Thu Jun 2 14:55:20 2016 +1000

----------------------------------------------------------------------
 .../feature/query/ans/insert-appendonlytrue.ans |   8 +
 .../feature/query/sql/insert-appendonlytrue.sql |   4 +
 src/test/feature/query/test_insert.cpp          | 172 +++++++++++++++++++
 3 files changed, 184 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b38fb124/src/test/feature/query/ans/insert-appendonlytrue.ans
----------------------------------------------------------------------
diff --git a/src/test/feature/query/ans/insert-appendonlytrue.ans 
b/src/test/feature/query/ans/insert-appendonlytrue.ans
new file mode 100644
index 0000000..c62512e
--- /dev/null
+++ b/src/test/feature/query/ans/insert-appendonlytrue.ans
@@ -0,0 +1,8 @@
+begin;
+BEGIN
+create table t (a int) with (appendonly=true);
+CREATE TABLE
+insert into t select * from generate_series(1,10);
+INSERT 0 10
+abort;
+ROLLBACK

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b38fb124/src/test/feature/query/sql/insert-appendonlytrue.sql
----------------------------------------------------------------------
diff --git a/src/test/feature/query/sql/insert-appendonlytrue.sql 
b/src/test/feature/query/sql/insert-appendonlytrue.sql
new file mode 100644
index 0000000..9565ec8
--- /dev/null
+++ b/src/test/feature/query/sql/insert-appendonlytrue.sql
@@ -0,0 +1,4 @@
+begin;
+create table t (a int) with (appendonly=true);
+insert into t select * from generate_series(1,10);
+abort;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b38fb124/src/test/feature/query/test_insert.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/query/test_insert.cpp 
b/src/test/feature/query/test_insert.cpp
new file mode 100644
index 0000000..1e05b9c
--- /dev/null
+++ b/src/test/feature/query/test_insert.cpp
@@ -0,0 +1,172 @@
+#include <pwd.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <vector>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <iostream>
+#include <string>
+
+#include "lib/sql_util.h"
+
+#include "gtest/gtest.h"
+
+class TestQueryInsert : public ::testing::Test {
+ public:
+  TestQueryInsert() {}
+  ~TestQueryInsert() {}
+};
+
+
+TEST_F(TestQueryInsert, TestInsertWithDefault) {
+  hawq::test::SQLUtility util;
+  // prepare
+  util.execute("drop table if exists inserttest");
+  util.execute("create table inserttest (col1 int4, "
+                                                                           
"col2 int4 not null,"
+                                                                           
"col3 text default 'testing')");
+  // test insert
+  util.execute("insert into inserttest(col2, col3) values(3,default)");
+  util.execute("insert into inserttest(col1, col2, col3) "
+                                   "values(default, 5, default)");
+  util.execute("insert into inserttest values(default, 5, 'test')");
+  util.execute("insert into inserttest values(default, 7)");
+
+  util.query("select col1, col2, col3 from inserttest order by col1, col2, 
col3",
+                    "|3|testing|\n"
+                    "|5|test|\n"
+                    "|5|testing|\n"
+                    "|7|testing|\n");
+  // cleanup
+  util.execute("drop table if exists inserttest");
+}
+
+TEST_F(TestQueryInsert, TestInsertWithDefaultNeg) {
+  hawq::test::SQLUtility util;
+  // prepare
+  util.execute("drop table if exists inserttest");
+  util.execute("create table inserttest (col1 int4, "
+                                                                               
"col2 int4 not null,"
+                                                                               
"col3 text default 'testing')");
+  // test insert
+  util.execute("insert into inserttest(col1, col2, col3) "
+                                                       "values(default, 
default, default)",
+                          false);
+  std::string errstr = "ERROR:  null value in column \"col2\" "
+                              "violates not-null constraint";
+  EXPECT_STREQ(errstr.c_str(),
+               util.getPSQL()->getLastResult().substr(0, 
errstr.size()).c_str());
+  // cleanup
+  util.execute("drop table if exists inserttest");
+}
+
+TEST_F(TestQueryInsert, TestInsertUnmatchedColNumber) {
+  hawq::test::SQLUtility util;
+  // prepare
+  util.execute("drop table if exists inserttest");
+  util.execute("create table inserttest (col1 int4, "
+                                                                               
"col2 int4 not null,"
+                                                                               
"col3 text default 'testing')");
+  // test insert
+  util.execute("insert into inserttest(col1, col2, col3) "
+                                                  "values(default, default)",
+                          false);
+  std::string errstr = "ERROR:  INSERT has more target columns than "
+                                          "expressions";
+  EXPECT_STREQ(errstr.c_str(),
+                          util.getPSQL()->getLastResult().substr(0, 
errstr.size()).c_str());
+
+  util.execute("insert into inserttest(col1, col2, col3) values(1, 2)",
+                          false);
+  EXPECT_STREQ(errstr.c_str(),
+                          util.getPSQL()->getLastResult().substr(0, 
errstr.size()).c_str());
+
+  util.execute("insert into inserttest(col1) values(1, 2)", false);
+  errstr = "ERROR:  INSERT has more expressions than target columns";
+  EXPECT_STREQ(errstr.c_str(),
+                          util.getPSQL()->getLastResult().substr(0, 
errstr.size()).c_str());
+
+  util.execute("insert into inserttest(col1) values(default, default)", false);
+  EXPECT_STREQ(errstr.c_str(),
+                          util.getPSQL()->getLastResult().substr(0, 
errstr.size()).c_str());
+
+  // cleanup
+  util.execute("drop table if exists inserttest");
+
+}
+
+TEST_F(TestQueryInsert, TestInsertValues) {
+  hawq::test::SQLUtility util;
+  // prepare
+  util.execute("drop table if exists inserttest");
+  util.execute("create table inserttest (col1 int4, "
+                                                                               
"col2 int4 not null,"
+                                                                               
"col3 text default 'testing')");
+  // test insert
+  util.execute("insert into inserttest "
+                                  "values(10,20,'40'),"
+                                        "(-1,2,default),"
+                                        "((select 2), "
+                                         "(select i from (values(3)) as 
foo(i)),"
+                                         "'values are fun!')");
+
+  util.query("select col1, col2, col3 from inserttest order by col1, col2, 
col3",
+                        "-1|2|testing|\n"
+                        "2|3|values are fun!|\n"
+                        "10|20|40|\n");
+  // cleanup
+  util.execute("drop table if exists inserttest");
+}
+
+TEST_F(TestQueryInsert, TestInsertAfterDropColumn) {
+  hawq::test::SQLUtility util;
+  // prepare
+  util.execute("drop table if exists bar");
+  util.execute("drop table if exists foo");
+  util.execute("create table bar(x int, y int) distributed randomly");
+  util.execute("create table foo(like bar) distributed randomly");
+
+  // test
+  util.execute("alter table foo drop column y");
+  util.execute("insert into bar values(1,1),(2,2)");
+  util.execute("insert into foo(x) select t1.x from bar t1 join bar t2 on 
t1.x=t2.x");
+  util.execute("insert into foo(x) select t1.x from bar t1");
+  util.execute("insert into foo(x) select t1.x from bar t1 group by t1.x");
+
+  // cleanup
+  util.execute("drop table if exists foo");
+  util.execute("drop table if exists bar");
+}
+
+TEST_F(TestQueryInsert, TestInsertAfterAddDropColumn) {
+  hawq::test::SQLUtility util;
+  // prepare
+  util.execute("drop table if exists bar");
+  util.execute("drop table if exists foo");
+  util.execute("create table bar(x int) distributed randomly");
+  util.execute("create table foo(like bar) distributed randomly");
+
+  // test add and drop the column at once
+  util.execute("alter table foo add column y int default 0");
+  util.execute("alter table foo drop column y");
+  util.execute("insert into bar values(1),(2)");
+  util.execute("insert into foo(x) select t1.x from bar t1 join bar t2 on 
t1.x=t2.x");
+  util.execute("insert into foo(x) select t1.x from bar t1");
+  util.execute("insert into foo(x) select t1.x from bar t1 group by t1.x");
+
+  // cleanup
+  util.execute("drop table if exists foo");
+  util.execute("drop table if exists bar");
+}
+
+TEST_F(TestQueryInsert, TestInsertAppendOnlyTrue) {
+  hawq::test::SQLUtility util;
+  // prepare
+  util.execute("drop table if exists t");
+  util.execSQLFile("query/sql/insert-appendonlytrue.sql",
+                                  "query/ans/insert-appendonlytrue.ans");
+  // cleanup
+  util.execute("drop table if exists t");
+}
+

Reply via email to