OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EmbeddedDbFSITest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <boost/filesystem.hpp>
18 #include <boost/program_options.hpp>
19 #include <exception>
20 #include <iostream>
21 #include "DBEngine.h"
22 
23 #include <arrow/api.h>
24 #include <arrow/csv/reader.h>
25 #include <arrow/io/file.h>
26 #include "Shared/ArrowUtil.h"
27 
28 using namespace EmbeddedDatabase;
29 
30 int main(int argc, char* argv[]) {
31  std::string base_path, csv_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  "csv", po::value<std::string>(&csv_path)->required(), "Directory path to CSV file")(
42  "calcite-port",
43  po::value<int>(&calcite_port)->default_value(calcite_port),
44  "Calcite port")("columnar-output",
45  po::value<bool>(&columnar_output)->default_value(columnar_output),
46  "Enable columnar_output");
47 
48  po::positional_options_description positionalOptions;
49  positionalOptions.add("data", 1);
50 
51  po::variables_map vm;
52 
53  try {
54  po::store(po::command_line_parser(argc, argv)
55  .options(desc)
56  .positional(positionalOptions)
57  .run(),
58  vm);
59  if (vm.count("help")) {
60  std::cout << desc;
61  return 0;
62  }
63  po::notify(vm);
64  } catch (boost::program_options::error& e) {
65  std::cerr << "Usage Error: " << e.what() << std::endl;
66  return 1;
67  }
68 
69  try {
70  auto opt_str = base_path + " --calcite-port " + std::to_string(calcite_port);
71  if (columnar_output) {
72  opt_str += "--columnar-output";
73  }
74  auto dbe = DBEngine::create(opt_str);
75  if (dbe) {
76  dbe->executeDDL(std::string(R"( CREATE TEMPORARY TABLE test ( trip_id BIGINT, vendor_id TEXT ENCODING NONE, pickup_datetime TIMESTAMP, dropoff_datetime TIMESTAMP, store_and_fwd_flag TEXT ENCODING DICT, rate_code_id BIGINT, pickup_longitude DOUBLE, pickup_latitude DOUBLE, dropoff_longitude DOUBLE, dropoff_latitude DOUBLE, passenger_count BIGINT, trip_distance DOUBLE, fare_amount DOUBLE, extra DOUBLE, mta_tax DOUBLE, tip_amount DOUBLE, tolls_amount DOUBLE, ehail_fee DOUBLE, improvement_surcharge DOUBLE, total_amount DOUBLE, payment_type TEXT ENCODING DICT, trip_type BIGINT, pickup TEXT ENCODING DICT, dropoff TEXT ENCODING NONE, cab_type TEXT ENCODING DICT, precipitation DOUBLE, snow_depth BIGINT, snowfall DOUBLE, max_temperature BIGINT, min_temperature BIGINT, average_wind_speed DOUBLE, pickup_nyct2010_gid BIGINT, pickup_ctlabel DOUBLE, pickup_borocode BIGINT, pickup_boroname TEXT ENCODING NONE, pickup_ct2010 BIGINT, pickup_boroct2010 BIGINT, pickup_cdeligibil TEXT ENCODING DICT, pickup_ntacode TEXT ENCODING DICT, pickup_ntaname TEXT ENCODING DICT, pickup_puma BIGINT, dropoff_nyct2010_gid BIGINT, dropoff_ctlabel DOUBLE, dropoff_borocode BIGINT, dropoff_boroname TEXT ENCODING NONE, dropoff_ct2010 BIGINT, dropoff_boroct2010 BIGINT, dropoff_cdeligibil TEXT ENCODING NONE, dropoff_ntacode TEXT ENCODING NONE, dropoff_ntaname TEXT ENCODING NONE, dropoff_puma BIGINT) WITH (storage_type='CSV:") + csv_path + std::string("', fragment_size=100);)"));
77  auto schema = dbe->getTableDetails("test");
78  for (auto& item : schema) {
79  std::cout << item.col_name << std::endl;
80  }
81  auto cursor = dbe->executeDML("select count(*) from test");
82  if (cursor) {
83  std::cout << cursor->getRowCount() << " rows selected" << std::endl;
84  std::shared_ptr<arrow::RecordBatch> rbatch = cursor->getArrowRecordBatch();
85  } else {
86  std::cerr << "Cursor is NULL" << std::endl;
87  }
88  }
89  } catch (std::exception& e) {
90  std::cerr << e.what() << "\n";
91  }
92  return 0;
93 }
94 
std::string to_string(char const *&&v)
tuple dbe
Definition: setup.in.py:24
static std::shared_ptr< DBEngine > create(const std::string &cmd_line)
Definition: DBEngine.cpp:450
static bool run