OmniSciDB  f17484ade4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
import_export::anonymous_namespace{Importer.cpp} Namespace Reference

Functions

SQLTypes get_type_for_datum (const SQLTypeInfo &ti)
 
std::tuple< int, SQLTypes,
std::string > 
explode_collections_step1 (const std::list< const ColumnDescriptor * > &col_descs)
 
int64_t explode_collections_step2 (OGRGeometry *ogr_geometry, SQLTypes collection_child_type, const std::string &collection_col_name, size_t row_or_feature_idx, std::function< void(OGRGeometry *)> execute_import_lambda)
 
int64_t int_value_at (const TypedImportBuffer &import_buffer, const size_t index)
 
float float_value_at (const TypedImportBuffer &import_buffer, const size_t index)
 
double double_value_at (const TypedImportBuffer &import_buffer, const size_t index)
 
OGRLayer & getLayerWithSpecifiedName (const std::string &geo_layer_name, const Geospatial::GDAL::DataSourceUqPtr &poDS, const std::string &file_name)
 
std::pair< SQLTypes, bool > ogr_to_type (const OGRFieldType &ogr_type)
 
SQLTypes ogr_to_type (const OGRwkbGeometryType &ogr_type)
 
RasterImporter::PointType convert_raster_point_type (const import_export::RasterPointType raster_point_type)
 
RasterImporter::PointTransform convert_raster_point_transform (const import_export::RasterPointTransform raster_point_transform)
 

Function Documentation

RasterImporter::PointTransform import_export::anonymous_namespace{Importer.cpp}::convert_raster_point_transform ( const import_export::RasterPointTransform  raster_point_transform)

Definition at line 4800 of file Importer.cpp.

References import_export::kAuto, import_export::RasterImporter::kAuto, import_export::kFile, import_export::RasterImporter::kFile, import_export::kNone, import_export::RasterImporter::kNone, import_export::kWorld, import_export::RasterImporter::kWorld, and UNREACHABLE.

Referenced by import_export::Importer::gdalToColumnDescriptorsRaster(), and import_export::Importer::importGDALRaster().

4801  {
4802  switch (raster_point_transform) {
4804  return RasterImporter::PointTransform::kNone;
4806  return RasterImporter::PointTransform::kAuto;
4808  return RasterImporter::PointTransform::kFile;
4810  return RasterImporter::PointTransform::kWorld;
4811  }
4812  UNREACHABLE();
4813  return RasterImporter::PointTransform::kNone;
4814 }
#define UNREACHABLE()
Definition: Logger.h:338

+ Here is the caller graph for this function:

RasterImporter::PointType import_export::anonymous_namespace{Importer.cpp}::convert_raster_point_type ( const import_export::RasterPointType  raster_point_type)

Definition at line 4778 of file Importer.cpp.

References import_export::kAuto, import_export::RasterImporter::kAuto, import_export::kDouble, import_export::RasterImporter::kDouble, import_export::kFloat, import_export::RasterImporter::kFloat, import_export::kInt, import_export::RasterImporter::kInt, import_export::kNone, import_export::RasterImporter::kNone, import_export::kPoint, import_export::RasterImporter::kPoint, import_export::kSmallInt, import_export::RasterImporter::kSmallInt, and UNREACHABLE.

Referenced by import_export::Importer::gdalToColumnDescriptorsRaster(), and import_export::Importer::importGDALRaster().

4779  {
4780  switch (raster_point_type) {
4782  return RasterImporter::PointType::kNone;
4784  return RasterImporter::PointType::kAuto;
4786  return RasterImporter::PointType::kSmallInt;
4788  return RasterImporter::PointType::kInt;
4790  return RasterImporter::PointType::kFloat;
4792  return RasterImporter::PointType::kDouble;
4794  return RasterImporter::PointType::kPoint;
4795  }
4796  UNREACHABLE();
4797  return RasterImporter::PointType::kNone;
4798 }
#define UNREACHABLE()
Definition: Logger.h:338

+ Here is the caller graph for this function:

double import_export::anonymous_namespace{Importer.cpp}::double_value_at ( const TypedImportBuffer &  import_buffer,
const size_t  index 
)

Definition at line 2730 of file Importer.cpp.

References CHECK_EQ, import_export::TypedImportBuffer::getAsBytes(), import_export::TypedImportBuffer::getTypeInfo(), and kDOUBLE.

Referenced by import_export::Loader::fillShardRow().

2730  {
2731  const auto& ti = import_buffer.getTypeInfo();
2732  CHECK_EQ(kDOUBLE, ti.get_type());
2733  const auto values_buffer = import_buffer.getAsBytes();
2734  return reinterpret_cast<const double*>(may_alias_ptr(values_buffer))[index];
2735 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::tuple<int, SQLTypes, std::string> import_export::anonymous_namespace{Importer.cpp}::explode_collections_step1 ( const std::list< const ColumnDescriptor * > &  col_descs)

Definition at line 1862 of file Importer.cpp.

References kLINESTRING, kNULLT, kPOINT, and kPOLYGON.

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

1863  {
1864  // validate the columns
1865  // for now we can only explode into a single destination column
1866  // which must be of the child type (POLYGON, LINESTRING, POINT)
1867  int collection_col_idx = -1;
1868  int col_idx = 0;
1869  std::string collection_col_name;
1870  SQLTypes collection_child_type = kNULLT;
1871  for (auto cd_it = col_descs.begin(); cd_it != col_descs.end(); cd_it++) {
1872  auto const& cd = *cd_it;
1873  auto const col_type = cd->columnType.get_type();
1874  if (col_type == kPOLYGON || col_type == kLINESTRING || col_type == kPOINT) {
1875  if (collection_col_idx >= 0) {
1876  throw std::runtime_error(
1877  "Explode Collections: Found more than one destination column");
1878  }
1879  collection_col_idx = col_idx;
1880  collection_child_type = col_type;
1881  collection_col_name = cd->columnName;
1882  }
1883  for (int i = 0; i < cd->columnType.get_physical_cols(); ++i) {
1884  ++cd_it;
1885  }
1886  col_idx++;
1887  }
1888  if (collection_col_idx < 0) {
1889  throw std::runtime_error(
1890  "Explode Collections: Failed to find a supported column type to explode "
1891  "into");
1892  }
1893  return std::make_tuple(collection_col_idx, collection_child_type, collection_col_name);
1894 }
SQLTypes
Definition: sqltypes.h:65

+ Here is the caller graph for this function:

int64_t import_export::anonymous_namespace{Importer.cpp}::explode_collections_step2 ( OGRGeometry *  ogr_geometry,
SQLTypes  collection_child_type,
const std::string &  collection_col_name,
size_t  row_or_feature_idx,
std::function< void(OGRGeometry *)>  execute_import_lambda 
)

Definition at line 1896 of file Importer.cpp.

References CHECK, measure< TimeT >::execution(), logger::INFO, kLINESTRING, kPOINT, kPOLYGON, and LOG.

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

1901  {
1902  auto ogr_geometry_type = wkbFlatten(ogr_geometry->getGeometryType());
1903  bool is_collection = false;
1904  switch (collection_child_type) {
1905  case kPOINT:
1906  switch (ogr_geometry_type) {
1907  case wkbMultiPoint:
1908  is_collection = true;
1909  break;
1910  case wkbPoint:
1911  break;
1912  default:
1913  throw std::runtime_error(
1914  "Explode Collections: Source geo type must be MULTIPOINT or POINT");
1915  }
1916  break;
1917  case kLINESTRING:
1918  switch (ogr_geometry_type) {
1919  case wkbMultiLineString:
1920  is_collection = true;
1921  break;
1922  case wkbLineString:
1923  break;
1924  default:
1925  throw std::runtime_error(
1926  "Explode Collections: Source geo type must be MULTILINESTRING or "
1927  "LINESTRING");
1928  }
1929  break;
1930  case kPOLYGON:
1931  switch (ogr_geometry_type) {
1932  case wkbMultiPolygon:
1933  is_collection = true;
1934  break;
1935  case wkbPolygon:
1936  break;
1937  default:
1938  throw std::runtime_error(
1939  "Explode Collections: Source geo type must be MULTIPOLYGON or POLYGON");
1940  }
1941  break;
1942  default:
1943  CHECK(false) << "Unsupported geo child type " << collection_child_type;
1944  }
1945 
1946  int64_t us = 0LL;
1947 
1948  // explode or just import
1949  if (is_collection) {
1950  // cast to collection
1951  OGRGeometryCollection* collection_geometry = ogr_geometry->toGeometryCollection();
1952  CHECK(collection_geometry);
1953 
1954 #if LOG_EXPLODE_COLLECTIONS
1955  // log number of children
1956  LOG(INFO) << "Exploding row/feature " << row_or_feature_idx << " for column '"
1957  << explode_col_name << "' into " << collection_geometry->getNumGeometries()
1958  << " child rows";
1959 #endif
1960 
1961  // loop over children
1962  uint32_t child_geometry_count = 0;
1963  auto child_geometry_it = collection_geometry->begin();
1964  while (child_geometry_it != collection_geometry->end()) {
1965  // get and import this child
1966  OGRGeometry* import_geometry = *child_geometry_it;
1968  [&] { execute_import_lambda(import_geometry); });
1969 
1970  // next child
1971  child_geometry_it++;
1972  child_geometry_count++;
1973  }
1974  } else {
1975  // import non-collection row just once
1977  [&] { execute_import_lambda(ogr_geometry); });
1978  }
1979 
1980  // done
1981  return us;
1982 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:285
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float import_export::anonymous_namespace{Importer.cpp}::float_value_at ( const TypedImportBuffer &  import_buffer,
const size_t  index 
)

Definition at line 2723 of file Importer.cpp.

References CHECK_EQ, import_export::TypedImportBuffer::getAsBytes(), import_export::TypedImportBuffer::getTypeInfo(), and kFLOAT.

Referenced by import_export::Loader::fillShardRow().

2723  {
2724  const auto& ti = import_buffer.getTypeInfo();
2725  CHECK_EQ(kFLOAT, ti.get_type());
2726  const auto values_buffer = import_buffer.getAsBytes();
2727  return reinterpret_cast<const float*>(may_alias_ptr(values_buffer))[index];
2728 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SQLTypes import_export::anonymous_namespace{Importer.cpp}::get_type_for_datum ( const SQLTypeInfo ti)
inline

Definition at line 260 of file Importer.cpp.

References decimal_to_int_type(), SQLTypeInfo::get_type(), SQLTypeInfo::is_decimal(), SQLTypeInfo::is_dict_encoded_string(), string_dict_to_int_type(), and run_benchmark_import::type.

Referenced by import_export::NullArrayDatum(), and NullDatum().

260  {
261  SQLTypes type;
262  if (ti.is_decimal()) {
263  type = decimal_to_int_type(ti);
264  } else if (ti.is_dict_encoded_string()) {
265  type = string_dict_to_int_type(ti);
266  } else {
267  type = ti.get_type();
268  }
269  return type;
270 }
SQLTypes
Definition: sqltypes.h:65
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:561
bool is_dict_encoded_string() const
Definition: sqltypes.h:641
bool is_decimal() const
Definition: sqltypes.h:568
SQLTypes string_dict_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:565

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

OGRLayer& import_export::anonymous_namespace{Importer.cpp}::getLayerWithSpecifiedName ( const std::string &  geo_layer_name,
const Geospatial::GDAL::DataSourceUqPtr poDS,
const std::string &  file_name 
)

Definition at line 4601 of file Importer.cpp.

Referenced by import_export::Importer::gdalToColumnDescriptorsGeo(), import_export::Importer::importGDALGeo(), and import_export::Importer::readMetadataSampleGDAL().

4603  {
4604  // get layer with specified name, or default to first layer
4605  OGRLayer* poLayer = nullptr;
4606  if (geo_layer_name.size()) {
4607  poLayer = poDS->GetLayerByName(geo_layer_name.c_str());
4608  if (poLayer == nullptr) {
4609  throw std::runtime_error("Layer '" + geo_layer_name + "' not found in " +
4610  file_name);
4611  }
4612  } else {
4613  poLayer = poDS->GetLayer(0);
4614  if (poLayer == nullptr) {
4615  throw std::runtime_error("No layers found in " + file_name);
4616  }
4617  }
4618  return *poLayer;
4619 }

+ Here is the caller graph for this function:

int64_t import_export::anonymous_namespace{Importer.cpp}::int_value_at ( const TypedImportBuffer &  import_buffer,
const size_t  index 
)

Definition at line 2692 of file Importer.cpp.

References CHECK, CHECK_EQ, logger::FATAL, import_export::TypedImportBuffer::getAsBytes(), import_export::TypedImportBuffer::getStringDictBuffer(), import_export::TypedImportBuffer::getTypeInfo(), kENCODING_DICT, LOG, and UNREACHABLE.

Referenced by import_export::Loader::distributeToShardsExistingColumns(), and import_export::Loader::fillShardRow().

2692  {
2693  const auto& ti = import_buffer.getTypeInfo();
2694  const int8_t* values_buffer{nullptr};
2695  if (ti.is_string()) {
2696  CHECK_EQ(kENCODING_DICT, ti.get_compression());
2697  values_buffer = import_buffer.getStringDictBuffer();
2698  } else {
2699  values_buffer = import_buffer.getAsBytes();
2700  }
2701  CHECK(values_buffer);
2702  const int logical_size = ti.is_string() ? ti.get_size() : ti.get_logical_size();
2703  switch (logical_size) {
2704  case 1: {
2705  return values_buffer[index];
2706  }
2707  case 2: {
2708  return reinterpret_cast<const int16_t*>(values_buffer)[index];
2709  }
2710  case 4: {
2711  return reinterpret_cast<const int32_t*>(values_buffer)[index];
2712  }
2713  case 8: {
2714  return reinterpret_cast<const int64_t*>(values_buffer)[index];
2715  }
2716  default:
2717  LOG(FATAL) << "Unexpected size for shard key: " << logical_size;
2718  }
2719  UNREACHABLE();
2720  return 0;
2721 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define LOG(tag)
Definition: Logger.h:285
#define UNREACHABLE()
Definition: Logger.h:338
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::pair<SQLTypes, bool> import_export::anonymous_namespace{Importer.cpp}::ogr_to_type ( const OGRFieldType &  ogr_type)

Definition at line 4720 of file Importer.cpp.

References kBIGINT, kDATE, kDOUBLE, kINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, and to_string().

Referenced by import_export::Importer::gdalToColumnDescriptorsGeo().

4720  {
4721  switch (ogr_type) {
4722  case OFTInteger:
4723  return std::make_pair(kINT, false);
4724  case OFTIntegerList:
4725  return std::make_pair(kINT, true);
4726 #if GDAL_VERSION_MAJOR > 1
4727  case OFTInteger64:
4728  return std::make_pair(kBIGINT, false);
4729  case OFTInteger64List:
4730  return std::make_pair(kBIGINT, true);
4731 #endif
4732  case OFTReal:
4733  return std::make_pair(kDOUBLE, false);
4734  case OFTRealList:
4735  return std::make_pair(kDOUBLE, true);
4736  case OFTString:
4737  return std::make_pair(kTEXT, false);
4738  case OFTStringList:
4739  return std::make_pair(kTEXT, true);
4740  case OFTDate:
4741  return std::make_pair(kDATE, false);
4742  case OFTTime:
4743  return std::make_pair(kTIME, false);
4744  case OFTDateTime:
4745  return std::make_pair(kTIMESTAMP, false);
4746  case OFTBinary:
4747  // Interpret binary blobs as byte arrays here
4748  // but actual import will store NULL as GDAL will not
4749  // extract the blob (OGRFeature::GetFieldAsString will
4750  // result in the import buffers having an empty string)
4751  return std::make_pair(kTINYINT, true);
4752  default:
4753  break;
4754  }
4755  throw std::runtime_error("Unknown OGR field type: " + std::to_string(ogr_type));
4756 }
Definition: sqltypes.h:76
std::string to_string(char const *&&v)
Definition: sqltypes.h:79
Definition: sqltypes.h:80
Definition: sqltypes.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SQLTypes import_export::anonymous_namespace{Importer.cpp}::ogr_to_type ( const OGRwkbGeometryType &  ogr_type)

Definition at line 4758 of file Importer.cpp.

References kLINESTRING, kMULTILINESTRING, kMULTIPOINT, kMULTIPOLYGON, kPOINT, kPOLYGON, and to_string().

4758  {
4759  switch (ogr_type) {
4760  case wkbPoint:
4761  return kPOINT;
4762  case wkbMultiPoint:
4763  return kMULTIPOINT;
4764  case wkbLineString:
4765  return kLINESTRING;
4766  case wkbMultiLineString:
4767  return kMULTILINESTRING;
4768  case wkbPolygon:
4769  return kPOLYGON;
4770  case wkbMultiPolygon:
4771  return kMULTIPOLYGON;
4772  default:
4773  break;
4774  }
4775  throw std::runtime_error("Unknown OGR geom type: " + std::to_string(ogr_type));
4776 }
std::string to_string(char const *&&v)

+ Here is the call graph for this function: