OmniSciDB  c07336695a
anonymous_namespace{TopKTest.cpp}::SQLiteComparator Class Reference
+ Collaboration diagram for anonymous_namespace{TopKTest.cpp}::SQLiteComparator:

Public Member Functions

 SQLiteComparator ()
 
void query (const std::string &query_string)
 
void compare (const std::string &query_string, const ExecutorDeviceType device_type)
 
void compare_arrow_output (const std::string &query_string, const std::string &sqlite_query_string, const ExecutorDeviceType device_type)
 
void compare (const std::string &query_string, const std::string &sqlite_query_string, const ExecutorDeviceType device_type)
 
void compare_timstamp_approx (const std::string &query_string, const ExecutorDeviceType device_type)
 

Private Member Functions

template<class MapDResults >
void compare_impl (const MapDResults *mapd_results, const std::string &sqlite_query_string, const ExecutorDeviceType device_type, bool timestamp_approx)
 

Static Private Member Functions

static void checkTypeConsistency (const int ref_col_type, const SQLTypeInfo &mapd_ti)
 

Private Attributes

SqliteConnector connector_
 

Detailed Description

Definition at line 79 of file TopKTest.cpp.

Constructor & Destructor Documentation

◆ SQLiteComparator()

anonymous_namespace{TopKTest.cpp}::SQLiteComparator::SQLiteComparator ( )
inline

Definition at line 81 of file TopKTest.cpp.

81 : connector_("sqliteTestDB", "") {}

Member Function Documentation

◆ checkTypeConsistency()

static void anonymous_namespace{TopKTest.cpp}::SQLiteComparator::checkTypeConsistency ( const int  ref_col_type,
const SQLTypeInfo mapd_ti 
)
inlinestaticprivate

Definition at line 276 of file TopKTest.cpp.

References CHECK_EQ, SQLTypeInfoCore< TYPE_FACET_PACK >::is_decimal(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_fp(), and SQLTypeInfoCore< TYPE_FACET_PACK >::is_integer().

276  {
277  if (ref_col_type == SQLITE_NULL) {
278  // TODO(alex): re-enable the check that mapd_ti is nullable,
279  // got invalidated because of outer joins
280  return;
281  }
282  if (mapd_ti.is_integer()) {
283  CHECK_EQ(SQLITE_INTEGER, ref_col_type);
284  } else if (mapd_ti.is_fp() || mapd_ti.is_decimal()) {
285  CHECK_EQ(SQLITE_FLOAT, ref_col_type);
286  } else {
287  CHECK_EQ(SQLITE_TEXT, ref_col_type);
288  }
289  }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
bool is_fp() const
Definition: sqltypes.h:450
bool is_integer() const
Definition: sqltypes.h:448
bool is_decimal() const
Definition: sqltypes.h:449
+ Here is the call graph for this function:

◆ compare() [1/2]

void anonymous_namespace{TopKTest.cpp}::SQLiteComparator::compare ( const std::string &  query_string,
const ExecutorDeviceType  device_type 
)
inline

Definition at line 85 of file TopKTest.cpp.

References run_multiple_agg().

Referenced by anonymous_namespace{TopKTest.cpp}::c().

85  {
86  const auto mapd_results = run_multiple_agg(query_string, device_type);
87  compare_impl(mapd_results.get(), query_string, device_type, false);
88  }
std::shared_ptr< ResultSet > run_multiple_agg(const string &query_str, const ExecutorDeviceType device_type, const bool allow_loop_joins)
Definition: TopKTest.cpp:45
void compare_impl(const MapDResults *mapd_results, const std::string &sqlite_query_string, const ExecutorDeviceType device_type, bool timestamp_approx)
Definition: TopKTest.cpp:114
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compare() [2/2]

void anonymous_namespace{TopKTest.cpp}::SQLiteComparator::compare ( const std::string &  query_string,
const std::string &  sqlite_query_string,
const ExecutorDeviceType  device_type 
)
inline

Definition at line 98 of file TopKTest.cpp.

References run_multiple_agg().

100  {
101  const auto mapd_results = run_multiple_agg(query_string, device_type);
102  compare_impl(mapd_results.get(), sqlite_query_string, device_type, false);
103  }
std::shared_ptr< ResultSet > run_multiple_agg(const string &query_str, const ExecutorDeviceType device_type, const bool allow_loop_joins)
Definition: TopKTest.cpp:45
void compare_impl(const MapDResults *mapd_results, const std::string &sqlite_query_string, const ExecutorDeviceType device_type, bool timestamp_approx)
Definition: TopKTest.cpp:114
+ Here is the call graph for this function:

◆ compare_arrow_output()

void anonymous_namespace{TopKTest.cpp}::SQLiteComparator::compare_arrow_output ( const std::string &  query_string,
const std::string &  sqlite_query_string,
const ExecutorDeviceType  device_type 
)
inline

Definition at line 90 of file TopKTest.cpp.

References QueryRunner::QueryRunner::get(), result_set_arrow_loopback(), and QueryRunner::QueryRunner::runSelectQuery().

92  {
93  const auto results = QR::get()->runSelectQuery(query_string, device_type, true, true);
94  const auto arrow_mapd_results = result_set_arrow_loopback(results);
95  compare_impl(arrow_mapd_results.get(), sqlite_query_string, device_type, false);
96  }
virtual ExecutionResult runSelectQuery(const std::string &query_str, const ExecutorDeviceType device_type, const bool hoist_literals, const bool allow_loop_joins, const bool just_explain=false)
void compare_impl(const MapDResults *mapd_results, const std::string &sqlite_query_string, const ExecutorDeviceType device_type, bool timestamp_approx)
Definition: TopKTest.cpp:114
static QueryRunner * get()
Definition: QueryRunner.h:115
std::unique_ptr< ArrowResultSet > result_set_arrow_loopback(const ExecutionResult &results)
+ Here is the call graph for this function:

◆ compare_impl()

template<class MapDResults >
void anonymous_namespace{TopKTest.cpp}::SQLiteComparator::compare_impl ( const MapDResults *  mapd_results,
const std::string &  sqlite_query_string,
const ExecutorDeviceType  device_type,
bool  timestamp_approx 
)
inlineprivate

Definition at line 114 of file TopKTest.cpp.

References anonymous_namespace{TopKTest.cpp}::approx_eq(), CHECK, CHECK_EQ, inline_fp_null_val(), inline_int_null_val(), kBIGINT, kBOOLEAN, kCHAR, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kNUMERIC, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kVARCHAR, num_rows, and split().

117  {
118  connector_.query(sqlite_query_string);
119  ASSERT_EQ(connector_.getNumRows(), mapd_results->rowCount());
120  const int num_rows{static_cast<int>(connector_.getNumRows())};
121  if (mapd_results->definitelyHasNoRows()) {
122  ASSERT_EQ(0, num_rows);
123  return;
124  }
125  if (!num_rows) {
126  return;
127  }
128  CHECK_EQ(connector_.getNumCols(), mapd_results->colCount());
129  const int num_cols{static_cast<int>(connector_.getNumCols())};
130  for (int row_idx = 0; row_idx < num_rows; ++row_idx) {
131  const auto crt_row = mapd_results->getNextRow(true, true);
132  CHECK(!crt_row.empty());
133  CHECK_EQ(static_cast<size_t>(num_cols), crt_row.size());
134  for (int col_idx = 0; col_idx < num_cols; ++col_idx) {
135  const auto ref_col_type = connector_.columnTypes[col_idx];
136  const auto mapd_variant = crt_row[col_idx];
137  const auto scalar_mapd_variant = boost::get<ScalarTargetValue>(&mapd_variant);
138  CHECK(scalar_mapd_variant);
139  const auto mapd_ti = mapd_results->getColType(col_idx);
140  const auto mapd_type = mapd_ti.get_type();
141  checkTypeConsistency(ref_col_type, mapd_ti);
142  const bool ref_is_null = connector_.isNull(row_idx, col_idx);
143  switch (mapd_type) {
144  case kSMALLINT:
145  case kINT:
146  case kBIGINT: {
147  const auto mapd_as_int_p = boost::get<int64_t>(scalar_mapd_variant);
148  ASSERT_NE(nullptr, mapd_as_int_p);
149  const auto mapd_val = *mapd_as_int_p;
150  if (ref_is_null) {
151  ASSERT_EQ(inline_int_null_val(mapd_ti), mapd_val);
152  } else {
153  const auto ref_val = connector_.getData<int64_t>(row_idx, col_idx);
154  ASSERT_EQ(ref_val, mapd_val);
155  }
156  break;
157  }
158  case kTEXT:
159  case kCHAR:
160  case kVARCHAR: {
161  const auto mapd_as_str_p = boost::get<NullableString>(scalar_mapd_variant);
162  ASSERT_NE(nullptr, mapd_as_str_p);
163  const auto mapd_str_notnull = boost::get<std::string>(mapd_as_str_p);
164  if (ref_is_null) {
165  CHECK(!mapd_str_notnull);
166  } else {
167  CHECK(mapd_str_notnull);
168  const auto ref_val = connector_.getData<std::string>(row_idx, col_idx);
169  const auto mapd_val = *mapd_str_notnull;
170  ASSERT_EQ(ref_val, mapd_val);
171  }
172  break;
173  }
174  case kNUMERIC:
175  case kDECIMAL:
176  case kDOUBLE: {
177  const auto mapd_as_double_p = boost::get<double>(scalar_mapd_variant);
178  ASSERT_NE(nullptr, mapd_as_double_p);
179  const auto mapd_val = *mapd_as_double_p;
180  if (ref_is_null) {
181  ASSERT_EQ(inline_fp_null_val(SQLTypeInfo(kDOUBLE, false)), mapd_val);
182  } else {
183  const auto ref_val = connector_.getData<double>(row_idx, col_idx);
184  ASSERT_TRUE(approx_eq(ref_val, mapd_val));
185  }
186  break;
187  }
188  case kFLOAT: {
189  const auto mapd_as_float_p = boost::get<float>(scalar_mapd_variant);
190  ASSERT_NE(nullptr, mapd_as_float_p);
191  const auto mapd_val = *mapd_as_float_p;
192  if (ref_is_null) {
193  if (inline_fp_null_val(SQLTypeInfo(kFLOAT, false)) != mapd_val) {
194  CHECK(false);
195  }
196  } else {
197  const auto ref_val = connector_.getData<float>(row_idx, col_idx);
198  if (!approx_eq(ref_val, mapd_val)) {
199  CHECK(false);
200  }
201  }
202  break;
203  }
204  case kTIMESTAMP:
205  case kDATE: {
206  const auto mapd_as_int_p = boost::get<int64_t>(scalar_mapd_variant);
207  CHECK(mapd_as_int_p);
208  const auto mapd_val = *mapd_as_int_p;
209  if (ref_is_null) {
210  CHECK_EQ(inline_int_null_val(mapd_ti), mapd_val);
211  } else {
212  struct tm tm_struct {
213  0
214  };
215  const auto ref_val = connector_.getData<std::string>(row_idx, col_idx);
216  const auto end_str =
217  strptime(ref_val.c_str(),
218  mapd_type == kTIMESTAMP ? "%Y-%m-%d %H:%M:%S" : "%Y-%m-%d",
219  &tm_struct);
220  if (end_str != nullptr) {
221  ASSERT_EQ(0, *end_str);
222  ASSERT_EQ(ref_val.size(), static_cast<size_t>(end_str - ref_val.c_str()));
223  }
224  if (timestamp_approx) {
225  // approximate result give 10 second lee way
226  ASSERT_NEAR(*mapd_as_int_p, timegm(&tm_struct), 10);
227  } else {
228  ASSERT_EQ(*mapd_as_int_p, timegm(&tm_struct));
229  }
230  }
231  break;
232  }
233  case kBOOLEAN: {
234  const auto mapd_as_int_p = boost::get<int64_t>(scalar_mapd_variant);
235  CHECK(mapd_as_int_p);
236  const auto mapd_val = *mapd_as_int_p;
237  if (ref_is_null) {
238  CHECK_EQ(inline_int_null_val(mapd_ti), mapd_val);
239  } else {
240  const auto ref_val = connector_.getData<std::string>(row_idx, col_idx);
241  if (ref_val == "t") {
242  ASSERT_EQ(1, *mapd_as_int_p);
243  } else {
244  CHECK_EQ("f", ref_val);
245  ASSERT_EQ(0, *mapd_as_int_p);
246  }
247  }
248  break;
249  }
250  case kTIME: {
251  const auto mapd_as_int_p = boost::get<int64_t>(scalar_mapd_variant);
252  CHECK(mapd_as_int_p);
253  const auto mapd_val = *mapd_as_int_p;
254  if (ref_is_null) {
255  CHECK_EQ(inline_int_null_val(mapd_ti), mapd_val);
256  } else {
257  const auto ref_val = connector_.getData<std::string>(row_idx, col_idx);
258  std::vector<std::string> time_tokens;
259  boost::split(time_tokens, ref_val, boost::is_any_of(":"));
260  ASSERT_EQ(size_t(3), time_tokens.size());
261  ASSERT_EQ(boost::lexical_cast<int64_t>(time_tokens[0]) * 3600 +
262  boost::lexical_cast<int64_t>(time_tokens[1]) * 60 +
263  boost::lexical_cast<int64_t>(time_tokens[2]),
264  *mapd_as_int_p);
265  }
266  break;
267  }
268  default:
269  CHECK(false);
270  }
271  }
272  }
273  }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
T getData(const int row, const int col)
const int8_t const int64_t * num_rows
Definition: sqltypes.h:51
void query(const std::string &queryString)
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
size_t getNumRows() const
size_t getNumCols() const
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:819
std::vector< int > columnTypes
bool approx_eq(const double v, const double target, const double eps=0.01)
Definition: TopKTest.cpp:73
Definition: sqltypes.h:54
Definition: sqltypes.h:55
std::vector< std::string > split(const std::string &str, const std::string &delim)
Definition: sqltypes.h:43
bool isNull(const int row, const int col) const
#define CHECK(condition)
Definition: Logger.h:187
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:47
static void checkTypeConsistency(const int ref_col_type, const SQLTypeInfo &mapd_ti)
Definition: TopKTest.cpp:276
+ Here is the call graph for this function:

◆ compare_timstamp_approx()

void anonymous_namespace{TopKTest.cpp}::SQLiteComparator::compare_timstamp_approx ( const std::string &  query_string,
const ExecutorDeviceType  device_type 
)
inline

Definition at line 106 of file TopKTest.cpp.

References run_multiple_agg().

107  {
108  const auto mapd_results = run_multiple_agg(query_string, device_type);
109  compare_impl(mapd_results.get(), query_string, device_type, true);
110  }
std::shared_ptr< ResultSet > run_multiple_agg(const string &query_str, const ExecutorDeviceType device_type, const bool allow_loop_joins)
Definition: TopKTest.cpp:45
void compare_impl(const MapDResults *mapd_results, const std::string &sqlite_query_string, const ExecutorDeviceType device_type, bool timestamp_approx)
Definition: TopKTest.cpp:114
+ Here is the call graph for this function:

◆ query()

void anonymous_namespace{TopKTest.cpp}::SQLiteComparator::query ( const std::string &  query_string)
inline

Definition at line 83 of file TopKTest.cpp.

Referenced by anonymous_namespace{TopKTest.cpp}::create_and_populate_tables(), and anonymous_namespace{TopKTest.cpp}::drop_tables().

83 { connector_.query(query_string); }
void query(const std::string &queryString)
+ Here is the caller graph for this function:

Member Data Documentation

◆ connector_

SqliteConnector anonymous_namespace{TopKTest.cpp}::SQLiteComparator::connector_
private

Definition at line 291 of file TopKTest.cpp.


The documentation for this class was generated from the following file: