OmniSciDB  04ee39c94c
CalciteOptimizeTest.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <boost/filesystem/operations.hpp>
3 #include <csignal>
4 #include <thread>
5 #include <tuple>
6 #include "../Catalog/Catalog.h"
7 #include "../Catalog/DBObject.h"
8 #include "../DataMgr/DataMgr.h"
9 #include "../Parser/parser.h"
10 #include "../QueryRunner/QueryRunner.h"
11 #include "Shared/MapDParameters.h"
12 #include "TestHelpers.h"
13 #include "gen-cpp/CalciteServer.h"
14 
16 namespace {
17 
18 std::shared_ptr<Calcite> g_calcite;
19 
20 inline void run_ddl_statement(const std::string& query) {
21  QR::get()->runDDLStatement(query);
22 }
23 
24 } // namespace
25 
26 struct ViewObject : testing::Test {
27  void setup_objects() {
28  run_ddl_statement("CREATE TABLE table1(i1 integer, i2 integer);");
29  run_ddl_statement("CREATE VIEW view_table1 AS SELECT i1, i2 FROM table1;");
30  run_ddl_statement("CREATE VIEW view_view_table1 AS SELECT i1, i2 FROM view_table1;");
31  run_ddl_statement("CREATE TABLE shape_table (block_group_id INT)");
33  "CREATE TABLE attribute_table( block_group_id INT, segment_name TEXT ENCODING "
34  "DICT(8), segment_type TEXT ENCODING DICT(8), agg_column TEXT ENCODING DICT(8))");
36  "CREATE VIEW attribute_view AS select "
37  "rowid,block_group_id,segment_name,segment_type,agg_column from attribute_table");
39  "CREATE VIEW shape_view AS select rowid, block_group_id from shape_table");
40  }
41 
42  void remove_objects() {
43  run_ddl_statement("DROP VIEW view_view_table1;");
44  run_ddl_statement("DROP VIEW view_table1;");
45  run_ddl_statement("DROP TABLE table1");
46  run_ddl_statement("DROP VIEW attribute_view");
47  run_ddl_statement("DROP VIEW shape_view");
48  run_ddl_statement("DROP TABLE shape_table");
49  run_ddl_statement("DROP TABLE attribute_table");
50  }
51 
52  explicit ViewObject() { setup_objects(); }
53  ~ViewObject() override { remove_objects(); }
54 };
55 
56 TEST_F(ViewObject, BasicTest) {
57  auto session = QR::get()->getSession();
58  CHECK(session);
59 
60  TPlanResult tresult =
61  g_calcite->process(*session, "select i1 from table1", {}, true, false, false);
62 
63  TPlanResult vresult = g_calcite->process(
64  *session, "select i1 from view_view_table1", {}, true, false, false);
65 
66  EXPECT_EQ(vresult.plan_result, tresult.plan_result);
67 
68  TPlanResult ovresult = g_calcite->process(
69  *session, "select i1 from view_view_table1", {}, true, false, true);
70 
71  EXPECT_EQ(ovresult.plan_result, tresult.plan_result);
72 
73  TPlanResult tab_result = g_calcite->process(
74  *session,
75  "SELECT shape_table.rowid FROM shape_table, attribute_table WHERE "
76  "shape_table.block_group_id = attribute_table.block_group_id",
77  {},
78  true,
79  false,
80  true);
81  TPlanResult view_result =
82  g_calcite->process(*session,
83  "SELECT shape_view.rowid FROM shape_view, attribute_view WHERE "
84  "shape_view.block_group_id = attribute_view.block_group_id",
85  {},
86  true,
87  false,
88  true);
89  EXPECT_EQ(tab_result.plan_result, view_result.plan_result);
90 }
91 
92 int main(int argc, char* argv[]) {
94  testing::InitGoogleTest(&argc, argv);
95 
97  g_calcite = QR::get()->getCatalog()->getCalciteMgr();
98 
99  int err{0};
100  try {
101  err = RUN_ALL_TESTS();
102  } catch (const std::exception& e) {
103  LOG(ERROR) << e.what();
104  }
105  QR::reset();
106  return err;
107 }
#define LOG(tag)
Definition: Logger.h:182
int main(int argc, char *argv[])
static QueryRunner * init(const char *db_path, const std::string &udf_filename="", const size_t max_gpu_mem=0, const int reserved_gpu_mem=256<< 20)
Definition: QueryRunner.h:70
virtual void runDDLStatement(const std::string &)
~ViewObject() override
std::shared_ptr< Catalog_Namespace::Catalog > getCatalog() const
static QueryRunner * get()
Definition: QueryRunner.h:115
#define CHECK(condition)
Definition: Logger.h:187
void init_logger_stderr_only(int argc, char const *const *argv)
Definition: TestHelpers.h:194
TSessionId session
TEST_F(ViewObject, BasicTest)
Catalog_Namespace::SessionInfo * getSession() const
Definition: QueryRunner.h:124
void run_ddl_statement(std::string ddl)
#define BASE_PATH