OmniSciDB  72c90bc290
 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
 

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 729 of file Importer.h.

Constructor & Destructor Documentation

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

Definition at line 3670 of file Importer.cpp.

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

3671  : DataStreamSink(cp, fp.string()), file_path(fp) {
3672 #ifdef ENABLE_IMPORT_PARQUET
3673  if (cp.source_type == import_export::SourceType::kParquetFile && g_enable_fsi &&
3674  !g_enable_legacy_parquet_import) {
3675  data_preview_ = get_parquet_data_preview(fp.string(), cp);
3676  } else
3677 #endif
3678  {
3679  read_file();
3680  init();
3681  }
3682 }
boost::filesystem::path file_path
Definition: Importer.h:774
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 3305 of file Importer.cpp.

References detect_sqltype().

Referenced by find_best_sqltypes_and_headers().

3305  {
3306  std::vector<SQLTypes> types(row.size());
3307  for (size_t i = 0; i < row.size(); i++) {
3308  types[i] = detect_sqltype(row[i]);
3309  }
3310  return types;
3311 }
static SQLTypes detect_sqltype(const std::string &str)
Definition: Importer.cpp:3216

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

References has_headers, and kTEXT.

Referenced by find_best_sqltypes_and_headers().

3450  {
3451  if (head_types.size() != tail_types.size()) {
3452  return false;
3453  }
3454  bool has_headers = false;
3455  for (size_t col_idx = 0; col_idx < tail_types.size(); col_idx++) {
3456  if (head_types[col_idx] != kTEXT) {
3457  return false;
3458  }
3459  has_headers = has_headers || tail_types[col_idx] != kTEXT;
3460  }
3461  return has_headers;
3462 }
Definition: sqltypes.h:79

+ Here is the caller graph for this function:

void import_export::Detector::detect_row_delimiter ( )
private

Definition at line 3156 of file Importer.cpp.

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

Referenced by init().

3156  {
3157  if (copy_params.delimiter == '\0') {
3158  copy_params.delimiter = ',';
3159  if (boost::filesystem::path(file_path).extension() == ".tsv") {
3160  copy_params.delimiter = '\t';
3161  }
3162  }
3163 }
boost::filesystem::path file_path
Definition: Importer.h:774

+ Here is the caller graph for this function:

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

Definition at line 3216 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_LINESTRING_TO_MULTILINESTRING, import_export::PROMOTE_POINT_TO_MULTIPOINT, import_export::PROMOTE_POLYGON_TO_MULTIPOLYGON, shared::transform(), and run_benchmark_import::type.

Referenced by detect_column_types(), and find_best_sqltypes().

3216  {
3217  SQLTypes type = kTEXT;
3218  if (try_cast<double>(str)) {
3219  type = kDOUBLE;
3220  /*if (try_cast<bool>(str)) {
3221  type = kBOOLEAN;
3222  }*/
3223  if (try_cast<int16_t>(str)) {
3224  type = kSMALLINT;
3225  } else if (try_cast<int32_t>(str)) {
3226  type = kINT;
3227  } else if (try_cast<int64_t>(str)) {
3228  type = kBIGINT;
3229  } else if (try_cast<float>(str)) {
3230  type = kFLOAT;
3231  }
3232  }
3233 
3234  // check for geo types
3235  if (type == kTEXT) {
3236  // convert to upper case
3237  std::string str_upper_case = str;
3239  str_upper_case.begin(), str_upper_case.end(), str_upper_case.begin(), ::toupper);
3240 
3241  // then test for leading words
3242  if (str_upper_case.find("POINT") == 0) {
3243  // promote column type?
3245  } else if (str_upper_case.find("MULTIPOINT") == 0) {
3246  type = kMULTIPOINT;
3247  } else if (str_upper_case.find("LINESTRING") == 0) {
3248  // promote column type?
3250  } else if (str_upper_case.find("MULTILINESTRING") == 0) {
3251  type = kMULTILINESTRING;
3252  } else if (str_upper_case.find("POLYGON") == 0) {
3253  // promote column type?
3255  } else if (str_upper_case.find("MULTIPOLYGON") == 0) {
3256  type = kMULTIPOLYGON;
3257  } else if (str_upper_case.find_first_not_of("0123456789ABCDEF") ==
3258  std::string::npos &&
3259  (str_upper_case.size() % 2) == 0) {
3260  // simple hex blob (two characters per byte, not uu-encode or base64)
3261  if (str_upper_case.size() >= 10) {
3262  // match WKB blobs for supported geometry types
3263  // the first byte specifies if the data is big-endian or little-endian
3264  // the next four bytes are the geometry type (1 = POINT etc.)
3265  // @TODO support eWKB, which has extra bits set in the geometry type
3266  auto first_five_bytes = str_upper_case.substr(0, 10);
3267  if (first_five_bytes == "0000000001" || first_five_bytes == "0101000000") {
3268  type = kPOINT;
3269  } else if (first_five_bytes == "0000000004" || first_five_bytes == "0104000000") {
3270  type = kMULTIPOINT;
3271  } else if (first_five_bytes == "0000000002" || first_five_bytes == "0102000000") {
3272  type = kLINESTRING;
3273  } else if (first_five_bytes == "0000000005" || first_five_bytes == "0105000000") {
3274  type = kMULTILINESTRING;
3275  } else if (first_five_bytes == "0000000003" || first_five_bytes == "0103000000") {
3276  type = kPOLYGON;
3277  } else if (first_five_bytes == "0000000006" || first_five_bytes == "0106000000") {
3278  type = kMULTIPOLYGON;
3279  } else {
3280  // unsupported WKB type
3281  return type;
3282  }
3283  } else {
3284  // too short to be WKB
3285  return type;
3286  }
3287  }
3288  }
3289 
3290  // check for time types
3291  if (type == kTEXT) {
3292  // This won't match unix timestamp, since floats and ints were checked above.
3293  if (dateTimeParseOptional<kTIME>(str, 0)) {
3294  type = kTIME;
3295  } else if (dateTimeParseOptional<kTIMESTAMP>(str, 0)) {
3296  type = kTIMESTAMP;
3297  } else if (dateTimeParseOptional<kDATE>(str, 0)) {
3298  type = kDATE;
3299  }
3300  }
3301 
3302  return type;
3303 }
Definition: sqltypes.h:76
SQLTypes
Definition: sqltypes.h:65
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_LINESTRING_TO_MULTILINESTRING
Definition: Importer.cpp:163
static constexpr bool PROMOTE_POLYGON_TO_MULTIPOLYGON
Definition: Importer.cpp:164
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:320
std::optional< int64_t > dateTimeParseOptional< kTIMESTAMP >(std::string_view str, unsigned const dim)
Definition: sqltypes.h:79
Definition: sqltypes.h:80
static constexpr bool PROMOTE_POINT_TO_MULTIPOINT
Definition: Importer.cpp:162
Definition: sqltypes.h:72

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

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

Referenced by find_best_sqltypes_and_headers().

3416  {
3417  if (raw_rows.size() < 1) {
3418  throw std::runtime_error("No rows found in: " +
3419  boost::filesystem::path(file_path).stem().string());
3420  }
3421  size_t num_cols = best_types.size();
3422  std::vector<EncodingType> best_encodes(num_cols, kENCODING_NONE);
3423  std::vector<size_t> num_rows_per_col(num_cols, 1);
3424  std::vector<std::unordered_set<std::string>> count_set(num_cols);
3425  for (auto row = row_begin; row != row_end; row++) {
3426  for (size_t col_idx = 0; col_idx < row->size() && col_idx < num_cols; col_idx++) {
3427  if (IS_STRING(best_types[col_idx])) {
3428  count_set[col_idx].insert(row->at(col_idx));
3429  num_rows_per_col[col_idx]++;
3430  }
3431  }
3432  }
3433  for (size_t col_idx = 0; col_idx < num_cols; col_idx++) {
3434  if (IS_STRING(best_types[col_idx])) {
3435  float uniqueRatio =
3436  static_cast<float>(count_set[col_idx].size()) / num_rows_per_col[col_idx];
3437  if (uniqueRatio < 0.75) {
3438  best_encodes[col_idx] = kENCODING_DICT;
3439  }
3440  }
3441  }
3442  return best_encodes;
3443 }
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:739
boost::filesystem::path file_path
Definition: Importer.h:774
#define IS_STRING(T)
Definition: sqltypes.h:309

+ Here is the caller graph for this function:

void import_export::Detector::find_best_sqltypes ( )
private

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

3360  {
3362 }
std::vector< SQLTypes > best_sqltypes
Definition: Importer.h:780
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:739

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

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

3366  {
3367  return find_best_sqltypes(raw_rows.begin(), raw_rows.end(), copy_params);
3368 }
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:739

+ 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 3370 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.

3373  {
3374  if (raw_rows.size() < 1) {
3375  throw std::runtime_error("No rows found in: " +
3376  boost::filesystem::path(file_path).stem().string());
3377  }
3378  auto end_time = std::chrono::steady_clock::now() + timeout;
3379  size_t num_cols = raw_rows.front().size();
3380  std::vector<SQLTypes> best_types(num_cols, kCHAR);
3381  std::vector<size_t> non_null_col_counts(num_cols, 0);
3382  for (auto row = row_begin; row != row_end; row++) {
3383  while (best_types.size() < row->size() || non_null_col_counts.size() < row->size()) {
3384  best_types.push_back(kCHAR);
3385  non_null_col_counts.push_back(0);
3386  }
3387  for (size_t col_idx = 0; col_idx < row->size(); col_idx++) {
3388  // do not count nulls
3389  if (row->at(col_idx) == "" || !row->at(col_idx).compare(copy_params.null_str)) {
3390  continue;
3391  }
3392  SQLTypes t = detect_sqltype(row->at(col_idx));
3393  non_null_col_counts[col_idx]++;
3394  if (!more_restrictive_sqltype(best_types[col_idx], t)) {
3395  best_types[col_idx] = t;
3396  }
3397  }
3398  if (std::chrono::steady_clock::now() > end_time) {
3399  break;
3400  }
3401  }
3402  for (size_t col_idx = 0; col_idx < num_cols; col_idx++) {
3403  // if we don't have any non-null values for this column make it text to be
3404  // safe b/c that is least restrictive type
3405  if (non_null_col_counts[col_idx] == 0) {
3406  best_types[col_idx] = kTEXT;
3407  }
3408  }
3409 
3410  return best_types;
3411 }
SQLTypes
Definition: sqltypes.h:65
static SQLTypes detect_sqltype(const std::string &str)
Definition: Importer.cpp:3216
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:739
boost::filesystem::path file_path
Definition: Importer.h:774
Definition: sqltypes.h:79
static bool more_restrictive_sqltype(const SQLTypes a, const SQLTypes b)
Definition: Importer.cpp:3313
std::chrono::duration< double > timeout
Definition: Importer.h:775
Definition: sqltypes.h:68

+ Here is the call graph for this function:

void import_export::Detector::find_best_sqltypes_and_headers ( )
private

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

3337  {
3339  best_encodings =
3340  find_best_encodings(raw_rows.begin() + 1, raw_rows.end(), best_sqltypes);
3341  std::vector<SQLTypes> head_types = detect_column_types(raw_rows.at(0));
3342  switch (copy_params.has_header) {
3344  has_headers = detect_headers(head_types, best_sqltypes);
3345  if (has_headers) {
3347  } else {
3349  }
3350  break;
3352  has_headers = false;
3353  break;
3355  has_headers = true;
3356  break;
3357  }
3358 }
std::vector< SQLTypes > best_sqltypes
Definition: Importer.h:780
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:3413
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:739
std::vector< EncodingType > best_encodings
Definition: Importer.h:781
bool detect_headers(const std::vector< SQLTypes > &first_types, const std::vector< SQLTypes > &rest_types)
Definition: Importer.cpp:3449
std::vector< SQLTypes > detect_column_types(const std::vector< std::string > &row)
Definition: Importer.cpp:3305

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

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

Referenced by DBHandler::detect_column_types().

3479  {
3480 #if defined(ENABLE_IMPORT_PARQUET)
3481  if (data_preview_.has_value()) {
3482  return data_preview_.value().column_names;
3483  } else
3484 #endif
3485  {
3486  std::vector<std::string> headers(best_sqltypes.size());
3487  for (size_t i = 0; i < best_sqltypes.size(); i++) {
3488  if (has_headers && i < raw_rows[0].size()) {
3489  headers[i] = raw_rows[0][i];
3490  } else {
3491  headers[i] = "column_" + std::to_string(i + 1);
3492  }
3493  }
3494  return headers;
3495  }
3496 }
std::vector< SQLTypes > best_sqltypes
Definition: Importer.h:780
std::string to_string(char const *&&v)
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:739

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

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

Referenced by DBHandler::detect_column_types().

3464  {
3465 #if defined(ENABLE_IMPORT_PARQUET)
3466  if (data_preview_.has_value()) {
3467  return data_preview_.value().sample_rows;
3468  } else
3469 #endif
3470  {
3471  n = std::min(n, raw_rows.size());
3472  size_t offset = (has_headers && raw_rows.size() > 1) ? 1 : 0;
3473  std::vector<std::vector<std::string>> sample_rows(raw_rows.begin() + offset,
3474  raw_rows.begin() + n);
3475  return sample_rows;
3476  }
3477 }
std::vector< std::vector< std::string > > raw_rows
Definition: Importer.h:739
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 3498 of file Importer.cpp.

References best_encodings, best_sqltypes, and CHECK_EQ.

Referenced by DBHandler::detect_column_types().

3498  {
3499 #if defined(ENABLE_IMPORT_PARQUET)
3500  if (data_preview_.has_value()) {
3501  return data_preview_.value().column_types;
3502  } else
3503 #endif
3504  {
3505  std::vector<SQLTypeInfo> types;
3506  CHECK_EQ(best_sqltypes.size(), best_encodings.size());
3507  for (size_t i = 0; i < best_sqltypes.size(); i++) {
3508  types.emplace_back(best_sqltypes[i], false, best_encodings[i]);
3509  }
3510  return types;
3511  }
3512 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< SQLTypes > best_sqltypes
Definition: Importer.h:780
std::vector< EncodingType > best_encodings
Definition: Importer.h:781

+ 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 3086 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.

3089  {
3090  // we do not check interrupt status for this detection
3091  if (!p_file) {
3092  p_file = fopen(file_path.c_str(), "rb");
3093  }
3094  if (!p_file) {
3095  throw std::runtime_error("failed to open file '" + file_path +
3096  "': " + strerror(errno));
3097  }
3098 
3099  // somehow clang does not support ext/stdio_filebuf.h, so
3100  // need to diy readline with customized copy_params.line_delim...
3101  std::string line;
3102  line.reserve(1 * 1024 * 1024);
3103  auto end_time = std::chrono::steady_clock::now() +
3104  timeout * (boost::istarts_with(file_path, "s3://") ? 3 : 1);
3105  try {
3106  while (!feof(p_file)) {
3107  int c;
3108  size_t n = 0;
3109  while (EOF != (c = fgetc(p_file)) && copy_params.line_delim != c) {
3110  if (n++ >= line.capacity()) {
3111  break;
3112  }
3113  line += c;
3114  }
3115  if (0 == n) {
3116  break;
3117  }
3118  // remember the first line, which is possibly a header line, to
3119  // ignore identical header line(s) in 2nd+ files of a archive;
3120  // otherwise, 2nd+ header may be mistaken as an all-string row
3121  // and so be final column types.
3122  if (line1.empty()) {
3123  line1 = line;
3124  } else if (line == line1) {
3125  line.clear();
3126  continue;
3127  }
3128 
3129  raw_data += line;
3131  line.clear();
3133  if (std::chrono::steady_clock::now() > end_time) {
3135  // stop import when row limit reached
3136  break;
3137  }
3138  }
3139  }
3140  } catch (std::exception& e) {
3141  }
3142 
3144  import_status_.load_failed = true;
3145 
3146  fclose(p_file);
3147  p_file = nullptr;
3148  return import_status_;
3149 }
std::lock_guard< T > lock_guard
::FILE * fopen(const char *filename, const char *mode)
Definition: heavyai_fs.cpp:74
boost::filesystem::path file_path
Definition: Importer.h:774
tuple line
Definition: parse_ast.py:10
static const size_t kImportRowLimit
Definition: Importer.cpp:170
std::chrono::duration< double > timeout
Definition: Importer.h:775
std::string raw_data
Definition: Importer.h:773
constexpr double n
Definition: Utm.h:38
heavyai::shared_mutex import_mutex_
Definition: Importer.h:723

+ Here is the call graph for this function:

void import_export::Detector::init ( )
private

Definition at line 3080 of file Importer.cpp.

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

Referenced by Detector().

3080  {
3082  split_raw_data();
3084 }
void find_best_sqltypes_and_headers()
Definition: Importer.cpp:3337

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

3313  {
3314  static std::array<int, kSQLTYPE_LAST> typeorder;
3315  typeorder[kCHAR] = 0;
3316  typeorder[kBOOLEAN] = 2;
3317  typeorder[kSMALLINT] = 3;
3318  typeorder[kINT] = 4;
3319  typeorder[kBIGINT] = 5;
3320  typeorder[kFLOAT] = 6;
3321  typeorder[kDOUBLE] = 7;
3322  typeorder[kTIMESTAMP] = 8;
3323  typeorder[kTIME] = 9;
3324  typeorder[kDATE] = 10;
3325  typeorder[kPOINT] = 11;
3326  typeorder[kMULTIPOINT] = 11;
3327  typeorder[kLINESTRING] = 11;
3328  typeorder[kMULTILINESTRING] = 11;
3329  typeorder[kPOLYGON] = 11;
3330  typeorder[kMULTIPOLYGON] = 11;
3331  typeorder[kTEXT] = 12;
3332 
3333  // note: b < a instead of a < b because the map is ordered most to least restrictive
3334  return typeorder[b] < typeorder[a];
3335 }
Definition: sqltypes.h:76
constexpr double a
Definition: Utm.h:32
Definition: sqltypes.h:79
Definition: sqltypes.h:80
Definition: sqltypes.h:68
Definition: sqltypes.h:72

+ Here is the caller graph for this function:

void import_export::Detector::read_file ( )
private

Definition at line 3151 of file Importer.cpp.

References import_export::DataStreamSink::archivePlumber().

Referenced by Detector().

3151  {
3152  // this becomes analogous to Importer::import()
3153  (void)DataStreamSink::archivePlumber(nullptr);
3154 }
ImportStatus archivePlumber(const Catalog_Namespace::SessionInfo *session_info)
Definition: Importer.cpp:3560

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

3165  {
3166  const char* buf = raw_data.c_str();
3167  const char* buf_end = buf + raw_data.size();
3168  bool try_single_thread = false;
3169  for (const char* p = buf; p < buf_end; p++) {
3170  std::vector<std::string> row;
3171  std::vector<std::unique_ptr<char[]>> tmp_buffers;
3173  buf_end,
3174  buf_end,
3175  copy_params,
3176  nullptr,
3177  row,
3178  tmp_buffers,
3179  try_single_thread,
3180  true);
3181  raw_rows.push_back(row);
3182  if (try_single_thread) {
3183  break;
3184  }
3185  }
3186  if (try_single_thread) {
3187  copy_params.threads = 1;
3188  raw_rows.clear();
3189  for (const char* p = buf; p < buf_end; p++) {
3190  std::vector<std::string> row;
3191  std::vector<std::unique_ptr<char[]>> tmp_buffers;
3193  buf_end,
3194  buf_end,
3195  copy_params,
3196  nullptr,
3197  row,
3198  tmp_buffers,
3199  try_single_thread,
3200  true);
3201  raw_rows.push_back(row);
3202  }
3203  }
3204 }
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:739
std::string raw_data
Definition: Importer.h:773

+ 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 781 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 774 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 776 of file Importer.h.

Referenced by importDelimited().

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

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

Referenced by find_best_sqltypes(), and importDelimited().


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