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

#include <Importer.h>

+ Inheritance diagram for Importer_NS::Importer:
+ Collaboration diagram for Importer_NS::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 ()
 
ImportStatus importDelimited (const std::string &file_path, const bool decompressed) override
 
ImportStatus importGDAL (std::map< std::string, std::string > colname_to_src)
 
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)
 
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 int32_t start_epoch)
 
auto getLoader () const
 
- Public Member Functions inherited from Importer_NS::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)
 

Static Public Member Functions

static bool hasGDALLibKML ()
 
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 bool gdalSupportsNetworkFileAccess ()
 
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, const int64_t replicate_count=0)
 
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, int render_group, const int64_t replicate_count=0)
 

Static Private Member Functions

static void initGDAL ()
 
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
 

Static Private Attributes

static std::mutex init_gdal_mutex
 

Additional Inherited Members

- Protected Member Functions inherited from Importer_NS::DataStreamSink
ImportStatus archivePlumber ()
 
- Protected Attributes inherited from Importer_NS::DataStreamSink
CopyParams copy_params
 
const std::string file_path
 
FILE * p_file = nullptr
 
ImportStatus import_status
 
bool load_failed = false
 
size_t total_file_size {0}
 
std::vector< size_t > file_offsets
 
std::mutex file_offsets_mutex
 

Detailed Description

Definition at line 736 of file Importer.h.

Member Enumeration Documentation

Enumerator
EMPTY 
GEO 
NON_GEO 
UNSUPPORTED_GEO 

Definition at line 783 of file Importer.h.

783 { EMPTY, GEO, NON_GEO, UNSUPPORTED_GEO };

Constructor & Destructor Documentation

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

Definition at line 149 of file Importer.cpp.

153  : 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:149
Importer_NS::Importer::Importer ( Loader providedLoader,
const std::string &  f,
const CopyParams p 
)

Definition at line 155 of file Importer.cpp.

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

156  : DataStreamSink(p, f), loader(providedLoader) {
157  import_id = boost::filesystem::path(file_path).filename().string();
158  file_size = 0;
159  max_threads = 0;
160  p_file = nullptr;
161  buffer[0] = nullptr;
162  buffer[1] = nullptr;
163  // we may be overallocating a little more memory here due to dropping phy cols.
164  // it shouldn't be an issue because iteration of it is not supposed to go OOB.
165  auto is_array = std::unique_ptr<bool[]>(new bool[loader->get_column_descs().size()]);
166  int i = 0;
167  bool has_array = false;
168  // TODO: replace this ugly way of skipping phy cols once if isPhyGeo is defined
169  int skip_physical_cols = 0;
170  for (auto& p : loader->get_column_descs()) {
171  // phy geo columns can't be in input file
172  if (skip_physical_cols-- > 0) {
173  continue;
174  }
175  // neither are rowid or $deleted$
176  // note: columns can be added after rowid/$deleted$
177  if (p->isVirtualCol || p->isDeletedCol) {
178  continue;
179  }
180  skip_physical_cols = p->columnType.get_physical_cols();
181  if (p->columnType.get_type() == kARRAY) {
182  is_array.get()[i] = true;
183  has_array = true;
184  } else {
185  is_array.get()[i] = false;
186  }
187  ++i;
188  }
189  if (has_array) {
190  is_array_a = std::unique_ptr<bool[]>(is_array.release());
191  } else {
192  is_array_a = std::unique_ptr<bool[]>(nullptr);
193  }
194 }
std::unique_ptr< Loader > loader
Definition: Importer.h:833
std::unique_ptr< bool[]> is_array_a
Definition: Importer.h:834
std::string import_id
Definition: Importer.h:828
const std::string file_path
Definition: Importer.h:654
Importer_NS::Importer::~Importer ( )
override

Definition at line 196 of file Importer.cpp.

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

196  {
197  if (p_file != nullptr) {
198  fclose(p_file);
199  }
200  if (buffer[0] != nullptr) {
201  free(buffer[0]);
202  }
203  if (buffer[1] != nullptr) {
204  free(buffer[1]);
205  }
206 }

Member Function Documentation

void Importer_NS::Importer::checkpoint ( const int32_t  start_epoch)

Definition at line 3117 of file Importer.cpp.

References DEBUG_TIMING, Data_Namespace::DISK_LEVEL, logger::ERROR, measure< TimeT >::execution(), import_buffers_vec, logger::INFO, Importer_NS::DataStreamSink::load_failed, loader, and LOG.

Referenced by importDelimited(), and importGDAL().

3117  {
3118  if (load_failed) {
3119  // rollback to starting epoch - undo all the added records
3120  loader->setTableEpoch(start_epoch);
3121  } else {
3122  loader->checkpoint();
3123  }
3124 
3125  if (loader->getTableDesc()->persistenceLevel ==
3126  Data_Namespace::MemoryLevel::DISK_LEVEL) { // only checkpoint disk-resident tables
3127  auto ms = measure<>::execution([&]() {
3128  if (!load_failed) {
3129  for (auto& p : import_buffers_vec[0]) {
3130  if (!p->stringDictCheckpoint()) {
3131  LOG(ERROR) << "Checkpointing Dictionary for Column "
3132  << p->getColumnDesc()->columnName << " failed.";
3133  load_failed = true;
3134  break;
3135  }
3136  }
3137  }
3138  });
3139  if (DEBUG_TIMING) {
3140  LOG(INFO) << "Dictionary Checkpointing took " << (double)ms / 1000.0 << " Seconds."
3141  << std::endl;
3142  }
3143  }
3144 }
std::unique_ptr< Loader > loader
Definition: Importer.h:833
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:185
#define DEBUG_TIMING
Definition: Importer.cpp:138
std::vector< std::vector< std::unique_ptr< TypedImportBuffer > > > import_buffers_vec
Definition: Importer.h:832

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4457 of file Importer.cpp.

References gdalStatInternal().

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

4457  {
4458  return gdalStatInternal(path, copy_params, false);
4459 }
static bool gdalStatInternal(const std::string &path, const CopyParams &copy_params, bool also_dir)
Definition: Importer.cpp:4424

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4462 of file Importer.cpp.

References gdalStatInternal().

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

4463  {
4464  return gdalStatInternal(path, copy_params, true);
4465 }
static bool gdalStatInternal(const std::string &path, const CopyParams &copy_params, bool also_dir)
Definition: Importer.cpp:4424

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4534 of file Importer.cpp.

References Importer_NS::gdalGatherFilesInArchiveRecursive(), initGDAL(), and setGDALAuthorizationTokens().

Referenced by find_first_geo_file_in_archive(), and MapDHandler::get_all_files_in_archive().

4536  {
4537  // lazy init GDAL
4538  initGDAL();
4539 
4540  // set authorization tokens
4542 
4543  // prepare to gather files
4544  std::vector<std::string> files;
4545 
4546  // gather the files recursively
4547  gdalGatherFilesInArchiveRecursive(archive_path, files);
4548 
4549  // convert to relative paths inside archive
4550  for (auto& file : files) {
4551  file.erase(0, archive_path.size() + 1); // remove archive_path and the slash
4552  }
4553 
4554  // done
4555  return files;
4556 }
static void setGDALAuthorizationTokens(const CopyParams &copy_params)
Definition: Importer.cpp:4087
void gdalGatherFilesInArchiveRecursive(const std::string &archive_path, std::vector< std::string > &files)
Definition: Importer.cpp:4467
static void initGDAL()
Definition: Importer.cpp:4040

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4559 of file Importer.cpp.

References CHECK(), EMPTY, GEO, initGDAL(), NON_GEO, openGDALDataset(), setGDALAuthorizationTokens(), and UNSUPPORTED_GEO.

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

4561  {
4562  // lazy init GDAL
4563  initGDAL();
4564 
4565  // set authorization tokens
4567 
4568  // prepare to gather layer info
4569  std::vector<GeoFileLayerInfo> layer_info;
4570 
4571  // open the data set
4573  if (poDS == nullptr) {
4574  throw std::runtime_error("openGDALDataset Error: Unable to open geo file " +
4575  file_name);
4576  }
4577 
4578  // enumerate the layers
4579  for (auto&& poLayer : poDS->GetLayers()) {
4581  // prepare to read this layer
4582  poLayer->ResetReading();
4583  // skip layer if empty
4584  if (poLayer->GetFeatureCount() > 0) {
4585  // get first feature
4586  OGRFeatureUqPtr first_feature(poLayer->GetNextFeature());
4587  CHECK(first_feature);
4588  // check feature for geometry
4589  const OGRGeometry* geometry = first_feature->GetGeometryRef();
4590  if (!geometry) {
4591  // layer has no geometry
4592  contents = GeoFileLayerContents::NON_GEO;
4593  } else {
4594  // check the geometry type
4595  const OGRwkbGeometryType geometry_type = geometry->getGeometryType();
4596  switch (wkbFlatten(geometry_type)) {
4597  case wkbPoint:
4598  case wkbLineString:
4599  case wkbPolygon:
4600  case wkbMultiPolygon:
4601  // layer has supported geo
4602  contents = GeoFileLayerContents::GEO;
4603  break;
4604  default:
4605  // layer has unsupported geometry
4607  break;
4608  }
4609  }
4610  }
4611  // store info for this layer
4612  layer_info.emplace_back(poLayer->GetName(), contents);
4613  }
4614 
4615  // done
4616  return layer_info;
4617 }
static void setGDALAuthorizationTokens(const CopyParams &copy_params)
Definition: Importer.cpp:4087
std::unique_ptr< OGRDataSource, OGRDataSourceDeleter > OGRDataSourceUqPtr
Definition: Importer.cpp:93
std::unique_ptr< OGRFeature, OGRFeatureDeleter > OGRFeatureUqPtr
Definition: Importer.cpp:102
CHECK(cgen_state)
static OGRDataSource * openGDALDataset(const std::string &fileName, const CopyParams &copy_params)
Definition: Importer.cpp:4157
static void initGDAL()
Definition: Importer.cpp:4040

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4424 of file Importer.cpp.

References initGDAL(), run_benchmark_import::result, and setGDALAuthorizationTokens().

Referenced by gdalFileExists(), and gdalFileOrDirectoryExists().

4426  {
4427  // lazy init GDAL
4428  initGDAL();
4429 
4430  // set authorization tokens
4432 
4433 #if (GDAL_VERSION_MAJOR > 2) || (GDAL_VERSION_MAJOR == 2 && GDAL_VERSION_MINOR >= 3)
4434  // clear GDAL stat cache
4435  // without this, file existence will be cached, even if authentication changes
4436  // supposed to be available from GDAL 2.2.1 but our CentOS build disagrees
4437  VSICurlClearCache();
4438 #endif
4439 
4440  // stat path
4441  VSIStatBufL sb;
4442  int result = VSIStatExL(path.c_str(), &sb, VSI_STAT_EXISTS_FLAG);
4443  if (result < 0) {
4444  return false;
4445  }
4446 
4447  // exists?
4448  if (also_dir && (VSI_ISREG(sb.st_mode) || VSI_ISDIR(sb.st_mode))) {
4449  return true;
4450  } else if (VSI_ISREG(sb.st_mode)) {
4451  return true;
4452  }
4453  return false;
4454 }
static void setGDALAuthorizationTokens(const CopyParams &copy_params)
Definition: Importer.cpp:4087
static void initGDAL()
Definition: Importer.cpp:4040

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Importer_NS::Importer::gdalSupportsNetworkFileAccess ( )
static

Definition at line 4620 of file Importer.cpp.

Referenced by add_vsi_network_prefix().

4620  {
4621 #if (GDAL_VERSION_MAJOR > 2) || (GDAL_VERSION_MAJOR == 2 && GDAL_VERSION_MINOR >= 2)
4622  return true;
4623 #else
4624  return false;
4625 #endif
4626 }

+ Here is the caller graph for this function:

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

Definition at line 4334 of file Importer.cpp.

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

Referenced by MapDHandler::detect_column_types(), and Importer_NS::ImportDriver::importGeoTable().

4337  {
4338  std::list<ColumnDescriptor> cds;
4339 
4341  if (poDS == nullptr) {
4342  throw std::runtime_error("openGDALDataset Error: Unable to open geo file " +
4343  file_name);
4344  }
4345 
4346  OGRLayer& layer =
4348 
4349  layer.ResetReading();
4350  // TODO(andrewseidl): support multiple features
4351  OGRFeatureUqPtr poFeature(layer.GetNextFeature());
4352  if (poFeature == nullptr) {
4353  throw std::runtime_error("No features found in " + file_name);
4354  }
4355  // get fields as regular columns
4356  OGRFeatureDefn* poFDefn = layer.GetLayerDefn();
4357  CHECK(poFDefn);
4358  int iField;
4359  for (iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
4360  OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
4361  auto typePair = ogr_to_type(poFieldDefn->GetType());
4362  ColumnDescriptor cd;
4363  cd.columnName = poFieldDefn->GetNameRef();
4364  cd.sourceName = poFieldDefn->GetNameRef();
4365  SQLTypeInfo ti;
4366  if (typePair.second) {
4367  ti.set_type(kARRAY);
4368  ti.set_subtype(typePair.first);
4369  } else {
4370  ti.set_type(typePair.first);
4371  }
4372  if (typePair.first == kTEXT) {
4374  ti.set_comp_param(32);
4375  }
4376  ti.set_fixed_size();
4377  cd.columnType = ti;
4378  cds.push_back(cd);
4379  }
4380  // get geo column, if any
4381  OGRGeometry* poGeometry = poFeature->GetGeometryRef();
4382  if (poGeometry) {
4383  ColumnDescriptor cd;
4384  cd.columnName = geo_column_name;
4385  cd.sourceName = geo_column_name;
4386 
4387  // get GDAL type
4388  auto ogr_type = wkbFlatten(poGeometry->getGeometryType());
4389 
4390  // if exploding, override any collection type to child type
4392  if (ogr_type == wkbMultiPolygon) {
4393  ogr_type = wkbPolygon;
4394  } else if (ogr_type == wkbMultiLineString) {
4395  ogr_type = wkbLineString;
4396  } else if (ogr_type == wkbMultiPoint) {
4397  ogr_type = wkbPoint;
4398  }
4399  }
4400 
4401  // convert to internal type
4402  SQLTypes geoType = ogr_to_type(ogr_type);
4403 
4404  // for now, we promote POLYGON to MULTIPOLYGON (unless exploding)
4406  geoType = (geoType == kPOLYGON) ? kMULTIPOLYGON : geoType;
4407  }
4408 
4409  // build full internal type
4410  SQLTypeInfo ti;
4411  ti.set_type(geoType);
4417  cd.columnType = ti;
4418 
4419  cds.push_back(cd);
4420  }
4421  return cds;
4422 }
std::pair< SQLTypes, bool > ogr_to_type(const OGRFieldType &ogr_type)
Definition: Importer.cpp:4284
SQLTypes
Definition: sqltypes.h:41
void set_input_srid(int d)
Definition: sqltypes.h:420
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:416
void set_fixed_size()
Definition: sqltypes.h:425
std::unique_ptr< OGRDataSource, OGRDataSourceDeleter > OGRDataSourceUqPtr
Definition: Importer.cpp:93
std::unique_ptr< OGRFeature, OGRFeatureDeleter > OGRFeatureUqPtr
Definition: Importer.cpp:102
void set_compression(EncodingType c)
Definition: sqltypes.h:426
std::string sourceName
void set_output_srid(int s)
Definition: sqltypes.h:422
EncodingType geo_coords_encoding
Definition: CopyParams.h:73
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:417
OGRLayer & getLayerWithSpecifiedName(const std::string &geo_layer_name, const OGRDataSourceUqPtr &poDS, const std::string &file_name)
Definition: Importer.cpp:4190
CHECK(cgen_state)
specifies the content in-memory of a row in the column metadata table
static OGRDataSource * openGDALDataset(const std::string &fileName, const CopyParams &copy_params)
Definition: Importer.cpp:4157
Definition: sqltypes.h:55
std::string geo_layer_name
Definition: CopyParams.h:78
void set_comp_param(int p)
Definition: sqltypes.h:427
SQLTypeInfo columnType
static constexpr bool PROMOTE_POLYGON_TO_MULTIPOLYGON
Definition: Importer.cpp:144
std::string columnName
int32_t geo_coords_comp_param
Definition: CopyParams.h:74

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 750 of file Importer.h.

References loader.

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

750  {
751  return loader->get_column_descs();
752  }
std::unique_ptr< Loader > loader
Definition: Importer.h:833

+ Here is the caller graph for this function:

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

Definition at line 749 of file Importer.h.

References Importer_NS::DataStreamSink::copy_params.

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

749 { return copy_params; }

+ Here is the caller graph for this function:

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

Definition at line 758 of file Importer.h.

References import_buffers_vec.

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

758  {
759  return import_buffers_vec[i];
760  }
std::vector< std::vector< std::unique_ptr< TypedImportBuffer > > > import_buffers_vec
Definition: Importer.h:832

+ Here is the caller graph for this function:

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

Definition at line 755 of file Importer.h.

References import_buffers_vec.

755  {
756  return import_buffers_vec;
757  }
std::vector< std::vector< std::unique_ptr< TypedImportBuffer > > > import_buffers_vec
Definition: Importer.h:832
ImportStatus Importer_NS::Importer::get_import_status ( const std::string &  id)
static

Definition at line 208 of file Importer.cpp.

References Importer_NS::import_status_map, and Importer_NS::status_mutex.

Referenced by MapDHandler::import_table_status().

208  {
209  mapd_shared_lock<mapd_shared_mutex> read_lock(status_mutex);
210  return import_status_map.at(import_id);
211 }
static std::map< std::string, ImportStatus > import_status_map
Definition: Importer.cpp:147
static mapd_shared_mutex status_mutex
Definition: Importer.cpp:146
std::string import_id
Definition: Importer.h:828

+ Here is the caller graph for this function:

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

Definition at line 761 of file Importer.h.

References is_array_a.

Referenced by Importer_NS::import_thread_delimited().

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

+ Here is the caller graph for this function:

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

Definition at line 794 of file Importer.h.

References loader.

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

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

+ Here is the caller graph for this function:

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

Definition at line 818 of file Importer.h.

References loader.

818 { return loader.get(); }
std::unique_ptr< Loader > loader
Definition: Importer.h:833
bool Importer_NS::Importer::hasGDALLibKML ( )
static

Definition at line 4082 of file Importer.cpp.

4082  {
4083  return GetGDALDriverManager()->GetDriverByName("libkml") != nullptr;
4084 }
ImportStatus Importer_NS::Importer::import ( )

Definition at line 3788 of file Importer.cpp.

References Importer_NS::DataStreamSink::archivePlumber().

3788  {
3790 }
ImportStatus archivePlumber()
Definition: Importer.cpp:3146

+ Here is the call graph for this function:

ImportStatus Importer_NS::Importer::importDelimited ( const std::string &  file_path,
const bool  decompressed 
)
overridevirtual

Implements Importer_NS::DataStreamSink.

Definition at line 3792 of file Importer.cpp.

References Importer_NS::CopyParams::buffer_size, CHECK(), checkpoint(), ColumnDescriptor::columnId, ColumnDescriptor::columnName, ColumnDescriptor::columnType, Importer_NS::DataStreamSink::copy_params, logger::ERROR, Importer_NS::DataStreamSink::file_offsets, Importer_NS::DataStreamSink::file_offsets_mutex, file_size, Importer_NS::DelimitedParserUtils::find_end(), Importer_NS::CopyParams::geo_assign_render_groups, SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), import_buffers_vec, import_id, Importer_NS::DataStreamSink::import_status, Importer_NS::import_thread_delimited(), kMULTIPOLYGON, kPOLYGON, Importer_NS::DataStreamSink::load_failed, Importer_NS::ImportStatus::load_truncated, loader, LOG, max_threads, Importer_NS::DataStreamSink::p_file, Importer_NS::ImportStatus::rows_completed, Importer_NS::ImportStatus::rows_estimated, Importer_NS::ImportStatus::rows_rejected, set_import_status(), Importer_NS::status_mutex, Importer_NS::CopyParams::threads, Importer_NS::DataStreamSink::total_file_size, and VLOG.

3793  {
3794  bool load_truncated = false;
3796 
3797  if (!p_file) {
3798  p_file = fopen(file_path.c_str(), "rb");
3799  }
3800  if (!p_file) {
3801  throw std::runtime_error("failed to open file '" + file_path +
3802  "': " + strerror(errno));
3803  }
3804 
3805  if (!decompressed) {
3806  (void)fseek(p_file, 0, SEEK_END);
3807  file_size = ftell(p_file);
3808  }
3809 
3810  if (copy_params.threads == 0) {
3811  max_threads = static_cast<size_t>(sysconf(_SC_NPROCESSORS_CONF));
3812  } else {
3813  max_threads = static_cast<size_t>(copy_params.threads);
3814  }
3815 
3816  // deal with small files
3817  size_t alloc_size = copy_params.buffer_size;
3818  if (!decompressed && file_size < alloc_size) {
3819  alloc_size = file_size;
3820  }
3821 
3822  for (size_t i = 0; i < max_threads; i++) {
3823  import_buffers_vec.emplace_back();
3824  for (const auto cd : loader->get_column_descs()) {
3825  import_buffers_vec[i].push_back(std::unique_ptr<TypedImportBuffer>(
3826  new TypedImportBuffer(cd, loader->getStringDict(cd))));
3827  }
3828  }
3829 
3830  auto scratch_buffer = std::make_unique<char[]>(alloc_size);
3831  size_t current_pos = 0;
3832  size_t end_pos;
3833  size_t begin_pos = 0;
3834 
3835  (void)fseek(p_file, current_pos, SEEK_SET);
3836  size_t size =
3837  fread(reinterpret_cast<void*>(scratch_buffer.get()), 1, alloc_size, p_file);
3838 
3839  // make render group analyzers for each poly column
3840  ColumnIdToRenderGroupAnalyzerMapType columnIdToRenderGroupAnalyzerMap;
3842  auto columnDescriptors = loader->getCatalog().getAllColumnMetadataForTable(
3843  loader->getTableDesc()->tableId, false, false, false);
3844  for (auto cd : columnDescriptors) {
3845  SQLTypes ct = cd->columnType.get_type();
3846  if (ct == kPOLYGON || ct == kMULTIPOLYGON) {
3847  auto rga = std::make_shared<RenderGroupAnalyzer>();
3848  rga->seedFromExistingTableContents(loader, cd->columnName);
3849  columnIdToRenderGroupAnalyzerMap[cd->columnId] = rga;
3850  }
3851  }
3852  }
3853 
3854  ChunkKey chunkKey = {loader->getCatalog().getCurrentDB().dbId,
3855  loader->getTableDesc()->tableId};
3856  auto start_epoch = loader->getTableEpoch();
3857  {
3858  std::list<std::future<ImportStatus>> threads;
3859 
3860  // use a stack to track thread_ids which must not overlap among threads
3861  // because thread_id is used to index import_buffers_vec[]
3862  std::stack<size_t> stack_thread_ids;
3863  for (size_t i = 0; i < max_threads; i++) {
3864  stack_thread_ids.push(i);
3865  }
3866  // added for true row index on error
3867  size_t first_row_index_this_buffer = 0;
3868 
3869  while (size > 0) {
3870  unsigned int num_rows_this_buffer = 0;
3871  CHECK(scratch_buffer);
3873  scratch_buffer.get(), size, copy_params, num_rows_this_buffer);
3874 
3875  // unput residual
3876  int nresidual = size - end_pos;
3877  std::unique_ptr<char[]> unbuf;
3878  if (nresidual > 0) {
3879  unbuf = std::make_unique<char[]>(nresidual);
3880  memcpy(unbuf.get(), scratch_buffer.get() + end_pos, nresidual);
3881  }
3882 
3883  // get a thread_id not in use
3884  auto thread_id = stack_thread_ids.top();
3885  stack_thread_ids.pop();
3886  // LOG(INFO) << " stack_thread_ids.pop " << thread_id << std::endl;
3887 
3888  threads.push_back(std::async(std::launch::async,
3890  thread_id,
3891  this,
3892  std::move(scratch_buffer),
3893  begin_pos,
3894  end_pos,
3895  end_pos,
3896  columnIdToRenderGroupAnalyzerMap,
3897  first_row_index_this_buffer));
3898 
3899  first_row_index_this_buffer += num_rows_this_buffer;
3900 
3901  current_pos += end_pos;
3902  scratch_buffer = std::make_unique<char[]>(alloc_size);
3903  CHECK(scratch_buffer);
3904  memcpy(scratch_buffer.get(), unbuf.get(), nresidual);
3905  size = nresidual + fread(scratch_buffer.get() + nresidual,
3906  1,
3907  copy_params.buffer_size - nresidual,
3908  p_file);
3909 
3910  begin_pos = 0;
3911 
3912  while (threads.size() > 0) {
3913  int nready = 0;
3914  for (std::list<std::future<ImportStatus>>::iterator it = threads.begin();
3915  it != threads.end();) {
3916  auto& p = *it;
3917  std::chrono::milliseconds span(
3918  0); //(std::distance(it, threads.end()) == 1? 1: 0);
3919  if (p.wait_for(span) == std::future_status::ready) {
3920  auto ret_import_status = p.get();
3921  import_status += ret_import_status;
3922  // sum up current total file offsets
3923  size_t total_file_offset{0};
3924  if (decompressed) {
3925  std::unique_lock<std::mutex> lock(file_offsets_mutex);
3926  for (const auto file_offset : file_offsets) {
3927  total_file_offset += file_offset;
3928  }
3929  }
3930  // estimate number of rows per current total file offset
3931  if (decompressed ? total_file_offset : current_pos) {
3933  (decompressed ? (float)total_file_size / total_file_offset
3934  : (float)file_size / current_pos) *
3935  import_status.rows_completed;
3936  }
3937  VLOG(3) << "rows_completed " << import_status.rows_completed
3938  << ", rows_estimated " << import_status.rows_estimated
3939  << ", total_file_size " << total_file_size << ", total_file_offset "
3940  << total_file_offset;
3942  // recall thread_id for reuse
3943  stack_thread_ids.push(ret_import_status.thread_id);
3944  threads.erase(it++);
3945  ++nready;
3946  } else {
3947  ++it;
3948  }
3949  }
3950 
3951  if (nready == 0) {
3952  std::this_thread::yield();
3953  }
3954 
3955  // on eof, wait all threads to finish
3956  if (0 == size) {
3957  continue;
3958  }
3959 
3960  // keep reading if any free thread slot
3961  // this is one of the major difference from old threading model !!
3962  if (threads.size() < max_threads) {
3963  break;
3964  }
3965  }
3966 
3967  if (import_status.rows_rejected > copy_params.max_reject) {
3968  load_truncated = true;
3969  load_failed = true;
3970  LOG(ERROR) << "Maximum rows rejected exceeded. Halting load";
3971  break;
3972  }
3973  if (load_failed) {
3974  load_truncated = true;
3975  LOG(ERROR) << "A call to the Loader::load failed, Please review the logs for "
3976  "more details";
3977  break;
3978  }
3979  }
3980 
3981  // join dangling threads in case of LOG(ERROR) above
3982  for (auto& p : threads) {
3983  p.wait();
3984  }
3985  }
3986 
3987  checkpoint(start_epoch);
3988 
3989  // must set import_status.load_truncated before closing this end of pipe
3990  // otherwise, the thread on the other end would throw an unwanted 'write()'
3991  // exception
3992  mapd_lock_guard<mapd_shared_mutex> write_lock(status_mutex);
3993  import_status.load_truncated = load_truncated;
3994 
3995  fclose(p_file);
3996  p_file = nullptr;
3997  return import_status;
3998 }
std::unique_ptr< Loader > loader
Definition: Importer.h:833
static size_t find_end(const char *buffer, size_t size, const CopyParams &copy_params, unsigned int &num_rows_this_buffer)
Finds the closest possible row ending to the end of the given buffer.
std::vector< int > ChunkKey
Definition: types.h:35
std::vector< size_t > file_offsets
Definition: Importer.h:659
SQLTypes
Definition: sqltypes.h:41
#define LOG(tag)
Definition: Logger.h:185
static mapd_shared_mutex status_mutex
Definition: Importer.cpp:146
std::vector< std::vector< std::unique_ptr< TypedImportBuffer > > > import_buffers_vec
Definition: Importer.h:832
CHECK(cgen_state)
std::string import_id
Definition: Importer.h:828
std::mutex file_offsets_mutex
Definition: Importer.h:660
std::map< int, std::shared_ptr< RenderGroupAnalyzer >> ColumnIdToRenderGroupAnalyzerMapType
Definition: Importer.cpp:135
void checkpoint(const int32_t start_epoch)
Definition: Importer.cpp:3117
ImportStatus import_status
Definition: Importer.h:656
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)
Definition: Importer.cpp:1777
static void set_import_status(const std::string &id, const ImportStatus is)
Definition: Importer.cpp:213
#define VLOG(n)
Definition: Logger.h:280
const std::string file_path
Definition: Importer.h:654

+ Here is the call graph for this function:

ImportStatus Importer_NS::Importer::importGDAL ( std::map< std::string, std::string >  colname_to_src)

Definition at line 4628 of file Importer.cpp.

References CHECK(), CHECK_EQ, checkpoint(), ColumnDescriptor::columnId, ColumnDescriptor::columnName, ColumnDescriptor::columnType, Importer_NS::DataStreamSink::copy_params, logger::ERROR, Importer_NS::CopyParams::geo_assign_render_groups, Importer_NS::CopyParams::geo_coords_srid, Importer_NS::CopyParams::geo_layer_name, SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), Importer_NS::anonymous_namespace{Importer.cpp}::getLayerWithSpecifiedName(), import_buffers_vec, import_id, Importer_NS::DataStreamSink::import_status, Importer_NS::import_thread_shapefile(), kMULTIPOLYGON, kPOLYGON, Importer_NS::DataStreamSink::load_failed, Importer_NS::ImportStatus::load_truncated, loader, LOG, Importer_NS::CopyParams::max_reject, max_threads, openGDALDataset(), Importer_NS::ImportStatus::rows_completed, Importer_NS::ImportStatus::rows_estimated, set_import_status(), and Importer_NS::CopyParams::threads.

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

4629  {
4630  // initial status
4631  bool load_truncated = false;
4633 
4635  if (poDS == nullptr) {
4636  throw std::runtime_error("openGDALDataset Error: Unable to open geo file " +
4637  file_path);
4638  }
4639 
4640  OGRLayer& layer =
4642 
4643  // get the number of features in this layer
4644  size_t numFeatures = layer.GetFeatureCount();
4645 
4646  // build map of metadata field (additional columns) name to index
4647  // use shared_ptr since we need to pass it to the worker
4648  FieldNameToIndexMapType fieldNameToIndexMap;
4649  OGRFeatureDefn* poFDefn = layer.GetLayerDefn();
4650  CHECK(poFDefn);
4651  size_t numFields = poFDefn->GetFieldCount();
4652  for (size_t iField = 0; iField < numFields; iField++) {
4653  OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
4654  fieldNameToIndexMap.emplace(std::make_pair(poFieldDefn->GetNameRef(), iField));
4655  }
4656 
4657  // the geographic spatial reference we want to put everything in
4658  OGRSpatialReferenceUqPtr poGeographicSR(new OGRSpatialReference());
4659  poGeographicSR->importFromEPSG(copy_params.geo_coords_srid);
4660 
4661 #if GDAL_VERSION_MAJOR >= 3
4662  // GDAL 3.x (really Proj.4 6.x) now enforces lat, lon order
4663  // this results in X and Y being transposed for angle-based
4664  // coordinate systems. This restores the previous behavior.
4665  poGeographicSR->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
4666 #endif
4667 
4668 #if DISABLE_MULTI_THREADED_SHAPEFILE_IMPORT
4669  // just one "thread"
4670  size_t max_threads = 1;
4671 #else
4672  // how many threads to use
4673  size_t max_threads = 0;
4674  if (copy_params.threads == 0) {
4675  max_threads = sysconf(_SC_NPROCESSORS_CONF);
4676  } else {
4677  max_threads = copy_params.threads;
4678  }
4679 #endif
4680 
4681  // make an import buffer for each thread
4682  CHECK_EQ(import_buffers_vec.size(), 0u);
4683  import_buffers_vec.resize(max_threads);
4684  for (size_t i = 0; i < max_threads; i++) {
4685  for (const auto cd : loader->get_column_descs()) {
4686  import_buffers_vec[i].emplace_back(
4687  new TypedImportBuffer(cd, loader->getStringDict(cd)));
4688  }
4689  }
4690 
4691  // make render group analyzers for each poly column
4692  ColumnIdToRenderGroupAnalyzerMapType columnIdToRenderGroupAnalyzerMap;
4694  auto columnDescriptors = loader->getCatalog().getAllColumnMetadataForTable(
4695  loader->getTableDesc()->tableId, false, false, false);
4696  for (auto cd : columnDescriptors) {
4697  SQLTypes ct = cd->columnType.get_type();
4698  if (ct == kPOLYGON || ct == kMULTIPOLYGON) {
4699  auto rga = std::make_shared<RenderGroupAnalyzer>();
4700  rga->seedFromExistingTableContents(loader, cd->columnName);
4701  columnIdToRenderGroupAnalyzerMap[cd->columnId] = rga;
4702  }
4703  }
4704  }
4705 
4706 #if !DISABLE_MULTI_THREADED_SHAPEFILE_IMPORT
4707  // threads
4708  std::list<std::future<ImportStatus>> threads;
4709 
4710  // use a stack to track thread_ids which must not overlap among threads
4711  // because thread_id is used to index import_buffers_vec[]
4712  std::stack<size_t> stack_thread_ids;
4713  for (size_t i = 0; i < max_threads; i++) {
4714  stack_thread_ids.push(i);
4715  }
4716 #endif
4717 
4718  // checkpoint the table
4719  auto start_epoch = loader->getTableEpoch();
4720 
4721  // reset the layer
4722  layer.ResetReading();
4723 
4724  static const size_t MAX_FEATURES_PER_CHUNK = 1000;
4725 
4726  // make a features buffer for each thread
4727  std::vector<FeaturePtrVector> features(max_threads);
4728 
4729  // for each feature...
4730  size_t firstFeatureThisChunk = 0;
4731  while (firstFeatureThisChunk < numFeatures) {
4732  // how many features this chunk
4733  size_t numFeaturesThisChunk =
4734  std::min(MAX_FEATURES_PER_CHUNK, numFeatures - firstFeatureThisChunk);
4735 
4736 // get a thread_id not in use
4737 #if DISABLE_MULTI_THREADED_SHAPEFILE_IMPORT
4738  size_t thread_id = 0;
4739 #else
4740  auto thread_id = stack_thread_ids.top();
4741  stack_thread_ids.pop();
4742  CHECK(thread_id < max_threads);
4743 #endif
4744 
4745  // fill features buffer for new thread
4746  for (size_t i = 0; i < numFeaturesThisChunk; i++) {
4747  features[thread_id].emplace_back(layer.GetNextFeature());
4748  }
4749 
4750 #if DISABLE_MULTI_THREADED_SHAPEFILE_IMPORT
4751  // call worker function directly
4752  auto ret_import_status = import_thread_shapefile(0,
4753  this,
4754  poGeographicSR.get(),
4755  std::move(features[thread_id]),
4756  firstFeatureThisChunk,
4757  numFeaturesThisChunk,
4758  fieldNameToIndexMap,
4759  columnNameToSourceNameMap,
4760  columnIdToRenderGroupAnalyzerMap);
4761  import_status += ret_import_status;
4762  import_status.rows_estimated = ((float)firstFeatureThisChunk / (float)numFeatures) *
4763  import_status.rows_completed;
4764  set_import_status(import_id, import_status);
4765 #else
4766  // fire up that thread to import this geometry
4767  threads.push_back(std::async(std::launch::async,
4769  thread_id,
4770  this,
4771  poGeographicSR.get(),
4772  std::move(features[thread_id]),
4773  firstFeatureThisChunk,
4774  numFeaturesThisChunk,
4775  fieldNameToIndexMap,
4776  columnNameToSourceNameMap,
4777  columnIdToRenderGroupAnalyzerMap));
4778 
4779  // let the threads run
4780  while (threads.size() > 0) {
4781  int nready = 0;
4782  for (std::list<std::future<ImportStatus>>::iterator it = threads.begin();
4783  it != threads.end();) {
4784  auto& p = *it;
4785  std::chrono::milliseconds span(
4786  0); //(std::distance(it, threads.end()) == 1? 1: 0);
4787  if (p.wait_for(span) == std::future_status::ready) {
4788  auto ret_import_status = p.get();
4789  import_status += ret_import_status;
4790  import_status.rows_estimated =
4791  ((float)firstFeatureThisChunk / (float)numFeatures) *
4792  import_status.rows_completed;
4793  set_import_status(import_id, import_status);
4794 
4795  // recall thread_id for reuse
4796  stack_thread_ids.push(ret_import_status.thread_id);
4797 
4798  threads.erase(it++);
4799  ++nready;
4800  } else {
4801  ++it;
4802  }
4803  }
4804 
4805  if (nready == 0) {
4806  std::this_thread::yield();
4807  }
4808 
4809  // keep reading if any free thread slot
4810  // this is one of the major difference from old threading model !!
4811  if (threads.size() < max_threads) {
4812  break;
4813  }
4814  }
4815 #endif
4816 
4817  // out of rows?
4818  if (import_status.rows_rejected > copy_params.max_reject) {
4819  load_truncated = true;
4820  load_failed = true;
4821  LOG(ERROR) << "Maximum rows rejected exceeded. Halting load";
4822  break;
4823  }
4824 
4825  // failed?
4826  if (load_failed) {
4827  load_truncated = true;
4828  LOG(ERROR)
4829  << "A call to the Loader::load failed, Please review the logs for more details";
4830  break;
4831  }
4832 
4833  firstFeatureThisChunk += numFeaturesThisChunk;
4834  }
4835 
4836 #if !DISABLE_MULTI_THREADED_SHAPEFILE_IMPORT
4837  // wait for any remaining threads
4838  if (threads.size()) {
4839  for (auto& p : threads) {
4840  // wait for the thread
4841  p.wait();
4842  // get the result and update the final import status
4843  auto ret_import_status = p.get();
4844  import_status += ret_import_status;
4845  import_status.rows_estimated = import_status.rows_completed;
4846  set_import_status(import_id, import_status);
4847  }
4848  }
4849 #endif
4850 
4851  checkpoint(start_epoch);
4852 
4853  // must set import_status.load_truncated before closing this end of pipe
4854  // otherwise, the thread on the other end would throw an unwanted 'write()'
4855  // exception
4856  import_status.load_truncated = load_truncated;
4857  return import_status;
4858 }
std::unique_ptr< Loader > loader
Definition: Importer.h:833
#define CHECK_EQ(x, y)
Definition: Logger.h:198
SQLTypes
Definition: sqltypes.h:41
std::unique_ptr< OGRSpatialReference, OGRSpatialReferenceDeleter > OGRSpatialReferenceUqPtr
Definition: Importer.cpp:112
#define LOG(tag)
Definition: Logger.h:185
std::unique_ptr< OGRDataSource, OGRDataSourceDeleter > OGRDataSourceUqPtr
Definition: Importer.cpp:93
OGRLayer & getLayerWithSpecifiedName(const std::string &geo_layer_name, const OGRDataSourceUqPtr &poDS, const std::string &file_name)
Definition: Importer.cpp:4190
std::vector< std::vector< std::unique_ptr< TypedImportBuffer > > > import_buffers_vec
Definition: Importer.h:832
CHECK(cgen_state)
std::string import_id
Definition: Importer.h:828
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)
Definition: Importer.cpp:2084
static OGRDataSource * openGDALDataset(const std::string &fileName, const CopyParams &copy_params)
Definition: Importer.cpp:4157
std::map< int, std::shared_ptr< RenderGroupAnalyzer >> ColumnIdToRenderGroupAnalyzerMapType
Definition: Importer.cpp:135
void checkpoint(const int32_t start_epoch)
Definition: Importer.cpp:3117
std::string geo_layer_name
Definition: CopyParams.h:78
ImportStatus import_status
Definition: Importer.h:656
std::map< std::string, size_t > FieldNameToIndexMapType
Definition: Importer.cpp:132
static void set_import_status(const std::string &id, const ImportStatus is)
Definition: Importer.cpp:213
const std::string file_path
Definition: Importer.h:654

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Importer_NS::Importer::initGDAL ( )
staticprivate

Definition at line 4040 of file Importer.cpp.

References Importer_NS::GDALErrorHandler(), logger::INFO, LOG, and mapd_root_abs_path().

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

4040  {
4041  // this should not be called from multiple threads, but...
4042  std::lock_guard<std::mutex> guard(Importer::init_gdal_mutex);
4043  // init under mutex
4044  static bool gdal_initialized = false;
4045  if (!gdal_initialized) {
4046  // FIXME(andrewseidl): investigate if CPLPushFinderLocation can be public
4047  setenv("GDAL_DATA",
4048  std::string(mapd_root_abs_path() + "/ThirdParty/gdal-data").c_str(),
4049  true);
4050 
4051  // configure SSL certificate path (per S3Archive::init_for_read)
4052  // in a production build, GDAL and Curl will have been built on
4053  // CentOS, so the baked-in system path will be wrong for Ubuntu
4054  // and other Linux distros. Unless the user is deliberately
4055  // overriding it by setting SSL_CERT_FILE explicitly in the server
4056  // environment, we set it to whichever CA bundle directory exists
4057  // on the machine we're running on
4058  std::list<std::string> v_known_ca_paths({
4059  "/etc/ssl/certs/ca-certificates.crt",
4060  "/etc/pki/tls/certs/ca-bundle.crt",
4061  "/usr/share/ssl/certs/ca-bundle.crt",
4062  "/usr/local/share/certs/ca-root.crt",
4063  "/etc/ssl/cert.pem",
4064  "/etc/ssl/ca-bundle.pem",
4065  });
4066  for (const auto& known_ca_path : v_known_ca_paths) {
4067  if (boost::filesystem::exists(known_ca_path)) {
4068  LOG(INFO) << "GDAL SSL Certificate path: " << known_ca_path;
4069  setenv("SSL_CERT_FILE", known_ca_path.c_str(), false); // no overwrite
4070  break;
4071  }
4072  }
4073 
4074  GDALAllRegister();
4075  OGRRegisterAll();
4076  CPLSetErrorHandler(*GDALErrorHandler);
4077  LOG(INFO) << "GDAL Initialized: " << GDALVersionInfo("--version");
4078  gdal_initialized = true;
4079  }
4080 }
#define LOG(tag)
Definition: Logger.h:185
std::string mapd_root_abs_path()
Definition: mapdpath.h:30
static std::mutex init_gdal_mutex
Definition: Importer.h:835
void GDALErrorHandler(CPLErr eErrClass, int err_no, const char *msg)
Definition: Importer.cpp:4017

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Importer_NS::Importer::load ( const std::vector< std::unique_ptr< TypedImportBuffer >> &  import_buffers,
size_t  row_count 
)

Definition at line 3110 of file Importer.cpp.

References Importer_NS::DataStreamSink::load_failed, and loader.

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

3111  {
3112  if (!loader->loadNoCheckpoint(import_buffers, row_count)) {
3113  load_failed = true;
3114  }
3115 }
std::unique_ptr< Loader > loader
Definition: Importer.h:833

+ Here is the caller graph for this function:

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

Definition at line 4157 of file Importer.cpp.

References logger::ERROR, logger::INFO, initGDAL(), LOG, and setGDALAuthorizationTokens().

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

4158  {
4159  // lazy init GDAL
4160  initGDAL();
4161 
4162  // set authorization tokens
4164 
4165  // open the file
4166  OGRDataSource* poDS;
4167 #if GDAL_VERSION_MAJOR == 1
4168  poDS = (OGRDataSource*)OGRSFDriverRegistrar::Open(file_name.c_str(), false);
4169 #else
4170  poDS = (OGRDataSource*)GDALOpenEx(
4171  file_name.c_str(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr);
4172  if (poDS == nullptr) {
4173  poDS = (OGRDataSource*)GDALOpenEx(
4174  file_name.c_str(), GDAL_OF_READONLY | GDAL_OF_VECTOR, nullptr, nullptr, nullptr);
4175  if (poDS) {
4176  LOG(INFO) << "openGDALDataset had to open as read-only";
4177  }
4178  }
4179 #endif
4180  if (poDS == nullptr) {
4181  LOG(ERROR) << "openGDALDataset Error: " << CPLGetLastErrorMsg();
4182  }
4183  // NOTE(adb): If extending this function, refactor to ensure any errors will not result
4184  // in a memory leak if GDAL successfully opened the input dataset.
4185  return poDS;
4186 }
static void setGDALAuthorizationTokens(const CopyParams &copy_params)
Definition: Importer.cpp:4087
#define LOG(tag)
Definition: Logger.h:185
static void initGDAL()
Definition: Importer.cpp:4040

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Importer_NS::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 4213 of file Importer.cpp.

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

Referenced by MapDHandler::detect_column_types().

4218  {
4220  if (poDS == nullptr) {
4221  throw std::runtime_error("openGDALDataset Error: Unable to open geo file " +
4222  file_name);
4223  }
4224 
4225  OGRLayer& layer =
4227 
4228  OGRFeatureDefn* poFDefn = layer.GetLayerDefn();
4229  CHECK(poFDefn);
4230 
4231  // typeof GetFeatureCount() is different between GDAL 1.x (int32_t) and 2.x (int64_t)
4232  auto nFeats = layer.GetFeatureCount();
4233  size_t numFeatures =
4234  std::max(static_cast<decltype(nFeats)>(0),
4235  std::min(static_cast<decltype(nFeats)>(rowLimit), nFeats));
4236  for (auto iField = 0; iField < poFDefn->GetFieldCount(); iField++) {
4237  OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(iField);
4238  // FIXME(andrewseidl): change this to the faster one used by readVerticesFromGDAL
4239  metadata.emplace(poFieldDefn->GetNameRef(), std::vector<std::string>(numFeatures));
4240  }
4241  metadata.emplace(geo_column_name, std::vector<std::string>(numFeatures));
4242  layer.ResetReading();
4243  size_t iFeature = 0;
4244  while (iFeature < numFeatures) {
4245  OGRFeatureUqPtr poFeature(layer.GetNextFeature());
4246  if (!poFeature) {
4247  break;
4248  }
4249 
4250  OGRGeometry* poGeometry = poFeature->GetGeometryRef();
4251  if (poGeometry != nullptr) {
4252  // validate geom type (again?)
4253  switch (wkbFlatten(poGeometry->getGeometryType())) {
4254  case wkbPoint:
4255  case wkbLineString:
4256  case wkbPolygon:
4257  case wkbMultiPolygon:
4258  break;
4259  default:
4260  throw std::runtime_error("Unsupported geometry type: " +
4261  std::string(poGeometry->getGeometryName()));
4262  }
4263 
4264  // populate metadata for regular fields
4265  for (auto i : metadata) {
4266  auto iField = poFeature->GetFieldIndex(i.first.c_str());
4267  if (iField >= 0) { // geom is -1
4268  metadata[i.first].at(iFeature) =
4269  std::string(poFeature->GetFieldAsString(iField));
4270  }
4271  }
4272 
4273  // populate metadata for geo column with WKT string
4274  char* wkts = nullptr;
4275  poGeometry->exportToWkt(&wkts);
4276  CHECK(wkts);
4277  metadata[geo_column_name].at(iFeature) = wkts;
4278  CPLFree(wkts);
4279  }
4280  iFeature++;
4281  }
4282 }
std::unique_ptr< OGRDataSource, OGRDataSourceDeleter > OGRDataSourceUqPtr
Definition: Importer.cpp:93
std::unique_ptr< OGRFeature, OGRFeatureDeleter > OGRFeatureUqPtr
Definition: Importer.cpp:102
OGRLayer & getLayerWithSpecifiedName(const std::string &geo_layer_name, const OGRDataSourceUqPtr &poDS, const std::string &file_name)
Definition: Importer.cpp:4190
CHECK(cgen_state)
static OGRDataSource * openGDALDataset(const std::string &fileName, const CopyParams &copy_params)
Definition: Importer.cpp:4157
std::string geo_layer_name
Definition: CopyParams.h:78

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Importer_NS::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,
const int64_t  replicate_count = 0 
)
static

Definition at line 1457 of file Importer.cpp.

References ColumnDescriptor::columnId, ColumnDescriptor::columnType, Importer_NS::compress_coords(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), Catalog_Namespace::Catalog::getMetadataForColumn(), kLINESTRING, kMULTIPOLYGON, kPOLYGON, and ColumnDescriptor::tableId.

Referenced by Importer_NS::TypedImportBuffer::convert_arrow_val_to_import_buffer(), Parser::AddColumnStmt::execute(), Importer_NS::import_thread_delimited(), and MapDHandler::load_table().

1467  {
1468  const auto col_ti = cd->columnType;
1469  const auto col_type = col_ti.get_type();
1470  auto columnId = cd->columnId;
1471  auto cd_coords = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1472  std::vector<TDatum> td_coords_data;
1473  std::vector<uint8_t> compressed_coords = compress_coords(coords, col_ti);
1474  for (auto cc : compressed_coords) {
1475  TDatum td_byte;
1476  td_byte.val.int_val = cc;
1477  td_coords_data.push_back(td_byte);
1478  }
1479  TDatum tdd_coords;
1480  tdd_coords.val.arr_val = td_coords_data;
1481  tdd_coords.is_null = false;
1482  import_buffers[col_idx++]->add_value(cd_coords, tdd_coords, false, replicate_count);
1483 
1484  if (col_type == kPOLYGON || col_type == kMULTIPOLYGON) {
1485  // Create ring_sizes array value and add it to the physical column
1486  auto cd_ring_sizes = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1487  std::vector<TDatum> td_ring_sizes;
1488  for (auto ring_size : ring_sizes) {
1489  TDatum td_ring_size;
1490  td_ring_size.val.int_val = ring_size;
1491  td_ring_sizes.push_back(td_ring_size);
1492  }
1493  TDatum tdd_ring_sizes;
1494  tdd_ring_sizes.val.arr_val = td_ring_sizes;
1495  tdd_ring_sizes.is_null = false;
1496  import_buffers[col_idx++]->add_value(
1497  cd_ring_sizes, tdd_ring_sizes, false, replicate_count);
1498  }
1499 
1500  if (col_type == kMULTIPOLYGON) {
1501  // Create poly_rings array value and add it to the physical column
1502  auto cd_poly_rings = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1503  std::vector<TDatum> td_poly_rings;
1504  for (auto num_rings : poly_rings) {
1505  TDatum td_num_rings;
1506  td_num_rings.val.int_val = num_rings;
1507  td_poly_rings.push_back(td_num_rings);
1508  }
1509  TDatum tdd_poly_rings;
1510  tdd_poly_rings.val.arr_val = td_poly_rings;
1511  tdd_poly_rings.is_null = false;
1512  import_buffers[col_idx++]->add_value(
1513  cd_poly_rings, tdd_poly_rings, false, replicate_count);
1514  }
1515 
1516  if (col_type == kLINESTRING || col_type == kPOLYGON || col_type == kMULTIPOLYGON) {
1517  auto cd_bounds = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1518  std::vector<TDatum> td_bounds_data;
1519  for (auto b : bounds) {
1520  TDatum td_double;
1521  td_double.val.real_val = b;
1522  td_bounds_data.push_back(td_double);
1523  }
1524  TDatum tdd_bounds;
1525  tdd_bounds.val.arr_val = td_bounds_data;
1526  tdd_bounds.is_null = false;
1527  import_buffers[col_idx++]->add_value(cd_bounds, tdd_bounds, false, replicate_count);
1528  }
1529 
1530  if (col_type == kPOLYGON || col_type == kMULTIPOLYGON) {
1531  // Create render_group value and add it to the physical column
1532  auto cd_render_group = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1533  TDatum td_render_group;
1534  td_render_group.val.int_val = render_group;
1535  td_render_group.is_null = false;
1536  import_buffers[col_idx++]->add_value(
1537  cd_render_group, td_render_group, false, replicate_count);
1538  }
1539 }
std::vector< uint8_t > compress_coords(std::vector< double > &coords, const SQLTypeInfo &ti)
Definition: Importer.cpp:1422
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
SQLTypeInfo columnType

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Importer_NS::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,
int  render_group,
const int64_t  replicate_count = 0 
)
static

Definition at line 1541 of file Importer.cpp.

References CHECK(), ColumnDescriptor::columnId, ColumnDescriptor::columnType, Importer_NS::compress_coords(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), Catalog_Namespace::Catalog::getMetadataForColumn(), kLINESTRING, kMULTIPOLYGON, kPOLYGON, and ColumnDescriptor::tableId.

Referenced by MapDHandler::load_table_binary_columnar().

1551  {
1552  const auto col_ti = cd->columnType;
1553  const auto col_type = col_ti.get_type();
1554  auto columnId = cd->columnId;
1555 
1556  auto coords_row_count = coords_column.size();
1557  auto cd_coords = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1558  for (auto coords : coords_column) {
1559  std::vector<TDatum> td_coords_data;
1560  std::vector<uint8_t> compressed_coords = compress_coords(coords, col_ti);
1561  for (auto cc : compressed_coords) {
1562  TDatum td_byte;
1563  td_byte.val.int_val = cc;
1564  td_coords_data.push_back(td_byte);
1565  }
1566  TDatum tdd_coords;
1567  tdd_coords.val.arr_val = td_coords_data;
1568  tdd_coords.is_null = false;
1569  import_buffers[col_idx]->add_value(cd_coords, tdd_coords, false, replicate_count);
1570  }
1571  col_idx++;
1572 
1573  if (col_type == kPOLYGON || col_type == kMULTIPOLYGON) {
1574  if (ring_sizes_column.size() != coords_row_count) {
1575  CHECK(false) << "Geometry import columnar: ring sizes column size mismatch";
1576  }
1577  // Create ring_sizes array value and add it to the physical column
1578  auto cd_ring_sizes = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1579  for (auto ring_sizes : ring_sizes_column) {
1580  std::vector<TDatum> td_ring_sizes;
1581  for (auto ring_size : ring_sizes) {
1582  TDatum td_ring_size;
1583  td_ring_size.val.int_val = ring_size;
1584  td_ring_sizes.push_back(td_ring_size);
1585  }
1586  TDatum tdd_ring_sizes;
1587  tdd_ring_sizes.val.arr_val = td_ring_sizes;
1588  tdd_ring_sizes.is_null = false;
1589  import_buffers[col_idx]->add_value(
1590  cd_ring_sizes, tdd_ring_sizes, false, replicate_count);
1591  }
1592  col_idx++;
1593  }
1594 
1595  if (col_type == kMULTIPOLYGON) {
1596  if (poly_rings_column.size() != coords_row_count) {
1597  CHECK(false) << "Geometry import columnar: poly rings column size mismatch";
1598  }
1599  // Create poly_rings array value and add it to the physical column
1600  auto cd_poly_rings = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1601  for (auto poly_rings : poly_rings_column) {
1602  std::vector<TDatum> td_poly_rings;
1603  for (auto num_rings : poly_rings) {
1604  TDatum td_num_rings;
1605  td_num_rings.val.int_val = num_rings;
1606  td_poly_rings.push_back(td_num_rings);
1607  }
1608  TDatum tdd_poly_rings;
1609  tdd_poly_rings.val.arr_val = td_poly_rings;
1610  tdd_poly_rings.is_null = false;
1611  import_buffers[col_idx]->add_value(
1612  cd_poly_rings, tdd_poly_rings, false, replicate_count);
1613  }
1614  col_idx++;
1615  }
1616 
1617  if (col_type == kLINESTRING || col_type == kPOLYGON || col_type == kMULTIPOLYGON) {
1618  if (bounds_column.size() != coords_row_count) {
1619  CHECK(false) << "Geometry import columnar: bounds column size mismatch";
1620  }
1621  auto cd_bounds = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1622  for (auto bounds : bounds_column) {
1623  std::vector<TDatum> td_bounds_data;
1624  for (auto b : bounds) {
1625  TDatum td_double;
1626  td_double.val.real_val = b;
1627  td_bounds_data.push_back(td_double);
1628  }
1629  TDatum tdd_bounds;
1630  tdd_bounds.val.arr_val = td_bounds_data;
1631  tdd_bounds.is_null = false;
1632  import_buffers[col_idx]->add_value(cd_bounds, tdd_bounds, false, replicate_count);
1633  }
1634  col_idx++;
1635  }
1636 
1637  if (col_type == kPOLYGON || col_type == kMULTIPOLYGON) {
1638  // Create render_group value and add it to the physical column
1639  auto cd_render_group = catalog.getMetadataForColumn(cd->tableId, ++columnId);
1640  TDatum td_render_group;
1641  td_render_group.val.int_val = render_group;
1642  td_render_group.is_null = false;
1643  for (decltype(coords_row_count) i = 0; i < coords_row_count; i++) {
1644  import_buffers[col_idx]->add_value(
1645  cd_render_group, td_render_group, false, replicate_count);
1646  }
1647  col_idx++;
1648  }
1649 }
std::vector< uint8_t > compress_coords(std::vector< double > &coords, const SQLTypeInfo &ti)
Definition: Importer.cpp:1422
CHECK(cgen_state)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
SQLTypeInfo columnType

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 213 of file Importer.cpp.

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

Referenced by importDelimited(), and importGDAL().

213  {
214  mapd_lock_guard<mapd_shared_mutex> write_lock(status_mutex);
215  is.end = std::chrono::steady_clock::now();
216  is.elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(is.end - is.start);
218 }
static std::map< std::string, ImportStatus > import_status_map
Definition: Importer.cpp:147
static mapd_shared_mutex status_mutex
Definition: Importer.cpp:146
std::string import_id
Definition: Importer.h:828

+ Here is the caller graph for this function:

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

Definition at line 4087 of file Importer.cpp.

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

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

4087  {
4088  // for now we only support S3
4089  // @TODO generalize CopyParams to have a dictionary of GDAL tokens
4090  // only set if non-empty to allow GDAL defaults to persist
4091  // explicitly clear if empty to revert to default and not reuse a previous session's
4092  // keys
4093  if (copy_params.s3_region.size()) {
4094 #if DEBUG_AWS_AUTHENTICATION
4095  LOG(INFO) << "GDAL: Setting AWS_REGION to '" << copy_params.s3_region << "'";
4096 #endif
4097  CPLSetConfigOption("AWS_REGION", copy_params.s3_region.c_str());
4098  } else {
4099 #if DEBUG_AWS_AUTHENTICATION
4100  LOG(INFO) << "GDAL: Clearing AWS_REGION";
4101 #endif
4102  CPLSetConfigOption("AWS_REGION", nullptr);
4103  }
4104  if (copy_params.s3_endpoint.size()) {
4105 #if DEBUG_AWS_AUTHENTICATION
4106  LOG(INFO) << "GDAL: Setting AWS_S3_ENDPOINT to '" << copy_params.s3_endpoint << "'";
4107 #endif
4108  CPLSetConfigOption("AWS_S3_ENDPOINT", copy_params.s3_endpoint.c_str());
4109  } else {
4110 #if DEBUG_AWS_AUTHENTICATION
4111  LOG(INFO) << "GDAL: Clearing AWS_S3_ENDPOINT";
4112 #endif
4113  CPLSetConfigOption("AWS_S3_ENDPOINT", nullptr);
4114  }
4115  if (copy_params.s3_access_key.size()) {
4116 #if DEBUG_AWS_AUTHENTICATION
4117  LOG(INFO) << "GDAL: Setting AWS_ACCESS_KEY_ID to '" << copy_params.s3_access_key
4118  << "'";
4119 #endif
4120  CPLSetConfigOption("AWS_ACCESS_KEY_ID", copy_params.s3_access_key.c_str());
4121  } else {
4122 #if DEBUG_AWS_AUTHENTICATION
4123  LOG(INFO) << "GDAL: Clearing AWS_ACCESS_KEY_ID";
4124 #endif
4125  CPLSetConfigOption("AWS_ACCESS_KEY_ID", nullptr);
4126  }
4127  if (copy_params.s3_secret_key.size()) {
4128 #if DEBUG_AWS_AUTHENTICATION
4129  LOG(INFO) << "GDAL: Setting AWS_SECRET_ACCESS_KEY to '" << copy_params.s3_secret_key
4130  << "'";
4131 #endif
4132  CPLSetConfigOption("AWS_SECRET_ACCESS_KEY", copy_params.s3_secret_key.c_str());
4133  } else {
4134 #if DEBUG_AWS_AUTHENTICATION
4135  LOG(INFO) << "GDAL: Clearing AWS_SECRET_ACCESS_KEY";
4136 #endif
4137  CPLSetConfigOption("AWS_SECRET_ACCESS_KEY", nullptr);
4138  }
4139 
4140 #if (GDAL_VERSION_MAJOR > 2) || (GDAL_VERSION_MAJOR == 2 && GDAL_VERSION_MINOR >= 3)
4141  // if we haven't set keys, we need to disable signed access
4142  if (copy_params.s3_access_key.size() || copy_params.s3_secret_key.size()) {
4143 #if DEBUG_AWS_AUTHENTICATION
4144  LOG(INFO) << "GDAL: Clearing AWS_NO_SIGN_REQUEST";
4145 #endif
4146  CPLSetConfigOption("AWS_NO_SIGN_REQUEST", nullptr);
4147  } else {
4148 #if DEBUG_AWS_AUTHENTICATION
4149  LOG(INFO) << "GDAL: Setting AWS_NO_SIGN_REQUEST to 'YES'";
4150 #endif
4151  CPLSetConfigOption("AWS_NO_SIGN_REQUEST", "YES");
4152  }
4153 #endif
4154 }
#define LOG(tag)
Definition: Logger.h:185
std::string s3_access_key
Definition: CopyParams.h:62
std::string s3_endpoint
Definition: CopyParams.h:65
std::string s3_region
Definition: CopyParams.h:64
std::string s3_secret_key
Definition: CopyParams.h:63

+ Here is the caller graph for this function:

Member Data Documentation

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

Definition at line 831 of file Importer.h.

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

size_t Importer_NS::Importer::file_size
private

Definition at line 829 of file Importer.h.

Referenced by importDelimited(), and Importer().

std::vector<std::vector<std::unique_ptr<TypedImportBuffer> > > Importer_NS::Importer::import_buffers_vec
private
std::string Importer_NS::Importer::import_id
private

Definition at line 828 of file Importer.h.

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

std::mutex Importer_NS::Importer::init_gdal_mutex
staticprivate

Definition at line 835 of file Importer.h.

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

Definition at line 834 of file Importer.h.

Referenced by get_is_array(), and Importer().

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

Definition at line 830 of file Importer.h.

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


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