OmniSciDB  04ee39c94c
UdfTest.cpp File Reference
#include <gtest/gtest.h>
#include <boost/filesystem.hpp>
#include <boost/filesystem/operations.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/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 UdfTest.cpp:

Go to the source code of this file.

Classes

class  anonymous_namespace{UdfTest.cpp}::SQLTestEnv
 
class  UDFCompilerTest
 

Namespaces

 anonymous_namespace{UdfTest.cpp}
 

Macros

#define BASE_PATH   "./tmp"
 
#define SKIP_NO_GPU()
 

Typedefs

using QR = QueryRunner::QueryRunner
 

Functions

std::string anonymous_namespace{UdfTest.cpp}::udf_file_name_base ("../../Tests/Udf/udf_sample")
 
std::shared_ptr< ResultSetanonymous_namespace{UdfTest.cpp}::run_multiple_agg (const std::string &query_str, const ExecutorDeviceType device_type, const bool allow_loop_joins)
 
std::shared_ptr< ResultSetanonymous_namespace{UdfTest.cpp}::run_multiple_agg (const std::string &query_str, const ExecutorDeviceType device_type)
 
TargetValue anonymous_namespace{UdfTest.cpp}::run_simple_agg (const std::string &query_str, const ExecutorDeviceType device_type, const bool allow_loop_joins=true)
 
std::string anonymous_namespace{UdfTest.cpp}::get_udf_filename ()
 
std::string anonymous_namespace{UdfTest.cpp}::get_udf_cpu_ir_filename ()
 
std::string anonymous_namespace{UdfTest.cpp}::get_udf_gpu_ir_filename ()
 
std::string anonymous_namespace{UdfTest.cpp}::get_udf_ast_filename ()
 
bool anonymous_namespace{UdfTest.cpp}::skip_tests (const ExecutorDeviceType device_type)
 
void anonymous_namespace{UdfTest.cpp}::run_ddl_statement (const std::string &query)
 
 TEST_F (UDFCompilerTest, CompileTest)
 
 TEST_F (UDFCompilerTest, CalciteRegistration)
 
 TEST_F (UDFCompilerTest, UdfQuery)
 
int main (int argc, char **argv)
 

Variables

std::shared_ptr< Calciteanonymous_namespace{UdfTest.cpp}::g_calcite = nullptr
 

Macro Definition Documentation

◆ BASE_PATH

#define BASE_PATH   "./tmp"

Definition at line 37 of file UdfTest.cpp.

Referenced by anonymous_namespace{UdfTest.cpp}::SQLTestEnv::SetUp().

◆ SKIP_NO_GPU

#define SKIP_NO_GPU ( )
Value:
if (skip_tests(dt)) { \
CHECK(dt == ExecutorDeviceType::GPU); \
LOG(WARNING) << "GPU not available, skipping GPU tests"; \
continue; \
}
bool skip_tests(const ExecutorDeviceType device_type)
Definition: UdfTest.cpp:93

Definition at line 45 of file UdfTest.cpp.

Referenced by TEST_F().

Typedef Documentation

◆ QR

Definition at line 43 of file UdfTest.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 248 of file UdfTest.cpp.

References logger::ERROR, TestHelpers::init_logger_stderr_only(), and LOG.

248  {
250  ::testing::InitGoogleTest(&argc, argv);
251  ::testing::AddGlobalTestEnvironment(new SQLTestEnv);
252 
253  int err{0};
254  try {
255  err = RUN_ALL_TESTS();
256  } catch (const std::exception& e) {
257  LOG(ERROR) << e.what();
258  }
259  return err;
260 }
#define LOG(tag)
Definition: Logger.h:182
void init_logger_stderr_only(int argc, char const *const *argv)
Definition: TestHelpers.h:194
+ Here is the call graph for this function:

◆ TEST_F() [1/3]

TEST_F ( UDFCompilerTest  ,
CompileTest   
)

Definition at line 169 of file UdfTest.cpp.

References UdfCompiler::compileUdf().

169  {
170  UdfCompiler compiler(getUdfFileName());
171  auto compile_result = compiler.compileUdf();
172 
173  EXPECT_EQ(compile_result, 0);
174  // TODO cannot test invalid file path because the compileUdf function uses
175  // LOG(FATAL) which stops the process and does not return
176 }
+ Here is the call graph for this function:

◆ TEST_F() [2/3]

TEST_F ( UDFCompilerTest  ,
CalciteRegistration   
)

Definition at line 178 of file UdfTest.cpp.

References UdfCompiler::compileUdf(), anonymous_namespace{UdfTest.cpp}::g_calcite, and ExtensionFunctionsWhitelist::get_udf().

178  {
179  UdfCompiler compiler(getUdfFileName());
180  auto compile_result = compiler.compileUdf();
181 
182  ASSERT_EQ(compile_result, 0);
183 
184  ASSERT_TRUE(g_calcite != nullptr);
185 
186  auto signature = ExtensionFunctionsWhitelist::get_udf("udf_truerange");
187  ASSERT_NE(signature, nullptr);
188 
189  auto signature2 = ExtensionFunctionsWhitelist::get_udf("udf_truehigh");
190  ASSERT_NE(signature2, nullptr);
191 
192  auto signature3 = ExtensionFunctionsWhitelist::get_udf("udf_truelow");
193  ASSERT_NE(signature3, nullptr);
194 
195  auto signature4 = ExtensionFunctionsWhitelist::get_udf("udf_range");
196  ASSERT_NE(signature4, nullptr);
197 
198  auto signature5 = ExtensionFunctionsWhitelist::get_udf("udf_range_int");
199  ASSERT_NE(signature5, nullptr);
200 
201  auto signature6 = ExtensionFunctionsWhitelist::get_udf("udf_range_integer");
202  ASSERT_EQ(signature6, nullptr);
203 }
static std::vector< ExtensionFunction > * get_udf(const std::string &name)
std::shared_ptr< Calcite > g_calcite
Definition: UdfTest.cpp:54
+ Here is the call graph for this function:

◆ TEST_F() [3/3]

TEST_F ( UDFCompilerTest  ,
UdfQuery   
)

Definition at line 205 of file UdfTest.cpp.

References UdfCompiler::compileUdf(), CPU, GPU, run_ddl_statement(), run_multiple_agg(), anonymous_namespace{UdfTest.cpp}::run_simple_agg(), and SKIP_NO_GPU.

205  {
206  UdfCompiler compiler(getUdfFileName());
207  auto compile_result = compiler.compileUdf();
208 
209  ASSERT_EQ(compile_result, 0);
210 
211  run_ddl_statement("DROP TABLE IF EXISTS stocks;");
213  "CREATE TABLE stocks(symbol text, open_p int, high_p int, "
214  "low_p int, close_p int, entry_d DATE);");
215 
216  std::string insert1(
217  "INSERT into stocks VALUES ('NVDA', '178', '178', '171', '173', '2019-05-07');");
218  EXPECT_NO_THROW(run_multiple_agg(insert1, ExecutorDeviceType::CPU));
219 
220  std::string insert2(
221  "INSERT into stocks VALUES ('NVDA', '175', '181', '174', '178', '2019-05-06');");
222  EXPECT_NO_THROW(run_multiple_agg(insert2, ExecutorDeviceType::CPU));
223 
224  std::string insert3(
225  "INSERT into stocks VALUES ('NVDA', '183', '184', '181', '183', '2019-05-03');");
226  EXPECT_NO_THROW(run_multiple_agg(insert3, ExecutorDeviceType::CPU));
227 
229  SKIP_NO_GPU();
230  ASSERT_EQ(7,
231  v<int64_t>(run_simple_agg("SELECT udf_range_int(high_p, low_p) from stocks "
232  "where entry_d = '2019-05-06';",
233  dt)));
234  ASSERT_EQ(3,
235  v<int64_t>(run_simple_agg("SELECT udf_range_int(high_p, low_p) from stocks "
236  "where entry_d = '2019-05-03';",
237  dt)));
238  }
239 
240  EXPECT_THROW(run_simple_agg("SELECT udf_range_integer(high_p, low_p) from stocks where "
241  "entry_d = '2019-05-06';",
243  std::exception);
244 
245  run_ddl_statement("DROP TABLE stocks;");
246 }
TargetValue run_simple_agg(const std::string &query_str, const ExecutorDeviceType device_type, const bool allow_loop_joins=true)
Definition: UdfTest.cpp:68
#define SKIP_NO_GPU()
Definition: UdfTest.cpp:45
void run_ddl_statement(std::string ddl)
TQueryResult run_multiple_agg(std::string sql)
+ Here is the call graph for this function: