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

Functions

int64_t fixed_encoding_nullable_val (const int64_t val, const SQLTypeInfo &type_info)
 
std::vector< size_t > get_padded_target_sizes (const ResultSet &rows, const std::vector< SQLTypeInfo > &target_types)
 
int64_t toBuffer (const TargetValue &col_val, const SQLTypeInfo &type_info, int8_t *buf)
 
int64_t computeTotalNofValuesForColumnArray (const ResultSet &rows, const size_t column_idx)
 
template<typename TargetValue , typename TargetValuePtr >
int64_t computeTotalNofValuesForColumnGeoType (const ResultSet &rows, const SQLTypeInfo &ti, const size_t column_idx)
 
int64_t computeTotalNofValuesForColumnTextEncodingNone (const ResultSet &rows, const size_t column_idx)
 
int64_t invalid_read_func (const ResultSet &rows, const size_t input_buffer_entry_idx, const size_t target_idx, const size_t slot_idx)
 
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t read_float_key_baseline (const ResultSet &rows, const size_t input_buffer_entry_idx, const size_t target_idx, const size_t slot_idx)
 
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t read_int64_func (const ResultSet &rows, const size_t input_buffer_entry_idx, const size_t target_idx, const size_t slot_idx)
 
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t read_int32_func (const ResultSet &rows, const size_t input_buffer_entry_idx, const size_t target_idx, const size_t slot_idx)
 
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t read_int16_func (const ResultSet &rows, const size_t input_buffer_entry_idx, const size_t target_idx, const size_t slot_idx)
 
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t read_int8_func (const ResultSet &rows, const size_t input_buffer_entry_idx, const size_t target_idx, const size_t slot_idx)
 
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t read_float_func (const ResultSet &rows, const size_t input_buffer_entry_idx, const size_t target_idx, const size_t slot_idx)
 
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t read_double_func (const ResultSet &rows, const size_t input_buffer_entry_idx, const size_t target_idx, const size_t slot_idx)
 

Function Documentation

int64_t anonymous_namespace{ColumnarResults.cpp}::computeTotalNofValuesForColumnArray ( const ResultSet rows,
const size_t  column_idx 
)

Definition at line 148 of file ColumnarResults.cpp.

References CHECK, and threading_serial::parallel_reduce().

Referenced by ColumnarResults::ColumnarResults().

149  {
150  return tbb::parallel_reduce(
151  tbb::blocked_range<int64_t>(0, rows.entryCount()),
152  static_cast<int64_t>(0),
153  [&](tbb::blocked_range<int64_t> r, int64_t running_count) {
154  for (int i = r.begin(); i < r.end(); ++i) {
155  const auto crt_row = rows.getRowAtNoTranslations(i);
156  if (crt_row.empty()) {
157  continue;
158  }
159  const auto arr_tv = boost::get<ArrayTargetValue>(&crt_row[column_idx]);
160  CHECK(arr_tv);
161  if (arr_tv->is_initialized()) {
162  const auto& vec = arr_tv->get();
163  running_count += vec.size();
164  }
165  }
166  return running_count;
167  },
168  std::plus<int64_t>());
169 }
tuple rows
Definition: report.py:114
Value parallel_reduce(const blocked_range< Int > &range, const Value &identity, const RealBody &real_body, const Reduction &reduction, const Partitioner &p=Partitioner())
Parallel iteration with reduction.
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename TargetValue , typename TargetValuePtr >
int64_t anonymous_namespace{ColumnarResults.cpp}::computeTotalNofValuesForColumnGeoType ( const ResultSet rows,
const SQLTypeInfo ti,
const size_t  column_idx 
)

Definition at line 172 of file ColumnarResults.cpp.

References CHECK, SQLTypeInfo::get_compression(), kENCODING_GEOINT, VarlenDatum::length, threading_serial::parallel_reduce(), and UNREACHABLE.

Referenced by ColumnarResults::ColumnarResults().

174  {
175  return tbb::parallel_reduce(
176  tbb::blocked_range<int64_t>(0, rows.entryCount()),
177  static_cast<int64_t>(0),
178  [&](tbb::blocked_range<int64_t> r, int64_t running_count) {
179  for (int i = r.begin(); i < r.end(); ++i) {
180  const auto crt_row = rows.getRowAtNoTranslations(i);
181  if (crt_row.empty()) {
182  continue;
183  }
184  if (const auto tv = boost::get<ScalarTargetValue>(&crt_row[column_idx])) {
185  const auto ns = boost::get<NullableString>(tv);
186  CHECK(ns);
187  const auto s_ptr = boost::get<std::string>(ns);
188  if (s_ptr) {
189  // We count the number of commas in WKT representation
190  // (e.g. POLYGON ((0 0,4 0,4 4,0 4,0 0),(1 1,1 2,2 2,2
191  // 1,1 1))) to get the number of points it contains.
192  // This method is usable for any geo type.
193  running_count += std::count(s_ptr->begin(), s_ptr->end(), ',') + 1;
194  }
195  } else if (const auto tv =
196  boost::get<GeoTargetValuePtr>(&crt_row[column_idx])) {
197  const auto s = boost::get<TargetValuePtr>(tv);
198  CHECK(s);
199  VarlenDatum* d = s->coords_data.get();
200  if (d != nullptr) {
201  running_count +=
202  d->length /
203  (ti.get_compression() == kENCODING_GEOINT ? sizeof(int32_t)
204  : sizeof(double)) /
205  2;
206  } // else s is NULL
207  } else if (const auto tv = boost::get<GeoTargetValue>(&crt_row[column_idx])) {
208  if (tv->get_ptr() != nullptr) {
209  const auto s = boost::get<TargetValue>(tv->get());
210  std::vector<double>* d = s.coords.get();
211  CHECK(d);
212  running_count += d->size();
213  } // else s is NULL
214  } else {
215  UNREACHABLE();
216  }
217  }
218  return running_count;
219  },
220  std::plus<int64_t>());
221 }
#define UNREACHABLE()
Definition: Logger.h:338
tuple rows
Definition: report.py:114
Value parallel_reduce(const blocked_range< Int > &range, const Value &identity, const RealBody &real_body, const Reduction &reduction, const Partitioner &p=Partitioner())
Parallel iteration with reduction.
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
#define CHECK(condition)
Definition: Logger.h:291
size_t length
Definition: Datum.h:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int64_t anonymous_namespace{ColumnarResults.cpp}::computeTotalNofValuesForColumnTextEncodingNone ( const ResultSet rows,
const size_t  column_idx 
)

Definition at line 223 of file ColumnarResults.cpp.

References CHECK, threading_serial::parallel_reduce(), and UNREACHABLE.

Referenced by ColumnarResults::ColumnarResults().

224  {
225  return tbb::parallel_reduce(
226  tbb::blocked_range<int64_t>(0, rows.entryCount()),
227  static_cast<int64_t>(0),
228  [&](tbb::blocked_range<int64_t> r, int64_t running_count) {
229  for (int i = r.begin(); i < r.end(); ++i) {
230  // Apparently, ResultSet permutation vector may be sparse
231  // (len(permutation) > entryCount), so we cannot ignore the
232  // permutation vector when iterating over all entries.
233  const auto crt_row = rows.getRowAtNoTranslations(i);
234  if (crt_row.empty()) {
235  continue;
236  }
237  const auto col_val = crt_row[column_idx];
238  if (const auto tv = boost::get<ScalarTargetValue>(&col_val)) {
239  const auto ns = boost::get<NullableString>(tv);
240  CHECK(ns);
241  const auto s_ptr = boost::get<std::string>(ns);
242  if (s_ptr) {
243  running_count += s_ptr->size();
244  }
245  } else {
246  UNREACHABLE();
247  }
248  }
249  return running_count;
250  },
251  std::plus<int64_t>());
252 }
#define UNREACHABLE()
Definition: Logger.h:338
tuple rows
Definition: report.py:114
Value parallel_reduce(const blocked_range< Int > &range, const Value &identity, const RealBody &real_body, const Reduction &reduction, const Partitioner &p=Partitioner())
Parallel iteration with reduction.
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int64_t anonymous_namespace{ColumnarResults.cpp}::fixed_encoding_nullable_val ( const int64_t  val,
const SQLTypeInfo type_info 
)
inline

Definition at line 35 of file ColumnarResults.cpp.

References CHECK, SQLTypeInfo::get_compression(), get_logical_type_info(), inline_fixed_encoding_null_val(), inline_int_null_val(), kENCODING_DICT, kENCODING_FIXED, and kENCODING_NONE.

Referenced by toBuffer(), and ColumnarResults::writeBackCellDirect().

36  {
37  if (type_info.get_compression() != kENCODING_NONE) {
38  CHECK(type_info.get_compression() == kENCODING_FIXED ||
39  type_info.get_compression() == kENCODING_DICT);
40  auto logical_ti = get_logical_type_info(type_info);
41  if (val == inline_int_null_val(logical_ti)) {
42  return inline_fixed_encoding_null_val(type_info);
43  }
44  }
45  return val;
46 }
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1470
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
#define CHECK(condition)
Definition: Logger.h:291
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
int64_t inline_fixed_encoding_null_val(const SQL_TYPE_INFO &ti)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<size_t> anonymous_namespace{ColumnarResults.cpp}::get_padded_target_sizes ( const ResultSet rows,
const std::vector< SQLTypeInfo > &  target_types 
)

Definition at line 48 of file ColumnarResults.cpp.

50  {
51  std::vector<size_t> padded_target_sizes;
52  // We have to check that the result set is valid as one entry point
53  // to columnar results constructs effectively a fake result set.
54  // In these cases it should be safe to assume that we can use the type
55  // target widths
56  if (!rows.hasValidBuffer() ||
57  rows.getQueryMemDesc().getColCount() < target_types.size()) {
58  for (const auto& target_type : target_types) {
59  padded_target_sizes.emplace_back(target_type.get_size());
60  }
61  return padded_target_sizes;
62  }
63 
64  // If here we have a valid result set, so use it's QMD padded widths
65  const auto col_context = rows.getQueryMemDesc().getColSlotContext();
66  for (size_t col_idx = 0; col_idx < target_types.size(); col_idx++) {
67  // Lazy fetch columns will have 0 as a padded with, so use the type's
68  // logical width for those
69  const auto idx = col_context.getSlotsForCol(col_idx).front();
70  const size_t padded_slot_width =
71  static_cast<size_t>(rows.getPaddedSlotWidthBytes(idx));
72  padded_target_sizes.emplace_back(
73  padded_slot_width == 0UL ? target_types[col_idx].get_size() : padded_slot_width);
74  }
75  return padded_target_sizes;
76 }
tuple rows
Definition: report.py:114
int64_t anonymous_namespace{ColumnarResults.cpp}::invalid_read_func ( const ResultSet rows,
const size_t  input_buffer_entry_idx,
const size_t  target_idx,
const size_t  slot_idx 
)

Definition at line 1733 of file ColumnarResults.cpp.

References UNREACHABLE.

Referenced by ColumnarResults::initReadFunctions().

1736  {
1737  UNREACHABLE() << "Invalid read function used, target should have been skipped.";
1738  return static_cast<int64_t>(0);
1739 }
#define UNREACHABLE()
Definition: Logger.h:338

+ Here is the caller graph for this function:

template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t anonymous_namespace{ColumnarResults.cpp}::read_double_func ( const ResultSet rows,
const size_t  input_buffer_entry_idx,
const size_t  target_idx,
const size_t  slot_idx 
)

Definition at line 1801 of file ColumnarResults.cpp.

1804  {
1805  auto dval = rows.getEntryAt<double, QUERY_TYPE, COLUMNAR_OUTPUT>(
1806  input_buffer_entry_idx, target_idx, slot_idx);
1807  return *reinterpret_cast<int64_t*>(may_alias_ptr(&dval));
1808 }
tuple rows
Definition: report.py:114
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t anonymous_namespace{ColumnarResults.cpp}::read_float_func ( const ResultSet rows,
const size_t  input_buffer_entry_idx,
const size_t  target_idx,
const size_t  slot_idx 
)

Definition at line 1791 of file ColumnarResults.cpp.

1794  {
1795  auto fval = rows.getEntryAt<float, QUERY_TYPE, COLUMNAR_OUTPUT>(
1796  input_buffer_entry_idx, target_idx, slot_idx);
1797  return *reinterpret_cast<int32_t*>(may_alias_ptr(&fval));
1798 }
tuple rows
Definition: report.py:114
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t anonymous_namespace{ColumnarResults.cpp}::read_float_key_baseline ( const ResultSet rows,
const size_t  input_buffer_entry_idx,
const size_t  target_idx,
const size_t  slot_idx 
)

Definition at line 1742 of file ColumnarResults.cpp.

1745  {
1746  // float keys in baseline hash are written as doubles in the buffer, so
1747  // the result should properly be casted before being written in the output
1748  // columns
1749  auto fval = static_cast<float>(rows.getEntryAt<double, QUERY_TYPE, COLUMNAR_OUTPUT>(
1750  input_buffer_entry_idx, target_idx, slot_idx));
1751  return *reinterpret_cast<int32_t*>(may_alias_ptr(&fval));
1752 }
tuple rows
Definition: report.py:114
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t anonymous_namespace{ColumnarResults.cpp}::read_int16_func ( const ResultSet rows,
const size_t  input_buffer_entry_idx,
const size_t  target_idx,
const size_t  slot_idx 
)

Definition at line 1773 of file ColumnarResults.cpp.

1776  {
1777  return rows.getEntryAt<int16_t, QUERY_TYPE, COLUMNAR_OUTPUT>(
1778  input_buffer_entry_idx, target_idx, slot_idx);
1779 }
tuple rows
Definition: report.py:114
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t anonymous_namespace{ColumnarResults.cpp}::read_int32_func ( const ResultSet rows,
const size_t  input_buffer_entry_idx,
const size_t  target_idx,
const size_t  slot_idx 
)

Definition at line 1764 of file ColumnarResults.cpp.

1767  {
1768  return rows.getEntryAt<int32_t, QUERY_TYPE, COLUMNAR_OUTPUT>(
1769  input_buffer_entry_idx, target_idx, slot_idx);
1770 }
tuple rows
Definition: report.py:114
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t anonymous_namespace{ColumnarResults.cpp}::read_int64_func ( const ResultSet rows,
const size_t  input_buffer_entry_idx,
const size_t  target_idx,
const size_t  slot_idx 
)

Definition at line 1755 of file ColumnarResults.cpp.

1758  {
1759  return rows.getEntryAt<int64_t, QUERY_TYPE, COLUMNAR_OUTPUT>(
1760  input_buffer_entry_idx, target_idx, slot_idx);
1761 }
tuple rows
Definition: report.py:114
template<QueryDescriptionType QUERY_TYPE, bool COLUMNAR_OUTPUT>
int64_t anonymous_namespace{ColumnarResults.cpp}::read_int8_func ( const ResultSet rows,
const size_t  input_buffer_entry_idx,
const size_t  target_idx,
const size_t  slot_idx 
)

Definition at line 1782 of file ColumnarResults.cpp.

1785  {
1786  return rows.getEntryAt<int8_t, QUERY_TYPE, COLUMNAR_OUTPUT>(
1787  input_buffer_entry_idx, target_idx, slot_idx);
1788 }
tuple rows
Definition: report.py:114
int64_t anonymous_namespace{ColumnarResults.cpp}::toBuffer ( const TargetValue col_val,
const SQLTypeInfo type_info,
int8_t *  buf 
)

Definition at line 78 of file ColumnarResults.cpp.

References CHECK, fixed_encoding_nullable_val(), SQLTypeInfo::get_elem_type(), SQLTypeInfo::get_size(), SQLTypeInfo::get_type(), SQLTypeInfo::is_array(), SQLTypeInfo::is_fp(), SQLTypeInfo::is_geometry(), kDOUBLE, kFLOAT, and UNREACHABLE.

Referenced by ColumnarResults::writeBackCell().

78  {
79  CHECK(!type_info.is_geometry());
80  if (type_info.is_array()) {
81  const auto array_col_val = boost::get<ArrayTargetValue>(&col_val);
82  CHECK(array_col_val);
83  const auto& vec = array_col_val->get();
84  int64_t offset = 0;
85  const auto elem_type_info = type_info.get_elem_type();
86  for (const auto& item : vec) {
87  offset += toBuffer(item, elem_type_info, buf + offset);
88  }
89  return offset;
90  } else if (type_info.is_fp()) {
91  const auto scalar_col_val = boost::get<ScalarTargetValue>(&col_val);
92  switch (type_info.get_type()) {
93  case kFLOAT: {
94  auto float_p = boost::get<float>(scalar_col_val);
95  *((float*)buf) = static_cast<float>(*float_p);
96  return 4;
97  }
98  case kDOUBLE: {
99  auto double_p = boost::get<double>(scalar_col_val);
100  *((double*)buf) = static_cast<double>(*double_p);
101  return 8;
102  }
103  default:
104  UNREACHABLE();
105  }
106  } else {
107  const auto scalar_col_val = boost::get<ScalarTargetValue>(&col_val);
108  CHECK(scalar_col_val);
109  auto i64_p = boost::get<int64_t>(scalar_col_val);
110  const auto val = fixed_encoding_nullable_val(*i64_p, type_info);
111  switch (type_info.get_size()) {
112  case 1:
113  *buf = static_cast<int8_t>(val);
114  return 1;
115  case 2:
116  *((int16_t*)buf) = static_cast<int16_t>(val);
117  return 2;
118  case 4:
119  *((int32_t*)buf) = static_cast<int32_t>(val);
120  return 4;
121  case 8:
122  *((int64_t*)buf) = static_cast<int64_t>(val);
123  return 8;
124  default:
125  UNREACHABLE();
126  }
127  }
128  return 0;
129 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:403
bool is_fp() const
Definition: sqltypes.h:571
#define UNREACHABLE()
Definition: Logger.h:338
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
int64_t fixed_encoding_nullable_val(const int64_t val, const SQLTypeInfo &type_info)
int64_t toBuffer(const TargetValue &col_val, const SQLTypeInfo &type_info, int8_t *buf)
#define CHECK(condition)
Definition: Logger.h:291
bool is_geometry() const
Definition: sqltypes.h:595
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:

+ Here is the caller graph for this function: