OmniSciDB  72c90bc290
 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 4801 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().

4802  {
4803  switch (raster_point_transform) {
4805  return RasterImporter::PointTransform::kNone;
4807  return RasterImporter::PointTransform::kAuto;
4809  return RasterImporter::PointTransform::kFile;
4811  return RasterImporter::PointTransform::kWorld;
4812  }
4813  UNREACHABLE();
4814  return RasterImporter::PointTransform::kNone;
4815 }
#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 4779 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().

4780  {
4781  switch (raster_point_type) {
4783  return RasterImporter::PointType::kNone;
4785  return RasterImporter::PointType::kAuto;
4787  return RasterImporter::PointType::kSmallInt;
4789  return RasterImporter::PointType::kInt;
4791  return RasterImporter::PointType::kFloat;
4793  return RasterImporter::PointType::kDouble;
4795  return RasterImporter::PointType::kPoint;
4796  }
4797  UNREACHABLE();
4798  return RasterImporter::PointType::kNone;
4799 }
#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 4602 of file Importer.cpp.

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

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

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

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

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

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

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

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

+ Here is the call graph for this function: