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

#include <Importer.h>

+ Inheritance diagram for import_export::Importer:
+ Collaboration diagram for import_export::Importer:

Classes

struct  GeoFileLayerInfo
 

Public Types

enum  GeoFileLayerContents { GeoFileLayerContents::EMPTY, GeoFileLayerContents::GEO, GeoFileLayerContents::NON_GEO, GeoFileLayerContents::UNSUPPORTED_GEO }
 

Public Member Functions

 Importer (Catalog_Namespace::Catalog &c, const TableDescriptor *t, const std::string &f, const CopyParams &p)
 
 Importer (Loader *providedLoader, const std::string &f, const CopyParams &p)
 
 ~Importer () override
 
ImportStatus import (const Catalog_Namespace::SessionInfo *session_info)
 
ImportStatus importDelimited (const std::string &file_path, const bool decompressed, const Catalog_Namespace::SessionInfo *session_info) override
 
ImportStatus importGDAL (std::map< std::string, std::string > colname_to_src, const Catalog_Namespace::SessionInfo *session_info)
 
const CopyParamsget_copy_params () const
 
const std::list< const
ColumnDescriptor * > & 
get_column_descs () const
 
void load (const std::vector< std::unique_ptr< TypedImportBuffer >> &import_buffers, size_t row_count, const Catalog_Namespace::SessionInfo *session_info)
 
std::vector< std::vector
< std::unique_ptr
< TypedImportBuffer > > > & 
get_import_buffers_vec ()
 
std::vector< std::unique_ptr
< TypedImportBuffer > > & 
get_import_buffers (int i)
 
const bool * get_is_array () const
 
Catalog_Namespace::CataloggetCatalog ()
 
void checkpoint (const std::vector< Catalog_Namespace::TableEpochInfo > &table_epochs)
 
auto getLoader () 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 ImportStatus get_import_status (const std::string &id)
 
static void set_import_status (const std::string &id, const ImportStatus is)
 
static const std::list
< ColumnDescriptor
gdalToColumnDescriptors (const std::string &fileName, const std::string &geoColumnName, const CopyParams &copy_params)
 
static void readMetadataSampleGDAL (const std::string &fileName, const std::string &geoColumnName, std::map< std::string, std::vector< std::string >> &metadata, int rowLimit, const CopyParams &copy_params)
 
static bool gdalFileExists (const std::string &path, const CopyParams &copy_params)
 
static bool gdalFileOrDirectoryExists (const std::string &path, const CopyParams &copy_params)
 
static std::vector< std::string > gdalGetAllFilesInArchive (const std::string &archive_path, const CopyParams &copy_params)
 
static std::vector
< GeoFileLayerInfo
gdalGetLayersInGeoFile (const std::string &file_name, const CopyParams &copy_params)
 
static void set_geo_physical_import_buffer (const Catalog_Namespace::Catalog &catalog, const ColumnDescriptor *cd, std::vector< std::unique_ptr< TypedImportBuffer >> &import_buffers, size_t &col_idx, std::vector< double > &coords, std::vector< double > &bounds, std::vector< int > &ring_sizes, std::vector< int > &poly_rings, int render_group)
 
static void set_geo_physical_import_buffer_columnar (const Catalog_Namespace::Catalog &catalog, const ColumnDescriptor *cd, std::vector< std::unique_ptr< TypedImportBuffer >> &import_buffers, size_t &col_idx, std::vector< std::vector< double >> &coords_column, std::vector< std::vector< double >> &bounds_column, std::vector< std::vector< int >> &ring_sizes_column, std::vector< std::vector< int >> &poly_rings_column, std::vector< int > &render_groups_column)
 

Static Private Member Functions

static bool gdalStatInternal (const std::string &path, const CopyParams &copy_params, bool also_dir)
 
static OGRDataSource * openGDALDataset (const std::string &fileName, const CopyParams &copy_params)
 
static void setGDALAuthorizationTokens (const CopyParams &copy_params)
 

Private Attributes

std::string import_id
 
size_t file_size
 
size_t max_threads
 
char * buffer [2]
 
std::vector< std::vector
< std::unique_ptr
< TypedImportBuffer > > > 
import_buffers_vec
 
std::unique_ptr< Loaderloader
 
std::unique_ptr< bool[]> is_array_a
 
bool interrupted
 

Static Private Attributes

static std::mutex init_gdal_mutex
 

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

Member Enumeration Documentation

Enumerator
EMPTY 
GEO 
NON_GEO 
UNSUPPORTED_GEO 

Definition at line 811 of file Importer.h.

811 { EMPTY, GEO, NON_GEO, UNSUPPORTED_GEO };

Constructor & Destructor Documentation

import_export::Importer::Importer ( Catalog_Namespace::Catalog c,
const TableDescriptor t,
const std::string &  f,
const CopyParams p 
)

Definition at line 171 of file Importer.cpp.

175  : Importer(new Loader(c, t), f, p) {}
Importer(Catalog_Namespace::Catalog &c, const TableDescriptor *t, const std::string &f, const CopyParams &p)
Definition: Importer.cpp:171
char * f
import_export::Importer::Importer ( Loader providedLoader,
const std::string &  f,
const CopyParams p 
)

Definition at line 177 of file Importer.cpp.

References buffer, import_export::DataStreamSink::file_path, file_size, i, import_id, is_array_a, kARRAY, loader, max_threads, and import_export::DataStreamSink::p_file.

178  : DataStreamSink(p, f), loader(providedLoader) {
179  import_id = boost::filesystem::path(file_path).filename().string();
180  file_size = 0;
181  max_threads = 0;
182  p_file = nullptr;
183  buffer[0] = nullptr;
184  buffer[1] = nullptr;
185  // we may be overallocating a little more memory here due to dropping phy cols.
186  // it shouldn't be an issue because iteration of it is not supposed to go OOB.
187  auto is_array = std::unique_ptr<bool[]>(new bool[loader->get_column_descs().size()]);
188  int i = 0;
189  bool has_array = false;
190  // TODO: replace this ugly way of skipping phy cols once if isPhyGeo is defined
191  int skip_physical_cols = 0;
192  for (auto& p : loader->get_column_descs()) {
193  // phy geo columns can't be in input file
194  if (skip_physical_cols-- > 0) {
195  continue;
196  }
197  // neither are rowid or $deleted$
198  // note: columns can be added after rowid/$deleted$
199  if (p->isVirtualCol || p->isDeletedCol) {
200  continue;
201  }
202  skip_physical_cols = p->columnType.get_physical_cols();
203  if (p->columnType.get_type() == kARRAY) {
204  is_array.get()[i] = true;
205  has_array = true;
206  } else {
207  is_array.get()[i] = false;
208  }
209  ++i;
210  }
211  if (has_array) {
212  is_array_a = std::unique_ptr<bool[]>(is_array.release());
213  } else {
214  is_array_a = std::unique_ptr<bool[]>(nullptr);
215  }
216 }
std::unique_ptr< bool[]> is_array_a
Definition: Importer.h:858
std::string import_id
Definition: Importer.h:852
char * f
std::unique_ptr< Loader > loader
Definition: Importer.h:857
const std::string file_path
Definition: Importer.h:675
import_export::Importer::~Importer ( )
override

Definition at line 218 of file Importer.cpp.

References buffer, and import_export::DataStreamSink::p_file.

218  {
219  if (p_file != nullptr) {
220  fclose(p_file);
221  }
222  if (buffer[0] != nullptr) {
223  free(buffer[0]);
224  }
225  if (buffer[1] != nullptr) {
226  free(buffer[1]);
227  }
228 }

Member Function Documentation

void import_export::Importer::checkpoint ( const std::vector< Catalog_Namespace::TableEpochInfo > &  table_epochs)

Definition at line 3379 of file Importer.cpp.

References DEBUG_TIMING, Data_Namespace::DISK_LEVEL, logger::ERROR, measure< TimeT >::execution(), StorageType::FOREIGN_TABLE, import_buffers_vec, import_export::DataStreamSink::import_mutex_, import_export::DataStreamSink::import_status_, logger::INFO, import_export::ImportStatus::load_failed, import_export::ImportStatus::load_msg, loader, and LOG.

Referenced by importDelimited(), and importGDAL().

3380  {
3381  if (loader->getTableDesc()->storageType != StorageType::FOREIGN_TABLE) {
3382  mapd_lock_guard<mapd_shared_mutex> read_lock(import_mutex_);
3384  // rollback to starting epoch - undo all the added records
3385  loader->setTableEpochs(table_epochs);
3386  } else {
3387  loader->checkpoint();
3388  }
3389  }
3390 
3391  if (loader->getTableDesc()->persistenceLevel ==
3392  Data_Namespace::MemoryLevel::DISK_LEVEL) { // only checkpoint disk-resident
3393  // tables
3394  auto ms = measure<>::execution([&]() {
3395  mapd_lock_guard<mapd_shared_mutex> write_lock(import_mutex_);
3396  if (!import_status_.load_failed) {
3397  for (auto& p : import_buffers_vec[0]) {
3398  if (!p->stringDictCheckpoint()) {
3399  LOG(ERROR) << "Checkpointing Dictionary for Column "
3400  << p->getColumnDesc()->columnName << " failed.";
3401  import_status_.load_failed = true;
3402  import_status_.load_msg = "Dictionary checkpoint failed";
3403  break;
3404  }
3405  }
3406  }
3407  });
3408  if (DEBUG_TIMING) {
3409  LOG(INFO) << "Dictionary Checkpointing took " << (double)ms / 1000.0 << " Seconds."
3410  << std::endl;
3411  }
3412  }
3413 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:188
mapd_shared_mutex import_mutex_
Definition: Importer.h:678
#define DEBUG_TIMING
Definition: Importer.cpp:160
std::vector< std::vector< std::unique_ptr< TypedImportBuffer > > > import_buffers_vec
Definition: Importer.h:856
mapd_shared_lock< mapd_shared_mutex > read_lock
mapd_unique_lock< mapd_shared_mutex > write_lock
static constexpr char const * FOREIGN_TABLE
std::unique_ptr< Loader > loader
Definition: Importer.h:857

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool import_export::Importer::gdalFileExists ( const std::string &  path,
const CopyParams copy_params 
)
static

Definition at line 4735 of file Importer.cpp.

References gdalStatInternal().

Referenced by DBHandler::check_geospatial_files(), DBHandler::detect_column_types(), DBHandler::get_all_files_in_archive(), DBHandler::get_first_geo_file_in_archive(), DBHandler::get_layers_in_geo_file(), and DBHandler::import_geo_table().

4735  {
4736  return gdalStatInternal(path, copy_params, false);
4737 }
static bool gdalStatInternal(const std::string &path, const CopyParams &copy_params, bool also_dir)
Definition: Importer.cpp:4702

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool import_export::Importer::gdalFileOrDirectoryExists ( const std::string &  path,
const CopyParams copy_params 
)
static

Definition at line 4740 of file Importer.cpp.

References gdalStatInternal().

Referenced by DBHandler::detect_column_types(), DBHandler::get_layers_in_geo_file(), and DBHandler::import_geo_table().

4741  {
4742  return gdalStatInternal(path, copy_params, true);
4743 }
static bool gdalStatInternal(const std::string &path, const CopyParams &copy_params, bool also_dir)
Definition: Importer.cpp:4702

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< std::string > import_export::Importer::gdalGetAllFilesInArchive ( const std::string &  archive_path,
const CopyParams copy_params 
)
static

Definition at line 4812 of file Importer.cpp.

References import_export::gdalGatherFilesInArchiveRecursive(), Geospatial::GDAL::init(), and setGDALAuthorizationTokens().

Referenced by anonymous_namespace{DBHandler.cpp}::find_first_geo_file_in_archive(), and DBHandler::get_all_files_in_archive().

4814  {
4815  // lazy init GDAL
4817 
4818  // set authorization tokens
4820 
4821  // prepare to gather files
4822  std::vector<std::string> files;
4823 
4824  // gather the files recursively
4825  gdalGatherFilesInArchiveRecursive(archive_path, files);
4826 
4827  // convert to relative paths inside archive
4828  for (auto& file : files) {
4829  file.erase(0, archive_path.size() + 1); // remove archive_path and the slash
4830  }
4831 
4832  // done
4833  return files;
4834 }
static void init()
Definition: GDAL.cpp:59
static void setGDALAuthorizationTokens(const CopyParams &copy_params)
Definition: Importer.cpp:4352
void gdalGatherFilesInArchiveRecursive(const std::string &archive_path, std::vector< std::string > &files)
Definition: Importer.cpp:4745

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< Importer::GeoFileLayerInfo > import_export::Importer::gdalGetLayersInGeoFile ( const std::string &  file_name,
const CopyParams copy_params 
)
static

Definition at line 4837 of file Importer.cpp.

References CHECK, EMPTY, GEO, import_export::CopyParams::geo_explode_collections, Geospatial::GDAL::init(), NON_GEO, openGDALDataset(), setGDALAuthorizationTokens(), and UNSUPPORTED_GEO.

Referenced by DBHandler::get_layers_in_geo_file(), and DBHandler::import_geo_table().

4839  {
4840  // lazy init GDAL
4842 
4843  // set authorization tokens
4845 
4846  // prepare to gather layer info
4847  std::vector<GeoFileLayerInfo> layer_info;
4848 
4849  // open the data set
4851  if (poDS == nullptr) {
4852  throw std::runtime_error("openGDALDataset Error: Unable to open geo file " +
4853  file_name);
4854  }
4855 
4856  // enumerate the layers
4857  for (auto&& poLayer : poDS->GetLayers()) {
4859  // prepare to read this layer
4860  poLayer->ResetReading();
4861  // skip layer if empty
4862  if (poLayer->GetFeatureCount() > 0) {
4863  // get first feature
4864  OGRFeatureUqPtr first_feature(poLayer->GetNextFeature());
4865  CHECK(first_feature);
4866  // check feature for geometry
4867  const OGRGeometry* geometry = first_feature->GetGeometryRef();
4868  if (!geometry) {
4869  // layer has no geometry
4870  contents = GeoFileLayerContents::NON_GEO;
4871  } else {
4872  // check the geometry type
4873  const OGRwkbGeometryType geometry_type = geometry->getGeometryType();
4874  switch (wkbFlatten(geometry_type)) {
4875  case wkbPoint:
4876  case wkbLineString:
4877  case wkbPolygon:
4878  case wkbMultiPolygon:
4879  // layer has supported geo
4880  contents = GeoFileLayerContents::GEO;
4881  break;
4882  case wkbMultiPoint:
4883  case wkbMultiLineString:
4884  // supported if geo_explode_collections is specified
4888  break;
4889  default:
4890  // layer has unsupported geometry
4892  break;
4893  }
4894  }
4895  }
4896  // store info for this layer
4897  layer_info.emplace_back(poLayer->GetName(), contents);
4898  }
4899 
4900  // done
4901  return layer_info;
4902 }
static void init()
Definition: GDAL.cpp:59
std::unique_ptr< OGRDataSource, OGRDataSourceDeleter > OGRDataSourceUqPtr
Definition: Importer.cpp:115
std::unique_ptr< OGRFeature, OGRFeatureDeleter > OGRFeatureUqPtr
Definition: Importer.cpp:124
static void setGDALAuthorizationTokens(const CopyParams &copy_params)
Definition: Importer.cpp:4352
#define CHECK(condition)
Definition: Logger.h:197
static OGRDataSource * openGDALDataset(const std::string &fileName, const CopyParams &copy_params)
Definition: Importer.cpp:4422

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool import_export::Importer::gdalStatInternal ( const std::string &  path,
const CopyParams copy_params,
bool  also_dir 
)
staticprivate

Definition at line 4702 of file Importer.cpp.

References Geospatial::GDAL::init(), run_benchmark_import::result, and setGDALAuthorizationTokens().

Referenced by gdalFileExists(), and gdalFileOrDirectoryExists().

4704  {
4705  // lazy init GDAL
4707 
4708  // set authorization tokens
4710 
4711 #if (GDAL_VERSION_MAJOR > 2) || (GDAL_VERSION_MAJOR == 2 && GDAL_VERSION_MINOR >= 3)
4712  // clear GDAL stat cache
4713  // without this, file existence will be cached, even if authentication changes
4714  // supposed to be available from GDAL 2.2.1 but our CentOS build disagrees
4715  VSICurlClearCache();
4716 #endif
4717 
4718  // stat path
4719  VSIStatBufL sb;
4720  int result = VSIStatExL(path.c_str(), &sb, VSI_STAT_EXISTS_FLAG);
4721  if (result < 0) {
4722  return false;
4723  }
4724 
4725  // exists?
4726  if (also_dir && (VSI_ISREG(sb.st_mode) || VSI_ISDIR(sb.st_mode))) {
4727  return true;
4728  } else if (VSI_ISREG(sb.st_mode)) {
4729  return true;
4730  }
4731  return false;
4732 }
static void init()
Definition: GDAL.cpp:59
static void setGDALAuthorizationTokens(const CopyParams &copy_params)
Definition: Importer.cpp:4352

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::list< ColumnDescriptor > import_export::Importer::gdalToColumnDescriptors ( const std::string &  fileName,
const std::string &  geoColumnName,
const CopyParams copy_params 
)
static

Definition at line 4612 of file Importer.cpp.

References CHECK, ColumnDescriptor::columnName, ColumnDescriptor::columnType, import_export::CopyParams::geo_coords_comp_param, import_export::CopyParams::geo_coords_encoding, import_export::CopyParams::geo_coords_srid, import_export::CopyParams::geo_coords_type, import_export::CopyParams::geo_explode_collections, import_export::CopyParams::geo_layer_name, import_export::anonymous_namespace{Importer.cpp}::getLayerWithSpecifiedName(), kARRAY, kENCODING_DICT, kMULTIPOLYGON, kPOLYGON, kTEXT, import_export::ogr_to_type(), openGDALDataset(), import_export::PROMOTE_POLYGON_TO_MULTIPOLYGON, SQLTypeInfo::set_comp_param(), SQLTypeInfo::set_compression(), SQLTypeInfo::set_fixed_size(), SQLTypeInfo::set_input_srid(), SQLTypeInfo::set_output_srid(), SQLTypeInfo::set_subtype(), SQLTypeInfo::set_type(), and ColumnDescriptor::sourceName.

Referenced by DBHandler::detect_column_types().

4615  {
4616  std::list<ColumnDescriptor> cds;
4617 
4619  if (poDS == nullptr) {
4620  throw std::runtime_error("openGDALDataset Error: Unable to open geo file " +
4621  file_name);
4622  }
4623 
4624  OGRLayer& layer =
4626 
4627  layer.ResetReading();
4628  // TODO(andrewseidl): support multiple features
4629  OGRFeatureUqPtr poFeature(layer.GetNextFeature());
4630  if (poFeature == nullptr) {
4631  throw std::runtime_error("No features found in " + file_name);
4632  }
4633  // get fields as regular columns
4634  OGRFeatureDefn* poFDefn = layer.GetLayerDefn();
4635  CHECK(poFDefn);
4636  int iField;
4637  for (iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
4638  OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
4639  auto typePair = ogr_to_type(poFieldDefn->GetType());
4640  ColumnDescriptor cd;
4641  cd.columnName = poFieldDefn->GetNameRef();
4642  cd.sourceName = poFieldDefn->GetNameRef();
4643  SQLTypeInfo ti;
4644  if (typePair.second) {
4645  ti.set_type(kARRAY);
4646  ti.set_subtype(typePair.first);
4647  } else {
4648  ti.set_type(typePair.first);
4649  }
4650  if (typePair.first == kTEXT) {
4652  ti.set_comp_param(32);
4653  }
4654  ti.set_fixed_size();
4655  cd.columnType = ti;
4656  cds.push_back(cd);
4657  }
4658  // get geo column, if any
4659  OGRGeometry* poGeometry = poFeature->GetGeometryRef();
4660  if (poGeometry) {
4661  ColumnDescriptor cd;
4662  cd.columnName = geo_column_name;
4663  cd.sourceName = geo_column_name;
4664 
4665  // get GDAL type
4666  auto ogr_type = wkbFlatten(poGeometry->getGeometryType());
4667 
4668  // if exploding, override any collection type to child type
4670  if (ogr_type == wkbMultiPolygon) {
4671  ogr_type = wkbPolygon;
4672  } else if (ogr_type == wkbMultiLineString) {
4673  ogr_type = wkbLineString;
4674  } else if (ogr_type == wkbMultiPoint) {
4675  ogr_type = wkbPoint;
4676  }
4677  }
4678 
4679  // convert to internal type
4680  SQLTypes geoType = ogr_to_type(ogr_type);
4681 
4682  // for now, we promote POLYGON to MULTIPOLYGON (unless exploding)
4684  geoType = (geoType == kPOLYGON) ? kMULTIPOLYGON : geoType;
4685  }
4686 
4687  // build full internal type
4688  SQLTypeInfo ti;
4689  ti.set_type(geoType);
4695  cd.columnType = ti;
4696 
4697  cds.push_back(cd);
4698  }
4699  return cds;
4700 }
void set_compression(EncodingType c)
Definition: sqltypes.h:414
SQLTypes
Definition: sqltypes.h:37
OGRLayer & getLayerWithSpecifiedName(const std::string &geo_layer_name, const OGRDataSourceUqPtr &poDS, const std::string &file_name)
Definition: Importer.cpp:4455
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:405
std::unique_ptr< OGRDataSource, OGRDataSourceDeleter > OGRDataSourceUqPtr
Definition: Importer.cpp:115
std::unique_ptr< OGRFeature, OGRFeatureDeleter > OGRFeatureUqPtr
Definition: Importer.cpp:124
std::string sourceName
void set_input_srid(int d)
Definition: sqltypes.h:408
void set_fixed_size()
Definition: sqltypes.h:413
static constexpr bool PROMOTE_POLYGON_TO_MULTIPOLYGON
Definition: Importer.cpp:166
specifies the content in-memory of a row in the column metadata table
void set_output_srid(int s)
Definition: sqltypes.h:410
void set_comp_param(int p)
Definition: sqltypes.h:415
std::string geo_layer_name
Definition: CopyParams.h:79
Definition: sqltypes.h:51
#define CHECK(condition)
Definition: Logger.h:197
SQLTypeInfo columnType
static OGRDataSource * openGDALDataset(const std::string &fileName, const CopyParams &copy_params)
Definition: Importer.cpp:4422
std::string columnName
std::pair< SQLTypes, bool > ogr_to_type(const OGRFieldType &ogr_type)
Definition: Importer.cpp:4557
EncodingType geo_coords_encoding
Definition: CopyParams.h:74
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:404

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::list<const ColumnDescriptor*>& import_export::Importer::get_column_descs ( ) const
inline

Definition at line 776 of file Importer.h.

References loader.

Referenced by import_export::import_thread_delimited(), and import_export::import_thread_shapefile().

776  {
777  return loader->get_column_descs();
778  }
std::unique_ptr< Loader > loader
Definition: Importer.h:857

+ Here is the caller graph for this function:

const CopyParams& import_export::Importer::get_copy_params ( ) const
inline

Definition at line 775 of file Importer.h.

References import_export::DataStreamSink::copy_params.

Referenced by import_export::import_thread_delimited(), and import_export::import_thread_shapefile().

775 { return copy_params; }

+ Here is the caller graph for this function:

std::vector<std::unique_ptr<TypedImportBuffer> >& import_export::Importer::get_import_buffers ( int  i)
inline

Definition at line 785 of file Importer.h.

References i, and import_buffers_vec.

Referenced by import_export::import_thread_delimited(), and import_export::import_thread_shapefile().

785  {
786  return import_buffers_vec[i];
787  }
std::vector< std::vector< std::unique_ptr< TypedImportBuffer > > > import_buffers_vec
Definition: Importer.h:856

+ Here is the caller graph for this function:

std::vector<std::vector<std::unique_ptr<TypedImportBuffer> > >& import_export::Importer::get_import_buffers_vec ( )
inline

Definition at line 782 of file Importer.h.

References import_buffers_vec.

782  {
783  return import_buffers_vec;
784  }
std::vector< std::vector< std::unique_ptr< TypedImportBuffer > > > import_buffers_vec
Definition: Importer.h:856
ImportStatus import_export::Importer::get_import_status ( const std::string &  id)
static

Definition at line 230 of file Importer.cpp.

References import_export::import_status_map, and import_export::status_mutex.

Referenced by DBHandler::import_table_status().

230  {
231  mapd_shared_lock<mapd_shared_mutex> read_lock(status_mutex);
232  return import_status_map.at(import_id);
233 }
static std::map< std::string, ImportStatus > import_status_map
Definition: Importer.cpp:169
std::string import_id
Definition: Importer.h:852
mapd_shared_lock< mapd_shared_mutex > read_lock
static mapd_shared_mutex status_mutex
Definition: Importer.cpp:168

+ Here is the caller graph for this function:

const bool* import_export::Importer::get_is_array ( ) const
inline

Definition at line 788 of file Importer.h.

References is_array_a.

Referenced by import_export::import_thread_delimited().

788 { return is_array_a.get(); }
std::unique_ptr< bool[]> is_array_a
Definition: Importer.h:858

+ Here is the caller graph for this function:

Catalog_Namespace::Catalog& import_export::Importer::getCatalog ( )
inline

Definition at line 821 of file Importer.h.

References loader.

Referenced by import_export::TypedImportBuffer::convert_arrow_val_to_import_buffer(), and import_export::import_thread_delimited().

821 { return loader->getCatalog(); }
std::unique_ptr< Loader > loader
Definition: Importer.h:857

+ Here is the caller graph for this function:

auto import_export::Importer::getLoader ( ) const
inline

Definition at line 843 of file Importer.h.

References loader.

843 { return loader.get(); }
std::unique_ptr< Loader > loader
Definition: Importer.h:857
ImportStatus import_export::Importer::import ( const Catalog_Namespace::SessionInfo session_info)

Definition at line 4110 of file Importer.cpp.

References import_export::DataStreamSink::archivePlumber().

4110  {
4111  return DataStreamSink::archivePlumber(session_info);
4112 }
ImportStatus archivePlumber(const Catalog_Namespace::SessionInfo *session_info)
Definition: Importer.cpp:3415

+ Here is the call graph for this function:

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

Implements import_export::DataStreamSink.

Definition at line 4114 of file Importer.cpp.

References import_export::CopyParams::buffer_size, CHECK, checkpoint(), ColumnDescriptor::columnId, ColumnDescriptor::columnName, ColumnDescriptor::columnType, import_export::DataStreamSink::copy_params, logger::ERROR, import_export::DataStreamSink::file_offsets, import_export::DataStreamSink::file_offsets_mutex, file_size, import_export::delimited_parser::find_row_end_pos(), omnisci::fopen(), g_max_import_threads, import_export::CopyParams::geo_assign_render_groups, Catalog_Namespace::SessionInfo::get_session_id(), SQLTypeInfo::get_type(), Executor::getExecutor(), i, import_buffers_vec, import_id, import_export::DataStreamSink::import_mutex_, import_export::DataStreamSink::import_status_, import_export::import_thread_delimited(), kMULTIPOLYGON, kPOLYGON, import_export::ImportStatus::load_failed, import_export::ImportStatus::load_msg, loader, LOG, import_export::CopyParams::max_reject, max_threads, import_export::DataStreamSink::p_file, import_export::ImportStatus::rows_completed, import_export::ImportStatus::rows_estimated, import_export::ImportStatus::rows_rejected, set_import_status(), logger::thread_id(), import_export::CopyParams::threads, import_export::DataStreamSink::total_file_size, Executor::UNITARY_EXECUTOR_ID, and VLOG.

4117  {
4119  auto query_session = session_info ? session_info->get_session_id() : "";
4120 
4121  if (!p_file) {
4122  p_file = fopen(file_path.c_str(), "rb");
4123  }
4124  if (!p_file) {
4125  throw std::runtime_error("failed to open file '" + file_path +
4126  "': " + strerror(errno));
4127  }
4128 
4129  if (!decompressed) {
4130  (void)fseek(p_file, 0, SEEK_END);
4131  file_size = ftell(p_file);
4132  }
4133 
4134  if (copy_params.threads == 0) {
4135  max_threads = std::min(static_cast<size_t>(sysconf(_SC_NPROCESSORS_CONF)),
4137  } else {
4138  max_threads = static_cast<size_t>(copy_params.threads);
4139  }
4140  VLOG(1) << "Delimited import # threads: " << max_threads;
4141 
4142  // deal with small files
4143  size_t alloc_size = copy_params.buffer_size;
4144  if (!decompressed && file_size < alloc_size) {
4145  alloc_size = file_size;
4146  }
4147 
4148  for (size_t i = 0; i < max_threads; i++) {
4149  import_buffers_vec.emplace_back();
4150  for (const auto cd : loader->get_column_descs()) {
4151  import_buffers_vec[i].emplace_back(
4152  std::make_unique<TypedImportBuffer>(cd, loader->getStringDict(cd)));
4153  }
4154  }
4155 
4156  auto scratch_buffer = std::make_unique<char[]>(alloc_size);
4157  size_t current_pos = 0;
4158  size_t end_pos;
4159  size_t begin_pos = 0;
4160 
4161  (void)fseek(p_file, current_pos, SEEK_SET);
4162  size_t size =
4163  fread(reinterpret_cast<void*>(scratch_buffer.get()), 1, alloc_size, p_file);
4164 
4165  // make render group analyzers for each poly column
4166  ColumnIdToRenderGroupAnalyzerMapType columnIdToRenderGroupAnalyzerMap;
4168  auto columnDescriptors = loader->getCatalog().getAllColumnMetadataForTable(
4169  loader->getTableDesc()->tableId, false, false, false);
4170  for (auto cd : columnDescriptors) {
4171  SQLTypes ct = cd->columnType.get_type();
4172  if (ct == kPOLYGON || ct == kMULTIPOLYGON) {
4173  auto rga = std::make_shared<RenderGroupAnalyzer>();
4174  rga->seedFromExistingTableContents(loader, cd->columnName);
4175  columnIdToRenderGroupAnalyzerMap[cd->columnId] = rga;
4176  }
4177  }
4178  }
4179 
4180  ChunkKey chunkKey = {loader->getCatalog().getCurrentDB().dbId,
4181  loader->getTableDesc()->tableId};
4182  auto table_epochs = loader->getTableEpochs();
4184  {
4185  std::list<std::future<ImportStatus>> threads;
4186 
4187  // use a stack to track thread_ids which must not overlap among threads
4188  // because thread_id is used to index import_buffers_vec[]
4189  std::stack<size_t> stack_thread_ids;
4190  for (size_t i = 0; i < max_threads; i++) {
4191  stack_thread_ids.push(i);
4192  }
4193  // added for true row index on error
4194  size_t first_row_index_this_buffer = 0;
4195 
4196  while (size > 0) {
4197  unsigned int num_rows_this_buffer = 0;
4198  CHECK(scratch_buffer);
4199  end_pos = delimited_parser::find_row_end_pos(alloc_size,
4200  scratch_buffer,
4201  size,
4202  copy_params,
4203  first_row_index_this_buffer,
4204  num_rows_this_buffer,
4205  p_file);
4206 
4207  // unput residual
4208  int nresidual = size - end_pos;
4209  std::unique_ptr<char[]> unbuf;
4210  if (nresidual > 0) {
4211  unbuf = std::make_unique<char[]>(nresidual);
4212  memcpy(unbuf.get(), scratch_buffer.get() + end_pos, nresidual);
4213  }
4214 
4215  // get a thread_id not in use
4216  auto thread_id = stack_thread_ids.top();
4217  stack_thread_ids.pop();
4218  // LOG(INFO) << " stack_thread_ids.pop " << thread_id << std::endl;
4219 
4220  threads.push_back(std::async(std::launch::async,
4222  thread_id,
4223  this,
4224  std::move(scratch_buffer),
4225  begin_pos,
4226  end_pos,
4227  end_pos,
4228  columnIdToRenderGroupAnalyzerMap,
4229  first_row_index_this_buffer,
4230  session_info,
4231  executor));
4232 
4233  first_row_index_this_buffer += num_rows_this_buffer;
4234 
4235  current_pos += end_pos;
4236  scratch_buffer = std::make_unique<char[]>(alloc_size);
4237  CHECK(scratch_buffer);
4238  memcpy(scratch_buffer.get(), unbuf.get(), nresidual);
4239  size = nresidual +
4240  fread(scratch_buffer.get() + nresidual, 1, alloc_size - nresidual, p_file);
4241 
4242  begin_pos = 0;
4243  while (threads.size() > 0) {
4244  int nready = 0;
4245  for (std::list<std::future<ImportStatus>>::iterator it = threads.begin();
4246  it != threads.end();) {
4247  auto& p = *it;
4248  std::chrono::milliseconds span(0);
4249  if (p.wait_for(span) == std::future_status::ready) {
4250  auto ret_import_status = p.get();
4251  {
4252  mapd_lock_guard<mapd_shared_mutex> write_lock(import_mutex_);
4253  import_status_ += ret_import_status;
4254  if (ret_import_status.load_failed) {
4256  }
4257  }
4258  // sum up current total file offsets
4259  size_t total_file_offset{0};
4260  if (decompressed) {
4261  std::unique_lock<std::mutex> lock(file_offsets_mutex);
4262  for (const auto file_offset : file_offsets) {
4263  total_file_offset += file_offset;
4264  }
4265  }
4266  // estimate number of rows per current total file offset
4267  if (decompressed ? total_file_offset : current_pos) {
4269  (decompressed ? (float)total_file_size / total_file_offset
4270  : (float)file_size / current_pos) *
4271  import_status_.rows_completed;
4272  }
4273  VLOG(3) << "rows_completed " << import_status_.rows_completed
4274  << ", rows_estimated " << import_status_.rows_estimated
4275  << ", total_file_size " << total_file_size << ", total_file_offset "
4276  << total_file_offset;
4278  // recall thread_id for reuse
4279  stack_thread_ids.push(ret_import_status.thread_id);
4280  threads.erase(it++);
4281  ++nready;
4282  } else {
4283  ++it;
4284  }
4285  }
4286 
4287  if (nready == 0) {
4288  std::this_thread::yield();
4289  }
4290 
4291  // on eof, wait all threads to finish
4292  if (0 == size) {
4293  continue;
4294  }
4295 
4296  // keep reading if any free thread slot
4297  // this is one of the major difference from old threading model !!
4298  if (threads.size() < max_threads) {
4299  break;
4300  }
4301  mapd_shared_lock<mapd_shared_mutex> read_lock(import_mutex_);
4303  break;
4304  }
4305  }
4306  mapd_unique_lock<mapd_shared_mutex> write_lock(import_mutex_);
4308  import_status_.load_failed = true;
4309  // todo use better message
4310  import_status_.load_msg = "Maximum rows rejected exceeded. Halting load";
4311  LOG(ERROR) << "Maximum rows rejected exceeded. Halting load";
4312  break;
4313  }
4315  LOG(ERROR) << "Load failed, the issue was: " + import_status_.load_msg;
4316  break;
4317  }
4318  }
4319 
4320  // join dangling threads in case of LOG(ERROR) above
4321  for (auto& p : threads) {
4322  p.wait();
4323  }
4324  }
4325 
4326  checkpoint(table_epochs);
4327 
4328  fclose(p_file);
4329  p_file = nullptr;
4330  return import_status_;
4331 }
std::vector< int > ChunkKey
Definition: types.h:37
static ImportStatus import_thread_delimited(int thread_id, Importer *importer, std::unique_ptr< char[]> scratch_buffer, size_t begin_pos, size_t end_pos, size_t total_size, const ColumnIdToRenderGroupAnalyzerMapType &columnIdToRenderGroupAnalyzerMap, size_t first_row_index_this_buffer, const Catalog_Namespace::SessionInfo *session_info, Executor *executor)
Definition: Importer.cpp:1826
SQLTypes
Definition: sqltypes.h:37
::FILE * fopen(const char *filename, const char *mode)
Definition: omnisci_fs.cpp:72
#define LOG(tag)
Definition: Logger.h:188
mapd_shared_mutex import_mutex_
Definition: Importer.h:678
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
Definition: Execute.cpp:161
std::vector< std::vector< std::unique_ptr< TypedImportBuffer > > > import_buffers_vec
Definition: Importer.h:856
std::string get_session_id() const
Definition: SessionInfo.h:77
static void set_import_status(const std::string &id, const ImportStatus is)
Definition: Importer.cpp:235
std::string import_id
Definition: Importer.h:852
void checkpoint(const std::vector< Catalog_Namespace::TableEpochInfo > &table_epochs)
Definition: Importer.cpp:3379
ThreadId thread_id()
Definition: Logger.cpp:732
mapd_shared_lock< mapd_shared_mutex > read_lock
#define CHECK(condition)
Definition: Logger.h:197
std::map< int, std::shared_ptr< RenderGroupAnalyzer >> ColumnIdToRenderGroupAnalyzerMapType
Definition: Importer.cpp:157
mapd_unique_lock< mapd_shared_mutex > write_lock
std::vector< size_t > file_offsets
Definition: Importer.h:680
size_t g_max_import_threads
Definition: Importer.cpp:84
size_t find_row_end_pos(size_t &alloc_size, std::unique_ptr< char[]> &buffer, size_t &buffer_size, const CopyParams &copy_params, const size_t buffer_first_row_index, unsigned int &num_rows_in_buffer, FILE *file, foreign_storage::CsvReader *csv_reader)
Finds the closest possible row ending to the end of the given buffer. The buffer is resized as needed...
#define VLOG(n)
Definition: Logger.h:291
std::unique_ptr< Loader > loader
Definition: Importer.h:857
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:367
const std::string file_path
Definition: Importer.h:675

+ Here is the call graph for this function:

ImportStatus import_export::Importer::importGDAL ( std::map< std::string, std::string >  colname_to_src,
const Catalog_Namespace::SessionInfo session_info 
)

Definition at line 4904 of file Importer.cpp.

References CHECK, CHECK_EQ, checkpoint(), ColumnDescriptor::columnId, ColumnDescriptor::columnName, ColumnDescriptor::columnType, import_export::DataStreamSink::copy_params, logger::ERROR, g_enable_non_kernel_time_query_interrupt, g_max_import_threads, import_export::CopyParams::geo_assign_render_groups, import_export::CopyParams::geo_coords_srid, import_export::CopyParams::geo_layer_name, Catalog_Namespace::SessionInfo::get_session_id(), SQLTypeInfo::get_type(), Executor::getExecutor(), import_export::anonymous_namespace{Importer.cpp}::getLayerWithSpecifiedName(), i, import_buffers_vec, import_id, import_export::DataStreamSink::import_mutex_, import_export::DataStreamSink::import_status_, import_export::import_thread_shapefile(), kMULTIPOLYGON, kPOLYGON, import_export::ImportStatus::load_failed, import_export::ImportStatus::load_msg, loader, LOG, import_export::CopyParams::max_reject, max_threads, openGDALDataset(), import_export::ImportStatus::rows_completed, import_export::ImportStatus::rows_estimated, import_export::ImportStatus::rows_rejected, set_import_status(), logger::thread_id(), import_export::CopyParams::threads, toString(), Executor::UNITARY_EXECUTOR_ID, and VLOG.

Referenced by QueryRunner::ImportDriver::importGeoTable().

4905  {
4906  // initial status
4909  if (poDS == nullptr) {
4910  throw std::runtime_error("openGDALDataset Error: Unable to open geo file " +
4911  file_path);
4912  }
4913 
4914  OGRLayer& layer =
4916 
4917  // get the number of features in this layer
4918  size_t numFeatures = layer.GetFeatureCount();
4919 
4920  // build map of metadata field (additional columns) name to index
4921  // use shared_ptr since we need to pass it to the worker
4922  FieldNameToIndexMapType fieldNameToIndexMap;
4923  OGRFeatureDefn* poFDefn = layer.GetLayerDefn();
4924  CHECK(poFDefn);
4925  size_t numFields = poFDefn->GetFieldCount();
4926  for (size_t iField = 0; iField < numFields; iField++) {
4927  OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
4928  fieldNameToIndexMap.emplace(std::make_pair(poFieldDefn->GetNameRef(), iField));
4929  }
4930 
4931  // the geographic spatial reference we want to put everything in
4932  OGRSpatialReferenceUqPtr poGeographicSR(new OGRSpatialReference());
4933  poGeographicSR->importFromEPSG(copy_params.geo_coords_srid);
4934 
4935 #if GDAL_VERSION_MAJOR >= 3
4936  // GDAL 3.x (really Proj.4 6.x) now enforces lat, lon order
4937  // this results in X and Y being transposed for angle-based
4938  // coordinate systems. This restores the previous behavior.
4939  poGeographicSR->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
4940 #endif
4941 
4942 #if DISABLE_MULTI_THREADED_SHAPEFILE_IMPORT
4943  // just one "thread"
4944  max_threads = 1;
4945 #else
4946  // how many threads to use
4947  if (copy_params.threads == 0) {
4948  max_threads = std::min(static_cast<size_t>(sysconf(_SC_NPROCESSORS_CONF)),
4950  } else {
4952  }
4953 #endif
4954 
4955  VLOG(1) << "GDAL import # threads: " << max_threads;
4956 
4957  // import geo table is specifically handled in both DBHandler and QueryRunner
4958  // that is separate path against a normal SQL execution
4959  // so we here explicitly enroll the import session to allow interruption
4960  // while importing geo table
4961  auto query_session = session_info ? session_info->get_session_id() : "";
4962  auto query_submitted_time = ::toString(std::chrono::system_clock::now());
4964  if (g_enable_non_kernel_time_query_interrupt && !query_session.empty()) {
4965  executor->enrollQuerySession(query_session,
4966  "Import Geo Table",
4967  query_submitted_time,
4969  QuerySessionStatus::QueryStatus::RUNNING);
4970  }
4971 
4972  ScopeGuard clearInterruptStatus = [executor, &query_session, &query_submitted_time] {
4973  // reset the runtime query interrupt status
4974  if (g_enable_non_kernel_time_query_interrupt && !query_session.empty()) {
4975  executor->clearQuerySessionStatus(query_session, query_submitted_time, false);
4976  }
4977  };
4978 
4979  // make an import buffer for each thread
4980  CHECK_EQ(import_buffers_vec.size(), 0u);
4982  for (size_t i = 0; i < max_threads; i++) {
4983  for (const auto cd : loader->get_column_descs()) {
4984  import_buffers_vec[i].emplace_back(
4985  new TypedImportBuffer(cd, loader->getStringDict(cd)));
4986  }
4987  }
4988 
4989  // make render group analyzers for each poly column
4990  ColumnIdToRenderGroupAnalyzerMapType columnIdToRenderGroupAnalyzerMap;
4992  auto columnDescriptors = loader->getCatalog().getAllColumnMetadataForTable(
4993  loader->getTableDesc()->tableId, false, false, false);
4994  for (auto cd : columnDescriptors) {
4995  SQLTypes ct = cd->columnType.get_type();
4996  if (ct == kPOLYGON || ct == kMULTIPOLYGON) {
4997  auto rga = std::make_shared<RenderGroupAnalyzer>();
4998  rga->seedFromExistingTableContents(loader, cd->columnName);
4999  columnIdToRenderGroupAnalyzerMap[cd->columnId] = rga;
5000  }
5001  }
5002  }
5003 
5004 #if !DISABLE_MULTI_THREADED_SHAPEFILE_IMPORT
5005  // threads
5006  std::list<std::future<ImportStatus>> threads;
5007 
5008  // use a stack to track thread_ids which must not overlap among threads
5009  // because thread_id is used to index import_buffers_vec[]
5010  std::stack<size_t> stack_thread_ids;
5011  for (size_t i = 0; i < max_threads; i++) {
5012  stack_thread_ids.push(i);
5013  }
5014 #endif
5015 
5016  // checkpoint the table
5017  auto table_epochs = loader->getTableEpochs();
5018 
5019  // reset the layer
5020  layer.ResetReading();
5021 
5022  static const size_t MAX_FEATURES_PER_CHUNK = 1000;
5023 
5024  // make a features buffer for each thread
5025  std::vector<FeaturePtrVector> features(max_threads);
5026 
5027  // for each feature...
5028  size_t firstFeatureThisChunk = 0;
5029  while (firstFeatureThisChunk < numFeatures) {
5030  // how many features this chunk
5031  size_t numFeaturesThisChunk =
5032  std::min(MAX_FEATURES_PER_CHUNK, numFeatures - firstFeatureThisChunk);
5033 
5034 // get a thread_id not in use
5035 #if DISABLE_MULTI_THREADED_SHAPEFILE_IMPORT
5036  size_t thread_id = 0;
5037 #else
5038  auto thread_id = stack_thread_ids.top();
5039  stack_thread_ids.pop();
5040  CHECK(thread_id < max_threads);
5041 #endif
5042 
5043  // fill features buffer for new thread
5044  for (size_t i = 0; i < numFeaturesThisChunk; i++) {
5045  features[thread_id].emplace_back(layer.GetNextFeature());
5046  }
5047 
5048 #if DISABLE_MULTI_THREADED_SHAPEFILE_IMPORT
5049  // call worker function directly
5050  auto ret_import_status = import_thread_shapefile(0,
5051  this,
5052  poGeographicSR.get(),
5053  std::move(features[thread_id]),
5054  firstFeatureThisChunk,
5055  numFeaturesThisChunk,
5056  fieldNameToIndexMap,
5057  columnNameToSourceNameMap,
5058  columnIdToRenderGroupAnalyzerMap,
5059  session_info,
5060  executor.get());
5061  import_status += ret_import_status;
5062  import_status.rows_estimated = ((float)firstFeatureThisChunk / (float)numFeatures) *
5063  import_status.rows_completed;
5064  set_import_status(import_id, import_status);
5065 #else
5066  // fire up that thread to import this geometry
5067  threads.push_back(std::async(std::launch::async,
5069  thread_id,
5070  this,
5071  poGeographicSR.get(),
5072  std::move(features[thread_id]),
5073  firstFeatureThisChunk,
5074  numFeaturesThisChunk,
5075  fieldNameToIndexMap,
5076  columnNameToSourceNameMap,
5077  columnIdToRenderGroupAnalyzerMap,
5078  session_info,
5079  executor.get()));
5080 
5081  // let the threads run
5082  while (threads.size() > 0) {
5083  int nready = 0;
5084  for (std::list<std::future<ImportStatus>>::iterator it = threads.begin();
5085  it != threads.end();) {
5086  auto& p = *it;
5087  std::chrono::milliseconds span(
5088  0); //(std::distance(it, threads.end()) == 1? 1: 0);
5089  if (p.wait_for(span) == std::future_status::ready) {
5090  auto ret_import_status = p.get();
5091  {
5092  mapd_lock_guard<mapd_shared_mutex> write_lock(import_mutex_);
5093  import_status_ += ret_import_status;
5095  ((float)firstFeatureThisChunk / (float)numFeatures) *
5099  break;
5100  }
5101  }
5102  // recall thread_id for reuse
5103  stack_thread_ids.push(ret_import_status.thread_id);
5104 
5105  threads.erase(it++);
5106  ++nready;
5107  } else {
5108  ++it;
5109  }
5110  }
5111 
5112  if (nready == 0) {
5113  std::this_thread::yield();
5114  }
5115 
5116  // keep reading if any free thread slot
5117  // this is one of the major difference from old threading model !!
5118  if (threads.size() < max_threads) {
5119  break;
5120  }
5121  }
5122 #endif
5123 
5124  // out of rows?
5125 
5126  mapd_unique_lock<mapd_shared_mutex> write_lock(import_mutex_);
5128  import_status_.load_failed = true;
5129  // todo use better message
5130  import_status_.load_msg = "Maximum rows rejected exceeded. Halting load";
5131  LOG(ERROR) << "Maximum rows rejected exceeded. Halting load";
5132  break;
5133  }
5135  LOG(ERROR) << "A call to the Loader failed in GDAL, Please review the logs for "
5136  "more details";
5137  break;
5138  }
5139 
5140  firstFeatureThisChunk += numFeaturesThisChunk;
5141  }
5142 
5143 #if !DISABLE_MULTI_THREADED_SHAPEFILE_IMPORT
5144  // wait for any remaining threads
5145  if (threads.size()) {
5146  for (auto& p : threads) {
5147  // wait for the thread
5148  p.wait();
5149  // get the result and update the final import status
5150  auto ret_import_status = p.get();
5151  import_status_ += ret_import_status;
5154  }
5155  }
5156 #endif
5157 
5158  checkpoint(table_epochs);
5159 
5160  return import_status_;
5161 }
std::map< std::string, size_t > FieldNameToIndexMapType
Definition: Importer.cpp:154
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::string toString(const ExtArgumentType &sig_type)
SQLTypes
Definition: sqltypes.h:37
std::unique_ptr< OGRSpatialReference, OGRSpatialReferenceDeleter > OGRSpatialReferenceUqPtr
Definition: Importer.cpp:134
#define LOG(tag)
Definition: Logger.h:188
OGRLayer & getLayerWithSpecifiedName(const std::string &geo_layer_name, const OGRDataSourceUqPtr &poDS, const std::string &file_name)
Definition: Importer.cpp:4455
std::unique_ptr< OGRDataSource, OGRDataSourceDeleter > OGRDataSourceUqPtr
Definition: Importer.cpp:115
bool g_enable_non_kernel_time_query_interrupt
Definition: Execute.cpp:115
mapd_shared_mutex import_mutex_
Definition: Importer.h:678
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
Definition: Execute.cpp:161
std::vector< std::vector< std::unique_ptr< TypedImportBuffer > > > import_buffers_vec
Definition: Importer.h:856
std::string get_session_id() const
Definition: SessionInfo.h:77
std::string geo_layer_name
Definition: CopyParams.h:79
static void set_import_status(const std::string &id, const ImportStatus is)
Definition: Importer.cpp:235
static ImportStatus import_thread_shapefile(int thread_id, Importer *importer, OGRSpatialReference *poGeographicSR, const FeaturePtrVector &features, size_t firstFeature, size_t numFeatures, const FieldNameToIndexMapType &fieldNameToIndexMap, const ColumnNameToSourceNameMapType &columnNameToSourceNameMap, const ColumnIdToRenderGroupAnalyzerMapType &columnIdToRenderGroupAnalyzerMap, const Catalog_Namespace::SessionInfo *session_info, Executor *executor)
Definition: Importer.cpp:2192
std::string import_id
Definition: Importer.h:852
void checkpoint(const std::vector< Catalog_Namespace::TableEpochInfo > &table_epochs)
Definition: Importer.cpp:3379
ThreadId thread_id()
Definition: Logger.cpp:732
#define CHECK(condition)
Definition: Logger.h:197
std::map< int, std::shared_ptr< RenderGroupAnalyzer >> ColumnIdToRenderGroupAnalyzerMapType
Definition: Importer.cpp:157
mapd_unique_lock< mapd_shared_mutex > write_lock
static OGRDataSource * openGDALDataset(const std::string &fileName, const CopyParams &copy_params)
Definition: Importer.cpp:4422
size_t g_max_import_threads
Definition: Importer.cpp:84
#define VLOG(n)
Definition: Logger.h:291
std::unique_ptr< Loader > loader
Definition: Importer.h:857
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:367
const std::string file_path
Definition: Importer.h:675

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void import_export::Importer::load ( const std::vector< std::unique_ptr< TypedImportBuffer >> &  import_buffers,
size_t  row_count,
const Catalog_Namespace::SessionInfo session_info 
)

Definition at line 3369 of file Importer.cpp.

References import_export::DataStreamSink::import_mutex_, import_export::DataStreamSink::import_status_, import_export::ImportStatus::load_failed, import_export::ImportStatus::load_msg, and loader.

Referenced by import_export::import_thread_delimited(), and import_export::import_thread_shapefile().

3371  {
3372  if (!loader->loadNoCheckpoint(import_buffers, row_count, session_info)) {
3373  mapd_lock_guard<mapd_shared_mutex> write_lock(import_mutex_);
3374  import_status_.load_failed = true;
3375  import_status_.load_msg = loader->getErrorMessage();
3376  }
3377 }
mapd_shared_mutex import_mutex_
Definition: Importer.h:678
mapd_unique_lock< mapd_shared_mutex > write_lock
std::unique_ptr< Loader > loader
Definition: Importer.h:857

+ Here is the caller graph for this function:

OGRDataSource * import_export::Importer::openGDALDataset ( const std::string &  fileName,
const CopyParams copy_params 
)
staticprivate

Definition at line 4422 of file Importer.cpp.

References logger::ERROR, logger::INFO, Geospatial::GDAL::init(), LOG, and setGDALAuthorizationTokens().

Referenced by gdalGetLayersInGeoFile(), gdalToColumnDescriptors(), importGDAL(), and readMetadataSampleGDAL().

4423  {
4424  // lazy init GDAL
4426 
4427  // set authorization tokens
4429 
4430  // open the file
4431  OGRDataSource* poDS;
4432 #if GDAL_VERSION_MAJOR == 1
4433  poDS = (OGRDataSource*)OGRSFDriverRegistrar::Open(file_name.c_str(), false);
4434 #else
4435  poDS = (OGRDataSource*)GDALOpenEx(
4436  file_name.c_str(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr);
4437  if (poDS == nullptr) {
4438  poDS = (OGRDataSource*)GDALOpenEx(
4439  file_name.c_str(), GDAL_OF_READONLY | GDAL_OF_VECTOR, nullptr, nullptr, nullptr);
4440  if (poDS) {
4441  LOG(INFO) << "openGDALDataset had to open as read-only";
4442  }
4443  }
4444 #endif
4445  if (poDS == nullptr) {
4446  LOG(ERROR) << "openGDALDataset Error: " << CPLGetLastErrorMsg();
4447  }
4448  // NOTE(adb): If extending this function, refactor to ensure any errors will not
4449  // result in a memory leak if GDAL successfully opened the input dataset.
4450  return poDS;
4451 }
#define LOG(tag)
Definition: Logger.h:188
static void init()
Definition: GDAL.cpp:59
static void setGDALAuthorizationTokens(const CopyParams &copy_params)
Definition: Importer.cpp:4352

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void import_export::Importer::readMetadataSampleGDAL ( const std::string &  fileName,
const std::string &  geoColumnName,
std::map< std::string, std::vector< std::string >> &  metadata,
int  rowLimit,
const CopyParams copy_params 
)
static

Definition at line 4478 of file Importer.cpp.

References CHECK, import_export::CopyParams::geo_explode_collections, import_export::CopyParams::geo_layer_name, import_export::anonymous_namespace{Importer.cpp}::getLayerWithSpecifiedName(), i, and openGDALDataset().

Referenced by DBHandler::detect_column_types().

4483  {
4485  if (poDS == nullptr) {
4486  throw std::runtime_error("openGDALDataset Error: Unable to open geo file " +
4487  file_name);
4488  }
4489 
4490  OGRLayer& layer =
4492 
4493  OGRFeatureDefn* poFDefn = layer.GetLayerDefn();
4494  CHECK(poFDefn);
4495 
4496  // typeof GetFeatureCount() is different between GDAL 1.x (int32_t) and 2.x (int64_t)
4497  auto nFeats = layer.GetFeatureCount();
4498  size_t numFeatures =
4499  std::max(static_cast<decltype(nFeats)>(0),
4500  std::min(static_cast<decltype(nFeats)>(rowLimit), nFeats));
4501  for (auto iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
4502  OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
4503  // FIXME(andrewseidl): change this to the faster one used by readVerticesFromGDAL
4504  metadata.emplace(poFieldDefn->GetNameRef(), std::vector<std::string>(numFeatures));
4505  }
4506  metadata.emplace(geo_column_name, std::vector<std::string>(numFeatures));
4507  layer.ResetReading();
4508  size_t iFeature = 0;
4509  while (iFeature < numFeatures) {
4510  OGRFeatureUqPtr poFeature(layer.GetNextFeature());
4511  if (!poFeature) {
4512  break;
4513  }
4514 
4515  OGRGeometry* poGeometry = poFeature->GetGeometryRef();
4516  if (poGeometry != nullptr) {
4517  // validate geom type (again?)
4518  switch (wkbFlatten(poGeometry->getGeometryType())) {
4519  case wkbPoint:
4520  case wkbLineString:
4521  case wkbPolygon:
4522  case wkbMultiPolygon:
4523  break;
4524  case wkbMultiPoint:
4525  case wkbMultiLineString:
4526  // supported if geo_explode_collections is specified
4528  throw std::runtime_error("Unsupported geometry type: " +
4529  std::string(poGeometry->getGeometryName()));
4530  }
4531  break;
4532  default:
4533  throw std::runtime_error("Unsupported geometry type: " +
4534  std::string(poGeometry->getGeometryName()));
4535  }
4536 
4537  // populate metadata for regular fields
4538  for (auto i : metadata) {
4539  auto iField = poFeature->GetFieldIndex(i.first.c_str());
4540  if (iField >= 0) { // geom is -1
4541  metadata[i.first].at(iFeature) =
4542  std::string(poFeature->GetFieldAsString(iField));
4543  }
4544  }
4545 
4546  // populate metadata for geo column with WKT string
4547  char* wkts = nullptr;
4548  poGeometry->exportToWkt(&wkts);
4549  CHECK(wkts);
4550  metadata[geo_column_name].at(iFeature) = wkts;
4551  CPLFree(wkts);
4552  }
4553  iFeature++;
4554  }
4555 }
OGRLayer & getLayerWithSpecifiedName(const std::string &geo_layer_name, const OGRDataSourceUqPtr &poDS, const std::string &file_name)
Definition: Importer.cpp:4455
std::unique_ptr< OGRDataSource, OGRDataSourceDeleter > OGRDataSourceUqPtr
Definition: Importer.cpp:115
std::unique_ptr< OGRFeature, OGRFeatureDeleter > OGRFeatureUqPtr
Definition: Importer.cpp:124
std::string geo_layer_name
Definition: CopyParams.h:79
#define CHECK(condition)
Definition: Logger.h:197
static OGRDataSource * openGDALDataset(const std::string &fileName, const CopyParams &copy_params)
Definition: Importer.cpp:4422

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void import_export::Importer::set_geo_physical_import_buffer ( const Catalog_Namespace::Catalog catalog,
const ColumnDescriptor cd,
std::vector< std::unique_ptr< TypedImportBuffer >> &  import_buffers,
size_t &  col_idx,
std::vector< double > &  coords,
std::vector< double > &  bounds,
std::vector< int > &  ring_sizes,
std::vector< int > &  poly_rings,
int  render_group 
)
static

Definition at line 1459 of file Importer.cpp.

References ColumnDescriptor::columnId, ColumnDescriptor::columnType, Geospatial::compress_coords(), SQLTypeInfo::get_type(), Catalog_Namespace::Catalog::getMetadataForColumn(), Geospatial::is_null_point(), kLINESTRING, kMULTIPOLYGON, kPOINT, kPOLYGON, NULL_ARRAY_DOUBLE, NULL_DOUBLE, and ColumnDescriptor::tableId.

Referenced by import_export::TypedImportBuffer::convert_arrow_val_to_import_buffer(), Parser::AddColumnStmt::execute(), import_export::fill_missing_columns(), import_export::import_thread_delimited(), DBHandler::load_table(), and foreign_storage::csv_file_buffer_parser::process_geo_column().

1468  {
1469  const auto col_ti = cd->columnType;
1470  const auto col_type = col_ti.get_type();
1471  auto columnId = cd->columnId;
1472  auto cd_coords = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1473  bool is_null_geo = false;
1474  bool is_null_point = false;
1475  if (!col_ti.get_notnull()) {
1476  // Check for NULL geo
1477  if (col_type == kPOINT && (coords.empty() || coords[0] == NULL_ARRAY_DOUBLE)) {
1478  is_null_point = true;
1479  coords.clear();
1480  }
1481  is_null_geo = coords.empty();
1482  if (is_null_point) {
1483  coords.push_back(NULL_ARRAY_DOUBLE);
1484  coords.push_back(NULL_DOUBLE);
1485  // Treating POINT coords as notnull, need to store actual encoding
1486  // [un]compressed+[not]null
1487  is_null_geo = false;
1488  }
1489  }
1490  TDatum tdd_coords;
1491  // Get the raw data representing [optionally compressed] non-NULL geo's coords.
1492  // One exception - NULL POINT geo: coords need to be processed to encode nullness
1493  // in a fixlen array, compressed and uncompressed.
1494  if (!is_null_geo) {
1495  std::vector<uint8_t> compressed_coords = Geospatial::compress_coords(coords, col_ti);
1496  tdd_coords.val.arr_val.reserve(compressed_coords.size());
1497  for (auto cc : compressed_coords) {
1498  tdd_coords.val.arr_val.emplace_back();
1499  tdd_coords.val.arr_val.back().val.int_val = cc;
1500  }
1501  }
1502  tdd_coords.is_null = is_null_geo;
1503  import_buffers[col_idx++]->add_value(cd_coords, tdd_coords, false);
1504 
1505  if (col_type == kPOLYGON || col_type == kMULTIPOLYGON) {
1506  // Create ring_sizes array value and add it to the physical column
1507  auto cd_ring_sizes = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1508  TDatum tdd_ring_sizes;
1509  tdd_ring_sizes.val.arr_val.reserve(ring_sizes.size());
1510  if (!is_null_geo) {
1511  for (auto ring_size : ring_sizes) {
1512  tdd_ring_sizes.val.arr_val.emplace_back();
1513  tdd_ring_sizes.val.arr_val.back().val.int_val = ring_size;
1514  }
1515  }
1516  tdd_ring_sizes.is_null = is_null_geo;
1517  import_buffers[col_idx++]->add_value(cd_ring_sizes, tdd_ring_sizes, false);
1518  }
1519 
1520  if (col_type == kMULTIPOLYGON) {
1521  // Create poly_rings array value and add it to the physical column
1522  auto cd_poly_rings = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1523  TDatum tdd_poly_rings;
1524  tdd_poly_rings.val.arr_val.reserve(poly_rings.size());
1525  if (!is_null_geo) {
1526  for (auto num_rings : poly_rings) {
1527  tdd_poly_rings.val.arr_val.emplace_back();
1528  tdd_poly_rings.val.arr_val.back().val.int_val = num_rings;
1529  }
1530  }
1531  tdd_poly_rings.is_null = is_null_geo;
1532  import_buffers[col_idx++]->add_value(cd_poly_rings, tdd_poly_rings, false);
1533  }
1534 
1535  if (col_type == kLINESTRING || col_type == kPOLYGON || col_type == kMULTIPOLYGON) {
1536  auto cd_bounds = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1537  TDatum tdd_bounds;
1538  tdd_bounds.val.arr_val.reserve(bounds.size());
1539  if (!is_null_geo) {
1540  for (auto b : bounds) {
1541  tdd_bounds.val.arr_val.emplace_back();
1542  tdd_bounds.val.arr_val.back().val.real_val = b;
1543  }
1544  }
1545  tdd_bounds.is_null = is_null_geo;
1546  import_buffers[col_idx++]->add_value(cd_bounds, tdd_bounds, false);
1547  }
1548 
1549  if (col_type == kPOLYGON || col_type == kMULTIPOLYGON) {
1550  // Create render_group value and add it to the physical column
1551  auto cd_render_group = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1552  TDatum td_render_group;
1553  td_render_group.val.int_val = render_group;
1554  td_render_group.is_null = is_null_geo;
1555  import_buffers[col_idx++]->add_value(cd_render_group, td_render_group, false);
1556  }
1557 }
#define NULL_DOUBLE
std::vector< uint8_t > compress_coords(std::vector< double > &coords, const SQLTypeInfo &ti)
Definition: Compression.cpp:52
bool is_null_point(const SQLTypeInfo &geo_ti, const int8_t *coords, const size_t coords_sz)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
#define NULL_ARRAY_DOUBLE
SQLTypeInfo columnType

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void import_export::Importer::set_geo_physical_import_buffer_columnar ( const Catalog_Namespace::Catalog catalog,
const ColumnDescriptor cd,
std::vector< std::unique_ptr< TypedImportBuffer >> &  import_buffers,
size_t &  col_idx,
std::vector< std::vector< double >> &  coords_column,
std::vector< std::vector< double >> &  bounds_column,
std::vector< std::vector< int >> &  ring_sizes_column,
std::vector< std::vector< int >> &  poly_rings_column,
std::vector< int > &  render_groups_column 
)
static

Definition at line 1559 of file Importer.cpp.

References CHECK, ColumnDescriptor::columnId, ColumnDescriptor::columnType, Geospatial::compress_coords(), SQLTypeInfo::get_type(), Catalog_Namespace::Catalog::getMetadataForColumn(), Geospatial::is_null_point(), kLINESTRING, kMULTIPOLYGON, kPOINT, kPOLYGON, NULL_ARRAY_DOUBLE, NULL_DOUBLE, and ColumnDescriptor::tableId.

Referenced by DBHandler::load_table_binary_columnar_internal().

1568  {
1569  const auto col_ti = cd->columnType;
1570  const auto col_type = col_ti.get_type();
1571  auto columnId = cd->columnId;
1572 
1573  auto coords_row_count = coords_column.size();
1574  auto cd_coords = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1575  for (auto& coords : coords_column) {
1576  bool is_null_geo = false;
1577  bool is_null_point = false;
1578  if (!col_ti.get_notnull()) {
1579  // Check for NULL geo
1580  if (col_type == kPOINT && (coords.empty() || coords[0] == NULL_ARRAY_DOUBLE)) {
1581  is_null_point = true;
1582  coords.clear();
1583  }
1584  is_null_geo = coords.empty();
1585  if (is_null_point) {
1586  coords.push_back(NULL_ARRAY_DOUBLE);
1587  coords.push_back(NULL_DOUBLE);
1588  // Treating POINT coords as notnull, need to store actual encoding
1589  // [un]compressed+[not]null
1590  is_null_geo = false;
1591  }
1592  }
1593  std::vector<TDatum> td_coords_data;
1594  if (!is_null_geo) {
1595  std::vector<uint8_t> compressed_coords =
1596  Geospatial::compress_coords(coords, col_ti);
1597  for (auto const& cc : compressed_coords) {
1598  TDatum td_byte;
1599  td_byte.val.int_val = cc;
1600  td_coords_data.push_back(td_byte);
1601  }
1602  }
1603  TDatum tdd_coords;
1604  tdd_coords.val.arr_val = td_coords_data;
1605  tdd_coords.is_null = is_null_geo;
1606  import_buffers[col_idx]->add_value(cd_coords, tdd_coords, false);
1607  }
1608  col_idx++;
1609 
1610  if (col_type == kPOLYGON || col_type == kMULTIPOLYGON) {
1611  if (ring_sizes_column.size() != coords_row_count) {
1612  CHECK(false) << "Geometry import columnar: ring sizes column size mismatch";
1613  }
1614  // Create ring_sizes array value and add it to the physical column
1615  auto cd_ring_sizes = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1616  for (auto const& ring_sizes : ring_sizes_column) {
1617  bool is_null_geo = false;
1618  if (!col_ti.get_notnull()) {
1619  // Check for NULL geo
1620  is_null_geo = ring_sizes.empty();
1621  }
1622  std::vector<TDatum> td_ring_sizes;
1623  for (auto const& ring_size : ring_sizes) {
1624  TDatum td_ring_size;
1625  td_ring_size.val.int_val = ring_size;
1626  td_ring_sizes.push_back(td_ring_size);
1627  }
1628  TDatum tdd_ring_sizes;
1629  tdd_ring_sizes.val.arr_val = td_ring_sizes;
1630  tdd_ring_sizes.is_null = is_null_geo;
1631  import_buffers[col_idx]->add_value(cd_ring_sizes, tdd_ring_sizes, false);
1632  }
1633  col_idx++;
1634  }
1635 
1636  if (col_type == kMULTIPOLYGON) {
1637  if (poly_rings_column.size() != coords_row_count) {
1638  CHECK(false) << "Geometry import columnar: poly rings column size mismatch";
1639  }
1640  // Create poly_rings array value and add it to the physical column
1641  auto cd_poly_rings = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1642  for (auto const& poly_rings : poly_rings_column) {
1643  bool is_null_geo = false;
1644  if (!col_ti.get_notnull()) {
1645  // Check for NULL geo
1646  is_null_geo = poly_rings.empty();
1647  }
1648  std::vector<TDatum> td_poly_rings;
1649  for (auto const& num_rings : poly_rings) {
1650  TDatum td_num_rings;
1651  td_num_rings.val.int_val = num_rings;
1652  td_poly_rings.push_back(td_num_rings);
1653  }
1654  TDatum tdd_poly_rings;
1655  tdd_poly_rings.val.arr_val = td_poly_rings;
1656  tdd_poly_rings.is_null = is_null_geo;
1657  import_buffers[col_idx]->add_value(cd_poly_rings, tdd_poly_rings, false);
1658  }
1659  col_idx++;
1660  }
1661 
1662  if (col_type == kLINESTRING || col_type == kPOLYGON || col_type == kMULTIPOLYGON) {
1663  if (bounds_column.size() != coords_row_count) {
1664  CHECK(false) << "Geometry import columnar: bounds column size mismatch";
1665  }
1666  auto cd_bounds = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1667  for (auto const& bounds : bounds_column) {
1668  bool is_null_geo = false;
1669  if (!col_ti.get_notnull()) {
1670  // Check for NULL geo
1671  is_null_geo = (bounds.empty() || bounds[0] == NULL_ARRAY_DOUBLE);
1672  }
1673  std::vector<TDatum> td_bounds_data;
1674  for (auto const& b : bounds) {
1675  TDatum td_double;
1676  td_double.val.real_val = b;
1677  td_bounds_data.push_back(td_double);
1678  }
1679  TDatum tdd_bounds;
1680  tdd_bounds.val.arr_val = td_bounds_data;
1681  tdd_bounds.is_null = is_null_geo;
1682  import_buffers[col_idx]->add_value(cd_bounds, tdd_bounds, false);
1683  }
1684  col_idx++;
1685  }
1686 
1687  if (col_type == kPOLYGON || col_type == kMULTIPOLYGON) {
1688  // Create render_group value and add it to the physical column
1689  auto cd_render_group = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1690  for (auto const& render_group : render_groups_column) {
1691  TDatum td_render_group;
1692  td_render_group.val.int_val = render_group;
1693  td_render_group.is_null = false;
1694  import_buffers[col_idx]->add_value(cd_render_group, td_render_group, false);
1695  }
1696  col_idx++;
1697  }
1698 }
#define NULL_DOUBLE
std::vector< uint8_t > compress_coords(std::vector< double > &coords, const SQLTypeInfo &ti)
Definition: Compression.cpp:52
bool is_null_point(const SQLTypeInfo &geo_ti, const int8_t *coords, const size_t coords_sz)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
#define NULL_ARRAY_DOUBLE
#define CHECK(condition)
Definition: Logger.h:197
SQLTypeInfo columnType

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void import_export::Importer::set_import_status ( const std::string &  id,
const ImportStatus  is 
)
static

Definition at line 235 of file Importer.cpp.

References import_export::ImportStatus::elapsed, import_export::ImportStatus::end, import_id, import_export::import_status_map, import_export::ImportStatus::start, and import_export::status_mutex.

Referenced by importDelimited(), and importGDAL().

235  {
236  mapd_lock_guard<mapd_shared_mutex> write_lock(status_mutex);
237  is.end = std::chrono::steady_clock::now();
238  is.elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(is.end - is.start);
240 }
static std::map< std::string, ImportStatus > import_status_map
Definition: Importer.cpp:169
std::string import_id
Definition: Importer.h:852
mapd_unique_lock< mapd_shared_mutex > write_lock
static mapd_shared_mutex status_mutex
Definition: Importer.cpp:168

+ Here is the caller graph for this function:

void import_export::Importer::setGDALAuthorizationTokens ( const CopyParams copy_params)
staticprivate

Definition at line 4352 of file Importer.cpp.

References logger::INFO, LOG, import_export::CopyParams::s3_access_key, import_export::CopyParams::s3_endpoint, import_export::CopyParams::s3_region, and import_export::CopyParams::s3_secret_key.

Referenced by gdalGetAllFilesInArchive(), gdalGetLayersInGeoFile(), gdalStatInternal(), and openGDALDataset().

4352  {
4353  // for now we only support S3
4354  // @TODO generalize CopyParams to have a dictionary of GDAL tokens
4355  // only set if non-empty to allow GDAL defaults to persist
4356  // explicitly clear if empty to revert to default and not reuse a previous session's
4357  // keys
4358  if (copy_params.s3_region.size()) {
4359 #if DEBUG_AWS_AUTHENTICATION
4360  LOG(INFO) << "GDAL: Setting AWS_REGION to '" << copy_params.s3_region << "'";
4361 #endif
4362  CPLSetConfigOption("AWS_REGION", copy_params.s3_region.c_str());
4363  } else {
4364 #if DEBUG_AWS_AUTHENTICATION
4365  LOG(INFO) << "GDAL: Clearing AWS_REGION";
4366 #endif
4367  CPLSetConfigOption("AWS_REGION", nullptr);
4368  }
4369  if (copy_params.s3_endpoint.size()) {
4370 #if DEBUG_AWS_AUTHENTICATION
4371  LOG(INFO) << "GDAL: Setting AWS_S3_ENDPOINT to '" << copy_params.s3_endpoint << "'";
4372 #endif
4373  CPLSetConfigOption("AWS_S3_ENDPOINT", copy_params.s3_endpoint.c_str());
4374  } else {
4375 #if DEBUG_AWS_AUTHENTICATION
4376  LOG(INFO) << "GDAL: Clearing AWS_S3_ENDPOINT";
4377 #endif
4378  CPLSetConfigOption("AWS_S3_ENDPOINT", nullptr);
4379  }
4380  if (copy_params.s3_access_key.size()) {
4381 #if DEBUG_AWS_AUTHENTICATION
4382  LOG(INFO) << "GDAL: Setting AWS_ACCESS_KEY_ID to '" << copy_params.s3_access_key
4383  << "'";
4384 #endif
4385  CPLSetConfigOption("AWS_ACCESS_KEY_ID", copy_params.s3_access_key.c_str());
4386  } else {
4387 #if DEBUG_AWS_AUTHENTICATION
4388  LOG(INFO) << "GDAL: Clearing AWS_ACCESS_KEY_ID";
4389 #endif
4390  CPLSetConfigOption("AWS_ACCESS_KEY_ID", nullptr);
4391  }
4392  if (copy_params.s3_secret_key.size()) {
4393 #if DEBUG_AWS_AUTHENTICATION
4394  LOG(INFO) << "GDAL: Setting AWS_SECRET_ACCESS_KEY to '" << copy_params.s3_secret_key
4395  << "'";
4396 #endif
4397  CPLSetConfigOption("AWS_SECRET_ACCESS_KEY", copy_params.s3_secret_key.c_str());
4398  } else {
4399 #if DEBUG_AWS_AUTHENTICATION
4400  LOG(INFO) << "GDAL: Clearing AWS_SECRET_ACCESS_KEY";
4401 #endif
4402  CPLSetConfigOption("AWS_SECRET_ACCESS_KEY", nullptr);
4403  }
4404 
4405 #if (GDAL_VERSION_MAJOR > 2) || (GDAL_VERSION_MAJOR == 2 && GDAL_VERSION_MINOR >= 3)
4406  // if we haven't set keys, we need to disable signed access
4407  if (copy_params.s3_access_key.size() || copy_params.s3_secret_key.size()) {
4408 #if DEBUG_AWS_AUTHENTICATION
4409  LOG(INFO) << "GDAL: Clearing AWS_NO_SIGN_REQUEST";
4410 #endif
4411  CPLSetConfigOption("AWS_NO_SIGN_REQUEST", nullptr);
4412  } else {
4413 #if DEBUG_AWS_AUTHENTICATION
4414  LOG(INFO) << "GDAL: Setting AWS_NO_SIGN_REQUEST to 'YES'";
4415 #endif
4416  CPLSetConfigOption("AWS_NO_SIGN_REQUEST", "YES");
4417  }
4418 #endif
4419 }
std::string s3_secret_key
Definition: CopyParams.h:63
#define LOG(tag)
Definition: Logger.h:188
std::string s3_access_key
Definition: CopyParams.h:62

+ Here is the caller graph for this function:

Member Data Documentation

char* import_export::Importer::buffer[2]
private

Definition at line 855 of file Importer.h.

Referenced by Importer(), and ~Importer().

size_t import_export::Importer::file_size
private

Definition at line 853 of file Importer.h.

Referenced by importDelimited(), and Importer().

std::vector<std::vector<std::unique_ptr<TypedImportBuffer> > > import_export::Importer::import_buffers_vec
private
std::mutex import_export::Importer::init_gdal_mutex
staticprivate

Definition at line 859 of file Importer.h.

bool import_export::Importer::interrupted
private

Definition at line 860 of file Importer.h.

std::unique_ptr<bool[]> import_export::Importer::is_array_a
private

Definition at line 858 of file Importer.h.

Referenced by get_is_array(), and Importer().

std::unique_ptr<Loader> import_export::Importer::loader
private
size_t import_export::Importer::max_threads
private

Definition at line 854 of file Importer.h.

Referenced by importDelimited(), Importer(), and importGDAL().


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