OmniSciDB  c1a53651b2
 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 4903 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().

4904  {
4905  switch (raster_point_transform) {
4907  return RasterImporter::PointTransform::kNone;
4909  return RasterImporter::PointTransform::kAuto;
4911  return RasterImporter::PointTransform::kFile;
4913  return RasterImporter::PointTransform::kWorld;
4914  }
4915  UNREACHABLE();
4916  return RasterImporter::PointTransform::kNone;
4917 }
#define UNREACHABLE()
Definition: Logger.h:337

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

4882  {
4883  switch (raster_point_type) {
4885  return RasterImporter::PointType::kNone;
4887  return RasterImporter::PointType::kAuto;
4889  return RasterImporter::PointType::kSmallInt;
4891  return RasterImporter::PointType::kInt;
4893  return RasterImporter::PointType::kFloat;
4895  return RasterImporter::PointType::kDouble;
4897  return RasterImporter::PointType::kPoint;
4898  }
4899  UNREACHABLE();
4900  return RasterImporter::PointType::kNone;
4901 }
#define UNREACHABLE()
Definition: Logger.h:337

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

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

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

2807  {
2808  const auto& ti = import_buffer.getTypeInfo();
2809  CHECK_EQ(kDOUBLE, ti.get_type());
2810  const auto values_buffer = import_buffer.getAsBytes();
2811  return reinterpret_cast<const double*>(may_alias_ptr(values_buffer))[index];
2812 }
#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 1876 of file Importer.cpp.

References kLINESTRING, kNULLT, kPOINT, and kPOLYGON.

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

1877  {
1878  // validate the columns
1879  // for now we can only explode into a single destination column
1880  // which must be of the child type (POLYGON, LINESTRING, POINT)
1881  int collection_col_idx = -1;
1882  int col_idx = 0;
1883  std::string collection_col_name;
1884  SQLTypes collection_child_type = kNULLT;
1885  for (auto cd_it = col_descs.begin(); cd_it != col_descs.end(); cd_it++) {
1886  auto const& cd = *cd_it;
1887  auto const col_type = cd->columnType.get_type();
1888  if (col_type == kPOLYGON || col_type == kLINESTRING || col_type == kPOINT) {
1889  if (collection_col_idx >= 0) {
1890  throw std::runtime_error(
1891  "Explode Collections: Found more than one destination column");
1892  }
1893  collection_col_idx = col_idx;
1894  collection_child_type = col_type;
1895  collection_col_name = cd->columnName;
1896  }
1897  for (int i = 0; i < cd->columnType.get_physical_cols(); ++i) {
1898  ++cd_it;
1899  }
1900  col_idx++;
1901  }
1902  if (collection_col_idx < 0) {
1903  throw std::runtime_error(
1904  "Explode Collections: Failed to find a supported column type to explode "
1905  "into");
1906  }
1907  return std::make_tuple(collection_col_idx, collection_child_type, collection_col_name);
1908 }
SQLTypes
Definition: sqltypes.h:55

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

1915  {
1916  auto ogr_geometry_type = wkbFlatten(ogr_geometry->getGeometryType());
1917  bool is_collection = false;
1918  switch (collection_child_type) {
1919  case kPOINT:
1920  switch (ogr_geometry_type) {
1921  case wkbMultiPoint:
1922  is_collection = true;
1923  break;
1924  case wkbPoint:
1925  break;
1926  default:
1927  throw std::runtime_error(
1928  "Explode Collections: Source geo type must be MULTIPOINT or POINT");
1929  }
1930  break;
1931  case kLINESTRING:
1932  switch (ogr_geometry_type) {
1933  case wkbMultiLineString:
1934  is_collection = true;
1935  break;
1936  case wkbLineString:
1937  break;
1938  default:
1939  throw std::runtime_error(
1940  "Explode Collections: Source geo type must be MULTILINESTRING or "
1941  "LINESTRING");
1942  }
1943  break;
1944  case kPOLYGON:
1945  switch (ogr_geometry_type) {
1946  case wkbMultiPolygon:
1947  is_collection = true;
1948  break;
1949  case wkbPolygon:
1950  break;
1951  default:
1952  throw std::runtime_error(
1953  "Explode Collections: Source geo type must be MULTIPOLYGON or POLYGON");
1954  }
1955  break;
1956  default:
1957  CHECK(false) << "Unsupported geo child type " << collection_child_type;
1958  }
1959 
1960  int64_t us = 0LL;
1961 
1962  // explode or just import
1963  if (is_collection) {
1964  // cast to collection
1965  OGRGeometryCollection* collection_geometry = ogr_geometry->toGeometryCollection();
1966  CHECK(collection_geometry);
1967 
1968 #if LOG_EXPLODE_COLLECTIONS
1969  // log number of children
1970  LOG(INFO) << "Exploding row/feature " << row_or_feature_idx << " for column '"
1971  << explode_col_name << "' into " << collection_geometry->getNumGeometries()
1972  << " child rows";
1973 #endif
1974 
1975  // loop over children
1976  uint32_t child_geometry_count = 0;
1977  auto child_geometry_it = collection_geometry->begin();
1978  while (child_geometry_it != collection_geometry->end()) {
1979  // get and import this child
1980  OGRGeometry* import_geometry = *child_geometry_it;
1982  [&] { execute_import_lambda(import_geometry); });
1983 
1984  // next child
1985  child_geometry_it++;
1986  child_geometry_count++;
1987  }
1988  } else {
1989  // import non-collection row just once
1991  [&] { execute_import_lambda(ogr_geometry); });
1992  }
1993 
1994  // done
1995  return us;
1996 }
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 2800 of file Importer.cpp.

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

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

2800  {
2801  const auto& ti = import_buffer.getTypeInfo();
2802  CHECK_EQ(kFLOAT, ti.get_type());
2803  const auto values_buffer = import_buffer.getAsBytes();
2804  return reinterpret_cast<const float*>(may_alias_ptr(values_buffer))[index];
2805 }
#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 259 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().

259  {
260  SQLTypes type;
261  if (ti.is_decimal()) {
262  type = decimal_to_int_type(ti);
263  } else if (ti.is_dict_encoded_string()) {
264  type = string_dict_to_int_type(ti);
265  } else {
266  type = ti.get_type();
267  }
268  return type;
269 }
SQLTypes
Definition: sqltypes.h:55
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:559
bool is_dict_encoded_string() const
Definition: sqltypes.h:632
bool is_decimal() const
Definition: sqltypes.h:583
SQLTypes string_dict_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:563

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

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

4706  {
4707  // get layer with specified name, or default to first layer
4708  OGRLayer* poLayer = nullptr;
4709  if (geo_layer_name.size()) {
4710  poLayer = poDS->GetLayerByName(geo_layer_name.c_str());
4711  if (poLayer == nullptr) {
4712  throw std::runtime_error("Layer '" + geo_layer_name + "' not found in " +
4713  file_name);
4714  }
4715  } else {
4716  poLayer = poDS->GetLayer(0);
4717  if (poLayer == nullptr) {
4718  throw std::runtime_error("No layers found in " + file_name);
4719  }
4720  }
4721  return *poLayer;
4722 }

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

2769  {
2770  const auto& ti = import_buffer.getTypeInfo();
2771  const int8_t* values_buffer{nullptr};
2772  if (ti.is_string()) {
2773  CHECK_EQ(kENCODING_DICT, ti.get_compression());
2774  values_buffer = import_buffer.getStringDictBuffer();
2775  } else {
2776  values_buffer = import_buffer.getAsBytes();
2777  }
2778  CHECK(values_buffer);
2779  const int logical_size = ti.is_string() ? ti.get_size() : ti.get_logical_size();
2780  switch (logical_size) {
2781  case 1: {
2782  return values_buffer[index];
2783  }
2784  case 2: {
2785  return reinterpret_cast<const int16_t*>(values_buffer)[index];
2786  }
2787  case 4: {
2788  return reinterpret_cast<const int32_t*>(values_buffer)[index];
2789  }
2790  case 8: {
2791  return reinterpret_cast<const int64_t*>(values_buffer)[index];
2792  }
2793  default:
2794  LOG(FATAL) << "Unexpected size for shard key: " << logical_size;
2795  }
2796  UNREACHABLE();
2797  return 0;
2798 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define LOG(tag)
Definition: Logger.h:285
#define UNREACHABLE()
Definition: Logger.h:337
#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 4823 of file Importer.cpp.

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

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

4823  {
4824  switch (ogr_type) {
4825  case OFTInteger:
4826  return std::make_pair(kINT, false);
4827  case OFTIntegerList:
4828  return std::make_pair(kINT, true);
4829 #if GDAL_VERSION_MAJOR > 1
4830  case OFTInteger64:
4831  return std::make_pair(kBIGINT, false);
4832  case OFTInteger64List:
4833  return std::make_pair(kBIGINT, true);
4834 #endif
4835  case OFTReal:
4836  return std::make_pair(kDOUBLE, false);
4837  case OFTRealList:
4838  return std::make_pair(kDOUBLE, true);
4839  case OFTString:
4840  return std::make_pair(kTEXT, false);
4841  case OFTStringList:
4842  return std::make_pair(kTEXT, true);
4843  case OFTDate:
4844  return std::make_pair(kDATE, false);
4845  case OFTTime:
4846  return std::make_pair(kTIME, false);
4847  case OFTDateTime:
4848  return std::make_pair(kTIMESTAMP, false);
4849  case OFTBinary:
4850  // Interpret binary blobs as byte arrays here
4851  // but actual import will store NULL as GDAL will not
4852  // extract the blob (OGRFeature::GetFieldAsString will
4853  // result in the import buffers having an empty string)
4854  return std::make_pair(kTINYINT, true);
4855  default:
4856  break;
4857  }
4858  throw std::runtime_error("Unknown OGR field type: " + std::to_string(ogr_type));
4859 }
Definition: sqltypes.h:66
std::string to_string(char const *&&v)
Definition: sqltypes.h:69
Definition: sqltypes.h:70
Definition: sqltypes.h:62

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

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

4861  {
4862  switch (ogr_type) {
4863  case wkbPoint:
4864  return kPOINT;
4865  case wkbMultiPoint:
4866  return kMULTIPOINT;
4867  case wkbLineString:
4868  return kLINESTRING;
4869  case wkbMultiLineString:
4870  return kMULTILINESTRING;
4871  case wkbPolygon:
4872  return kPOLYGON;
4873  case wkbMultiPolygon:
4874  return kMULTIPOLYGON;
4875  default:
4876  break;
4877  }
4878  throw std::runtime_error("Unknown OGR geom type: " + std::to_string(ogr_type));
4879 }
std::string to_string(char const *&&v)

+ Here is the call graph for this function: