OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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)
 
std::vector< SQLTypeInfogetBestColumnTypes () const
 
- 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
 
bool has_headers = false
 

Static Public Attributes

static constexpr size_t kDefaultSampleRowsCount {100}
 

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
 
std::vector< SQLTypesbest_sqltypes
 
std::vector< EncodingTypebest_encodings
 

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_
 
heavyai::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 721 of file Importer.h.

Constructor & Destructor Documentation

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

Definition at line 3787 of file Importer.cpp.

References g_enable_fsi, init(), import_export::kParquetFile, read_file(), and import_export::CopyParams::source_type.

3788  : DataStreamSink(cp, fp.string()), file_path(fp) {
3789 #ifdef ENABLE_IMPORT_PARQUET
3790  if (cp.source_type == import_export::SourceType::kParquetFile && g_enable_fsi &&
3791  !g_enable_legacy_parquet_import) {
3792  data_preview_ = get_parquet_data_preview(fp.string(), cp);
3793  } else
3794 #endif
3795  {
3796  read_file();
3797  init();
3798  }
3799 }
boost::filesystem::path file_path
Definition: Importer.h:768
bool g_enable_fsi
Definition: Catalog.cpp:96

+ 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 3422 of file Importer.cpp.

References detect_sqltype().

Referenced by find_best_sqltypes_and_headers().

3422  {
3423  std::vector<SQLTypes> types(row.size());
3424  for (size_t i = 0; i < row.size(); i++) {
3425  types[i] = detect_sqltype(row[i]);
3426  }
3427  return types;
3428 }
static SQLTypes detect_sqltype(const std::string &str)
Definition: Importer.cpp:3332

+ 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 3566 of file Importer.cpp.

References has_headers, and kTEXT.

Referenced by find_best_sqltypes_and_headers().

3567  {
3568  if (head_types.size() != tail_types.size()) {
3569  return false;
3570  }
3571  bool has_headers = false;
3572  for (size_t col_idx = 0; col_idx < tail_types.size(); col_idx++) {
3573  if (head_types[col_idx] != kTEXT) {
3574  return false;
3575  }
3576  has_headers = has_headers || tail_types[col_idx] != kTEXT;
3577  }
3578  return has_headers;
3579 }
Definition: sqltypes.h:66

+ Here is the caller graph for this function:

void import_export::Detector::detect_row_delimiter ( )
private

Definition at line 3272 of file Importer.cpp.

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

Referenced by init().

3272  {
3273  if (copy_params.delimiter == '\0') {
3274  copy_params.delimiter = ',';
3275  if (boost::filesystem::extension(file_path) == ".tsv") {
3276  copy_params.delimiter = '\t';
3277  }
3278  }
3279 }
boost::filesystem::path file_path
Definition: Importer.h:768

+ Here is the caller graph for this function:

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

Definition at line 3332 of file Importer.cpp.

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

Referenced by detect_column_types(), and find_best_sqltypes().

3332  {
3333  SQLTypes type = kTEXT;
3334  if (try_cast<double>(str)) {
3335  type = kDOUBLE;
3336  /*if (try_cast<bool>(str)) {
3337  type = kBOOLEAN;
3338  }*/
3339  if (try_cast<int16_t>(str)) {
3340  type = kSMALLINT;
3341  } else if (try_cast<int32_t>(str)) {
3342  type = kINT;
3343  } else if (try_cast<int64_t>(str)) {
3344  type = kBIGINT;
3345  } else if (try_cast<float>(str)) {
3346  type = kFLOAT;
3347  }
3348  }
3349 
3350  // check for geo types
3351  if (type == kTEXT) {
3352  // convert to upper case
3353  std::string str_upper_case = str;
3355  str_upper_case.begin(), str_upper_case.end(), str_upper_case.begin(), ::toupper);
3356 
3357  // then test for leading words
3358  if (str_upper_case.find("POINT") == 0) {
3359  type = kPOINT;
3360  } else if (str_upper_case.find("MULTIPOINT") == 0) {
3361  type = kMULTIPOINT;
3362  } else if (str_upper_case.find("LINESTRING") == 0) {
3363  type = kLINESTRING;
3364  } else if (str_upper_case.find("MULTILINESTRING") == 0) {
3365  type = kMULTILINESTRING;
3366  } else if (str_upper_case.find("POLYGON") == 0) {
3368  type = kMULTIPOLYGON;
3369  } else {
3370  type = kPOLYGON;
3371  }
3372  } else if (str_upper_case.find("MULTIPOLYGON") == 0) {
3373  type = kMULTIPOLYGON;
3374  } else if (str_upper_case.find_first_not_of("0123456789ABCDEF") ==
3375  std::string::npos &&
3376  (str_upper_case.size() % 2) == 0) {
3377  // simple hex blob (two characters per byte, not uu-encode or base64)
3378  if (str_upper_case.size() >= 10) {
3379  // match WKB blobs for supported geometry types
3380  // the first byte specifies if the data is big-endian or little-endian
3381  // the next four bytes are the geometry type (1 = POINT etc.)
3382  // @TODO support eWKB, which has extra bits set in the geometry type
3383  auto first_five_bytes = str_upper_case.substr(0, 10);
3384  if (first_five_bytes == "0000000001" || first_five_bytes == "0101000000") {
3385  type = kPOINT;
3386  } else if (first_five_bytes == "0000000004" || first_five_bytes == "0104000000") {
3387  type = kMULTIPOINT;
3388  } else if (first_five_bytes == "0000000002" || first_five_bytes == "0102000000") {
3389  type = kLINESTRING;
3390  } else if (first_five_bytes == "0000000005" || first_five_bytes == "0105000000") {
3391  type = kMULTILINESTRING;
3392  } else if (first_five_bytes == "0000000003" || first_five_bytes == "0103000000") {
3393  type = kPOLYGON;
3394  } else if (first_five_bytes == "0000000006" || first_five_bytes == "0106000000") {
3395  type = kMULTIPOLYGON;
3396  } else {
3397  // unsupported WKB type
3398  return type;
3399  }
3400  } else {
3401  // too short to be WKB
3402  return type;
3403  }
3404  }
3405  }
3406 
3407  // check for time types
3408  if (type == kTEXT) {
3409  // This won't match unix timestamp, since floats and ints were checked above.
3410  if (dateTimeParseOptional<kTIME>(str, 0)) {
3411  type = kTIME;
3412  } else if (dateTimeParseOptional<kTIMESTAMP>(str, 0)) {
3413  type = kTIMESTAMP;
3414  } else if (dateTimeParseOptional<kDATE>(str, 0)) {
3415  type = kDATE;
3416  }
3417  }
3418 
3419  return type;
3420 }
Definition: sqltypes.h:63
SQLTypes
Definition: sqltypes.h:52
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:163
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:296
std::optional< int64_t > dateTimeParseOptional< kTIMESTAMP >(std::string_view str, unsigned const dim)
Definition: sqltypes.h:66
Definition: sqltypes.h:67
Definition: sqltypes.h:59

+ 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 3530 of file Importer.cpp.

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

Referenced by find_best_sqltypes_and_headers().

3533  {
3534  if (raw_rows.size() < 1) {
3535  throw std::runtime_error("No rows found in: " +
3536  boost::filesystem::basename(file_path));
3537  }
3538  size_t num_cols = best_types.size();
3539  std::vector<EncodingType> best_encodes(num_cols, kENCODING_NONE);
3540  std::vector<size_t> num_rows_per_col(num_cols, 1);
3541  std::vector<std::unordered_set<std::string>> count_set(num_cols);
3542  for (auto row = row_begin; row != row_end; row++) {
3543  for (size_t col_idx = 0; col_idx < row->size() && col_idx < num_cols; col_idx++) {
3544  if (IS_STRING(best_types[col_idx])) {
3545  count_set[col_idx].insert(row->at(col_idx));
3546  num_rows_per_col[col_idx]++;
3547  }
3548  }
3549  }
3550  for (size_t col_idx = 0; col_idx < num_cols; col_idx++) {
3551  if (IS_STRING(best_types[col_idx])) {
3552  float uniqueRatio =
3553  static_cast<float>(count_set[col_idx].size()) / num_rows_per_col[col_idx];
3554  if (uniqueRatio < 0.75) {
3555  best_encodes[col_idx] = kENCODING_DICT;
3556  }
3557  }
3558  }
3559  return best_encodes;
3560 }
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:731
boost::filesystem::path file_path
Definition: Importer.h:768
#define IS_STRING(T)
Definition: sqltypes.h:322

+ Here is the caller graph for this function:

void import_export::Detector::find_best_sqltypes ( )
private

Definition at line 3477 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().

3477  {
3479 }
std::vector< SQLTypes > best_sqltypes
Definition: Importer.h:774
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:731

+ 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 3481 of file Importer.cpp.

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

3483  {
3484  return find_best_sqltypes(raw_rows.begin(), raw_rows.end(), copy_params);
3485 }
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:731

+ 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 3487 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, and timeout.

3490  {
3491  if (raw_rows.size() < 1) {
3492  throw std::runtime_error("No rows found in: " +
3493  boost::filesystem::basename(file_path));
3494  }
3495  auto end_time = std::chrono::steady_clock::now() + timeout;
3496  size_t num_cols = raw_rows.front().size();
3497  std::vector<SQLTypes> best_types(num_cols, kCHAR);
3498  std::vector<size_t> non_null_col_counts(num_cols, 0);
3499  for (auto row = row_begin; row != row_end; row++) {
3500  while (best_types.size() < row->size() || non_null_col_counts.size() < row->size()) {
3501  best_types.push_back(kCHAR);
3502  non_null_col_counts.push_back(0);
3503  }
3504  for (size_t col_idx = 0; col_idx < row->size(); col_idx++) {
3505  // do not count nulls
3506  if (row->at(col_idx) == "" || !row->at(col_idx).compare(copy_params.null_str)) {
3507  continue;
3508  }
3509  SQLTypes t = detect_sqltype(row->at(col_idx));
3510  non_null_col_counts[col_idx]++;
3511  if (!more_restrictive_sqltype(best_types[col_idx], t)) {
3512  best_types[col_idx] = t;
3513  }
3514  }
3515  if (std::chrono::steady_clock::now() > end_time) {
3516  break;
3517  }
3518  }
3519  for (size_t col_idx = 0; col_idx < num_cols; col_idx++) {
3520  // if we don't have any non-null values for this column make it text to be
3521  // safe b/c that is least restrictive type
3522  if (non_null_col_counts[col_idx] == 0) {
3523  best_types[col_idx] = kTEXT;
3524  }
3525  }
3526 
3527  return best_types;
3528 }
SQLTypes
Definition: sqltypes.h:52
static SQLTypes detect_sqltype(const std::string &str)
Definition: Importer.cpp:3332
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:731
boost::filesystem::path file_path
Definition: Importer.h:768
Definition: sqltypes.h:66
static bool more_restrictive_sqltype(const SQLTypes a, const SQLTypes b)
Definition: Importer.cpp:3430
std::chrono::duration< double > timeout
Definition: Importer.h:769
Definition: sqltypes.h:55

+ Here is the call graph for this function:

void import_export::Detector::find_best_sqltypes_and_headers ( )
private

Definition at line 3454 of file Importer.cpp.

References best_encodings, best_sqltypes, import_export::DataStreamSink::copy_params, detect_column_types(), detect_headers(), find_best_encodings(), find_best_sqltypes(), import_export::CopyParams::has_header, has_headers, import_export::kAutoDetect, import_export::kHasHeader, import_export::kNoHeader, and raw_rows.

Referenced by init().

3454  {
3456  best_encodings =
3457  find_best_encodings(raw_rows.begin() + 1, raw_rows.end(), best_sqltypes);
3458  std::vector<SQLTypes> head_types = detect_column_types(raw_rows.at(0));
3459  switch (copy_params.has_header) {
3461  has_headers = detect_headers(head_types, best_sqltypes);
3462  if (has_headers) {
3464  } else {
3466  }
3467  break;
3469  has_headers = false;
3470  break;
3472  has_headers = true;
3473  break;
3474  }
3475 }
std::vector< SQLTypes > best_sqltypes
Definition: Importer.h:774
ImportHeaderRow has_header
Definition: CopyParams.h:46
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:3530
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:731
std::vector< EncodingType > best_encodings
Definition: Importer.h:775
bool detect_headers(const std::vector< SQLTypes > &first_types, const std::vector< SQLTypes > &rest_types)
Definition: Importer.cpp:3566
std::vector< SQLTypes > detect_column_types(const std::vector< std::string > &row)
Definition: Importer.cpp:3422

+ 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 3596 of file Importer.cpp.

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

Referenced by DBHandler::detect_column_types().

3596  {
3597 #if defined(ENABLE_IMPORT_PARQUET)
3598  if (data_preview_.has_value()) {
3599  return data_preview_.value().column_names;
3600  } else
3601 #endif
3602  {
3603  std::vector<std::string> headers(best_sqltypes.size());
3604  for (size_t i = 0; i < best_sqltypes.size(); i++) {
3605  if (has_headers && i < raw_rows[0].size()) {
3606  headers[i] = raw_rows[0][i];
3607  } else {
3608  headers[i] = "column_" + std::to_string(i + 1);
3609  }
3610  }
3611  return headers;
3612  }
3613 }
std::vector< SQLTypes > best_sqltypes
Definition: Importer.h:774
std::string to_string(char const *&&v)
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:731

+ 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 3581 of file Importer.cpp.

References has_headers, anonymous_namespace{Utm.h}::n, and raw_rows.

Referenced by DBHandler::detect_column_types().

3581  {
3582 #if defined(ENABLE_IMPORT_PARQUET)
3583  if (data_preview_.has_value()) {
3584  return data_preview_.value().sample_rows;
3585  } else
3586 #endif
3587  {
3588  n = std::min(n, raw_rows.size());
3589  size_t offset = (has_headers && raw_rows.size() > 1) ? 1 : 0;
3590  std::vector<std::vector<std::string>> sample_rows(raw_rows.begin() + offset,
3591  raw_rows.begin() + n);
3592  return sample_rows;
3593  }
3594 }
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:731
constexpr double n
Definition: Utm.h:38

+ Here is the caller graph for this function:

std::vector< SQLTypeInfo > import_export::Detector::getBestColumnTypes ( ) const

Definition at line 3615 of file Importer.cpp.

References best_encodings, best_sqltypes, and CHECK_EQ.

Referenced by DBHandler::detect_column_types().

3615  {
3616 #if defined(ENABLE_IMPORT_PARQUET)
3617  if (data_preview_.has_value()) {
3618  return data_preview_.value().column_types;
3619  } else
3620 #endif
3621  {
3622  std::vector<SQLTypeInfo> types;
3623  CHECK_EQ(best_sqltypes.size(), best_encodings.size());
3624  for (size_t i = 0; i < best_sqltypes.size(); i++) {
3625  types.emplace_back(best_sqltypes[i], false, best_encodings[i]);
3626  }
3627  return types;
3628  }
3629 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::vector< SQLTypes > best_sqltypes
Definition: Importer.h:774
std::vector< EncodingType > best_encodings
Definition: Importer.h:775

+ 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 3202 of file Importer.cpp.

References import_export::DataStreamSink::copy_params, run_benchmark_import::end_time, heavyai::fopen(), import_export::DataStreamSink::import_mutex_, import_export::DataStreamSink::import_status_, import_export::kImportRowLimit, parse_ast::line, line1, import_export::CopyParams::line_delim, import_export::ImportStatus::load_failed, anonymous_namespace{Utm.h}::n, import_export::DataStreamSink::p_file, raw_data, import_export::ImportStatus::rows_completed, and timeout.

3205  {
3206  // we do not check interrupt status for this detection
3207  if (!p_file) {
3208  p_file = fopen(file_path.c_str(), "rb");
3209  }
3210  if (!p_file) {
3211  throw std::runtime_error("failed to open file '" + file_path +
3212  "': " + strerror(errno));
3213  }
3214 
3215  // somehow clang does not support ext/stdio_filebuf.h, so
3216  // need to diy readline with customized copy_params.line_delim...
3217  std::string line;
3218  line.reserve(1 * 1024 * 1024);
3219  auto end_time = std::chrono::steady_clock::now() +
3220  timeout * (boost::istarts_with(file_path, "s3://") ? 3 : 1);
3221  try {
3222  while (!feof(p_file)) {
3223  int c;
3224  size_t n = 0;
3225  while (EOF != (c = fgetc(p_file)) && copy_params.line_delim != c) {
3226  if (n++ >= line.capacity()) {
3227  break;
3228  }
3229  line += c;
3230  }
3231  if (0 == n) {
3232  break;
3233  }
3234  // remember the first line, which is possibly a header line, to
3235  // ignore identical header line(s) in 2nd+ files of a archive;
3236  // otherwise, 2nd+ header may be mistaken as an all-string row
3237  // and so be final column types.
3238  if (line1.empty()) {
3239  line1 = line;
3240  } else if (line == line1) {
3241  line.clear();
3242  continue;
3243  }
3244 
3245  raw_data += line;
3247  line.clear();
3249  if (std::chrono::steady_clock::now() > end_time) {
3251  // stop import when row limit reached
3252  break;
3253  }
3254  }
3255  }
3256  } catch (std::exception& e) {
3257  }
3258 
3260  import_status_.load_failed = true;
3261 
3262  fclose(p_file);
3263  p_file = nullptr;
3264  return import_status_;
3265 }
std::lock_guard< T > lock_guard
heavyai::unique_lock< heavyai::shared_mutex > write_lock
::FILE * fopen(const char *filename, const char *mode)
Definition: heavyai_fs.cpp:74
boost::filesystem::path file_path
Definition: Importer.h:768
tuple line
Definition: parse_ast.py:10
static const size_t kImportRowLimit
Definition: Importer.cpp:169
std::chrono::duration< double > timeout
Definition: Importer.h:769
std::string raw_data
Definition: Importer.h:767
constexpr double n
Definition: Utm.h:38
heavyai::shared_mutex import_mutex_
Definition: Importer.h:715

+ Here is the call graph for this function:

void import_export::Detector::init ( )
private

Definition at line 3196 of file Importer.cpp.

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

Referenced by Detector().

3196  {
3198  split_raw_data();
3200 }
void find_best_sqltypes_and_headers()
Definition: Importer.cpp:3454

+ 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 3430 of file Importer.cpp.

References anonymous_namespace{Utm.h}::a, kBIGINT, kBOOLEAN, kCHAR, kDATE, kDOUBLE, kFLOAT, kINT, kLINESTRING, kMULTILINESTRING, kMULTIPOINT, kMULTIPOLYGON, kPOINT, kPOLYGON, kSMALLINT, kTEXT, kTIME, and kTIMESTAMP.

Referenced by find_best_sqltypes().

3430  {
3431  static std::array<int, kSQLTYPE_LAST> typeorder;
3432  typeorder[kCHAR] = 0;
3433  typeorder[kBOOLEAN] = 2;
3434  typeorder[kSMALLINT] = 3;
3435  typeorder[kINT] = 4;
3436  typeorder[kBIGINT] = 5;
3437  typeorder[kFLOAT] = 6;
3438  typeorder[kDOUBLE] = 7;
3439  typeorder[kTIMESTAMP] = 8;
3440  typeorder[kTIME] = 9;
3441  typeorder[kDATE] = 10;
3442  typeorder[kPOINT] = 11;
3443  typeorder[kMULTIPOINT] = 11;
3444  typeorder[kLINESTRING] = 11;
3445  typeorder[kMULTILINESTRING] = 11;
3446  typeorder[kPOLYGON] = 11;
3447  typeorder[kMULTIPOLYGON] = 11;
3448  typeorder[kTEXT] = 12;
3449 
3450  // note: b < a instead of a < b because the map is ordered most to least restrictive
3451  return typeorder[b] < typeorder[a];
3452 }
Definition: sqltypes.h:63
constexpr double a
Definition: Utm.h:32
Definition: sqltypes.h:66
Definition: sqltypes.h:67
Definition: sqltypes.h:55
Definition: sqltypes.h:59

+ Here is the caller graph for this function:

void import_export::Detector::read_file ( )
private

Definition at line 3267 of file Importer.cpp.

References import_export::DataStreamSink::archivePlumber().

Referenced by Detector().

3267  {
3268  // this becomes analogous to Importer::import()
3269  (void)DataStreamSink::archivePlumber(nullptr);
3270 }
ImportStatus archivePlumber(const Catalog_Namespace::SessionInfo *session_info)
Definition: Importer.cpp:3677

+ 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 3281 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().

3281  {
3282  const char* buf = raw_data.c_str();
3283  const char* buf_end = buf + raw_data.size();
3284  bool try_single_thread = false;
3285  for (const char* p = buf; p < buf_end; p++) {
3286  std::vector<std::string> row;
3287  std::vector<std::unique_ptr<char[]>> tmp_buffers;
3289  buf_end,
3290  buf_end,
3291  copy_params,
3292  nullptr,
3293  row,
3294  tmp_buffers,
3295  try_single_thread,
3296  true);
3297  raw_rows.push_back(row);
3298  if (try_single_thread) {
3299  break;
3300  }
3301  }
3302  if (try_single_thread) {
3303  copy_params.threads = 1;
3304  raw_rows.clear();
3305  for (const char* p = buf; p < buf_end; p++) {
3306  std::vector<std::string> row;
3307  std::vector<std::unique_ptr<char[]>> tmp_buffers;
3309  buf_end,
3310  buf_end,
3311  copy_params,
3312  nullptr,
3313  row,
3314  tmp_buffers,
3315  try_single_thread,
3316  true);
3317  raw_rows.push_back(row);
3318  }
3319  }
3320 }
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:731
std::string raw_data
Definition: Importer.h:767

+ 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
private

Definition at line 775 of file Importer.h.

Referenced by find_best_sqltypes_and_headers(), and getBestColumnTypes().

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

Definition at line 768 of file Importer.h.

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

bool import_export::Detector::has_headers = false
constexpr size_t import_export::Detector::kDefaultSampleRowsCount {100}
static

Definition at line 737 of file Importer.h.

Referenced by DBHandler::detect_column_types().

std::string import_export::Detector::line1
private

Definition at line 770 of file Importer.h.

Referenced by importDelimited().

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

Definition at line 767 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 769 of file Importer.h.

Referenced by find_best_sqltypes(), and importDelimited().


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