You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by li...@apache.org on 2016/05/12 00:17:23 UTC
incubator-hawq git commit: HAWQ-731. Implement Data Generator
Repository: incubator-hawq
Updated Branches:
refs/heads/master c3d8546e7 -> c0dcb5d60
HAWQ-731. Implement Data Generator
Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/c0dcb5d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/c0dcb5d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/c0dcb5d6
Branch: refs/heads/master
Commit: c0dcb5d6049bdd621d6750127a900c0f6dd4fb9d
Parents: c3d8546
Author: Lili Ma <ic...@gmail.com>
Authored: Wed May 11 18:09:52 2016 +0800
Committer: Lili Ma <ic...@gmail.com>
Committed: Thu May 12 08:10:42 2016 +0800
----------------------------------------------------------------------
src/test/feature/lib/Makefile | 2 +-
src/test/feature/lib/data-gen.cpp | 138 +++++++++++++++++++++++++++++
src/test/feature/lib/data-gen.h | 58 ++++++++++++
src/test/feature/lib/psql.cpp | 2 +-
src/test/feature/testlib/test-lib.cpp | 12 +++
5 files changed, 210 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c0dcb5d6/src/test/feature/lib/Makefile
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/Makefile b/src/test/feature/lib/Makefile
index 8c7d74d..411613a 100644
--- a/src/test/feature/lib/Makefile
+++ b/src/test/feature/lib/Makefile
@@ -8,7 +8,7 @@ override CPPFLAGS := -I/usr/include -I/usr/local/include -I/usr/include/libxml2
override LIBS := $(LIBS) -lpq -lxml2
override LDFLAGS += -L/usr/local/lib -L/usr/lib
-PROG = string-util.cpp psql.cpp command.cpp xml-parser.cpp hawq-config.cpp
+PROG = string-util.cpp psql.cpp command.cpp xml-parser.cpp hawq-config.cpp data-gen.cpp
all:
g++ $(CPPFLAGS) $(CXXFLAGS) $(PROG)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c0dcb5d6/src/test/feature/lib/data-gen.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/data-gen.cpp b/src/test/feature/lib/data-gen.cpp
new file mode 100644
index 0000000..da58b32
--- /dev/null
+++ b/src/test/feature/lib/data-gen.cpp
@@ -0,0 +1,138 @@
+#include <iostream>
+#include "data-gen.h"
+
+void
+DataGenerator::genSimpleTable(std::string tableName,
+ bool appendonly,
+ std::string orientation,
+ std::string compresstype,
+ int compresslevel) {
+ std::string desc =
+ genTableDesc(appendonly, orientation, compresstype, compresslevel);
+ std::string createSql = "create table " + tableName
+ + "(a int, b int) " + desc;
+ sqlUtil.execute(createSql);
+
+ std::string insertSql = "insert into " + tableName
+ + " values(51,62), (14,15), (1,3);";
+ sqlUtil.execute(insertSql);
+}
+
+void
+DataGenerator::genTableWithSeries(std::string tableName,
+ bool appendonly,
+ std::string orientation,
+ std::string compresstype,
+ int compresslevel) {
+ std::string desc =
+ genTableDesc(appendonly, orientation, compresstype, compresslevel);
+ std::string createSql = "create table " + tableName
+ + "(a int, b varchar(20)) " + desc;
+ sqlUtil.execute(createSql);
+
+ std::string insertSql = "insert into " + tableName
+ + " values(generate_series(1,10000), 'abc')";
+ sqlUtil.execute(insertSql);
+}
+
+
+void
+DataGenerator::genTableWithFullTypes(std::string tableName,
+ bool appendonly,
+ std::string orientation,
+ std::string compresstype,
+ int compresslevel) {
+ std::string desc =
+ genTableDesc(appendonly, orientation, compresstype, compresslevel);
+ std::string createSql = "create table " + tableName + "(c0 int4, c1 polygon, "
+ "c2 text, c3 time, c4 timetz, c5 macaddr, c6 timestamptz, c7 char(10), "
+ "c8 int2, c9 bool, c10 cidr, c11 circle, c12 lseg, c13 interval, "
+ "c14 bit, c15 money, c16 box, c17 bytea, c18 xml, c19 bit(5), "
+ "c20 varchar(10), c21 inet, c22 int8, c23 varbit, c24 serial, "
+ "c25 float4, c26 point, c27 date, c28 float8) " + desc;
+ sqlUtil.execute(createSql);
+
+ std::string insertSql = "insert into " + tableName +
+ " values (2147483647, null, null, '00:00:00', null, 'FF:89:71:45:AE:01',"
+ " '2000-01-01 08:00:00+09', null, 32767, 'true', '192.168.1.255/32', "
+ "'<(1,2),3>', '[(0,0),(6,6)]', '-178000000 years', '0', '-21474836.48', "
+ "'((100,200),(200,400))', null, '<aa>bb</aa>', null, '123456789a', "
+ "'2001:db8:85a3:8d3:1319:8a2e:370:7344/64', null, null, 1, 0, POINT(1,2),"
+ " '4277-12-31 AD', 128);";
+ sqlUtil.execute(insertSql);
+
+ std::string insertSql2 = "insert into " + tableName +
+ " values (0, '((100,123),(5,10),(7,2),(4,5))', 'hello world', null, "
+ "'04:45:05.0012+08:40', null, null, 'bbccddeeff', 128, null, "
+ "'2001:db8:85a3:8d3:1319:8a2e:370:7344/128', '<(1,2),3>', '[(0,0),(6,6)]',"
+ " null, '1', '0', '((0,1),(2,3))', 'hello world', '<aa>bb</aa>', null, "
+ "'aaaa', '2001:db8:85a3:8d3:1319:8a2e:370:7344/64', 0, null, 2147483647, "
+ "'-Infinity', POINT(1,2), '4277-12-31 AD', 'Infinity');";
+ sqlUtil.execute(insertSql2);
+
+ std::string insertSql3 = "insert into " + tableName +
+ " values (null, null, 'abcd', '15:01:03', null, null, "
+ " '2000-01-01 08:00:00+09', null, null, 'true', null, "
+ "null, '[(0,0),(6,6)]', '-178000000 years', '0', '-21474836.48', "
+ "'((100,200),(200,400))', null, '<aa>bb</aa>', null, '123456789a', "
+ "'2001:db8:85a3:8d3:1319:8a2e:370:7344/64', null, null, 1, 0, POINT(1,2),"
+ " '4277-12-31 AD', 128);";
+ sqlUtil.execute(insertSql3);
+
+ std::string insertSql4 = "insert into " + tableName +
+ " values (0, '((100,123),(5,10),(7,2),(4,5))', 'hello world', null, "
+ "'04:45:05.0012+08:40', null, null, 'bbccddeeff', 128, null, "
+ "'2001:db8:85a3:8d3:1319:8a2e:370:7344/128', '<(1,2),3>', null,"
+ " null, null, '0', null, 'hello world', null, null, "
+ "'aaaa', '2001:db8:85a3:8d3:1319:8a2e:370:7344/64', 0, null, 2147483647, "
+ "'-Infinity', POINT(1,2), '4277-12-31 AD', 'Infinity');";
+ sqlUtil.execute(insertSql4);
+
+ std::string insertSql5 = "insert into " + tableName +
+ " values (0, '((100,123),(5,10),(7,2),(4,5))', 'hello world', null, "
+ "'04:45:05.0012+08:40', null, null, 'bbccddeeff', 128, null, "
+ "'2001:db8:85a3:8d3:1319:8a2e:370:7344/128', '<(1,2),3>', null,"
+ " null, null, '0', null, 'hello world', null, null, "
+ "null, null, 0, null, 2147483647, "
+ "'-Infinity', POINT(1,2), '4277-12-31 AD', 'Infinity');";
+ sqlUtil.execute(insertSql5);
+
+ std::string insertSql6 = "insert into " + tableName +
+ " values (0, '((100,123),(5,10),(7,2),(4,5))', 'hello world', null, "
+ "'04:45:05.0012+08:40', null, null, 'bbccddeeff', 128, null, "
+ "'2001:db8:85a3:8d3:1319:8a2e:370:7344/128', '<(1,2),3>', null,"
+ " null, null, null, null, 'hello world', null, null, "
+ "null, null, 0, null, 34, "
+ "null, null, null, null);";
+ sqlUtil.execute(insertSql6);
+}
+
+void
+DataGenerator::genTableWithNull(std::string tableName,
+ bool appendonly,
+ std::string orientation,
+ std::string compresstype,
+ int compresslevel) {
+ std::string desc =
+ genTableDesc(appendonly, orientation, compresstype, compresslevel);
+ std::string createSql = "create table " + tableName +
+ " (a int, b float, c varchar(20)) " + desc;
+ sqlUtil.execute(createSql);
+
+ std::string insertSql = "insert into " + tableName +
+ " values (15, null, 'aa'), (null, null, 'WET'), (null, 51, null);";
+ sqlUtil.execute(insertSql);
+}
+
+
+std::string
+DataGenerator::genTableDesc(bool appendonly,
+ std::string orientation, std::string compresstype,
+ int compresslevel) {
+ std::string desc =
+ (appendonly ? "with (appendonly = true, orientation = "
+ : "with (appendonly = false, orientation = ")
+ + orientation + ", compresstype = " + compresstype
+ + ", compresslevel = " + std::to_string(compresslevel) + ")";
+ return desc;
+}
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c0dcb5d6/src/test/feature/lib/data-gen.h
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/data-gen.h b/src/test/feature/lib/data-gen.h
new file mode 100644
index 0000000..38bed69
--- /dev/null
+++ b/src/test/feature/lib/data-gen.h
@@ -0,0 +1,58 @@
+/*
+ * data-gen.h
+ *
+ * Created on: May 11, 2016
+ * Author: malili
+ */
+
+#ifndef SRC_TEST_FEATURE_LIB_DATA_GEN_H_
+#define SRC_TEST_FEATURE_LIB_DATA_GEN_H_
+
+#include <string>
+
+#include "gtest/gtest.h"
+#include "sql-util.h"
+
+class DataGenerator {
+ public:
+ DataGenerator() {}
+
+ ~DataGenerator() {}
+
+ void genSimpleTable(std::string tableName,
+ bool appendonly = true,
+ std::string orientation = "row",
+ std::string compresstype = "none",
+ int compresslevel = 0);
+
+ void genTableWithFullTypes(std::string tableName,
+ bool appendonly = true,
+ std::string orientation = "row",
+ std::string compresstype = "none",
+ int compresslevel = 0);
+
+ void genTableWithSeries(std::string tableName,
+ bool appendonly = true,
+ std::string orientation = "row",
+ std::string compresstype = "none",
+ int compresslevel = 0);
+
+ void genTableWithNull(std::string tableName,
+ bool appendonly = true,
+ std::string orientation = "row",
+ std::string compresstype = "none",
+ int compresslevel = 0);
+
+ private:
+ std::string genTableDesc(bool appendonly, std::string orientation,
+ std::string compresstype, int compresslevel);
+
+
+ private:
+ SQLUtility sqlUtil;
+};
+
+
+
+
+#endif /* SRC_TEST_FEATURE_LIB_DATA_GEN_H_ */
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c0dcb5d6/src/test/feature/lib/psql.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/lib/psql.cpp b/src/test/feature/lib/psql.cpp
index 0b0a8a6..bb936b0 100644
--- a/src/test/feature/lib/psql.cpp
+++ b/src/test/feature/lib/psql.cpp
@@ -218,7 +218,7 @@ const std::string PSQL::_getPSQLBaseCommand() const
const std::string PSQL::_getPSQLQueryCommand(const std::string& query) const
{
std::string command = this->_getPSQLBaseCommand();
- return command.append(" -c '").append(query).append("'");
+ return command.append(" -c \"").append(query).append("\"");
}
const std::string PSQL::_getPSQLFileCommand(const std::string& file) const
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/c0dcb5d6/src/test/feature/testlib/test-lib.cpp
----------------------------------------------------------------------
diff --git a/src/test/feature/testlib/test-lib.cpp b/src/test/feature/testlib/test-lib.cpp
index 68413f9..6e283ca 100644
--- a/src/test/feature/testlib/test-lib.cpp
+++ b/src/test/feature/testlib/test-lib.cpp
@@ -8,6 +8,7 @@
#include "lib/command.h"
#include "lib/common.h"
+#include "lib/data-gen.h"
#include "lib/hawq-config.h"
#include "lib/sql-util.h"
@@ -74,3 +75,14 @@ TEST_F(TestCommonLib, TestSqlUtil) {
util.execute("insert into test values(1),(2)");
util.query("select * from test", 2);
}
+
+TEST_F(TestCommonLib, TestDataGenerator) {
+ DataGenerator dGen;
+ dGen.genSimpleTable("simpleAO");
+ dGen.genSimpleTable("simpleParquet", true, "parquet");
+
+ dGen.genTableWithFullTypes("fullTypeAO");
+ dGen.genTableWithSeries("tSeries");
+
+ dGen.genTableWithNull("tNull");
+}