OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{ResultSetIteration.cpp} Namespace Reference

Classes

struct  GeoLazyFetchHandler
 
struct  GeoQueryOutputFetchHandler
 
struct  GeoTargetValueBuilder
 

Functions

TargetValue 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 * 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 * columnar_elem_ptr (const size_t entry_idx, const int8_t *col1_ptr, const int8_t compact_sz1)
 
int64_t int_resize_cast (const int64_t ival, const size_t sz)
 
template<class T >
ScalarTargetValue make_scalar_tv (const T val)
 
template<>
ScalarTargetValue make_scalar_tv (const float val)
 
template<>
ScalarTargetValue make_scalar_tv (const double val)
 
template<class T >
TargetValue build_array_target_value (const int8_t *buff, const size_t buff_sz, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
 
TargetValue 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 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 > > 
make_vals_vector (std::index_sequence< indices...>, const Tuple &tuple)
 
std::unique_ptr< ArrayDatumlazy_fetch_chunk (const int8_t *ptr, const int64_t varlen_ptr)
 
std::unique_ptr< ArrayDatumfetch_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 > 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<typename T >
size_t make_bin_search (size_t l, size_t r, T &&is_empty_fn)
 

Function Documentation

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 
)

Definition at line 82 of file ResultSetIteration.cpp.

References advance_slot(), advance_to_next_columnar_target_buff(), CHECK, CHECK_LT, get_cols_ptr(), QueryMemoryDescriptor::getBufferColSlotCount(), and kAVG.

Referenced by ResultSetStorage::isEmptyEntryColumnar().

86  {
87  auto crt_col_ptr = get_cols_ptr(buff, query_mem_desc);
88  const auto buffer_col_count = query_mem_desc.getBufferColSlotCount();
89  size_t agg_col_idx{0};
90  for (size_t target_idx = 0; target_idx < targets.size(); ++target_idx) {
91  if (agg_col_idx == slot_idx) {
92  return crt_col_ptr;
93  }
94  CHECK_LT(agg_col_idx, buffer_col_count);
95  const auto& agg_info = targets[target_idx];
96  crt_col_ptr =
97  advance_to_next_columnar_target_buff(crt_col_ptr, query_mem_desc, agg_col_idx);
98  if (agg_info.is_agg && agg_info.agg_kind == kAVG) {
99  if (agg_col_idx + 1 == slot_idx) {
100  return crt_col_ptr;
101  }
103  crt_col_ptr, query_mem_desc, agg_col_idx + 1);
104  }
105  agg_col_idx = advance_slot(agg_col_idx, agg_info, separate_varlen_storage);
106  }
107  CHECK(false);
108  return nullptr;
109 }
T advance_to_next_columnar_target_buff(T target_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t target_slot_idx)
size_t advance_slot(const size_t j, const TargetInfo &target_info, const bool separate_varlen_storage)
#define CHECK_LT(x, y)
Definition: Logger.h:303
#define CHECK(condition)
Definition: Logger.h:291
T get_cols_ptr(T buff, const QueryMemoryDescriptor &query_mem_desc)
Definition: sqldefs.h:74

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 
)

Definition at line 779 of file ResultSetIteration.cpp.

References CHECK_EQ, and heavydb.dtypes::T.

Referenced by getTargetValueFromFlatBuffer(), and ResultSet::makeVarlenTargetValue().

782  {
783  std::vector<ScalarTargetValue> values;
784  auto buff_elems = reinterpret_cast<const T*>(buff);
785  CHECK_EQ(size_t(0), buff_sz % sizeof(T));
786  const size_t num_elems = buff_sz / sizeof(T);
787  for (size_t i = 0; i < num_elems; ++i) {
788  values.push_back(make_scalar_tv<T>(buff_elems[i]));
789  }
790  return ArrayTargetValue(values);
791 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
boost::optional< std::vector< ScalarTargetValue >> ArrayTargetValue
Definition: TargetValue.h:181

+ Here is the caller graph for this function:

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 
)

Definition at line 828 of file ResultSetIteration.cpp.

References build_string_array_target_value(), CHECK, SQLTypeInfo::get_elem_type(), and SQLTypeInfo::is_array().

833  {
834  CHECK(array_ti.is_array());
835  const auto& elem_ti = array_ti.get_elem_type();
836  if (elem_ti.is_string()) {
837  return build_string_array_target_value(reinterpret_cast<const int32_t*>(buff),
838  buff_sz,
839  elem_ti.getStringDictKey(),
840  translate_strings,
841  row_set_mem_owner);
842  }
843  switch (elem_ti.get_size()) {
844  case 1:
845  return build_array_target_value<int8_t>(buff, buff_sz, row_set_mem_owner);
846  case 2:
847  return build_array_target_value<int16_t>(buff, buff_sz, row_set_mem_owner);
848  case 4:
849  if (elem_ti.is_fp()) {
850  return build_array_target_value<float>(buff, buff_sz, row_set_mem_owner);
851  } else {
852  return build_array_target_value<int32_t>(buff, buff_sz, row_set_mem_owner);
853  }
854  case 8:
855  if (elem_ti.is_fp()) {
856  return build_array_target_value<double>(buff, buff_sz, row_set_mem_owner);
857  } else {
858  return build_array_target_value<int64_t>(buff, buff_sz, row_set_mem_owner);
859  }
860  default:
861  CHECK(false);
862  }
863  CHECK(false);
864  return TargetValue(nullptr);
865 }
TargetValue 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)
#define CHECK(condition)
Definition: Logger.h:291
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:195
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:975
bool is_array() const
Definition: sqltypes.h:583

+ Here is the call graph for this function:

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 
)

Definition at line 793 of file ResultSetIteration.cpp.

References CHECK_EQ, shared::StringDictKey::dict_id, StringDictionaryProxy::getString(), ResultSet::getString(), and NULL_INT.

Referenced by build_array_target_value().

798  {
799  std::vector<ScalarTargetValue> values;
800  CHECK_EQ(size_t(0), buff_sz % sizeof(int32_t));
801  const size_t num_elems = buff_sz / sizeof(int32_t);
802  if (translate_strings) {
803  for (size_t i = 0; i < num_elems; ++i) {
804  const auto string_id = buff[i];
805 
806  if (string_id == NULL_INT) {
807  values.emplace_back(NullableString(nullptr));
808  } else {
809  if (dict_key.dict_id == 0) {
810  StringDictionaryProxy* sdp = row_set_mem_owner->getLiteralStringDictProxy();
811  values.emplace_back(sdp->getString(string_id));
812  } else {
813  values.emplace_back(NullableString(
814  row_set_mem_owner
815  ->getOrAddStringDictProxy(dict_key, /*with_generation=*/false)
816  ->getString(string_id)));
817  }
818  }
819  }
820  } else {
821  for (size_t i = 0; i < num_elems; i++) {
822  values.emplace_back(static_cast<int64_t>(buff[i]));
823  }
824  }
825  return ArrayTargetValue(values);
826 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::string getString(int32_t string_id) const
#define NULL_INT
boost::optional< std::vector< ScalarTargetValue >> ArrayTargetValue
Definition: TargetValue.h:181
boost::variant< std::string, void * > NullableString
Definition: TargetValue.h:179

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 
)

Definition at line 345 of file ResultSetIteration.cpp.

Referenced by ResultSet::ColumnWiseTargetAccessor::getColumnInternal(), and ResultSet::getTargetValueFromBufferColwise().

347  {
348  return col1_ptr + compact_sz1 * entry_idx;
349 }

+ Here is the caller graph for this function:

std::unique_ptr<ArrayDatum> anonymous_namespace{ResultSetIteration.cpp}::fetch_data_from_gpu ( int64_t  varlen_ptr,
const int64_t  length,
Data_Namespace::DataMgr data_mgr,
const int  device_id 
)
inline

Definition at line 927 of file ResultSetIteration.cpp.

References getQueryEngineCudaStreamForDevice().

Referenced by anonymous_namespace{ResultSetIteration.cpp}::GeoQueryOutputFetchHandler::yieldGpuDatumFetcher().

930  {
931  auto cpu_buf =
932  std::shared_ptr<int8_t>(new int8_t[length], std::default_delete<int8_t[]>());
933  auto allocator = std::make_unique<CudaAllocator>(
934  data_mgr, device_id, getQueryEngineCudaStreamForDevice(device_id));
935  allocator->copyFromDevice(cpu_buf.get(), reinterpret_cast<int8_t*>(varlen_ptr), length);
936  // Just fetching the data from gpu, not checking geo nullness
937  return std::make_unique<ArrayDatum>(length, cpu_buf, false);
938 }
CUstream getQueryEngineCudaStreamForDevice(int device_num)
Definition: QueryEngine.cpp:7

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 
)
inline

Definition at line 1069 of file ResultSetIteration.cpp.

References CHECK_GE, and CHECK_LT.

Referenced by ResultSet::getColumnFrag().

1072  {
1073  CHECK_GE(global_idx, int64_t(0));
1074  for (int64_t frag_id = frag_offsets.size() - 1; frag_id > 0; --frag_id) {
1075  CHECK_LT(tab_or_col_idx, frag_offsets[frag_id].size());
1076  const auto frag_off = static_cast<int64_t>(frag_offsets[frag_id][tab_or_col_idx]);
1077  if (frag_off < global_idx) {
1078  return {frag_id, global_idx - frag_off};
1079  }
1080  }
1081  return {-1, -1};
1082 }
#define CHECK_GE(x, y)
Definition: Logger.h:306
#define CHECK_LT(x, y)
Definition: Logger.h:303

+ Here is the caller graph for this function:

int64_t anonymous_namespace{ResultSetIteration.cpp}::int_resize_cast ( const int64_t  ival,
const size_t  sz 
)

Definition at line 351 of file ResultSetIteration.cpp.

References UNREACHABLE.

Referenced by ResultSet::RowWiseTargetAccessor::getColumnInternal(), ResultSet::ColumnWiseTargetAccessor::getColumnInternal(), and ResultSet::makeTargetValue().

351  {
352  switch (sz) {
353  case 8:
354  return ival;
355  case 4:
356  return static_cast<int32_t>(ival);
357  case 2:
358  return static_cast<int16_t>(ival);
359  case 1:
360  return static_cast<int8_t>(ival);
361  default:
362  UNREACHABLE();
363  }
364  UNREACHABLE();
365  return 0;
366 }
#define UNREACHABLE()
Definition: Logger.h:338

+ Here is the caller graph for this function:

std::unique_ptr<ArrayDatum> anonymous_namespace{ResultSetIteration.cpp}::lazy_fetch_chunk ( const int8_t *  ptr,
const int64_t  varlen_ptr 
)
inline

Definition at line 875 of file ResultSetIteration.cpp.

References CHECK, and ChunkIter_get_nth().

Referenced by anonymous_namespace{ResultSetIteration.cpp}::GeoLazyFetchHandler::fetch().

876  {
877  auto ad = std::make_unique<ArrayDatum>();
878  bool is_end;
879  ChunkIter_get_nth(reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(ptr)),
880  varlen_ptr,
881  ad.get(),
882  &is_end);
883  CHECK(!is_end);
884  return ad;
885 }
DEVICE void ChunkIter_get_nth(ChunkIter *it, int n, bool uncompress, VarlenDatum *result, bool *is_end)
Definition: ChunkIter.cpp:182
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 
)

Definition at line 46 of file ResultSetIteration.cpp.

References TargetInfo::agg_arg_type, TargetInfo::agg_kind, CHECK, kAVG, pair_to_double(), read_int_from_buff(), TargetInfo::sql_type, and takes_float_argument().

Referenced by ResultSet::getTargetValueFromBufferColwise(), and ResultSet::getTargetValueFromBufferRowwise().

50  {
51  int64_t sum{0};
52  CHECK(target_info.agg_kind == kAVG);
53  const bool float_argument_input = takes_float_argument(target_info);
54  const auto actual_compact_sz1 = float_argument_input ? sizeof(float) : compact_sz1;
55  const auto& agg_ti = target_info.agg_arg_type;
56  if (agg_ti.is_integer() || agg_ti.is_decimal()) {
57  sum = read_int_from_buff(ptr1, actual_compact_sz1);
58  } else if (agg_ti.is_fp()) {
59  switch (actual_compact_sz1) {
60  case 8: {
61  double d = *reinterpret_cast<const double*>(ptr1);
62  sum = *reinterpret_cast<const int64_t*>(may_alias_ptr(&d));
63  break;
64  }
65  case 4: {
66  double d = *reinterpret_cast<const float*>(ptr1);
67  sum = *reinterpret_cast<const int64_t*>(may_alias_ptr(&d));
68  break;
69  }
70  default:
71  CHECK(false);
72  }
73  } else {
74  CHECK(false);
75  }
76  const auto count = read_int_from_buff(ptr2, compact_sz2);
77  return pair_to_double({sum, count}, target_info.sql_type, false);
78 }
SQLTypeInfo sql_type
Definition: TargetInfo.h:52
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
double pair_to_double(const std::pair< int64_t, int64_t > &fp_pair, const SQLTypeInfo &ti, const bool float_argument_input)
bool takes_float_argument(const TargetInfo &target_info)
Definition: TargetInfo.h:106
SQLTypeInfo agg_arg_type
Definition: TargetInfo.h:53
SQLAgg agg_kind
Definition: TargetInfo.h:51
#define CHECK(condition)
Definition: Logger.h:291
Definition: sqldefs.h:74

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
size_t anonymous_namespace{ResultSetIteration.cpp}::make_bin_search ( size_t  l,
size_t  r,
T &&  is_empty_fn 
)
inline

Definition at line 2551 of file ResultSetIteration.cpp.

Referenced by ResultSetStorage::binSearchRowCount().

2551  {
2552  // Avoid search if there are no empty keys.
2553  if (!is_empty_fn(r - 1)) {
2554  return r;
2555  }
2556 
2557  --r;
2558  while (l != r) {
2559  size_t c = (l + r) / 2;
2560  if (is_empty_fn(c)) {
2561  r = c;
2562  } else {
2563  l = c + 1;
2564  }
2565  }
2566 
2567  return r;
2568 }

+ Here is the caller graph for this function:

template<class T >
ScalarTargetValue anonymous_namespace{ResultSetIteration.cpp}::make_scalar_tv ( const T  val)

Definition at line 764 of file ResultSetIteration.cpp.

764  {
765  return ScalarTargetValue(static_cast<int64_t>(val));
766 }
boost::variant< int64_t, double, float, NullableString > ScalarTargetValue
Definition: TargetValue.h:180
template<>
ScalarTargetValue anonymous_namespace{ResultSetIteration.cpp}::make_scalar_tv ( const float  val)

Definition at line 769 of file ResultSetIteration.cpp.

769  {
770  return ScalarTargetValue(val);
771 }
boost::variant< int64_t, double, float, NullableString > ScalarTargetValue
Definition: TargetValue.h:180
template<>
ScalarTargetValue anonymous_namespace{ResultSetIteration.cpp}::make_scalar_tv ( const double  val)

Definition at line 774 of file ResultSetIteration.cpp.

774  {
775  return ScalarTargetValue(val);
776 }
boost::variant< int64_t, double, float, NullableString > ScalarTargetValue
Definition: TargetValue.h:180
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 
)
inline

Definition at line 868 of file ResultSetIteration.cpp.

Referenced by anonymous_namespace{ResultSetIteration.cpp}::GeoLazyFetchHandler::fetch().

870  {
871  return std::vector<std::pair<const int8_t*, const int64_t>>{
872  std::make_pair(std::get<2 * indices>(tuple), std::get<2 * indices + 1>(tuple))...};
873 }

+ Here is the caller graph for this function: