OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EmbeddedDbTest.cpp File Reference
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <exception>
#include <iostream>
#include "DBEngine.h"
#include <arrow/api.h>
#include <arrow/csv/reader.h>
#include <arrow/io/file.h>
#include "Shared/ArrowUtil.h"
+ Include dependency graph for EmbeddedDbTest.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 30 of file EmbeddedDbTest.cpp.

References ARROW_THROW_NOT_OK, EmbeddedDatabase::DBEngine::create(), setup::dbe, run, and to_string().

30  {
31  std::string base_path;
32  int calcite_port = 5555;
33  bool columnar_output = true;
34  namespace po = boost::program_options;
35 
36  po::options_description desc("Options");
37  desc.add_options()("help,h", "Print help messages ")(
38  "data",
39  po::value<std::string>(&base_path)->required(),
40  "Directory path to OmniSci catalogs")(
41  "calcite-port",
42  po::value<int>(&calcite_port)->default_value(calcite_port),
43  "Calcite port")("columnar-output",
44  po::value<bool>(&columnar_output)->default_value(columnar_output),
45  "Enable columnar_output");
46 
47  po::positional_options_description positionalOptions;
48  positionalOptions.add("data", 1);
49 
50  po::variables_map vm;
51 
52  try {
53  po::store(po::command_line_parser(argc, argv)
54  .options(desc)
55  .positional(positionalOptions)
56  .run(),
57  vm);
58  if (vm.count("help")) {
59  std::cout << desc;
60  return 0;
61  }
62  po::notify(vm);
63  } catch (boost::program_options::error& e) {
64  std::cerr << "Usage Error: " << e.what() << std::endl;
65  return 1;
66  }
67 
68  try {
69  auto opt_str = base_path + " --calcite-port " + std::to_string(calcite_port);
70  if (columnar_output) {
71  opt_str += "--columnar-output";
72  }
73  auto dbe = DBEngine::create(opt_str);
74  if (dbe) {
75  auto memory_pool = arrow::default_memory_pool();
76  auto arrow_parse_options = arrow::csv::ParseOptions::Defaults();
77  auto arrow_read_options = arrow::csv::ReadOptions::Defaults();
78  auto arrow_convert_options = arrow::csv::ConvertOptions::Defaults();
79  std::shared_ptr<arrow::io::ReadableFile> inp;
80  auto file_result = arrow::io::ReadableFile::Open("/localdisk/artemale/test.csv");
81  ARROW_THROW_NOT_OK(file_result.status());
82  inp = file_result.ValueOrDie();
83  auto table_reader_result = arrow::csv::TableReader::Make(memory_pool,
84  inp,
85  arrow_read_options,
86  arrow_parse_options,
87  arrow_convert_options);
88  ARROW_THROW_NOT_OK(table_reader_result.status());
89  auto table_reader = table_reader_result.ValueOrDie();
90  std::shared_ptr<arrow::Table> arrowTable;
91  auto arrow_table_result = table_reader->Read();
92  ARROW_THROW_NOT_OK(arrow_table_result.status());
93  arrowTable = arrow_table_result.ValueOrDie();
94  dbe->importArrowTable("test", arrowTable);
95 
96  auto schema = dbe->getTableDetails("test");
97  for (auto& item : schema) {
98  std::cout << item.col_name << std::endl;
99  }
100  auto cursor = dbe->executeDML("select * from test");
101  if (cursor) {
102  std::cout << cursor->getRowCount() << " rows selected" << std::endl;
103  std::shared_ptr<arrow::RecordBatch> rbatch = cursor->getArrowRecordBatch();
104  } else {
105  std::cerr << "Cursor is NULL" << std::endl;
106  }
107  }
108  } catch (std::exception& e) {
109  std::cerr << e.what() << "\n";
110  }
111  return 0;
112 }
#define ARROW_THROW_NOT_OK(s)
Definition: ArrowUtil.h:36
std::string to_string(char const *&&v)
FILE * create(const std::string &basePath, const int fileId, const size_t pageSize, const size_t numPages)
Definition: File.cpp:49
tuple dbe
Definition: setup.in.py:24
static bool run

+ Here is the call graph for this function: