OmniSciDB  bf83d84833
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 int dict_id, const bool translate_strings, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const Catalog_Namespace::Catalog *catalog)
 
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, const Catalog_Namespace::Catalog *catalog)
 
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)
 
double calculate_quantile (int8_t const *ptr, double const q)
 
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 83 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().

87  {
88  auto crt_col_ptr = get_cols_ptr(buff, query_mem_desc);
89  const auto buffer_col_count = query_mem_desc.getBufferColSlotCount();
90  size_t agg_col_idx{0};
91  for (size_t target_idx = 0; target_idx < targets.size(); ++target_idx) {
92  if (agg_col_idx == slot_idx) {
93  return crt_col_ptr;
94  }
95  CHECK_LT(agg_col_idx, buffer_col_count);
96  const auto& agg_info = targets[target_idx];
97  crt_col_ptr =
98  advance_to_next_columnar_target_buff(crt_col_ptr, query_mem_desc, agg_col_idx);
99  if (agg_info.is_agg && agg_info.agg_kind == kAVG) {
100  if (agg_col_idx + 1 == slot_idx) {
101  return crt_col_ptr;
102  }
104  crt_col_ptr, query_mem_desc, agg_col_idx + 1);
105  }
106  agg_col_idx = advance_slot(agg_col_idx, agg_info, separate_varlen_storage);
107  }
108  CHECK(false);
109  return nullptr;
110 }
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:207
#define CHECK(condition)
Definition: Logger.h:197
size_t getBufferColSlotCount() const
T get_cols_ptr(T buff, const QueryMemoryDescriptor &query_mem_desc)
Definition: sqldefs.h:72

+ 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 780 of file ResultSetIteration.cpp.

References CHECK_EQ, and omnisci.dtypes::T.

Referenced by ResultSet::makeVarlenTargetValue().

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

+ 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,
const Catalog_Namespace::Catalog catalog 
)

Definition at line 830 of file ResultSetIteration.cpp.

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

835  {
836  CHECK(array_ti.is_array());
837  const auto& elem_ti = array_ti.get_elem_type();
838  if (elem_ti.is_string()) {
839  return build_string_array_target_value(reinterpret_cast<const int32_t*>(buff),
840  buff_sz,
841  elem_ti.get_comp_param(),
842  translate_strings,
843  row_set_mem_owner,
844  catalog);
845  }
846  switch (elem_ti.get_size()) {
847  case 1:
848  return build_array_target_value<int8_t>(buff, buff_sz, row_set_mem_owner);
849  case 2:
850  return build_array_target_value<int16_t>(buff, buff_sz, row_set_mem_owner);
851  case 4:
852  if (elem_ti.is_fp()) {
853  return build_array_target_value<float>(buff, buff_sz, row_set_mem_owner);
854  } else {
855  return build_array_target_value<int32_t>(buff, buff_sz, row_set_mem_owner);
856  }
857  case 8:
858  if (elem_ti.is_fp()) {
859  return build_array_target_value<double>(buff, buff_sz, row_set_mem_owner);
860  } else {
861  return build_array_target_value<int64_t>(buff, buff_sz, row_set_mem_owner);
862  }
863  default:
864  CHECK(false);
865  }
866  CHECK(false);
867  return TargetValue(nullptr);
868 }
TargetValue build_string_array_target_value(const int32_t *buff, const size_t buff_sz, const int dict_id, const bool translate_strings, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const Catalog_Namespace::Catalog *catalog)
#define CHECK(condition)
Definition: Logger.h:197
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:167
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:697
bool is_array() const
Definition: sqltypes.h:486

+ 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 int  dict_id,
const bool  translate_strings,
std::shared_ptr< RowSetMemoryOwner row_set_mem_owner,
const Catalog_Namespace::Catalog catalog 
)

Definition at line 794 of file ResultSetIteration.cpp.

References CHECK_EQ, StringDictionaryProxy::getString(), and NULL_INT.

Referenced by build_array_target_value().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double anonymous_namespace{ResultSetIteration.cpp}::calculate_quantile ( int8_t const *  ptr,
double const  q 
)

Definition at line 1852 of file ResultSetIteration.cpp.

References CHECK, and NULL_DOUBLE.

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

1852  {
1853  static_assert(sizeof(int64_t) == sizeof(quantile::TDigest*));
1854  auto* t_digest = *reinterpret_cast<quantile::TDigest* const*>(ptr);
1855  CHECK(t_digest) << "ptr=" << (void const*)ptr << ", q=" << q;
1856  t_digest->mergeBuffer();
1857  double const median = t_digest->quantile(q);
1858  return boost::math::isnan(median) ? NULL_DOUBLE : median;
1859 }
#define NULL_DOUBLE
#define CHECK(condition)
Definition: Logger.h:197

+ 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 347 of file ResultSetIteration.cpp.

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

349  {
350  return col1_ptr + compact_sz1 * entry_idx;
351 }

+ 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 930 of file ResultSetIteration.cpp.

References copy_from_gpu().

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

933  {
934  auto cpu_buf = std::shared_ptr<int8_t>(new int8_t[length], FreeDeleter());
936  data_mgr, cpu_buf.get(), static_cast<CUdeviceptr>(varlen_ptr), length, device_id);
937  // Just fetching the data from gpu, not checking geo nullness
938  return std::make_unique<ArrayDatum>(length, cpu_buf, false);
939 }
unsigned long long CUdeviceptr
Definition: nocuda.h:27
void copy_from_gpu(Data_Namespace::DataMgr *data_mgr, void *dst, const CUdeviceptr src, const size_t num_bytes, const int device_id)

+ 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 1065 of file ResultSetIteration.cpp.

References CHECK_GE, and CHECK_LT.

Referenced by ResultSet::getColumnFrag().

1068  {
1069  CHECK_GE(global_idx, int64_t(0));
1070  for (int64_t frag_id = frag_offsets.size() - 1; frag_id > 0; --frag_id) {
1071  CHECK_LT(tab_or_col_idx, frag_offsets[frag_id].size());
1072  const auto frag_off = static_cast<int64_t>(frag_offsets[frag_id][tab_or_col_idx]);
1073  if (frag_off < global_idx) {
1074  return {frag_id, global_idx - frag_off};
1075  }
1076  }
1077  return {-1, -1};
1078 }
#define CHECK_GE(x, y)
Definition: Logger.h:210
#define CHECK_LT(x, y)
Definition: Logger.h:207

+ 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 353 of file ResultSetIteration.cpp.

References UNREACHABLE.

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

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

+ 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 878 of file ResultSetIteration.cpp.

References CHECK, and ChunkIter_get_nth().

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

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

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

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

+ 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 2133 of file ResultSetIteration.cpp.

Referenced by ResultSetStorage::binSearchRowCount().

2133  {
2134  // Avoid search if there are no empty keys.
2135  if (!is_empty_fn(r - 1)) {
2136  return r;
2137  }
2138 
2139  --r;
2140  while (l != r) {
2141  size_t c = (l + r) / 2;
2142  if (is_empty_fn(c)) {
2143  r = c;
2144  } else {
2145  l = c + 1;
2146  }
2147  }
2148 
2149  return r;
2150 }

+ 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 765 of file ResultSetIteration.cpp.

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

Definition at line 770 of file ResultSetIteration.cpp.

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

Definition at line 775 of file ResultSetIteration.cpp.

775  {
776  return ScalarTargetValue(val);
777 }
boost::variant< int64_t, double, float, NullableString > ScalarTargetValue
Definition: TargetValue.h:156
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 871 of file ResultSetIteration.cpp.

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

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

+ Here is the caller graph for this function: