Skip to content
Permalink
Browse files
HAWQ-732. Workable test framework.
  • Loading branch information
ztao1987 committed May 12, 2016
1 parent c0dcb5d commit fb14dbd981ed2ecc450ce27d1a9cfff0de8f51b7
Show file tree
Hide file tree
Showing 11 changed files with 518 additions and 409 deletions.
@@ -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 data-gen.cpp
PROG = $(abspath string-util.cpp psql.cpp command.cpp xml-parser.cpp hawq-config.cpp sql-util.cpp data-gen.cpp)

all:
g++ $(CPPFLAGS) $(CXXFLAGS) $(PROG)
@@ -1,138 +1,140 @@
#include <iostream>
#include "data-gen.h"

void
DataGenerator::genSimpleTable(std::string tableName,
bool appendonly,
std::string orientation,
std::string compresstype,
int compresslevel) {
#include <iostream>

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 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);
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) {
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);
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);
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) {
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, "
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);
"c25 float4, c26 point, c27 date, c28 float8) " +
desc;
sqlUtil->execute(createSql);

std::string insertSql = "insert into " + tableName +
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);
sqlUtil->execute(insertSql);

std::string insertSql2 = "insert into " + tableName +
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)]',"
"'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);
sqlUtil->execute(insertSql2);

std::string insertSql3 = "insert into " + tableName +
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);
sqlUtil->execute(insertSql3);

std::string insertSql4 = "insert into " + tableName +
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);
sqlUtil->execute(insertSql4);

std::string insertSql5 = "insert into " + tableName +
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);
sqlUtil->execute(insertSql5);

std::string insertSql6 = "insert into " + tableName +
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);
sqlUtil->execute(insertSql6);
}

void
DataGenerator::genTableWithNull(std::string tableName,
bool appendonly,
std::string orientation,
std::string compresstype,
int compresslevel) {
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);
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 +
std::string insertSql =
"insert into " + tableName +
" values (15, null, 'aa'), (null, null, 'WET'), (null, 51, null);";
sqlUtil.execute(insertSql);
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) + ")";
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;
}
@@ -15,30 +15,25 @@

class DataGenerator {
public:
DataGenerator() {}
explicit DataGenerator(SQLUtility *sqlUtil) : sqlUtil(sqlUtil) {}

~DataGenerator() {}

void genSimpleTable(std::string tableName,
bool appendonly = true,
void genSimpleTable(std::string tableName, bool appendonly = true,
std::string orientation = "row",
std::string compresstype = "none",
int compresslevel = 0);
std::string compresstype = "none", int compresslevel = 0);

void genTableWithFullTypes(std::string tableName,
bool appendonly = true,
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,
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,
void genTableWithNull(std::string tableName, bool appendonly = true,
std::string orientation = "row",
std::string compresstype = "none",
int compresslevel = 0);
@@ -47,12 +42,8 @@ class DataGenerator {
std::string genTableDesc(bool appendonly, std::string orientation,
std::string compresstype, int compresslevel);


private:
SQLUtility sqlUtil;
SQLUtility *sqlUtil = nullptr;
};




#endif /* SRC_TEST_FEATURE_LIB_DATA_GEN_H_ */
@@ -28,7 +28,7 @@ bool HawqConfig::LoadFromConfigFile() {

bool HawqConfig::getMaster(std::string &hostname, int &port) {
bool ret = LoadFromConfigFile();
if(!ret){
if (!ret) {
return false;
}
hostname = xmlconf->getString("hawq_master_address_host");
@@ -37,7 +37,7 @@ bool HawqConfig::getMaster(std::string &hostname, int &port) {
}

void HawqConfig::getStandbyMaster(std::string &hostname, int &port) {
PSQLQueryResult result = psql.getQueryResult(
const PSQLQueryResult &result = psql.getQueryResult(
"select hostname, port from gp_segment_configuration where role ='s'");
std::vector<std::vector<std::string> > table = result.getRows();
if (table.size() > 0) {
@@ -48,8 +48,8 @@ void HawqConfig::getStandbyMaster(std::string &hostname, int &port) {
}

void HawqConfig::getTotalSegments(std::vector<std::string> &hostname,
std::vector<int> &port) {
PSQLQueryResult result = psql.getQueryResult(
std::vector<int> &port) {
const PSQLQueryResult &result = psql.getQueryResult(
"select hostname, port from gp_segment_configuration where role ='p'");
std::vector<std::vector<std::string> > table = result.getRows();
for (int i = 0; i < table.size(); i++) {
@@ -60,9 +60,8 @@ void HawqConfig::getTotalSegments(std::vector<std::string> &hostname,
}

void HawqConfig::getSlaves(std::vector<std::string> &hostname) {

std::ifstream inFile;
char* GPHOME = getenv("GPHOME");
char *GPHOME = getenv("GPHOME");
if (GPHOME == nullptr) {
return;
}
@@ -77,10 +76,10 @@ void HawqConfig::getSlaves(std::vector<std::string> &hostname) {
}

void HawqConfig::getUpSegments(std::vector<std::string> &hostname,
std::vector<int> &port) {
PSQLQueryResult result =
psql.getQueryResult(
"select hostname, port from gp_segment_configuration where role = 'p' and status = 'u'");
std::vector<int> &port) {
const PSQLQueryResult &result = psql.getQueryResult(
"select hostname, port from gp_segment_configuration where role = 'p' "
"and status = 'u'");
std::vector<std::vector<std::string> > table = result.getRows();

if (table.size() > 0) {
@@ -91,10 +90,10 @@ void HawqConfig::getUpSegments(std::vector<std::string> &hostname,
}

void HawqConfig::getDownSegments(std::vector<std::string> &hostname,
std::vector<int> &port) {
PSQLQueryResult result =
psql.getQueryResult(
"select hostname, port from gp_segment_configuration where role = 'p' and status != 'u'");
std::vector<int> &port) {
const PSQLQueryResult &result = psql.getQueryResult(
"select hostname, port from gp_segment_configuration where role = 'p' "
"and status != 'u'");
std::vector<std::vector<std::string> > table = result.getRows();

if (table.size() > 0) {
@@ -132,8 +131,8 @@ std::string HawqConfig::setGucValue(std::string gucName, std::string gucValue) {
}

bool HawqConfig::isMasterMirrorSynchronized() {
PSQLQueryResult result = psql.getQueryResult(
"select summary_state from gp_master_mirroring");
const PSQLQueryResult &result =
psql.getQueryResult("select summary_state from gp_master_mirroring");
if (result.getRows().size() > 0) {
std::string syncInfo = result.getData(0, 0);
syncInfo = StringUtil::trim(syncInfo);
@@ -147,8 +146,8 @@ bool HawqConfig::isMasterMirrorSynchronized() {
}

bool HawqConfig::isMultinodeMode() {
PSQLQueryResult result = psql.getQueryResult(
"select hostname from gp_segment_configuration");
const PSQLQueryResult &result =
psql.getQueryResult("select hostname from gp_segment_configuration");
std::vector<std::vector<std::string> > table = result.getRows();

std::set<std::string> hostnameMap;

0 comments on commit fb14dbd

Please sign in to comment.