OmniSciDB  5ade3759e0
anonymous_namespace{AlterColumnTest.cpp} Namespace Reference

Classes

class  AlterColumnTest
 

Functions

void run_ddl_statement (const std::string &input_str)
 
std::shared_ptr< ResultSetrun_query (const std::string &query_str)
 
template<typename E = std::runtime_error>
bool alter_common (const std::string &table, const std::string &column, const std::string &type, const std::string &comp, const std::string &val, const std::string &val2, const bool expect_throw=false)
 
void import_table_file (const std::string &table, const std::string &file)
 
void init_table_data (const std::string &table="trips", const std::string &create_table_cmd=create_table_trips, const std::string &file="trip_data_b.txt")
 
 TEST_F (AlterColumnTest, Add_column_with_default)
 
 TEST_F (AlterColumnTest, Add_column_with_null)
 
 TEST (AlterColumnTest2, Drop_after_fail_to_add)
 

Variables

bool g_hoist_literals {true}
 
const char * create_table_trips
 
std::vector< std::tuple< std::string, std::string, std::string, std::string > > type_vals
 

Function Documentation

◆ alter_common()

template<typename E = std::runtime_error>
bool anonymous_namespace{AlterColumnTest.cpp}::alter_common ( const std::string &  table,
const std::string &  column,
const std::string &  type,
const std::string &  comp,
const std::string &  val,
const std::string &  val2,
const bool  expect_throw = false 
)

Definition at line 56 of file AlterColumnTest.cpp.

References CHECK_EQ, run_ddl_statement(), run_query(), and run-benchmark-import::type.

Referenced by TEST_F().

62  {
63  std::string alter_query = "alter table " + table + " add column " + column + " " + type;
64  if (val != "") {
65  alter_query += " default " + val;
66  }
67  if (comp != "") {
68  alter_query += " encoding " + comp;
69  }
70 
71  if (expect_throw) {
72  EXPECT_THROW(run_ddl_statement(alter_query + ";"), E);
73  return true;
74  } else {
75  EXPECT_NO_THROW(run_ddl_statement(alter_query + ";"););
76  }
77 
78  if (val2 != "") {
79  std::string query_str = "SELECT " + column + " FROM " + table;
80  auto rows = run_query(query_str + ";");
81  int r_cnt = 0;
82  while (true) {
83  auto crt_row = rows->getNextRow(true, true);
84  if (0 == crt_row.size()) {
85  break;
86  }
87  auto geo = boost::get<std::string>(v<NullableString>(crt_row[0]));
88 #if 1
89  if (geo == val2) {
90  ++r_cnt;
91  }
92 #else
93  // somehow these do not work as advertised ...
94  using namespace Geo_namespace;
95  if (boost::iequals(type, "POINT") && GeoPoint(geo) == GeoPoint(val2))
96  ++r_cnt;
97  else if (boost::iequals(type, "LINESTRING") &&
98  GeoLineString(geo) == GeoLineString(val2))
99  ++r_cnt;
100  else if (boost::iequals(type, "POLYGON") && GeoPolygon(geo) == GeoPolygon(val2))
101  ++r_cnt;
102  else if (boost::iequals(type, "MULTIPOLYGON") &&
103  GeoMultiPolygon(geo) == GeoMultiPolygon(val2))
104  ++r_cnt;
105 #endif
106  }
107  return r_cnt == 100;
108  } else {
109  std::string query_str =
110  "SELECT count(*) FROM " + table + " WHERE " + column +
111  ("" == val || boost::iequals("NULL", val) ? " IS NULL" : (" = " + val));
112  auto rows = run_query(query_str + ";");
113  auto crt_row = rows->getNextRow(true, true);
114  CHECK_EQ(size_t(1), crt_row.size());
115  auto r_cnt = v<int64_t>(crt_row[0]);
116  return r_cnt == 100;
117  }
118 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
std::shared_ptr< ResultSet > run_query(const std::string &query_str)
void run_ddl_statement(std::string ddl)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ import_table_file()

void anonymous_namespace{AlterColumnTest.cpp}::import_table_file ( const std::string &  table,
const std::string &  file 
)

Definition at line 120 of file AlterColumnTest.cpp.

References CHECK_EQ, QueryRunner::QueryRunner::get(), run-benchmark-import::parser, and QueryRunner::QueryRunner::runImport().

Referenced by init_table_data().

120  {
121  const auto query_str = std::string("COPY trips FROM '") +
122  "../../Tests/Import/datafiles/" + file +
123  "' WITH (header='true');";
124 
125  SQLParser parser;
126  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
127  std::string last_parsed;
128  if (parser.parse(query_str, parse_trees, last_parsed)) {
129  throw std::runtime_error("Failed to parse: " + query_str);
130  }
131  CHECK_EQ(parse_trees.size(), size_t(1));
132 
133  const auto& stmt = parse_trees.front();
134  auto copy_stmt = dynamic_cast<Parser::CopyTableStmt*>(stmt.get());
135  if (!copy_stmt) {
136  throw std::runtime_error("Expected a CopyTableStatment: " + query_str);
137  }
138  QR::get()->runImport(copy_stmt);
139 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
virtual void runImport(Parser::CopyTableStmt *import_stmt)
static QueryRunner * get()
Definition: QueryRunner.h:115
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_table_data()

void anonymous_namespace{AlterColumnTest.cpp}::init_table_data ( const std::string &  table = "trips",
const std::string &  create_table_cmd = create_table_trips,
const std::string &  file = "trip_data_b.txt" 
)

Definition at line 162 of file AlterColumnTest.cpp.

References import_table_file(), and run_ddl_statement().

Referenced by anonymous_namespace{AlterColumnTest.cpp}::AlterColumnTest::SetUp().

164  {
165  run_ddl_statement("drop table if exists " + table + ";");
166  run_ddl_statement(create_table_cmd);
167  if (file.size()) {
168  import_table_file(table, file);
169  }
170 }
void import_table_file(const std::string &table, const std::string &file)
void run_ddl_statement(std::string ddl)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run_ddl_statement()

void anonymous_namespace{AlterColumnTest.cpp}::run_ddl_statement ( const std::string &  input_str)
inline

Definition at line 47 of file AlterColumnTest.cpp.

References QueryRunner::QueryRunner::get(), and QueryRunner::QueryRunner::runDDLStatement().

47  {
48  QR::get()->runDDLStatement(input_str);
49 }
virtual void runDDLStatement(const std::string &)
static QueryRunner * get()
Definition: QueryRunner.h:115
+ Here is the call graph for this function:

◆ run_query()

std::shared_ptr<ResultSet> anonymous_namespace{AlterColumnTest.cpp}::run_query ( const std::string &  query_str)

Definition at line 51 of file AlterColumnTest.cpp.

References CPU, g_hoist_literals, QueryRunner::QueryRunner::get(), and QueryRunner::QueryRunner::runSQL().

Referenced by alter_common(), and TEST().

51  {
52  return QR::get()->runSQL(query_str, ExecutorDeviceType::CPU, g_hoist_literals, true);
53 }
virtual std::shared_ptr< ResultSet > runSQL(const std::string &query_str, const ExecutorDeviceType device_type, const bool hoist_literals=true, const bool allow_loop_joins=true)
static QueryRunner * get()
Definition: QueryRunner.h:115
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TEST()

anonymous_namespace{AlterColumnTest.cpp}::TEST ( AlterColumnTest2  ,
Drop_after_fail_to_add   
)

Definition at line 245 of file AlterColumnTest.cpp.

References run_ddl_statement(), and run_query().

245  {
246  EXPECT_NO_THROW(run_ddl_statement("drop table if exists t;"););
247  EXPECT_NO_THROW(run_ddl_statement("create table t(c1 int);"););
248  EXPECT_NO_THROW(run_query("insert into t values (10);"););
249  EXPECT_THROW(
250  run_ddl_statement("alter table t add column c2 TEXT NOT NULL ENCODING DICT;"),
251  std::runtime_error);
252  EXPECT_NO_THROW(run_ddl_statement("drop table t;"););
253 }
std::shared_ptr< ResultSet > run_query(const std::string &query_str)
void run_ddl_statement(std::string ddl)
+ Here is the call graph for this function:

◆ TEST_F() [1/2]

anonymous_namespace{AlterColumnTest.cpp}::TEST_F ( AlterColumnTest  ,
Add_column_with_default   
)

Definition at line 209 of file AlterColumnTest.cpp.

References alter_common(), and to_string().

209  {
210  int cid = 0;
211  for (const auto& tv : type_vals) {
212  EXPECT_TRUE(alter_common("trips",
213  "x" + std::to_string(++cid),
214  std::get<0>(tv),
215  std::get<1>(tv),
216  std::get<2>(tv),
217  std::get<3>(tv),
218  false));
219  }
220 }
std::vector< std::tuple< std::string, std::string, std::string, std::string > > type_vals
std::string to_string(char const *&&v)
bool alter_common(const std::string &table, const std::string &column, const std::string &type, const std::string &comp, const std::string &val, const std::string &val2, const bool expect_throw=false)
+ Here is the call graph for this function:

◆ TEST_F() [2/2]

anonymous_namespace{AlterColumnTest.cpp}::TEST_F ( AlterColumnTest  ,
Add_column_with_null   
)

Definition at line 222 of file AlterColumnTest.cpp.

References alter_common(), and to_string().

222  {
223  int cid = 0;
224  for (const auto& tv : type_vals) {
225  if (std::get<3>(tv) == "") {
226  EXPECT_TRUE(alter_common("trips",
227  "x" + std::to_string(++cid),
228  std::get<0>(tv),
229  std::get<1>(tv),
230  "",
231  "",
232  false));
233  } else {
234  EXPECT_TRUE(alter_common("trips",
235  "x" + std::to_string(++cid),
236  std::get<0>(tv),
237  std::get<1>(tv),
238  "",
239  std::get<3>(tv),
240  true));
241  }
242  }
243 }
std::vector< std::tuple< std::string, std::string, std::string, std::string > > type_vals
std::string to_string(char const *&&v)
bool alter_common(const std::string &table, const std::string &column, const std::string &type, const std::string &comp, const std::string &val, const std::string &val2, const bool expect_throw=false)
+ Here is the call graph for this function:

Variable Documentation

◆ create_table_trips

const char* anonymous_namespace{AlterColumnTest.cpp}::create_table_trips
Initial value:
=
" CREATE TABLE trips ("
" medallion TEXT ENCODING DICT,"
" hack_license TEXT ENCODING DICT,"
" vendor_id TEXT ENCODING DICT,"
" rate_code_id SMALLINT,"
" store_and_fwd_flag TEXT ENCODING DICT,"
" pickup_datetime TIMESTAMP,"
" dropoff_datetime TIMESTAMP,"
" passenger_count SMALLINT,"
" trip_time_in_secs INTEGER,"
" trip_distance FLOAT,"
" pickup_longitude DECIMAL(14,7),"
" pickup_latitude DECIMAL(14,7),"
" dropoff_longitude DOUBLE,"
" dropoff_latitude DECIMAL(18,5),"
" deleted BOOLEAN"
" ) WITH (FRAGMENT_SIZE=50);"

Definition at line 143 of file AlterColumnTest.cpp.

◆ g_hoist_literals

bool anonymous_namespace{AlterColumnTest.cpp}::g_hoist_literals {true}

Definition at line 45 of file AlterColumnTest.cpp.

Referenced by run_query().

◆ type_vals

std::vector<std::tuple<std::string, std::string, std::string, std::string> > anonymous_namespace{AlterColumnTest.cpp}::type_vals
Initial value:
= {
MT("text", "none", "'abc'", ""),
MT("text", "dict(8)", "'ijk'", ""),
MT("text", "dict(32)", "'xyz'", ""),
MT("float", "", "1.25", ""),
MT("double", "", "1.25", ""),
MT("smallint", "", "123", ""),
MT("integer", "", "123", ""),
MT("bigint", "", "123", ""),
MT("bigint encoding fixed(8)", "", "", ""),
MT("bigint encoding fixed(16)", "", "", ""),
MT("bigint encoding fixed(32)", "", "", ""),
MT("decimal(8)", "", "123", ""),
MT("decimal(8,2)", "", "1.23", ""),
MT("date", "", "'2011-10-23'", ""),
MT("time", "", "'10:23:45'", ""),
MT("timestamp", "", "'2011-10-23 10:23:45'", ""),
MT("POINT", "", "'POINT (1 2)'", "POINT (1 2)"),
MT("LINESTRING", "", "'LINESTRING (1 1,2 2,3 3)'", "LINESTRING (1 1,2 2,3 3)"),
MT("POLYGON",
"",
"'POLYGON((0 0,0 9,9 9,9 0),(1 1,2 2,3 3))'",
"POLYGON ((9 0,9 9,0 9,0 0,9 0),(3 3,2 2,1 1,3 3))"),
MT("MULTIPOLYGON",
"",
"'MULTIPOLYGON(((0 0,0 9,9 9,9 0),(1 1,2 2,3 3)))'",
"MULTIPOLYGON (((9 0,9 9,0 9,0 0,9 0),(3 3,2 2,1 1,3 3)))"),
}
#define MT

Definition at line 179 of file AlterColumnTest.cpp.