OmniSciDB  04ee39c94c
DataGen.cpp File Reference

Sample MapD Client code for generating random data that can be inserted into a given MapD table. More...

#include <cfloat>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <random>
#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 DataGen.cpp:

Go to the source code of this file.

Namespaces

 mapd
 
 anonymous_namespace{DataGen.cpp}
 

Functions

std::default_random_engine anonymous_namespace{DataGen.cpp}::random_gen (std::random_device{}())
 
std::string anonymous_namespace{DataGen.cpp}::gen_int ()
 
std::string anonymous_namespace{DataGen.cpp}::gen_real ()
 
std::string anonymous_namespace{DataGen.cpp}::gen_string ()
 
std::string anonymous_namespace{DataGen.cpp}::gen_bool ()
 
std::string anonymous_namespace{DataGen.cpp}::gen_time ()
 
std::string anonymous_namespace{DataGen.cpp}::gen_timestamp ()
 
std::string anonymous_namespace{DataGen.cpp}::gen_date ()
 
void anonymous_namespace{DataGen.cpp}::data_gen (const TRowDescriptor &row_desc, const char *delimiter, int num_rows)
 
int main (int argc, char **argv)
 

Variables

const int anonymous_namespace{DataGen.cpp}::max_str_len = 100
 

Detailed Description

Sample MapD Client code for generating random data that can be inserted into a given MapD table.

Usage:

<user> <password> [<num rows>="">] [hostname[:port]] The program executes the following:

  1. connect to omnisci_server at hostname:port (default: localhost:6274) with <database> <user> <password>
  2. get the table descriptor of
    randomly generate tab-delimited data that can be imported to
    disconnect from omnisci_server

Copyright (c) 2014 MapD Technologies, Inc. All rights reserved.

Definition in file DataGen.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 185 of file DataGen.cpp.

References client, anonymous_namespace{DataGen.cpp}::data_gen(), num_rows, and session.

185  {
186  std::string server_host("localhost"); // default to localhost
187  int port = 6274; // default port number
188  int num_rows = 1000000; // default number of rows to generate
189  const char* delimiter = "\t"; // only support tab delimiter for now
190 
191  if (argc < 5) {
192  std::cout
193  << "Usage: <table> <database> <user> <password> [<num rows>] [hostname[:port]]"
194  << std::endl;
195  return 1;
196  }
197  std::string table_name(argv[1]);
198  std::string db_name(argv[2]);
199  std::string user_name(argv[3]);
200  std::string passwd(argv[4]);
201 
202  if (argc >= 6) {
203  num_rows = atoi(argv[5]);
204  if (argc >= 7) {
205  char* host = strtok(argv[6], ":");
206  char* portno = strtok(NULL, ":");
207  server_host = host;
208  if (portno != NULL) {
209  port = atoi(portno);
210  }
211  }
212  }
213 
214  mapd::shared_ptr<TTransport> socket(new TSocket(server_host, port));
215  mapd::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
216  mapd::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
217  MapDClient client(protocol);
218  TSessionId session;
219  try {
220  transport->open(); // open transport
221  client.connect(session, user_name, passwd, db_name); // connect to omnisci_server
222  TTableDetails table_details;
223  client.get_table_details(table_details, session, table_name);
224  data_gen(table_details.row_desc, delimiter, num_rows);
225  client.disconnect(session); // disconnect from omnisci_server
226  transport->close(); // close transport
227  } catch (TMapDException& e) {
228  std::cerr << e.error_msg << std::endl;
229  return 1;
230  } catch (TException& te) {
231  std::cerr << "Thrift error: " << te.what() << std::endl;
232  return 1;
233  }
234 
235  return 0;
236 }
const int8_t const int64_t * num_rows
void data_gen(const TRowDescriptor &row_desc, const char *delimiter, int num_rows)
Definition: DataGen.cpp:138
mapd::shared_ptr< MapDClient > client
TSessionId session
+ Here is the call graph for this function: