OmniSciDB  5ade3759e0
anonymous_namespace{StreamInsertSimple.cpp} Namespace Reference

Functions

void stream_insert (MapDClient &client, const TSessionId session, const std::string &table_name, const TRowDescriptor &row_desc, const char *delimiter)
 

Variables

const size_t INSERT_BATCH_SIZE = 10000
 

Function Documentation

◆ stream_insert()

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

Definition at line 61 of file StreamInsertSimple.cpp.

References INSERT_BATCH_SIZE.

65  {
66  std::string line;
67  std::vector<TStringRow> input_rows;
68  TStringRow row;
69  boost::char_separator<char> sep{delimiter, "", boost::keep_empty_tokens};
70  while (std::getline(std::cin, line)) {
71  row.cols.clear();
72  boost::tokenizer<boost::char_separator<char>> tok{line, sep};
73  for (const auto& s : tok) {
74  TStringValue ts;
75  ts.str_val = s;
76  ts.is_null = s.empty();
77  row.cols.push_back(ts);
78  }
79  if (row.cols.size() != row_desc.size()) {
80  std::cerr << "Incorrect number of columns: (" << row.cols.size() << " vs "
81  << row_desc.size() << ") " << line << std::endl;
82  continue;
83  }
84  input_rows.push_back(row);
85  if (input_rows.size() >= INSERT_BATCH_SIZE) {
86  try {
87  client.load_table(session, table_name, input_rows);
88  } catch (TMapDException& e) {
89  std::cerr << e.error_msg << std::endl;
90  }
91  input_rows.clear();
92  }
93  }
94  // load remaining rowset if any
95  if (input_rows.size() > 0) {
96  client.load_table(session, table_name, input_rows);
97  }
98 }
mapd::shared_ptr< MapDClient > client
TSessionId session

Variable Documentation

◆ INSERT_BATCH_SIZE

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

Definition at line 57 of file StreamInsertSimple.cpp.

Referenced by stream_insert().