OmniSciDB  bf83d84833
 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 2568 of file Importer.cpp.

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

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

2568  {
2569  const auto& ti = import_buffer.getTypeInfo();
2570  CHECK_EQ(kDOUBLE, ti.get_type());
2571  const auto values_buffer = import_buffer.getAsBytes();
2572  return reinterpret_cast<const double*>(may_alias_ptr(values_buffer))[index];
2573 }
#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 1684 of file Importer.cpp.

References kLINESTRING, kNULLT, kPOINT, and kPOLYGON.

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

1685  {
1686  // validate the columns
1687  // for now we can only explode into a single destination column
1688  // which must be of the child type (POLYGON, LINESTRING, POINT)
1689  int collection_col_idx = -1;
1690  int col_idx = 0;
1691  std::string collection_col_name;
1692  SQLTypes collection_child_type = kNULLT;
1693  for (auto cd_it = col_descs.begin(); cd_it != col_descs.end(); cd_it++) {
1694  auto const& cd = *cd_it;
1695  auto const col_type = cd->columnType.get_type();
1696  if (col_type == kPOLYGON || col_type == kLINESTRING || col_type == kPOINT) {
1697  if (collection_col_idx >= 0) {
1698  throw std::runtime_error(
1699  "Explode Collections: Found more than one destination column");
1700  }
1701  collection_col_idx = col_idx;
1702  collection_child_type = col_type;
1703  collection_col_name = cd->columnName;
1704  }
1705  for (int i = 0; i < cd->columnType.get_physical_cols(); ++i) {
1706  ++cd_it;
1707  }
1708  col_idx++;
1709  }
1710  if (collection_col_idx < 0) {
1711  throw std::runtime_error(
1712  "Explode Collections: Failed to find a supported column type to explode "
1713  "into");
1714  }
1715  return std::make_tuple(collection_col_idx, collection_child_type, collection_col_name);
1716 }
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 1718 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().

1723  {
1724  auto ogr_geometry_type = wkbFlatten(ogr_geometry->getGeometryType());
1725  bool is_collection = false;
1726  switch (collection_child_type) {
1727  case kPOINT:
1728  switch (ogr_geometry_type) {
1729  case wkbMultiPoint:
1730  is_collection = true;
1731  break;
1732  case wkbPoint:
1733  break;
1734  default:
1735  throw std::runtime_error(
1736  "Explode Collections: Source geo type must be MULTIPOINT or POINT");
1737  }
1738  break;
1739  case kLINESTRING:
1740  switch (ogr_geometry_type) {
1741  case wkbMultiLineString:
1742  is_collection = true;
1743  break;
1744  case wkbLineString:
1745  break;
1746  default:
1747  throw std::runtime_error(
1748  "Explode Collections: Source geo type must be MULTILINESTRING or "
1749  "LINESTRING");
1750  }
1751  break;
1752  case kPOLYGON:
1753  switch (ogr_geometry_type) {
1754  case wkbMultiPolygon:
1755  is_collection = true;
1756  break;
1757  case wkbPolygon:
1758  break;
1759  default:
1760  throw std::runtime_error(
1761  "Explode Collections: Source geo type must be MULTIPOLYGON or POLYGON");
1762  }
1763  break;
1764  default:
1765  CHECK(false) << "Unsupported geo child type " << collection_child_type;
1766  }
1767 
1768  int64_t us = 0LL;
1769 
1770  // explode or just import
1771  if (is_collection) {
1772  // cast to collection
1773  OGRGeometryCollection* collection_geometry = ogr_geometry->toGeometryCollection();
1774  CHECK(collection_geometry);
1775 
1776 #if LOG_EXPLODE_COLLECTIONS
1777  // log number of children
1778  LOG(INFO) << "Exploding row/feature " << row_or_feature_idx << " for column '"
1779  << explode_col_name << "' into " << collection_geometry->getNumGeometries()
1780  << " child rows";
1781 #endif
1782 
1783  // loop over children
1784  uint32_t child_geometry_count = 0;
1785  auto child_geometry_it = collection_geometry->begin();
1786  while (child_geometry_it != collection_geometry->end()) {
1787  // get and import this child
1788  OGRGeometry* import_geometry = *child_geometry_it;
1790  [&] { execute_import_lambda(import_geometry); });
1791 
1792  // next child
1793  child_geometry_it++;
1794  child_geometry_count++;
1795  }
1796  } else {
1797  // import non-collection row just once
1799  [&] { execute_import_lambda(ogr_geometry); });
1800  }
1801 
1802  // done
1803  return us;
1804 }
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 2561 of file Importer.cpp.

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

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

2561  {
2562  const auto& ti = import_buffer.getTypeInfo();
2563  CHECK_EQ(kFLOAT, ti.get_type());
2564  const auto values_buffer = import_buffer.getAsBytes();
2565  return reinterpret_cast<const float*>(may_alias_ptr(values_buffer))[index];
2566 }
#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 4319 of file Importer.cpp.

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

4321  {
4322  // get layer with specified name, or default to first layer
4323  OGRLayer* poLayer = nullptr;
4324  if (geo_layer_name.size()) {
4325  poLayer = poDS->GetLayerByName(geo_layer_name.c_str());
4326  if (poLayer == nullptr) {
4327  throw std::runtime_error("Layer '" + geo_layer_name + "' not found in " +
4328  file_name);
4329  }
4330  } else {
4331  poLayer = poDS->GetLayer(0);
4332  if (poLayer == nullptr) {
4333  throw std::runtime_error("No layers found in " + file_name);
4334  }
4335  }
4336  return *poLayer;
4337 }

+ 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 2530 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::distributeToShards().

2530  {
2531  const auto& ti = import_buffer.getTypeInfo();
2532  const int8_t* values_buffer{nullptr};
2533  if (ti.is_string()) {
2534  CHECK_EQ(kENCODING_DICT, ti.get_compression());
2535  values_buffer = import_buffer.getStringDictBuffer();
2536  } else {
2537  values_buffer = import_buffer.getAsBytes();
2538  }
2539  CHECK(values_buffer);
2540  const int logical_size = ti.is_string() ? ti.get_size() : ti.get_logical_size();
2541  switch (logical_size) {
2542  case 1: {
2543  return values_buffer[index];
2544  }
2545  case 2: {
2546  return reinterpret_cast<const int16_t*>(values_buffer)[index];
2547  }
2548  case 4: {
2549  return reinterpret_cast<const int32_t*>(values_buffer)[index];
2550  }
2551  case 8: {
2552  return reinterpret_cast<const int64_t*>(values_buffer)[index];
2553  }
2554  default:
2555  LOG(FATAL) << "Unexpected size for shard key: " << logical_size;
2556  }
2557  UNREACHABLE();
2558  return 0;
2559 }
#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: