17 #include <boost/filesystem.hpp>
18 #include <boost/program_options.hpp>
23 #include <arrow/api.h>
24 #include <arrow/csv/reader.h>
25 #include <arrow/io/file.h>
28 using namespace EmbeddedDatabase;
30 int main(
int argc,
char* argv[]) {
31 std::string base_path;
32 int calcite_port = 5555;
33 bool columnar_output =
true;
34 namespace po = boost::program_options;
36 po::options_description desc(
"Options");
37 desc.add_options()(
"help,h",
"Print help messages ")(
39 po::value<std::string>(&base_path)->required(),
40 "Directory path to HeavyDB catalogs")(
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");
47 po::positional_options_description positionalOptions;
48 positionalOptions.add(
"data", 1);
53 po::store(po::command_line_parser(argc, argv)
55 .positional(positionalOptions)
58 if (vm.count(
"help")) {
63 }
catch (boost::program_options::error& e) {
64 std::cerr <<
"Usage Error: " << e.what() << std::endl;
69 auto opt_str = base_path +
" --calcite-port " +
std::to_string(calcite_port);
70 if (columnar_output) {
71 opt_str +=
" --columnar-output";
75 arrow::io::IOContext io_context = arrow::io::default_io_context();
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");
82 inp = file_result.ValueOrDie();
83 auto table_reader_result = arrow::csv::TableReader::Make(io_context,
87 arrow_convert_options);
89 auto table_reader = table_reader_result.ValueOrDie();
90 std::shared_ptr<arrow::Table> arrowTable;
91 auto arrow_table_result = table_reader->Read();
93 arrowTable = arrow_table_result.ValueOrDie();
94 dbe->importArrowTable(
"test", arrowTable);
96 auto schema =
dbe->getTableDetails(
"test");
97 for (
auto& item : schema) {
98 std::cout << item.col_name << std::endl;
100 auto cursor =
dbe->executeDML(
"select * from test");
102 std::cout << cursor->getRowCount() <<
" rows selected" << std::endl;
103 std::shared_ptr<arrow::RecordBatch> rbatch = cursor->getArrowRecordBatch();
105 std::cerr <<
"Cursor is NULL" << std::endl;
108 }
catch (std::exception& e) {
109 std::cerr << e.what() <<
"\n";
#define ARROW_THROW_NOT_OK(s)
static std::shared_ptr< DBEngine > create(const std::string &cmd_line)