void cb_per_line(int separator, struct cb_data* data) { if ((!data->unsafe) && (data->column != data->table_columns)) { throw CSVLoaderError("Less data than columns"); } data->row++; data->column = 0; }
void cb_per_field(char *field_buffer, size_t field_length, struct cb_data *data) { if (data->column >= data->table_columns) { if (data->unsafe) goto ignore_data; else throw CSVLoaderError("There is more data than columns!"); } switch (data->table->typeOfColumn(data->column)) { case IntegerType: data->table->setValue<hyrise_int_t>(data->column, data->row, atol(field_buffer)); break; case FloatType: data->table->setValue<hyrise_float_t>(data->column, data->row, atof(field_buffer)); break; case StringType: data->table->setValue<hyrise_string_t>(data->column, data->row, std::string(field_buffer)); break; default: throw std::runtime_error("FUUUU"); break; } ignore_data: ++data->column; }
bool detectHeader(const std::string& filename) { // Take a peak into file to check wether it features a header std::ifstream file(filename); if (file.fail()) { throw CSVLoaderError("File '" + filename + "' does not exist"); } std::string line; for (int i = 0; i < 4; ++i) getline(file, line); return "===" == line; }