OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ResultSetIteration.cpp File Reference

Iteration part of the row set interface. More...

#include "Execute.h"
#include "Geospatial/Compression.h"
#include "Geospatial/Types.h"
#include "ParserNode.h"
#include "QueryEngine/QueryEngine.h"
#include "QueryEngine/TargetValue.h"
#include "QueryEngine/Utils/FlatBuffer.h"
#include "ResultSet.h"
#include "ResultSetGeoSerialization.h"
#include "RuntimeFunctions.h"
#include "Shared/SqlTypesLayout.h"
#include "Shared/likely.h"
#include "Shared/sqltypes.h"
#include "TypePunning.h"
#include <boost/math/special_functions/fpclassify.hpp>
#include <memory>
#include <utility>
+ Include dependency graph for ResultSetIteration.cpp:

Go to the source code of this file.

Classes

struct  anonymous_namespace{ResultSetIteration.cpp}::GeoLazyFetchHandler
 
struct  anonymous_namespace{ResultSetIteration.cpp}::GeoQueryOutputFetchHandler
 
struct  anonymous_namespace{ResultSetIteration.cpp}::GeoTargetValueBuilder< GEO_SOURCE_TYPE, GeoTargetFetcher >
 

Namespaces

 anonymous_namespace{ResultSetIteration.cpp}
 

Macros

#define DEF_GET_ENTRY_AT(query_type, columnar_output)
 
#define DATA_T   int64_t
 
#define DATA_T   int32_t
 
#define DATA_T   int16_t
 
#define DATA_T   int8_t
 
#define DATA_T   float
 
#define DATA_T   double
 

Functions

TargetValue anonymous_namespace{ResultSetIteration.cpp}::make_avg_target_value (const int8_t *ptr1, const int8_t compact_sz1, const int8_t *ptr2, const int8_t compact_sz2, const TargetInfo &target_info)
 
const int8_t * anonymous_namespace{ResultSetIteration.cpp}::advance_col_buff_to_slot (const int8_t *buff, const QueryMemoryDescriptor &query_mem_desc, const std::vector< TargetInfo > &targets, const size_t slot_idx, const bool separate_varlen_storage)
 
const int8_t * anonymous_namespace{ResultSetIteration.cpp}::columnar_elem_ptr (const size_t entry_idx, const int8_t *col1_ptr, const int8_t compact_sz1)
 
int64_t anonymous_namespace{ResultSetIteration.cpp}::int_resize_cast (const int64_t ival, const size_t sz)
 
template<class T >
ScalarTargetValue anonymous_namespace{ResultSetIteration.cpp}::make_scalar_tv (const T val)
 
template<>
ScalarTargetValue anonymous_namespace{ResultSetIteration.cpp}::make_scalar_tv (const float val)
 
template<>
ScalarTargetValue anonymous_namespace{ResultSetIteration.cpp}::make_scalar_tv (const double val)
 
template<class T >
TargetValue anonymous_namespace{ResultSetIteration.cpp}::build_array_target_value (const int8_t *buff, const size_t buff_sz, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
 
TargetValue anonymous_namespace{ResultSetIteration.cpp}::build_string_array_target_value (const int32_t *buff, const size_t buff_sz, const shared::StringDictKey &dict_key, const bool translate_strings, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
 
TargetValue anonymous_namespace{ResultSetIteration.cpp}::build_array_target_value (const SQLTypeInfo &array_ti, const int8_t *buff, const size_t buff_sz, const bool translate_strings, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
 
template<class Tuple , size_t... indices>
std::vector< std::pair< const
int8_t *, const int64_t > > 
anonymous_namespace{ResultSetIteration.cpp}::make_vals_vector (std::index_sequence< indices...>, const Tuple &tuple)
 
std::unique_ptr< ArrayDatumanonymous_namespace{ResultSetIteration.cpp}::lazy_fetch_chunk (const int8_t *ptr, const int64_t varlen_ptr)
 
std::unique_ptr< ArrayDatumanonymous_namespace{ResultSetIteration.cpp}::fetch_data_from_gpu (int64_t varlen_ptr, const int64_t length, Data_Namespace::DataMgr *data_mgr, const int device_id)
 
template<typename T >
std::pair< int64_t, int64_t > anonymous_namespace{ResultSetIteration.cpp}::get_frag_id_and_local_idx (const std::vector< std::vector< T >> &frag_offsets, const size_t tab_or_col_idx, const int64_t global_idx)
 
template<size_t NDIM, typename GeospatialGeoType , typename GeoTypeTargetValue , typename GeoTypeTargetValuePtr >
TargetValue NestedArrayToGeoTargetValue (const int8_t *buf, const int64_t index, const SQLTypeInfo &ti, const ResultSet::GeoReturnType return_type)
 
TargetValue getTargetValueFromFlatBuffer (const int8_t *col_ptr, const TargetInfo &target_info, const size_t slot_idx, const size_t target_logical_idx, const size_t global_entry_idx, const size_t local_entry_idx, const bool translate_strings, const std::shared_ptr< RowSetMemoryOwner > &row_set_mem_owner_)
 
template<typename T >
size_t anonymous_namespace{ResultSetIteration.cpp}::make_bin_search (size_t l, size_t r, T &&is_empty_fn)
 

Detailed Description

Iteration part of the row set interface.

Definition in file ResultSetIteration.cpp.

Macro Definition Documentation

#define DATA_T   int64_t

Definition at line 1273 of file ResultSetIteration.cpp.

#define DATA_T   int32_t

Definition at line 1273 of file ResultSetIteration.cpp.

#define DATA_T   int16_t

Definition at line 1273 of file ResultSetIteration.cpp.

#define DATA_T   int8_t

Definition at line 1273 of file ResultSetIteration.cpp.

#define DATA_T   float

Definition at line 1273 of file ResultSetIteration.cpp.

#define DATA_T   double

Definition at line 1273 of file ResultSetIteration.cpp.

#define DEF_GET_ENTRY_AT (   query_type,
  columnar_output 
)
Value:
template DATA_T ResultSet::getEntryAt<DATA_T, query_type, columnar_output>( \
const size_t row_idx, const size_t target_idx, const size_t slot_idx) const;
#define DATA_T

Definition at line 1234 of file ResultSetIteration.cpp.

Function Documentation

TargetValue getTargetValueFromFlatBuffer ( const int8_t *  col_ptr,
const TargetInfo target_info,
const size_t  slot_idx,
const size_t  target_logical_idx,
const size_t  global_entry_idx,
const size_t  local_entry_idx,
const bool  translate_strings,
const std::shared_ptr< RowSetMemoryOwner > &  row_set_mem_owner_ 
)

Definition at line 2214 of file ResultSetIteration.cpp.

References anonymous_namespace{ResultSetIteration.cpp}::build_array_target_value(), CHECK, CHECK_EQ, CHECK_GE, SQLTypeInfo::get_type(), FlatBufferManager::NestedArrayItem< NDIM >::is_null, FlatBufferManager::isFlatBuffer(), kARRAY, FlatBufferManager::NestedArrayItem< NDIM >::nof_values, run_benchmark_import::optional, TargetInfo::sql_type, UNREACHABLE, and FlatBufferManager::NestedArrayItem< NDIM >::values.

Referenced by ResultSet::getTargetValueFromBufferColwise().

2222  {
2224  FlatBufferManager m{const_cast<int8_t*>(col_ptr)};
2225  FlatBufferManager::Status status{};
2226  CHECK(m.isNestedArray());
2227  switch (target_info.sql_type.get_type()) {
2228  case kARRAY: {
2229  ArrayDatum ad;
2231  status = m.getItem(local_entry_idx, item);
2232  if (status == FlatBufferManager::Status::Success) {
2233  ad.length = item.nof_values * m.getValueSize();
2234  ad.pointer = item.values;
2235  ad.is_null = item.is_null;
2236  } else {
2237  ad.length = 0;
2238  ad.pointer = NULL;
2239  ad.is_null = true;
2240  CHECK_EQ(status, FlatBufferManager::Status::ItemUnspecifiedError);
2241  }
2242  if (ad.is_null) {
2243  return ArrayTargetValue(boost::optional<std::vector<ScalarTargetValue>>{});
2244  }
2245  CHECK_GE(ad.length, 0u);
2246  if (ad.length > 0) {
2247  CHECK(ad.pointer);
2248  }
2249  return build_array_target_value(target_info.sql_type,
2250  ad.pointer,
2251  ad.length,
2252  translate_strings,
2253  row_set_mem_owner_);
2254  } break;
2255  default:
2256  UNREACHABLE() << "ti=" << target_info.sql_type;
2257  }
2258  CHECK(false);
2259  return {};
2260 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
SQLTypeInfo sql_type
Definition: TargetInfo.h:52
#define UNREACHABLE()
Definition: Logger.h:338
#define CHECK_GE(x, y)
Definition: Logger.h:306
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
TargetValue build_array_target_value(const int8_t *buff, const size_t buff_sz, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
std::conditional_t< is_cuda_compiler(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
Definition: sqltypes.h:229
boost::optional< std::vector< ScalarTargetValue >> ArrayTargetValue
Definition: TargetValue.h:181
#define CHECK(condition)
Definition: Logger.h:291
HOST static DEVICE bool isFlatBuffer(const void *buffer)
Definition: FlatBuffer.h:528

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<size_t NDIM, typename GeospatialGeoType , typename GeoTypeTargetValue , typename GeoTypeTargetValuePtr >
TargetValue NestedArrayToGeoTargetValue ( const int8_t *  buf,
const int64_t  index,
const SQLTypeInfo ti,
const ResultSet::GeoReturnType  return_type 
)

Definition at line 1520 of file ResultSetIteration.cpp.

References CHECK_EQ, Geospatial::decompress_coords< double, SQLTypeInfo >(), ResultSet::GeoTargetValue, ResultSet::GeoTargetValueGpuPtr, ResultSet::GeoTargetValuePtr, SQLTypeInfo::get_compression(), SQLTypeInfoLite::is_geoint(), FlatBufferManager::NestedArrayItem< NDIM >::is_null, kENCODING_GEOINT, kENCODING_NONE, FlatBufferManager::NestedArrayItem< NDIM >::nof_sizes, FlatBufferManager::NestedArrayItem< NDIM >::nof_values, FlatBufferManager::NestedArrayItem< NDIM >::sizes_buffers, FlatBufferManager::NestedArrayItem< NDIM >::sizes_lengths, UNREACHABLE, FlatBufferManager::NestedArrayItem< NDIM >::values, and ResultSet::WktString.

Referenced by ResultSet::makeGeoTargetValue().

1523  {
1524  FlatBufferManager m{const_cast<int8_t*>(buf)};
1525  const SQLTypeInfoLite* ti_lite =
1526  reinterpret_cast<const SQLTypeInfoLite*>(m.get_user_data_buffer());
1527  if (ti_lite->is_geoint()) {
1529  } else {
1531  }
1533  auto status = m.getItem(index, item);
1534  CHECK_EQ(status, FlatBufferManager::Status::Success);
1535  if (!item.is_null) {
1536  // to ensure we can access item.sizes_buffers[...] and item.sizes_lengths[...]
1537  CHECK_EQ(item.nof_sizes, NDIM - 1);
1538  }
1539  switch (return_type) {
1541  if (item.is_null) {
1542  return NullableString(nullptr);
1543  }
1544  std::vector<double> coords;
1545  if (ti_lite->is_geoint()) {
1547  ti, item.values, 2 * item.nof_values * sizeof(int32_t));
1548  } else {
1549  const double* values_buf = reinterpret_cast<const double*>(item.values);
1550  coords.insert(coords.end(), values_buf, values_buf + 2 * item.nof_values);
1551  }
1552  if constexpr (NDIM == 1) {
1553  GeospatialGeoType obj(coords);
1554  return NullableString(obj.getWktString());
1555  } else if constexpr (NDIM == 2) {
1556  std::vector<int32_t> rings;
1557  rings.insert(rings.end(),
1558  item.sizes_buffers[0],
1559  item.sizes_buffers[0] + item.sizes_lengths[0]);
1560  GeospatialGeoType obj(coords, rings);
1561  return NullableString(obj.getWktString());
1562  } else if constexpr (NDIM == 3) {
1563  std::vector<int32_t> rings;
1564  std::vector<int32_t> poly_rings;
1565  poly_rings.insert(poly_rings.end(),
1566  item.sizes_buffers[0],
1567  item.sizes_buffers[0] + item.sizes_lengths[0]);
1568  rings.insert(rings.end(),
1569  item.sizes_buffers[1],
1570  item.sizes_buffers[1] + item.sizes_lengths[1]);
1571  GeospatialGeoType obj(coords, rings, poly_rings);
1572  return NullableString(obj.getWktString());
1573  } else {
1574  UNREACHABLE();
1575  }
1576  } break;
1578  if (item.is_null) {
1579  return GeoTargetValue();
1580  }
1581  std::vector<double> coords;
1582  if (ti_lite->is_geoint()) {
1584  ti, item.values, 2 * item.nof_values * sizeof(int32_t));
1585  } else {
1586  const double* values_buf = reinterpret_cast<const double*>(item.values);
1587  coords.insert(coords.end(), values_buf, values_buf + 2 * item.nof_values);
1588  }
1589  if constexpr (NDIM == 1) {
1590  return GeoTargetValue(GeoTypeTargetValue(coords));
1591  } else if constexpr (NDIM == 2) {
1592  std::vector<int32_t> rings;
1593  rings.insert(rings.end(),
1594  item.sizes_buffers[0],
1595  item.sizes_buffers[0] + item.sizes_lengths[0]);
1596  return GeoTargetValue(GeoTypeTargetValue(coords, rings));
1597  } else if constexpr (NDIM == 3) {
1598  std::vector<int32_t> rings;
1599  std::vector<int32_t> poly_rings;
1600  poly_rings.insert(poly_rings.end(),
1601  item.sizes_buffers[0],
1602  item.sizes_buffers[0] + item.sizes_lengths[0]);
1603  rings.insert(rings.end(),
1604  item.sizes_buffers[1],
1605  item.sizes_buffers[1] + item.sizes_lengths[1]);
1606  return GeoTargetValue(GeoTypeTargetValue(coords, rings, poly_rings));
1607  } else {
1608  UNREACHABLE();
1609  }
1610  } break;
1613  if (item.is_null) {
1614  return GeoTypeTargetValuePtr();
1615  }
1616  auto coords = std::make_shared<VarlenDatum>(
1617  item.nof_values * m.getValueSize(), item.values, false);
1618 
1619  if constexpr (NDIM == 1) {
1620  return GeoTypeTargetValuePtr({std::move(coords)});
1621  } else if constexpr (NDIM == 2) {
1622  auto rings = std::make_shared<VarlenDatum>(
1623  item.sizes_lengths[0] * sizeof(int32_t),
1624  reinterpret_cast<int8_t*>(item.sizes_buffers[0]),
1625  false);
1626  return GeoTypeTargetValuePtr({std::move(coords), std::move(rings)});
1627  } else if constexpr (NDIM == 3) {
1628  auto poly_rings = std::make_shared<VarlenDatum>(
1629  item.sizes_lengths[0] * sizeof(int32_t),
1630  reinterpret_cast<int8_t*>(item.sizes_buffers[0]),
1631  false);
1632  auto rings = std::make_shared<VarlenDatum>(
1633  item.sizes_lengths[1] * sizeof(int32_t),
1634  reinterpret_cast<int8_t*>(item.sizes_buffers[1]),
1635  false);
1636  return GeoTypeTargetValuePtr(
1637  {std::move(coords), std::move(rings), std::move(poly_rings)});
1638  } else {
1639  UNREACHABLE();
1640  }
1641  } break;
1642  default:
1643  UNREACHABLE();
1644  }
1645  return TargetValue(nullptr);
1646 }
bool is_geoint() const
Definition: sqltypes_lite.h:61
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define UNREACHABLE()
Definition: Logger.h:338
std::shared_ptr< std::vector< double > > decompress_coords< double, SQLTypeInfo >(const SQLTypeInfo &geo_ti, const int8_t *coords, const size_t coords_sz)
boost::optional< boost::variant< GeoPointTargetValue, GeoMultiPointTargetValue, GeoLineStringTargetValue, GeoMultiLineStringTargetValue, GeoPolyTargetValue, GeoMultiPolyTargetValue >> GeoTargetValue
Definition: TargetValue.h:187
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
boost::variant< std::string, void * > NullableString
Definition: TargetValue.h:179
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:195

+ Here is the call graph for this function:

+ Here is the caller graph for this function: