OmniSciDB  c1a53651b2
 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 countNumberOfValues (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}::countNumberOfValues ( const ResultSet rows,
const size_t  column_idx 
)

Definition at line 128 of file ColumnarResults.cpp.

References CHECK, and threading_serial::parallel_reduce().

Referenced by ColumnarResults::ColumnarResults().

128  {
129  return tbb::parallel_reduce(
130  tbb::blocked_range<int64_t>(0, rows.rowCount()),
131  static_cast<int64_t>(0),
132  [&](tbb::blocked_range<int64_t> r, int64_t running_count) {
133  for (int i = r.begin(); i < r.end(); ++i) {
134  const auto crt_row = rows.getRowAtNoTranslations(i);
135  const auto arr_tv = boost::get<ArrayTargetValue>(&crt_row[column_idx]);
136  CHECK(arr_tv);
137  if (arr_tv->is_initialized()) {
138  const auto& vec = arr_tv->get();
139  running_count += vec.size();
140  }
141  }
142  return running_count;
143  },
144  std::plus<int64_t>());
145 }
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 33 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().

34  {
35  if (type_info.get_compression() != kENCODING_NONE) {
36  CHECK(type_info.get_compression() == kENCODING_FIXED ||
37  type_info.get_compression() == kENCODING_DICT);
38  auto logical_ti = get_logical_type_info(type_info);
39  if (val == inline_int_null_val(logical_ti)) {
40  return inline_fixed_encoding_null_val(type_info);
41  }
42  }
43  return val;
44 }
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1235
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:389
#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 46 of file ColumnarResults.cpp.

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

References UNREACHABLE.

Referenced by ColumnarResults::initReadFunctions().

1172  {
1173  UNREACHABLE() << "Invalid read function used, target should have been skipped.";
1174  return static_cast<int64_t>(0);
1175 }
#define UNREACHABLE()
Definition: Logger.h:337

+ 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 1237 of file ColumnarResults.cpp.

1240  {
1241  auto dval = rows.getEntryAt<double, QUERY_TYPE, COLUMNAR_OUTPUT>(
1242  input_buffer_entry_idx, target_idx, slot_idx);
1243  return *reinterpret_cast<int64_t*>(may_alias_ptr(&dval));
1244 }
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 1227 of file ColumnarResults.cpp.

1230  {
1231  auto fval = rows.getEntryAt<float, QUERY_TYPE, COLUMNAR_OUTPUT>(
1232  input_buffer_entry_idx, target_idx, slot_idx);
1233  return *reinterpret_cast<int32_t*>(may_alias_ptr(&fval));
1234 }
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 1178 of file ColumnarResults.cpp.

1181  {
1182  // float keys in baseline hash are written as doubles in the buffer, so
1183  // the result should properly be casted before being written in the output
1184  // columns
1185  auto fval = static_cast<float>(rows.getEntryAt<double, QUERY_TYPE, COLUMNAR_OUTPUT>(
1186  input_buffer_entry_idx, target_idx, slot_idx));
1187  return *reinterpret_cast<int32_t*>(may_alias_ptr(&fval));
1188 }
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 1209 of file ColumnarResults.cpp.

1212  {
1213  return rows.getEntryAt<int16_t, QUERY_TYPE, COLUMNAR_OUTPUT>(
1214  input_buffer_entry_idx, target_idx, slot_idx);
1215 }
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 1200 of file ColumnarResults.cpp.

1203  {
1204  return rows.getEntryAt<int32_t, QUERY_TYPE, COLUMNAR_OUTPUT>(
1205  input_buffer_entry_idx, target_idx, slot_idx);
1206 }
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 1191 of file ColumnarResults.cpp.

1194  {
1195  return rows.getEntryAt<int64_t, QUERY_TYPE, COLUMNAR_OUTPUT>(
1196  input_buffer_entry_idx, target_idx, slot_idx);
1197 }
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 1218 of file ColumnarResults.cpp.

1221  {
1222  return rows.getEntryAt<int8_t, QUERY_TYPE, COLUMNAR_OUTPUT>(
1223  input_buffer_entry_idx, target_idx, slot_idx);
1224 }
int64_t anonymous_namespace{ColumnarResults.cpp}::toBuffer ( const TargetValue col_val,
const SQLTypeInfo type_info,
int8_t *  buf 
)

Definition at line 76 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(), kDOUBLE, kFLOAT, and UNREACHABLE.

Referenced by ColumnarResults::writeBackCell().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function: