OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
import_export::Detector Class Reference

#include <Importer.h>

+ Inheritance diagram for import_export::Detector:
+ Collaboration diagram for import_export::Detector:

Public Member Functions

 Detector (const boost::filesystem::path &fp, CopyParams &cp)
 
std::vector< std::string > get_headers ()
 
std::vector< std::vector
< std::string > > 
get_sample_rows (size_t n)
 
- Public Member Functions inherited from import_export::DataStreamSink
 DataStreamSink ()
 
 DataStreamSink (const CopyParams &copy_params, const std::string file_path)
 
virtual ~DataStreamSink ()
 
const CopyParamsget_copy_params () const
 
void import_compressed (std::vector< std::string > &file_paths, const Catalog_Namespace::SessionInfo *session_info)
 

Static Public Member Functions

static SQLTypes detect_sqltype (const std::string &str)
 

Public Attributes

std::vector< std::vector
< std::string > > 
raw_rows
 
std::vector< SQLTypesbest_sqltypes
 
std::vector< EncodingTypebest_encodings
 
bool has_headers = false
 

Private Member Functions

void init ()
 
void read_file ()
 
void detect_row_delimiter ()
 
void split_raw_data ()
 
std::vector< SQLTypesdetect_column_types (const std::vector< std::string > &row)
 
void find_best_sqltypes ()
 
std::vector< SQLTypesfind_best_sqltypes (const std::vector< std::vector< std::string >> &raw_rows, const CopyParams &copy_params)
 
std::vector< SQLTypesfind_best_sqltypes (const std::vector< std::vector< std::string >>::const_iterator &row_begin, const std::vector< std::vector< std::string >>::const_iterator &row_end, const CopyParams &copy_params)
 
std::vector< EncodingTypefind_best_encodings (const std::vector< std::vector< std::string >>::const_iterator &row_begin, const std::vector< std::vector< std::string >>::const_iterator &row_end, const std::vector< SQLTypes > &best_types)
 
bool detect_headers (const std::vector< SQLTypes > &first_types, const std::vector< SQLTypes > &rest_types)
 
void find_best_sqltypes_and_headers ()
 
ImportStatus importDelimited (const std::string &file_path, const bool decompressed, const Catalog_Namespace::SessionInfo *session_info) override
 

Static Private Member Functions

static bool more_restrictive_sqltype (const SQLTypes a, const SQLTypes b)
 

Private Attributes

std::string raw_data
 
boost::filesystem::path file_path
 
std::chrono::duration< double > timeout {1}
 
std::string line1
 

Additional Inherited Members

- Protected Member Functions inherited from import_export::DataStreamSink
ImportStatus archivePlumber (const Catalog_Namespace::SessionInfo *session_info)
 
- Protected Attributes inherited from import_export::DataStreamSink
CopyParams copy_params
 
const std::string file_path
 
FILE * p_file = nullptr
 
ImportStatus import_status_
 
mapd_shared_mutex import_mutex_
 
size_t total_file_size {0}
 
std::vector< size_t > file_offsets
 
std::mutex file_offsets_mutex
 

Detailed Description

Definition at line 684 of file Importer.h.

Constructor & Destructor Documentation

import_export::Detector::Detector ( const boost::filesystem::path &  fp,
CopyParams cp 
)
inline

Definition at line 686 of file Importer.h.

References init(), and read_file().

687  : DataStreamSink(cp, fp.string()), file_path(fp) {
688  read_file();
689  init();
690  };
boost::filesystem::path file_path
Definition: Importer.h:732

+ Here is the call graph for this function:

Member Function Documentation

std::vector< SQLTypes > import_export::Detector::detect_column_types ( const std::vector< std::string > &  row)
private

Definition at line 3192 of file Importer.cpp.

References detect_sqltype(), and i.

Referenced by find_best_sqltypes_and_headers().

3192  {
3193  std::vector<SQLTypes> types(row.size());
3194  for (size_t i = 0; i < row.size(); i++) {
3195  types[i] = detect_sqltype(row[i]);
3196  }
3197  return types;
3198 }
static SQLTypes detect_sqltype(const std::string &str)
Definition: Importer.cpp:3110

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool import_export::Detector::detect_headers ( const std::vector< SQLTypes > &  first_types,
const std::vector< SQLTypes > &  rest_types 
)
private

Definition at line 3334 of file Importer.cpp.

References has_headers, and kTEXT.

Referenced by find_best_sqltypes_and_headers().

3335  {
3336  if (head_types.size() != tail_types.size()) {
3337  return false;
3338  }
3339  bool has_headers = false;
3340  for (size_t col_idx = 0; col_idx < tail_types.size(); col_idx++) {
3341  if (head_types[col_idx] != kTEXT) {
3342  return false;
3343  }
3344  has_headers = has_headers || tail_types[col_idx] != kTEXT;
3345  }
3346  return has_headers;
3347 }
Definition: sqltypes.h:51

+ Here is the caller graph for this function:

void import_export::Detector::detect_row_delimiter ( )
private

Definition at line 3050 of file Importer.cpp.

References import_export::DataStreamSink::copy_params, import_export::CopyParams::delimiter, and file_path.

Referenced by init().

3050  {
3051  if (copy_params.delimiter == '\0') {
3052  copy_params.delimiter = ',';
3053  if (boost::filesystem::extension(file_path) == ".tsv") {
3054  copy_params.delimiter = '\t';
3055  }
3056  }
3057 }
boost::filesystem::path file_path
Definition: Importer.h:732

+ Here is the caller graph for this function:

SQLTypes import_export::Detector::detect_sqltype ( const std::string &  str)
static

Definition at line 3110 of file Importer.cpp.

References dateTimeParseOptional< kDATE >(), dateTimeParseOptional< kTIME >(), dateTimeParseOptional< kTIMESTAMP >(), kBIGINT, kDATE, kDOUBLE, kFLOAT, kINT, kLINESTRING, kMULTIPOLYGON, kPOINT, kPOLYGON, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, import_export::PROMOTE_POLYGON_TO_MULTIPOLYGON, and run_benchmark_import::type.

Referenced by detect_column_types(), and find_best_sqltypes().

3110  {
3111  SQLTypes type = kTEXT;
3112  if (try_cast<double>(str)) {
3113  type = kDOUBLE;
3114  /*if (try_cast<bool>(str)) {
3115  type = kBOOLEAN;
3116  }*/
3117  if (try_cast<int16_t>(str)) {
3118  type = kSMALLINT;
3119  } else if (try_cast<int32_t>(str)) {
3120  type = kINT;
3121  } else if (try_cast<int64_t>(str)) {
3122  type = kBIGINT;
3123  } else if (try_cast<float>(str)) {
3124  type = kFLOAT;
3125  }
3126  }
3127 
3128  // check for geo types
3129  if (type == kTEXT) {
3130  // convert to upper case
3131  std::string str_upper_case = str;
3132  std::transform(
3133  str_upper_case.begin(), str_upper_case.end(), str_upper_case.begin(), ::toupper);
3134 
3135  // then test for leading words
3136  if (str_upper_case.find("POINT") == 0) {
3137  type = kPOINT;
3138  } else if (str_upper_case.find("LINESTRING") == 0) {
3139  type = kLINESTRING;
3140  } else if (str_upper_case.find("POLYGON") == 0) {
3142  type = kMULTIPOLYGON;
3143  } else {
3144  type = kPOLYGON;
3145  }
3146  } else if (str_upper_case.find("MULTIPOLYGON") == 0) {
3147  type = kMULTIPOLYGON;
3148  } else if (str_upper_case.find_first_not_of("0123456789ABCDEF") ==
3149  std::string::npos &&
3150  (str_upper_case.size() % 2) == 0) {
3151  // simple hex blob (two characters per byte, not uu-encode or base64)
3152  if (str_upper_case.size() >= 10) {
3153  // match WKB blobs for supported geometry types
3154  // the first byte specifies if the data is big-endian or little-endian
3155  // the next four bytes are the geometry type (1 = POINT etc.)
3156  // @TODO support eWKB, which has extra bits set in the geometry type
3157  auto first_five_bytes = str_upper_case.substr(0, 10);
3158  if (first_five_bytes == "0000000001" || first_five_bytes == "0101000000") {
3159  type = kPOINT;
3160  } else if (first_five_bytes == "0000000002" || first_five_bytes == "0102000000") {
3161  type = kLINESTRING;
3162  } else if (first_five_bytes == "0000000003" || first_five_bytes == "0103000000") {
3163  type = kPOLYGON;
3164  } else if (first_five_bytes == "0000000006" || first_five_bytes == "0106000000") {
3165  type = kMULTIPOLYGON;
3166  } else {
3167  // unsupported WKB type
3168  return type;
3169  }
3170  } else {
3171  // too short to be WKB
3172  return type;
3173  }
3174  }
3175  }
3176 
3177  // check for time types
3178  if (type == kTEXT) {
3179  // This won't match unix timestamp, since floats and ints were checked above.
3180  if (dateTimeParseOptional<kTIME>(str, 0)) {
3181  type = kTIME;
3182  } else if (dateTimeParseOptional<kTIMESTAMP>(str, 0)) {
3183  type = kTIMESTAMP;
3184  } else if (dateTimeParseOptional<kDATE>(str, 0)) {
3185  type = kDATE;
3186  }
3187  }
3188 
3189  return type;
3190 }
Definition: sqltypes.h:48
SQLTypes
Definition: sqltypes.h:37
std::optional< int64_t > dateTimeParseOptional< kTIME >(std::string_view str, unsigned const dim)
std::optional< int64_t > dateTimeParseOptional< kDATE >(std::string_view str, unsigned const dim)
static constexpr bool PROMOTE_POLYGON_TO_MULTIPOLYGON
Definition: Importer.cpp:166
std::optional< int64_t > dateTimeParseOptional< kTIMESTAMP >(std::string_view str, unsigned const dim)
Definition: sqltypes.h:51
Definition: sqltypes.h:52
Definition: sqltypes.h:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< EncodingType > import_export::Detector::find_best_encodings ( const std::vector< std::vector< std::string >>::const_iterator &  row_begin,
const std::vector< std::vector< std::string >>::const_iterator &  row_end,
const std::vector< SQLTypes > &  best_types 
)
private

Definition at line 3298 of file Importer.cpp.

References file_path, IS_STRING, kENCODING_DICT, kENCODING_NONE, and raw_rows.

Referenced by find_best_sqltypes_and_headers().

3301  {
3302  if (raw_rows.size() < 1) {
3303  throw std::runtime_error("No rows found in: " +
3304  boost::filesystem::basename(file_path));
3305  }
3306  size_t num_cols = best_types.size();
3307  std::vector<EncodingType> best_encodes(num_cols, kENCODING_NONE);
3308  std::vector<size_t> num_rows_per_col(num_cols, 1);
3309  std::vector<std::unordered_set<std::string>> count_set(num_cols);
3310  for (auto row = row_begin; row != row_end; row++) {
3311  for (size_t col_idx = 0; col_idx < row->size() && col_idx < num_cols; col_idx++) {
3312  if (IS_STRING(best_types[col_idx])) {
3313  count_set[col_idx].insert(row->at(col_idx));
3314  num_rows_per_col[col_idx]++;
3315  }
3316  }
3317  }
3318  for (size_t col_idx = 0; col_idx < num_cols; col_idx++) {
3319  if (IS_STRING(best_types[col_idx])) {
3320  float uniqueRatio =
3321  static_cast<float>(count_set[col_idx].size()) / num_rows_per_col[col_idx];
3322  if (uniqueRatio < 0.75) {
3323  best_encodes[col_idx] = kENCODING_DICT;
3324  }
3325  }
3326  }
3327  return best_encodes;
3328 }
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:697
boost::filesystem::path file_path
Definition: Importer.h:732
#define IS_STRING(T)
Definition: sqltypes.h:244

+ Here is the caller graph for this function:

void import_export::Detector::find_best_sqltypes ( )
private

Definition at line 3245 of file Importer.cpp.

References best_sqltypes, import_export::DataStreamSink::copy_params, and raw_rows.

Referenced by find_best_sqltypes(), and find_best_sqltypes_and_headers().

3245  {
3247 }
std::vector< SQLTypes > best_sqltypes
Definition: Importer.h:699
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:697

+ Here is the caller graph for this function:

std::vector< SQLTypes > import_export::Detector::find_best_sqltypes ( const std::vector< std::vector< std::string >> &  raw_rows,
const CopyParams copy_params 
)
private

Definition at line 3249 of file Importer.cpp.

References import_export::DataStreamSink::copy_params, find_best_sqltypes(), and raw_rows.

3251  {
3252  return find_best_sqltypes(raw_rows.begin(), raw_rows.end(), copy_params);
3253 }
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:697

+ Here is the call graph for this function:

std::vector< SQLTypes > import_export::Detector::find_best_sqltypes ( const std::vector< std::vector< std::string >>::const_iterator &  row_begin,
const std::vector< std::vector< std::string >>::const_iterator &  row_end,
const CopyParams copy_params 
)
private

Definition at line 3255 of file Importer.cpp.

References detect_sqltype(), run_benchmark_import::end_time, file_path, kCHAR, kTEXT, more_restrictive_sqltype(), import_export::CopyParams::null_str, raw_rows, t, and timeout.

3258  {
3259  if (raw_rows.size() < 1) {
3260  throw std::runtime_error("No rows found in: " +
3261  boost::filesystem::basename(file_path));
3262  }
3263  auto end_time = std::chrono::steady_clock::now() + timeout;
3264  size_t num_cols = raw_rows.front().size();
3265  std::vector<SQLTypes> best_types(num_cols, kCHAR);
3266  std::vector<size_t> non_null_col_counts(num_cols, 0);
3267  for (auto row = row_begin; row != row_end; row++) {
3268  while (best_types.size() < row->size() || non_null_col_counts.size() < row->size()) {
3269  best_types.push_back(kCHAR);
3270  non_null_col_counts.push_back(0);
3271  }
3272  for (size_t col_idx = 0; col_idx < row->size(); col_idx++) {
3273  // do not count nulls
3274  if (row->at(col_idx) == "" || !row->at(col_idx).compare(copy_params.null_str)) {
3275  continue;
3276  }
3277  SQLTypes t = detect_sqltype(row->at(col_idx));
3278  non_null_col_counts[col_idx]++;
3279  if (!more_restrictive_sqltype(best_types[col_idx], t)) {
3280  best_types[col_idx] = t;
3281  }
3282  }
3283  if (std::chrono::steady_clock::now() > end_time) {
3284  break;
3285  }
3286  }
3287  for (size_t col_idx = 0; col_idx < num_cols; col_idx++) {
3288  // if we don't have any non-null values for this column make it text to be
3289  // safe b/c that is least restrictive type
3290  if (non_null_col_counts[col_idx] == 0) {
3291  best_types[col_idx] = kTEXT;
3292  }
3293  }
3294 
3295  return best_types;
3296 }
SQLTypes
Definition: sqltypes.h:37
static SQLTypes detect_sqltype(const std::string &str)
Definition: Importer.cpp:3110
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:697
boost::filesystem::path file_path
Definition: Importer.h:732
Definition: sqltypes.h:51
static bool more_restrictive_sqltype(const SQLTypes a, const SQLTypes b)
Definition: Importer.cpp:3200
std::chrono::duration< double > timeout
Definition: Importer.h:733
Definition: sqltypes.h:40
char * t

+ Here is the call graph for this function:

void import_export::Detector::find_best_sqltypes_and_headers ( )
private

Definition at line 3222 of file Importer.cpp.

References import_export::AUTODETECT, best_encodings, best_sqltypes, import_export::DataStreamSink::copy_params, detect_column_types(), detect_headers(), find_best_encodings(), find_best_sqltypes(), import_export::HAS_HEADER, import_export::CopyParams::has_header, has_headers, import_export::NO_HEADER, and raw_rows.

Referenced by init().

3222  {
3224  best_encodings =
3225  find_best_encodings(raw_rows.begin() + 1, raw_rows.end(), best_sqltypes);
3226  std::vector<SQLTypes> head_types = detect_column_types(raw_rows.at(0));
3227  switch (copy_params.has_header) {
3229  has_headers = detect_headers(head_types, best_sqltypes);
3230  if (has_headers) {
3232  } else {
3234  }
3235  break;
3237  has_headers = false;
3238  break;
3240  has_headers = true;
3241  break;
3242  }
3243 }
std::vector< SQLTypes > best_sqltypes
Definition: Importer.h:699
ImportHeaderRow has_header
Definition: CopyParams.h:48
std::vector< EncodingType > find_best_encodings(const std::vector< std::vector< std::string >>::const_iterator &row_begin, const std::vector< std::vector< std::string >>::const_iterator &row_end, const std::vector< SQLTypes > &best_types)
Definition: Importer.cpp:3298
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:697
std::vector< EncodingType > best_encodings
Definition: Importer.h:700
bool detect_headers(const std::vector< SQLTypes > &first_types, const std::vector< SQLTypes > &rest_types)
Definition: Importer.cpp:3334
std::vector< SQLTypes > detect_column_types(const std::vector< std::string > &row)
Definition: Importer.cpp:3192

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< std::string > import_export::Detector::get_headers ( )

Definition at line 3357 of file Importer.cpp.

References best_sqltypes, has_headers, i, raw_rows, and to_string().

Referenced by DBHandler::detect_column_types().

3357  {
3358  std::vector<std::string> headers(best_sqltypes.size());
3359  for (size_t i = 0; i < best_sqltypes.size(); i++) {
3360  if (has_headers && i < raw_rows[0].size()) {
3361  headers[i] = raw_rows[0][i];
3362  } else {
3363  headers[i] = "column_" + std::to_string(i + 1);
3364  }
3365  }
3366  return headers;
3367 }
std::vector< SQLTypes > best_sqltypes
Definition: Importer.h:699
std::string to_string(char const *&&v)
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:697

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< std::vector< std::string > > import_export::Detector::get_sample_rows ( size_t  n)

Definition at line 3349 of file Importer.cpp.

References has_headers, and raw_rows.

Referenced by DBHandler::detect_column_types().

3349  {
3350  n = std::min(n, raw_rows.size());
3351  size_t offset = (has_headers && raw_rows.size() > 1) ? 1 : 0;
3352  std::vector<std::vector<std::string>> sample_rows(raw_rows.begin() + offset,
3353  raw_rows.begin() + n);
3354  return sample_rows;
3355 }
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:697

+ Here is the caller graph for this function:

ImportStatus import_export::Detector::importDelimited ( const std::string &  file_path,
const bool  decompressed,
const Catalog_Namespace::SessionInfo session_info 
)
overrideprivatevirtual

Implements import_export::DataStreamSink.

Definition at line 2981 of file Importer.cpp.

References import_export::DataStreamSink::copy_params, run_benchmark_import::end_time, omnisci::fopen(), import_export::DataStreamSink::import_mutex_, import_export::DataStreamSink::import_status_, generate_TableFunctionsFactory_init::line, line1, import_export::CopyParams::line_delim, import_export::ImportStatus::load_failed, import_export::DataStreamSink::p_file, raw_data, import_export::ImportStatus::rows_completed, and timeout.

2984  {
2985  // we do not check interrupt status for this detection
2986  if (!p_file) {
2987  p_file = fopen(file_path.c_str(), "rb");
2988  }
2989  if (!p_file) {
2990  throw std::runtime_error("failed to open file '" + file_path +
2991  "': " + strerror(errno));
2992  }
2993 
2994  // somehow clang does not support ext/stdio_filebuf.h, so
2995  // need to diy readline with customized copy_params.line_delim...
2996  std::string line;
2997  line.reserve(1 * 1024 * 1024);
2998  auto end_time = std::chrono::steady_clock::now() +
2999  timeout * (boost::istarts_with(file_path, "s3://") ? 3 : 1);
3000  try {
3001  while (!feof(p_file)) {
3002  int c;
3003  size_t n = 0;
3004  while (EOF != (c = fgetc(p_file)) && copy_params.line_delim != c) {
3005  if (n++ >= line.capacity()) {
3006  break;
3007  }
3008  line += c;
3009  }
3010  if (0 == n) {
3011  break;
3012  }
3013  // remember the first line, which is possibly a header line, to
3014  // ignore identical header line(s) in 2nd+ files of a archive;
3015  // otherwise, 2nd+ header may be mistaken as an all-string row
3016  // and so be final column types.
3017  if (line1.empty()) {
3018  line1 = line;
3019  } else if (line == line1) {
3020  line.clear();
3021  continue;
3022  }
3023 
3024  raw_data += line;
3026  line.clear();
3028  if (std::chrono::steady_clock::now() > end_time) {
3029  if (import_status_.rows_completed > 10000) {
3030  break;
3031  }
3032  }
3033  }
3034  } catch (std::exception& e) {
3035  }
3036 
3037  mapd_lock_guard<mapd_shared_mutex> write_lock(import_mutex_);
3038  import_status_.load_failed = true;
3039 
3040  fclose(p_file);
3041  p_file = nullptr;
3042  return import_status_;
3043 }
::FILE * fopen(const char *filename, const char *mode)
Definition: omnisci_fs.cpp:72
mapd_shared_mutex import_mutex_
Definition: Importer.h:678
boost::filesystem::path file_path
Definition: Importer.h:732
std::chrono::duration< double > timeout
Definition: Importer.h:733
std::string raw_data
Definition: Importer.h:731
mapd_unique_lock< mapd_shared_mutex > write_lock

+ Here is the call graph for this function:

void import_export::Detector::init ( )
private

Definition at line 2975 of file Importer.cpp.

References detect_row_delimiter(), find_best_sqltypes_and_headers(), and split_raw_data().

Referenced by Detector().

2975  {
2977  split_raw_data();
2979 }
void find_best_sqltypes_and_headers()
Definition: Importer.cpp:3222

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool import_export::Detector::more_restrictive_sqltype ( const SQLTypes  a,
const SQLTypes  b 
)
staticprivate

Definition at line 3200 of file Importer.cpp.

References kBIGINT, kBOOLEAN, kCHAR, kDATE, kDOUBLE, kFLOAT, kINT, kLINESTRING, kMULTIPOLYGON, kPOINT, kPOLYGON, kSMALLINT, kTEXT, kTIME, and kTIMESTAMP.

Referenced by find_best_sqltypes().

3200  {
3201  static std::array<int, kSQLTYPE_LAST> typeorder;
3202  typeorder[kCHAR] = 0;
3203  typeorder[kBOOLEAN] = 2;
3204  typeorder[kSMALLINT] = 3;
3205  typeorder[kINT] = 4;
3206  typeorder[kBIGINT] = 5;
3207  typeorder[kFLOAT] = 6;
3208  typeorder[kDOUBLE] = 7;
3209  typeorder[kTIMESTAMP] = 8;
3210  typeorder[kTIME] = 9;
3211  typeorder[kDATE] = 10;
3212  typeorder[kPOINT] = 11;
3213  typeorder[kLINESTRING] = 11;
3214  typeorder[kPOLYGON] = 11;
3215  typeorder[kMULTIPOLYGON] = 11;
3216  typeorder[kTEXT] = 12;
3217 
3218  // note: b < a instead of a < b because the map is ordered most to least restrictive
3219  return typeorder[b] < typeorder[a];
3220 }
Definition: sqltypes.h:48
Definition: sqltypes.h:51
Definition: sqltypes.h:52
Definition: sqltypes.h:40
Definition: sqltypes.h:44

+ Here is the caller graph for this function:

void import_export::Detector::read_file ( )
private

Definition at line 3045 of file Importer.cpp.

References import_export::DataStreamSink::archivePlumber().

Referenced by Detector().

3045  {
3046  // this becomes analogous to Importer::import()
3047  (void)DataStreamSink::archivePlumber(nullptr);
3048 }
ImportStatus archivePlumber(const Catalog_Namespace::SessionInfo *session_info)
Definition: Importer.cpp:3415

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void import_export::Detector::split_raw_data ( )
private

Definition at line 3059 of file Importer.cpp.

References import_export::DataStreamSink::copy_params, import_export::delimited_parser::get_row(), raw_data, raw_rows, and import_export::CopyParams::threads.

Referenced by init().

3059  {
3060  const char* buf = raw_data.c_str();
3061  const char* buf_end = buf + raw_data.size();
3062  bool try_single_thread = false;
3063  for (const char* p = buf; p < buf_end; p++) {
3064  std::vector<std::string> row;
3065  std::vector<std::unique_ptr<char[]>> tmp_buffers;
3067  buf_end,
3068  buf_end,
3069  copy_params,
3070  nullptr,
3071  row,
3072  tmp_buffers,
3073  try_single_thread,
3074  true);
3075  raw_rows.push_back(row);
3076  if (try_single_thread) {
3077  break;
3078  }
3079  }
3080  if (try_single_thread) {
3081  copy_params.threads = 1;
3082  raw_rows.clear();
3083  for (const char* p = buf; p < buf_end; p++) {
3084  std::vector<std::string> row;
3085  std::vector<std::unique_ptr<char[]>> tmp_buffers;
3087  buf_end,
3088  buf_end,
3089  copy_params,
3090  nullptr,
3091  row,
3092  tmp_buffers,
3093  try_single_thread,
3094  true);
3095  raw_rows.push_back(row);
3096  }
3097  }
3098 }
const char * get_row(const char *buf, const char *buf_end, const char *entire_buf_end, const import_export::CopyParams &copy_params, const bool *is_array, std::vector< T > &row, std::vector< std::unique_ptr< char[]>> &tmp_buffers, bool &try_single_thread, bool filter_empty_lines)
Parses the first row in the given buffer and inserts fields into given vector.
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:697
std::string raw_data
Definition: Importer.h:731

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::vector<EncodingType> import_export::Detector::best_encodings

Definition at line 700 of file Importer.h.

Referenced by DBHandler::detect_column_types(), and find_best_sqltypes_and_headers().

std::vector<SQLTypes> import_export::Detector::best_sqltypes
boost::filesystem::path import_export::Detector::file_path
private

Definition at line 732 of file Importer.h.

Referenced by detect_row_delimiter(), find_best_encodings(), and find_best_sqltypes().

bool import_export::Detector::has_headers = false
std::string import_export::Detector::line1
private

Definition at line 734 of file Importer.h.

Referenced by importDelimited().

std::string import_export::Detector::raw_data
private

Definition at line 731 of file Importer.h.

Referenced by importDelimited(), and split_raw_data().

std::vector<std::vector<std::string> > import_export::Detector::raw_rows
std::chrono::duration<double> import_export::Detector::timeout {1}
private

Definition at line 733 of file Importer.h.

Referenced by find_best_sqltypes(), and importDelimited().


The documentation for this class was generated from the following files: