Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
HAWQ-731. Implement Data Generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ictmalili committed May 12, 2016
1 parent c3d8546 commit c0dcb5d
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/test/feature/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
138 changes: 138 additions & 0 deletions src/test/feature/lib/data-gen.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
58 changes: 58 additions & 0 deletions src/test/feature/lib/data-gen.h
Original file line number Diff line number Diff line change
@@ -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_ */
2 changes: 1 addition & 1 deletion src/test/feature/lib/psql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/test/feature/testlib/test-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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");
}

0 comments on commit c0dcb5d

Please sign in to comment.