hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From y...@apache.org
Subject [1/4] incubator-hawq git commit: HAWQ-750. Test prepare and sequence using new test library
Date Mon, 23 May 2016 08:52:09 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/master 120ee70ba -> ec5a9bad8


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/ec5a9bad/src/test/feature/query/sql/prepare-parameters.sql
----------------------------------------------------------------------
diff --git a/src/test/feature/query/sql/prepare-parameters.sql b/src/test/feature/query/sql/prepare-parameters.sql
new file mode 100644
index 0000000..e014307
--- /dev/null
+++ b/src/test/feature/query/sql/prepare-parameters.sql
@@ -0,0 +1,31 @@
+PREPARE q2(text) AS
+        SELECT datname, datistemplate, datallowconn
+        FROM pg_database WHERE datname = $1;
+
+EXECUTE q2('regression');
+
+PREPARE q3(text, int, float, boolean, oid, smallint) AS
+        SELECT * FROM test1 WHERE string4 = $1 AND (four = $2 OR
+        ten = $3::bigint OR true = $4 OR oid = $5 OR odd = $6::int) ORDER BY 1,2,3,4;
+
+EXECUTE q3('AAAAxx', 5::smallint, 10.5::float, false, 500::oid, 4::bigint);
+
+EXECUTE q3('bool');
+
+EXECUTE q3('bytea', 5::smallint, 10.5::float, false, 500::oid, 4::bigint, true);
+
+EXECUTE q3(5::smallint, 10.5::float, false, 500::oid, 4::bigint, 'bytea');
+
+PREPARE q4(nonexistenttype) AS SELECT $1;
+
+PREPARE q5(int, text) AS
+        SELECT * FROM test1 WHERE unique1 = $1 OR stringu1 = $2;
+CREATE TEMPORARY TABLE q5_prep_results AS EXECUTE q5(200, 'DTAAAA');
+SELECT * FROM q5_prep_results ORDER BY 1,2,3,4;
+
+PREPARE q6 AS
+    SELECT * FROM test1 WHERE unique1 = $1 AND stringu1 = $2;
+PREPARE q7(unknown) AS
+    SELECT * FROM test2 WHERE thepath = $1;
+
+SELECT name, statement, parameter_types FROM pg_prepared_statements ORDER BY name;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/ec5a9bad/src/test/feature/query/sql/prepare-uniqueness.sql
----------------------------------------------------------------------
diff --git a/src/test/feature/query/sql/prepare-uniqueness.sql b/src/test/feature/query/sql/prepare-uniqueness.sql
new file mode 100644
index 0000000..07f663c
--- /dev/null
+++ b/src/test/feature/query/sql/prepare-uniqueness.sql
@@ -0,0 +1,18 @@
+SELECT name, statement, parameter_types FROM pg_prepared_statements ORDER BY 1,2,3;
+
+PREPARE q1 AS SELECT 1 AS a;
+EXECUTE q1;
+
+PREPARE q1 AS SELECT 2;
+
+DEALLOCATE q1;
+PREPARE q1 AS SELECT 2;
+EXECUTE q1;
+PREPARE q2 AS SELECT 2 AS b;
+
+SELECT name, statement, parameter_types FROM pg_prepared_statements ORDER BY 1,2,3;
+
+DEALLOCATE PREPARE q1;
+DEALLOCATE PREPARE q2;
+
+SELECT name, statement, parameter_types FROM pg_prepared_statements ORDER BY 1,2,3;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/ec5a9bad/src/test/feature/query/sql/sequence-dependency.sql
----------------------------------------------------------------------
diff --git a/src/test/feature/query/sql/sequence-dependency.sql b/src/test/feature/query/sql/sequence-dependency.sql
new file mode 100644
index 0000000..508d718
--- /dev/null
+++ b/src/test/feature/query/sql/sequence-dependency.sql
@@ -0,0 +1,14 @@
+CREATE TEMP SEQUENCE myseq2;
+CREATE TEMPORARY SEQUENCE myseq3;
+CREATE TEMP TABLE t1 (f1 SERIAL, 
+                      f2 INT DEFAULT NEXTVAL('myseq2'),
+                      f3 INT DEFAULT NEXTVAL('myseq3'::text)
+);
+
+DROP SEQUENCE t1_f1_seq;
+DROP SEQUENCE myseq2;
+DROP SEQUENCE myseq3;
+DROP TABLE t1;
+DROP SEQUENCE t1_f1_seq;
+DROP SEQUENCE myseq2;
+					  
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/ec5a9bad/src/test/feature/query/sql/sequence-serialcol-null.sql
----------------------------------------------------------------------
diff --git a/src/test/feature/query/sql/sequence-serialcol-null.sql b/src/test/feature/query/sql/sequence-serialcol-null.sql
new file mode 100644
index 0000000..edc5d00
--- /dev/null
+++ b/src/test/feature/query/sql/sequence-serialcol-null.sql
@@ -0,0 +1 @@
+INSERT INTO serialtest VALUES('wrong',NULL);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/ec5a9bad/src/test/feature/query/sql/sequence-serialcol-query.sql
----------------------------------------------------------------------
diff --git a/src/test/feature/query/sql/sequence-serialcol-query.sql b/src/test/feature/query/sql/sequence-serialcol-query.sql
new file mode 100644
index 0000000..cebcd37
--- /dev/null
+++ b/src/test/feature/query/sql/sequence-serialcol-query.sql
@@ -0,0 +1 @@
+select * from serialtest order by f2;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/ec5a9bad/src/test/feature/query/test-prepare.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/query/test-prepare.cpp b/src/test/feature/query/test-prepare.cpp
new file mode 100644
index 0000000..89b806c
--- /dev/null
+++ b/src/test/feature/query/test-prepare.cpp
@@ -0,0 +1,72 @@
+#include <pwd.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <vector>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <iostream>
+
+#include "lib/command.h"
+#include "lib/common.h"
+#include "lib/data-gen.h"
+#include "lib/hawq-config.h"
+#include "lib/sql-util.h"
+
+#include "gtest/gtest.h"
+
+class TestQueryPrepare : public ::testing::Test {
+ public:
+  TestQueryPrepare() {}
+  ~TestQueryPrepare() {}
+};
+
+
+TEST_F(TestQueryPrepare, TestPrepareUniqueness) {
+  SQLUtility util;
+  util.execSQLFile("query/sql/prepare-uniqueness.sql",
+		  	  	   "query/ans/prepare-uniqueness.ans");
+}
+
+TEST_F(TestQueryPrepare, TestPrepareParameters) {
+  SQLUtility util;
+  // prepare
+  util.execute("drop table if exists test1");
+  util.execute("drop table if exists test2");
+  util.execute("create table test1 ("
+		  	   "	unique1		int4,"
+		  	   "	unique2		int4,"
+		  	   "	two			int4,"
+		  	   "	four		int4,"
+		  	   "	ten			int4,"
+		  	   "	twenty		int4,"
+		  	   "	hundred		int4,"
+		  	   "	thousand	int4,"
+		  	   "	twothousand	int4,"
+		  	   "	fivethous	int4,"
+		  	   "	tenthous	int4,"
+		  	   "	odd			int4,"
+		  	   "	even		int4,"
+		  	   "	stringu1	name,"
+		  	   "	stringu2	name,"
+		  	   "	string4		name) with oids");
+  util.execute("create table test2 ("
+		  	   "	name		text,"
+		  	   "	thepath		path)");
+
+  std::string pwd = util.getTestRootPath();
+  std::string cmd = "COPY test1 FROM '" + pwd + "/query/data/tenk.data'";
+  std::cout << cmd << std::endl;
+  util.execute(cmd);
+  cmd = "COPY test2 FROM '" + pwd + "/query/data/streets.data'";
+  std::cout << cmd << std::endl;
+  util.execute(cmd);
+
+  // do test
+  util.execSQLFile("query/sql/prepare-parameters.sql",
+		  	  	   "query/ans/prepare-parameters.ans");
+
+  // cleanup
+  util.execute("drop table test1");
+  util.execute("drop table test2");
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/ec5a9bad/src/test/feature/query/test-sequence.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/query/test-sequence.cpp b/src/test/feature/query/test-sequence.cpp
new file mode 100644
index 0000000..d657dab
--- /dev/null
+++ b/src/test/feature/query/test-sequence.cpp
@@ -0,0 +1,122 @@
+#include <pwd.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <vector>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <iostream>
+
+#include "lib/command.h"
+#include "lib/common.h"
+#include "lib/data-gen.h"
+#include "lib/hawq-config.h"
+#include "lib/sql-util.h"
+
+#include "gtest/gtest.h"
+
+class TestQuerySequence : public ::testing::Test {
+ public:
+  TestQuerySequence() {}
+  ~TestQuerySequence() {}
+};
+
+
+TEST_F(TestQuerySequence, TestSequenceCreateSerialColumn) {
+  SQLUtility util;
+
+  util.execute("drop table if exists serialtest");
+  util.execute("create table serialtest (f1 text, f2 serial)");
+  util.execute("insert into serialtest values('foo')");
+  util.execute("insert into serialtest values('force',100)");
+  // expect failure due to null value in serial column
+  util.execSQLFile("query/sql/sequence-serialcol-null.sql",
+		  	  	   "query/ans/sequence-serialcol-null.ans");
+  // query table to check rows with generated and specified values in serial col
+  util.execSQLFile("query/sql/sequence-serialcol-query.sql",
+		  	  	   "query/ans/sequence-serialcol-query.ans");
+
+  // rename the sequence for that serial column
+  util.execute("alter table serialtest_f2_seq rename to serialtest_f2_foo");
+  util.execute("insert into serialtest values('more')");
+
+  // query table to check rows
+  util.execSQLFile("query/sql/sequence-serialcol-query.sql",
+		  	  	   "query/ans/sequence-serialcol-query2.ans");
+
+  // cleanup
+  util.execute("drop table serialtest");
+}
+
+TEST_F(TestQuerySequence, TestSequenceBasicOperations) {
+	SQLUtility util;
+
+	// prepare
+	util.execute("drop sequence if exists sequence_test");
+	util.execute("create sequence sequence_test");
+
+	// normal nextval operation
+	util.query("select nextval('sequence_test'::text)", "1|\n");
+	util.query("select nextval('sequence_test'::regclass)", "2|\n");
+
+	// setval with different params
+	util.query("select setval('sequence_test'::text, 32)", "32|\n");
+	util.query("select nextval('sequence_test'::regclass)", "33|\n");
+
+	util.query("select setval('sequence_test'::text, 99, false)", "99|\n");
+	util.query("select nextval('sequence_test'::regclass)", "99|\n");
+
+	util.query("select setval('sequence_test'::regclass, 32)", "32|\n");
+	util.query("select nextval('sequence_test'::text)", "33|\n");
+
+	util.query("select setval('sequence_test'::regclass, 99, false)", "99|\n");
+	util.query("select nextval('sequence_test'::text)", "99|\n");
+
+	// cleanup
+	util.execute("drop sequence sequence_test");
+}
+
+TEST_F(TestQuerySequence, TestSequenceRenaming) {
+	SQLUtility util;
+	// prepare
+	util.execute("drop sequence if exists foo_seq");
+	util.execute("create sequence foo_seq");
+	// alter sequence name
+	util.execute("alter table foo_seq rename to foo_seq_new");
+	util.query("select * from foo_seq_new",
+			   "foo_seq|1|1|9223372036854775807|1|1|1|f|f|\n");
+	// cleanup
+	util.execute("drop sequence foo_seq_new");
+}
+
+TEST_F(TestQuerySequence, TestSequenceDependency) {
+	SQLUtility util;
+	util.execSQLFile("query/sql/sequence-dependency.sql",
+			  	  	 "query/ans/sequence-dependency.ans");
+}
+
+TEST_F(TestQuerySequence, TestSequenceAlternate) {
+	SQLUtility util;
+	// prepare
+	util.execute("drop sequence if exists sequence_test2");
+	util.execute("create sequence sequence_test2 start with 32");
+	util.query("select nextval('sequence_test2')", "32|\n");
+
+	// alter sequence
+	util.execute("alter sequence sequence_test2 "
+				 	 "restart with 16 "
+				 	 "increment by 4 "
+				 	 "maxvalue 22 "
+				 	 "minvalue 5 "
+				 	 "cycle");
+	// check the sequence value
+	util.query("select nextval('sequence_test2')","16|\n");
+	util.query("select nextval('sequence_test2')","20|\n");
+	util.query("select nextval('sequence_test2')","5|\n");
+
+	// cleanup
+	util.execute("drop sequence sequence_test2");
+}
+
+
+


Mime
View raw message