OmniSciDB  04ee39c94c
StreamInsertSimple.cpp File Reference
#include <boost/tokenizer.hpp>
#include <cstring>
#include <iostream>
#include <string>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/transport/TSocket.h>
#include "gen-cpp/MapD.h"
#include <boost/make_shared.hpp>
+ Include dependency graph for StreamInsertSimple.cpp:

Go to the source code of this file.

Namespaces

 mapd
 
 anonymous_namespace{StreamInsertSimple.cpp}
 

Functions

void anonymous_namespace{StreamInsertSimple.cpp}::stream_insert (MapDClient &client, const TSessionId session, const std::string &table_name, const TRowDescriptor &row_desc, const char *delimiter)
 
int main (int argc, char **argv)
 

Variables

const size_t anonymous_namespace{StreamInsertSimple.cpp}::INSERT_BATCH_SIZE = 10000
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 101 of file StreamInsertSimple.cpp.

References client, session, and stream_insert().

101  {
102  std::string server_host("localhost"); // default to localohost
103  int port = 6274; // default port number
104  const char* delimiter = "\t"; // only support tab delimiter for now
105 
106  if (argc < 5) {
107  std::cout << "Usage: <table> <database> <user> <password> [hostname[:port]]"
108  << std::endl;
109  return 1;
110  }
111  std::string table_name(argv[1]);
112  std::string db_name(argv[2]);
113  std::string user_name(argv[3]);
114  std::string passwd(argv[4]);
115 
116  if (argc >= 6) {
117  char* host = strtok(argv[5], ":");
118  char* portno = strtok(NULL, ":");
119  server_host = host;
120  if (portno != NULL) {
121  port = atoi(portno);
122  }
123  }
124 
125  mapd::shared_ptr<TTransport> socket(new TSocket(server_host, port));
126  mapd::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
127  mapd::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
128  MapDClient client(protocol);
129  TSessionId session;
130  try {
131  transport->open(); // open transport
132  client.connect(session, user_name, passwd, db_name); // connect to omnisci_server
133  TTableDetails table_details;
134  client.get_table_details(table_details, session, table_name);
135  stream_insert(client, session, table_name, table_details.row_desc, delimiter);
136  client.disconnect(session); // disconnect from omnisci_server
137  transport->close(); // close transport
138  } catch (TMapDException& e) {
139  std::cerr << e.error_msg << std::endl;
140  return 1;
141  } catch (TException& te) {
142  std::cerr << "Thrift error: " << te.what() << std::endl;
143  return 1;
144  }
145 
146  return 0;
147 }
mapd::shared_ptr< MapDClient > client
void stream_insert(RowToColumnLoader &row_loader, const std::map< std::string, std::pair< std::unique_ptr< boost::regex >, std::unique_ptr< std::string >>> &transformations, const Importer_NS::CopyParams &copy_params, const bool remove_quotes)
TSessionId session
+ Here is the call graph for this function: