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

Functions

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 OGRDataSourceUqPtr &poDS, const std::string &file_name)
 

Function Documentation

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

Definition at line 2624 of file Importer.cpp.

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

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

2624  {
2625  const auto& ti = import_buffer.getTypeInfo();
2626  CHECK_EQ(kDOUBLE, ti.get_type());
2627  const auto values_buffer = import_buffer.getAsBytes();
2628  return reinterpret_cast<const double*>(may_alias_ptr(values_buffer))[index];
2629 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205

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

References i, kLINESTRING, kNULLT, kPOINT, and kPOLYGON.

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

1703  {
1704  // validate the columns
1705  // for now we can only explode into a single destination column
1706  // which must be of the child type (POLYGON, LINESTRING, POINT)
1707  int collection_col_idx = -1;
1708  int col_idx = 0;
1709  std::string collection_col_name;
1710  SQLTypes collection_child_type = kNULLT;
1711  for (auto cd_it = col_descs.begin(); cd_it != col_descs.end(); cd_it++) {
1712  auto const& cd = *cd_it;
1713  auto const col_type = cd->columnType.get_type();
1714  if (col_type == kPOLYGON || col_type == kLINESTRING || col_type == kPOINT) {
1715  if (collection_col_idx >= 0) {
1716  throw std::runtime_error(
1717  "Explode Collections: Found more than one destination column");
1718  }
1719  collection_col_idx = col_idx;
1720  collection_child_type = col_type;
1721  collection_col_name = cd->columnName;
1722  }
1723  for (int i = 0; i < cd->columnType.get_physical_cols(); ++i) {
1724  ++cd_it;
1725  }
1726  col_idx++;
1727  }
1728  if (collection_col_idx < 0) {
1729  throw std::runtime_error(
1730  "Explode Collections: Failed to find a supported column type to explode "
1731  "into");
1732  }
1733  return std::make_tuple(collection_col_idx, collection_child_type, collection_col_name);
1734 }
SQLTypes
Definition: sqltypes.h:37

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

1741  {
1742  auto ogr_geometry_type = wkbFlatten(ogr_geometry->getGeometryType());
1743  bool is_collection = false;
1744  switch (collection_child_type) {
1745  case kPOINT:
1746  switch (ogr_geometry_type) {
1747  case wkbMultiPoint:
1748  is_collection = true;
1749  break;
1750  case wkbPoint:
1751  break;
1752  default:
1753  throw std::runtime_error(
1754  "Explode Collections: Source geo type must be MULTIPOINT or POINT");
1755  }
1756  break;
1757  case kLINESTRING:
1758  switch (ogr_geometry_type) {
1759  case wkbMultiLineString:
1760  is_collection = true;
1761  break;
1762  case wkbLineString:
1763  break;
1764  default:
1765  throw std::runtime_error(
1766  "Explode Collections: Source geo type must be MULTILINESTRING or "
1767  "LINESTRING");
1768  }
1769  break;
1770  case kPOLYGON:
1771  switch (ogr_geometry_type) {
1772  case wkbMultiPolygon:
1773  is_collection = true;
1774  break;
1775  case wkbPolygon:
1776  break;
1777  default:
1778  throw std::runtime_error(
1779  "Explode Collections: Source geo type must be MULTIPOLYGON or POLYGON");
1780  }
1781  break;
1782  default:
1783  CHECK(false) << "Unsupported geo child type " << collection_child_type;
1784  }
1785 
1786  int64_t us = 0LL;
1787 
1788  // explode or just import
1789  if (is_collection) {
1790  // cast to collection
1791  OGRGeometryCollection* collection_geometry = ogr_geometry->toGeometryCollection();
1792  CHECK(collection_geometry);
1793 
1794 #if LOG_EXPLODE_COLLECTIONS
1795  // log number of children
1796  LOG(INFO) << "Exploding row/feature " << row_or_feature_idx << " for column '"
1797  << explode_col_name << "' into " << collection_geometry->getNumGeometries()
1798  << " child rows";
1799 #endif
1800 
1801  // loop over children
1802  uint32_t child_geometry_count = 0;
1803  auto child_geometry_it = collection_geometry->begin();
1804  while (child_geometry_it != collection_geometry->end()) {
1805  // get and import this child
1806  OGRGeometry* import_geometry = *child_geometry_it;
1808  [&] { execute_import_lambda(import_geometry); });
1809 
1810  // next child
1811  child_geometry_it++;
1812  child_geometry_count++;
1813  }
1814  } else {
1815  // import non-collection row just once
1817  [&] { execute_import_lambda(ogr_geometry); });
1818  }
1819 
1820  // done
1821  return us;
1822 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:188
#define CHECK(condition)
Definition: Logger.h:197

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

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

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

2617  {
2618  const auto& ti = import_buffer.getTypeInfo();
2619  CHECK_EQ(kFLOAT, ti.get_type());
2620  const auto values_buffer = import_buffer.getAsBytes();
2621  return reinterpret_cast<const float*>(may_alias_ptr(values_buffer))[index];
2622 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205

+ 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 OGRDataSourceUqPtr &  poDS,
const std::string &  file_name 
)

Definition at line 4455 of file Importer.cpp.

Referenced by import_export::Importer::gdalToColumnDescriptors(), import_export::Importer::importGDAL(), and import_export::Importer::readMetadataSampleGDAL().

4457  {
4458  // get layer with specified name, or default to first layer
4459  OGRLayer* poLayer = nullptr;
4460  if (geo_layer_name.size()) {
4461  poLayer = poDS->GetLayerByName(geo_layer_name.c_str());
4462  if (poLayer == nullptr) {
4463  throw std::runtime_error("Layer '" + geo_layer_name + "' not found in " +
4464  file_name);
4465  }
4466  } else {
4467  poLayer = poDS->GetLayer(0);
4468  if (poLayer == nullptr) {
4469  throw std::runtime_error("No layers found in " + file_name);
4470  }
4471  }
4472  return *poLayer;
4473 }

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

2586  {
2587  const auto& ti = import_buffer.getTypeInfo();
2588  const int8_t* values_buffer{nullptr};
2589  if (ti.is_string()) {
2590  CHECK_EQ(kENCODING_DICT, ti.get_compression());
2591  values_buffer = import_buffer.getStringDictBuffer();
2592  } else {
2593  values_buffer = import_buffer.getAsBytes();
2594  }
2595  CHECK(values_buffer);
2596  const int logical_size = ti.is_string() ? ti.get_size() : ti.get_logical_size();
2597  switch (logical_size) {
2598  case 1: {
2599  return values_buffer[index];
2600  }
2601  case 2: {
2602  return reinterpret_cast<const int16_t*>(values_buffer)[index];
2603  }
2604  case 4: {
2605  return reinterpret_cast<const int32_t*>(values_buffer)[index];
2606  }
2607  case 8: {
2608  return reinterpret_cast<const int64_t*>(values_buffer)[index];
2609  }
2610  default:
2611  LOG(FATAL) << "Unexpected size for shard key: " << logical_size;
2612  }
2613  UNREACHABLE();
2614  return 0;
2615 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
#define LOG(tag)
Definition: Logger.h:188
#define UNREACHABLE()
Definition: Logger.h:241
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

+ Here is the caller graph for this function: