OmniSciDB  04ee39c94c
JoinHashTableTest.cpp File Reference
#include <gtest/gtest.h>
#include <boost/filesystem.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/program_options.hpp>
#include <csignal>
#include <exception>
#include <memory>
#include <vector>
#include "Catalog/Catalog.h"
#include "Catalog/DBObject.h"
#include "DataMgr/DataMgr.h"
#include "QueryEngine/Execute.h"
#include "QueryEngine/ExtensionFunctionsWhitelist.h"
#include "QueryEngine/OverlapsJoinHashTable.h"
#include "QueryEngine/ResultSet.h"
#include "QueryEngine/UDFCompiler.h"
#include "QueryRunner/QueryRunner.h"
#include "Shared/Logger.h"
#include "Shared/MapDParameters.h"
#include "TestHelpers.h"
+ Include dependency graph for JoinHashTableTest.cpp:

Go to the source code of this file.

Namespaces

 anonymous_namespace{JoinHashTableTest.cpp}
 

Macros

#define BASE_PATH   "./tmp"
 

Typedefs

using QR = QueryRunner::QueryRunner
 

Functions

auto sql (const std::string &sql_stmts)
 
int deviceCount (const Catalog_Namespace::Catalog *catalog, const ExecutorDeviceType device_type)
 
 TEST (Memcmp, OverlapsJoinHashTable)
 
int main (int argc, char **argv)
 

Variables

constexpr size_t c_calcite_port = 36279
 
ExecutorDeviceType anonymous_namespace{JoinHashTableTest.cpp}::g_device_type
 

Macro Definition Documentation

◆ BASE_PATH

#define BASE_PATH   "./tmp"

Definition at line 41 of file JoinHashTableTest.cpp.

Referenced by main().

Typedef Documentation

◆ QR

Definition at line 49 of file JoinHashTableTest.cpp.

Function Documentation

◆ deviceCount()

int deviceCount ( const Catalog_Namespace::Catalog catalog,
const ExecutorDeviceType  device_type 
)

Definition at line 59 of file JoinHashTableTest.cpp.

References CHECK, Data_Namespace::DataMgr::getCudaMgr(), Catalog_Namespace::Catalog::getDataMgr(), and GPU.

Referenced by CodeGenerator::codegen(), and TEST().

60  {
61  if (device_type == ExecutorDeviceType::GPU) {
62  const auto cuda_mgr = catalog->getDataMgr().getCudaMgr();
63  CHECK(cuda_mgr);
64  return cuda_mgr->getDeviceCount();
65  } else {
66  return 1;
67  }
68 }
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:177
CudaMgr_Namespace::CudaMgr * getCudaMgr() const
Definition: DataMgr.h:116
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 131 of file JoinHashTableTest.cpp.

References BASE_PATH, logger::DEBUG1, logger::ERROR, QueryRunner::QueryRunner::init(), logger::init(), LOG, QueryRunner::QueryRunner::reset(), and logger::LogOptions::severity_.

131  {
132  testing::InitGoogleTest(&argc, argv);
133 
134  logger::LogOptions log_options(argv[0]);
135  log_options.severity_ = logger::Severity::DEBUG1;
136  logger::init(log_options);
137 
139 
140  int err{0};
141  try {
142  err = RUN_ALL_TESTS();
143  } catch (const std::exception& e) {
144  LOG(ERROR) << e.what();
145  }
146  QR::reset();
147  return err;
148 }
#define LOG(tag)
Definition: Logger.h:182
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
void init(LogOptions const &log_opts)
Definition: Logger.cpp:260
#define BASE_PATH
+ Here is the call graph for this function:

◆ sql()

auto sql ( const std::string &  sql_stmts)
inline

Definition at line 55 of file JoinHashTableTest.cpp.

References anonymous_namespace{JoinHashTableTest.cpp}::g_device_type, QueryRunner::QueryRunner::get(), and QueryRunner::QueryRunner::runMultipleStatements().

Referenced by Catalog_Namespace::SysCatalog::alterUser(), com.mapd.calcite.parser.MapDParser::captureIdentifiers(), Worker::doQuery(), com.omnisci.jdbc.OmniSciStatement::execute(), com.omnisci.jdbc.OmniSciStatement::executeQuery(), com.omnisci.jdbc.OmniSciStatement::executeUpdate(), com.omnisci.jdbc.OmniSciStatement::fnReplace(), com.mapd.parser.server.CalciteServerHandler::getCompletionHints(), com.mapd.bench.BenchmarkCloud::getQueries(), com.mapd.calcite.parser.MapDParser::getRelAlgebra(), Catalog_Namespace::SysCatalog::getRoles(), SampleJDBC::main(), FirstTry::main(), org.apache.calcite.prepare.SqlIdentifierCapturer::main(), MapDHandler::max_bytes_for_thrift(), com.omnisci.jdbc.OmniSciPreparedStatement::OmniSciPreparedStatement(), com.omnisci.jdbc.OmniSciConnection::prepareStatement(), com.mapd.calcite.parser.MapDParser::processSQL(), com.mapd.calcite.parser.MapDParser::queryToSqlNode(), org.apache.calcite.prepare.MapDPlanner::rel(), com.mapd.tests.MapdTestClient::runSql(), com.mapd.tests.UpdateDeleteInsertConcurrencyTest::runTest(), TEST(), com.mapd.parser.server.test.SqlIdentifierCapturerTest::testDelete(), com.mapd.parser.server.test.SqlIdentifierCapturerTest::testDeletes(), com.mapd.parser.server.test.SqlIdentifierCapturerTest::testDeletesWithSchema(), com.mapd.parser.server.test.SqlIdentifierCapturerTest::testInsert(), com.mapd.parser.server.test.SqlIdentifierCapturerTest::testInserts(), com.mapd.parser.server.test.SqlIdentifierCapturerTest::testInsertsWithSchema(), com.mapd.parser.server.test.SqlIdentifierCapturerTest::testSelect(), com.mapd.parser.server.test.SqlIdentifierCapturerTest::testSelects(), com.mapd.parser.server.test.SqlIdentifierCapturerTest::testSelectsWithSchema(), com.mapd.parser.server.test.SqlIdentifierCapturerTest::testUpdate(), com.mapd.parser.server.test.SqlIdentifierCapturerTest::testUpdates(), and com.mapd.parser.server.test.SqlIdentifierCapturerTest::testUpdatesWithSchema().

55  {
56  return QR::get()->runMultipleStatements(sql_stmts, g_device_type);
57 }
virtual std::vector< std::shared_ptr< ResultSet > > runMultipleStatements(const std::string &, const ExecutorDeviceType)
static QueryRunner * get()
Definition: QueryRunner.h:115
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TEST()

TEST ( Memcmp  ,
OverlapsJoinHashTable   
)

Definition at line 70 of file JoinHashTableTest.cpp.

References CHECK_EQ, CPU, Data_Namespace::CPU_LEVEL, deviceCount(), anonymous_namespace{JoinHashTableTest.cpp}::g_device_type, QueryRunner::QueryRunner::get(), QueryRunner::QueryRunner::getCatalog(), Executor::getExecutor(), OverlapsJoinHashTable::getInstance(), kARRAY, kBOOLEAN, kDOUBLE, kENCODING_NONE, kGEOMETRY, kONE, kOVERLAPS, kPOINT, and sql().

70  {
72 
73  sql(R"(
74  drop table if exists my_points;
75  drop table if exists my_grid;
76  )");
77 
78  sql(R"(
79  create table my_points (locations geometry(point, 4326) encoding none);
80  create table my_grid (cells geometry(multipolygon, 4326) encoding none);
81 
82  insert into my_points values ('point(5 5)');
83  insert into my_points values ('point(5 25)');
84  insert into my_points values ('point(10 5)');
85 
86  insert into my_grid values ('multipolygon(((0 0,10 0,10 10,0 10,0 0)))');
87  insert into my_grid values ('multipolygon(((10 0,20 0,20 10,10 10,10 0)))');
88  insert into my_grid values ('multipolygon(((0 10,10 10,10 20,0 20,0 10)))');
89  insert into my_grid values ('multipolygon(((10 10,20 10,20 20,10 20,10 10)))');
90  )");
91 
92  auto catalog = QR::get()->getCatalog();
93  auto executor = Executor::getExecutor(catalog->getCurrentDB().dbId);
94 
95  auto tmeta1 = catalog->getMetadataForTable("my_points");
96  auto tmeta2 = catalog->getMetadataForTable("my_grid");
97 
98  SQLTypeInfo ti1{kPOINT, 4326, 4326, false, kENCODING_NONE, 64, kGEOMETRY};
99  SQLTypeInfo ti2{kARRAY, 0, 0, true, kENCODING_NONE, 0, kDOUBLE};
100  ti2.set_size(32);
101 
102  auto a1 = std::make_shared<Analyzer::ColumnVar>(ti1, tmeta1->tableId, 1, 0);
103  auto a2 = std::make_shared<Analyzer::ColumnVar>(ti2, tmeta2->tableId, 5, 1);
104 
105  auto op = std::make_shared<Analyzer::BinOper>(kBOOLEAN, kOVERLAPS, kONE, a1, a2);
106 
107  size_t number_of_join_tables{2};
108  std::vector<InputTableInfo> viti(number_of_join_tables);
109  viti[0].table_id = tmeta1->tableId;
110  viti[0].info = tmeta1->fragmenter->getFragmentsForQuery();
111  viti[1].table_id = tmeta2->tableId;
112  viti[1].info = tmeta2->fragmenter->getFragmentsForQuery();
113 
114  auto memory_level = Data_Namespace::CPU_LEVEL;
115 
116  auto device_count = deviceCount(catalog.get(), g_device_type);
117 
118  ColumnCacheMap ccm;
119 
120  auto hash_table = OverlapsJoinHashTable::getInstance(
121  op, viti, memory_level, device_count, ccm, executor.get());
122 
123  auto ptr1 =
124  reinterpret_cast<const int32_t*>(hash_table->getJoinHashBuffer(g_device_type, 0));
125  auto ptr2 = reinterpret_cast<const int32_t*>(
126  hash_table->getJoinHashBuffer(g_device_type, 0) + hash_table->offsetBufferOff());
127  CHECK_EQ(*ptr1, -1);
128  CHECK_EQ(*ptr2, -1);
129 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
static std::shared_ptr< Executor > getExecutor(const int db_id, const std::string &debug_dir="", const std::string &debug_file="", const MapDParameters mapd_parameters=MapDParameters(), ::QueryRenderer::QueryRenderManager *render_manager=nullptr)
Definition: Execute.cpp:122
auto sql(const std::string &sql_stmts)
static std::shared_ptr< OverlapsJoinHashTable > getInstance(const std::shared_ptr< Analyzer::BinOper > condition, const std::vector< InputTableInfo > &query_infos, const Data_Namespace::MemoryLevel memory_level, const int device_count, ColumnCacheMap &column_map, Executor *executor)
std::shared_ptr< Catalog_Namespace::Catalog > getCatalog() const
static QueryRunner * get()
Definition: QueryRunner.h:115
Definition: sqldefs.h:69
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > > > ColumnCacheMap
int deviceCount(const Catalog_Namespace::Catalog *catalog, const ExecutorDeviceType device_type)
+ Here is the call graph for this function:

Variable Documentation

◆ c_calcite_port

constexpr size_t c_calcite_port = 36279

Definition at line 44 of file JoinHashTableTest.cpp.