38 #include <boost/math/special_functions/fpclassify.hpp>
47 const int8_t compact_sz1,
49 const int8_t compact_sz2,
54 const auto actual_compact_sz1 = float_argument_input ?
sizeof(float) : compact_sz1;
56 if (agg_ti.is_integer() || agg_ti.is_decimal()) {
58 }
else if (agg_ti.is_fp()) {
59 switch (actual_compact_sz1) {
61 double d = *
reinterpret_cast<const double*
>(ptr1);
62 sum = *
reinterpret_cast<const int64_t*
>(may_alias_ptr(&d));
66 double d = *
reinterpret_cast<const float*
>(ptr1);
67 sum = *
reinterpret_cast<const int64_t*
>(may_alias_ptr(&d));
84 const std::vector<TargetInfo>& targets,
85 const size_t slot_idx,
86 const bool separate_varlen_storage) {
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) {
94 CHECK_LT(agg_col_idx, buffer_col_count);
95 const auto& agg_info = targets[target_idx];
98 if (agg_info.is_agg && agg_info.agg_kind ==
kAVG) {
99 if (agg_col_idx + 1 == slot_idx) {
103 crt_col_ptr, query_mem_desc, agg_col_idx + 1);
105 agg_col_idx =
advance_slot(agg_col_idx, agg_info, separate_varlen_storage);
120 const size_t global_entry_idx,
121 const bool translate_strings,
123 const bool fixup_count_distinct_pointers,
124 const std::vector<bool>& targets_to_skip )
const {
125 const auto storage_lookup_result =
126 fixup_count_distinct_pointers
127 ? StorageLookupResult{storage_.get(), global_entry_idx, 0}
128 : findStorage(global_entry_idx);
129 const auto storage = storage_lookup_result.storage_ptr;
130 const auto local_entry_idx = storage_lookup_result.fixedup_entry_idx;
131 if (!fixup_count_distinct_pointers && storage->isEmptyEntry(local_entry_idx)) {
134 const auto buff = storage->buff_;
136 std::vector<TargetValue> row;
137 size_t agg_col_idx = 0;
138 int8_t* rowwise_target_ptr{
nullptr};
139 int8_t* keys_ptr{
nullptr};
140 const int8_t* crt_col_ptr{
nullptr};
141 if (query_mem_desc_.didOutputColumnar()) {
143 crt_col_ptr =
get_cols_ptr(buff, storage->query_mem_desc_);
146 const auto key_bytes_with_padding =
148 rowwise_target_ptr = keys_ptr + key_bytes_with_padding;
150 for (
size_t target_idx = 0; target_idx < storage->targets_.size(); ++target_idx) {
151 const auto& agg_info = storage->targets_[target_idx];
152 if (query_mem_desc_.didOutputColumnar()) {
153 if (
UNLIKELY(!targets_to_skip.empty())) {
154 row.push_back(!targets_to_skip[target_idx]
155 ? getTargetValueFromBufferColwise(crt_col_ptr,
157 storage->query_mem_desc_,
167 row.push_back(getTargetValueFromBufferColwise(crt_col_ptr,
169 storage->query_mem_desc_,
181 storage->query_mem_desc_,
182 separate_varlen_storage_valid_);
184 if (
UNLIKELY(!targets_to_skip.empty())) {
185 row.push_back(!targets_to_skip[target_idx]
186 ? getTargetValueFromBufferRowwise(rowwise_target_ptr,
194 fixup_count_distinct_pointers)
197 row.push_back(getTargetValueFromBufferRowwise(rowwise_target_ptr,
205 fixup_count_distinct_pointers));
211 separate_varlen_storage_valid_);
213 agg_col_idx =
advance_slot(agg_col_idx, agg_info, separate_varlen_storage_valid_);
220 const size_t col_idx,
221 const bool translate_strings,
222 const bool decimal_to_double )
const {
223 std::lock_guard<std::mutex> lock(row_iteration_mutex_);
225 for (
size_t i = 0; i < row_idx; ++i) {
226 auto crt_row = getNextRowUnlocked(translate_strings, decimal_to_double);
227 CHECK(!crt_row.empty());
229 auto crt_row = getNextRowUnlocked(translate_strings, decimal_to_double);
230 CHECK(!crt_row.empty());
231 return crt_row[col_idx];
235 const auto storage_lookup_result = findStorage(global_entry_idx);
236 const auto storage = storage_lookup_result.storage_ptr;
237 const auto local_entry_idx = storage_lookup_result.fixedup_entry_idx;
238 if (storage->isEmptyEntry(local_entry_idx)) {
241 const auto buff = storage->buff_;
243 CHECK(!query_mem_desc_.didOutputColumnar());
244 const auto keys_ptr =
row_ptr_rowwise(buff, query_mem_desc_, local_entry_idx);
245 const auto key_bytes_with_padding =
247 const auto rowwise_target_ptr = keys_ptr + key_bytes_with_padding;
248 const auto tv = getTargetValueFromBufferRowwise(rowwise_target_ptr,
257 const auto scalar_tv = boost::get<ScalarTargetValue>(&tv);
259 const auto ival_ptr = boost::get<int64_t>(scalar_tv);
261 return {*ival_ptr,
true};
265 if (logical_index >= entryCount()) {
268 const auto entry_idx =
269 permutation_.empty() ? logical_index : permutation_[logical_index];
270 return getRowAt(entry_idx,
true,
false,
false);
274 const size_t logical_index,
275 const std::vector<bool>& targets_to_skip )
const {
276 if (logical_index >= entryCount()) {
279 const auto entry_idx =
280 permutation_.empty() ? logical_index : permutation_[logical_index];
281 return getRowAt(entry_idx,
false,
false,
false, targets_to_skip);
285 if (logical_index >= entryCount()) {
288 const auto entry_idx =
289 permutation_.empty() ? logical_index : permutation_[logical_index];
290 const auto storage_lookup_result = findStorage(entry_idx);
291 const auto storage = storage_lookup_result.storage_ptr;
292 const auto local_entry_idx = storage_lookup_result.fixedup_entry_idx;
293 return storage->isEmptyEntry(local_entry_idx);
297 const bool decimal_to_double)
const {
298 std::lock_guard<std::mutex> lock(row_iteration_mutex_);
299 if (!storage_ && !just_explain_) {
302 return getNextRowUnlocked(translate_strings, decimal_to_double);
306 const bool translate_strings,
307 const bool decimal_to_double)
const {
309 if (fetched_so_far_) {
313 return {explanation_};
315 return getNextRowImpl(translate_strings, decimal_to_double);
319 const bool decimal_to_double)
const {
320 size_t entry_buff_idx = 0;
322 if (keep_first_ && fetched_so_far_ >= drop_first_ + keep_first_) {
326 entry_buff_idx = advanceCursorToNextEntry();
328 if (crt_row_buff_idx_ >= entryCount()) {
329 CHECK_EQ(entryCount(), crt_row_buff_idx_);
335 }
while (drop_first_ && fetched_so_far_ <= drop_first_);
337 auto row = getRowAt(entry_buff_idx, translate_strings, decimal_to_double,
false);
346 const int8_t* col1_ptr,
347 const int8_t compact_sz1) {
348 return col1_ptr + compact_sz1 * entry_idx;
356 return static_cast<int32_t
>(ival);
358 return static_cast<int16_t
>(ival);
360 return static_cast<int8_t
>(ival);
372 for (
size_t storage_idx = 0; storage_idx <
result_set_->appended_storage_.size() + 1;
376 const int8_t* rowwise_target_ptr{0};
378 size_t agg_col_idx = 0;
379 for (
size_t target_idx = 0; target_idx <
result_set_->storage_->targets_.size();
381 const auto& agg_info =
result_set_->storage_->targets_[target_idx];
383 auto ptr1 = rowwise_target_ptr;
384 const auto compact_sz1 =
385 result_set_->query_mem_desc_.getPaddedSlotWidthBytes(agg_col_idx)
386 ?
result_set_->query_mem_desc_.getPaddedSlotWidthBytes(agg_col_idx)
389 const int8_t* ptr2{
nullptr};
390 int8_t compact_sz2{0};
391 if ((agg_info.is_agg && agg_info.agg_kind ==
kAVG)) {
392 ptr2 = ptr1 + compact_sz1;
394 result_set_->query_mem_desc_.getPaddedSlotWidthBytes(agg_col_idx + 1);
396 ptr2 = ptr1 + compact_sz1;
397 if (!
result_set_->separate_varlen_storage_valid_) {
401 result_set_->query_mem_desc_.getPaddedSlotWidthBytes(agg_col_idx + 1);
406 static_cast<size_t>(compact_sz1),
408 static_cast<size_t>(compact_sz2)});
417 agg_col_idx, agg_info,
result_set_->separate_varlen_storage_valid_);
426 const size_t entry_idx,
427 const size_t target_logical_idx,
430 const int8_t* rowwise_target_ptr{
nullptr};
431 const int8_t* keys_ptr{
nullptr};
433 const size_t storage_idx = storage_lookup_result.
storage_idx;
435 CHECK_LT(storage_idx, offsets_for_storage_.size());
436 CHECK_LT(target_logical_idx, offsets_for_storage_[storage_idx].size());
438 const auto& offsets_for_target = offsets_for_storage_[storage_idx][target_logical_idx];
439 const auto& agg_info = result_set_->storage_->targets_[target_logical_idx];
440 const auto& type_info = agg_info.sql_type;
442 keys_ptr = get_rowwise_ptr(buff, entry_idx);
443 rowwise_target_ptr = keys_ptr + key_bytes_with_padding_;
444 auto ptr1 = rowwise_target_ptr +
reinterpret_cast<size_t>(offsets_for_target.ptr1);
445 if (result_set_->query_mem_desc_.targetGroupbyIndicesSize() > 0) {
446 if (result_set_->query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) >= 0) {
448 result_set_->query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) *
455 storage_lookup_result);
456 if (agg_info.is_agg && agg_info.agg_kind ==
kAVG) {
457 CHECK(offsets_for_target.ptr2);
459 rowwise_target_ptr +
reinterpret_cast<size_t>(offsets_for_target.ptr2);
463 if (type_info.is_string() && type_info.get_compression() ==
kENCODING_NONE) {
464 CHECK(!agg_info.is_agg);
465 if (!result_set_->lazy_fetch_info_.empty()) {
466 CHECK_LT(target_logical_idx, result_set_->lazy_fetch_info_.size());
467 const auto& col_lazy_fetch = result_set_->lazy_fetch_info_[target_logical_idx];
468 if (col_lazy_fetch.is_lazily_fetched) {
472 if (result_set_->separate_varlen_storage_valid_) {
478 result_set_->serialized_varlen_buffer_.size());
479 const auto& varlen_buffer_for_fragment =
480 result_set_->serialized_varlen_buffer_[storage_lookup_result.
storage_idx];
481 CHECK_LT(static_cast<size_t>(i1), varlen_buffer_for_fragment.size());
484 CHECK(offsets_for_target.ptr2);
486 rowwise_target_ptr +
reinterpret_cast<size_t>(offsets_for_target.ptr2);
489 return result_set_->getVarlenOrderEntry(i1, str_len);
490 }
else if (agg_info.is_agg && agg_info.agg_kind ==
kMODE) {
494 type_info.is_fp() ? i1 :
int_resize_cast(i1, type_info.get_logical_size()));
500 const auto key_width = result_set_->query_mem_desc_.getEffectiveKeyWidth();
501 for (
size_t storage_idx = 0; storage_idx < result_set_->appended_storage_.size() + 1;
503 offsets_for_storage_.emplace_back();
505 const int8_t* buff = storage_idx == 0
506 ? result_set_->storage_->buff_
507 : result_set_->appended_storage_[storage_idx - 1]->buff_;
510 const auto& crt_query_mem_desc =
512 ? result_set_->storage_->query_mem_desc_
513 : result_set_->appended_storage_[storage_idx - 1]->query_mem_desc_;
514 const int8_t* crt_col_ptr =
get_cols_ptr(buff, crt_query_mem_desc);
516 size_t agg_col_idx = 0;
517 for (
size_t target_idx = 0; target_idx < result_set_->storage_->targets_.size();
519 const auto& agg_info = result_set_->storage_->targets_[target_idx];
521 const auto compact_sz1 =
522 crt_query_mem_desc.getPaddedSlotWidthBytes(agg_col_idx)
523 ? crt_query_mem_desc.getPaddedSlotWidthBytes(agg_col_idx)
527 crt_col_ptr, crt_query_mem_desc, agg_col_idx);
528 const bool uses_two_slots = (agg_info.is_agg && agg_info.agg_kind ==
kAVG) ||
530 const auto col2_ptr = uses_two_slots ? next_col_ptr :
nullptr;
531 const auto compact_sz2 =
533 ? crt_query_mem_desc.getPaddedSlotWidthBytes(agg_col_idx + 1)
536 offsets_for_storage_[storage_idx].push_back(
538 static_cast<size_t>(compact_sz1),
540 static_cast<size_t>(compact_sz2)});
542 crt_col_ptr = next_col_ptr;
543 if (uses_two_slots) {
545 crt_col_ptr, crt_query_mem_desc, agg_col_idx + 1);
548 agg_col_idx, agg_info, result_set_->separate_varlen_storage_valid_);
550 CHECK_EQ(offsets_for_storage_[storage_idx].size(),
551 result_set_->storage_->targets_.size());
557 const size_t entry_idx,
558 const size_t target_logical_idx,
560 const size_t storage_idx = storage_lookup_result.
storage_idx;
562 CHECK_LT(storage_idx, offsets_for_storage_.size());
563 CHECK_LT(target_logical_idx, offsets_for_storage_[storage_idx].size());
565 const auto& offsets_for_target = offsets_for_storage_[storage_idx][target_logical_idx];
566 const auto& agg_info = result_set_->storage_->targets_[target_logical_idx];
567 const auto& type_info = agg_info.sql_type;
568 auto ptr1 = offsets_for_target.ptr1;
569 if (result_set_->query_mem_desc_.targetGroupbyIndicesSize() > 0) {
570 if (result_set_->query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) >= 0) {
572 buff + result_set_->query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) *
573 result_set_->query_mem_desc_.getEffectiveKeyWidth() *
574 result_set_->query_mem_desc_.entry_count_;
578 const auto i1 = result_set_->lazyReadInt(
581 offsets_for_target.compact_sz1),
583 storage_lookup_result);
584 if (agg_info.is_agg && agg_info.agg_kind ==
kAVG) {
585 CHECK(offsets_for_target.ptr2);
588 entry_idx, offsets_for_target.ptr2, offsets_for_target.compact_sz2),
589 offsets_for_target.compact_sz2);
593 if (type_info.is_string() && type_info.get_compression() ==
kENCODING_NONE) {
594 CHECK(!agg_info.is_agg);
595 if (!result_set_->lazy_fetch_info_.empty()) {
596 CHECK_LT(target_logical_idx, result_set_->lazy_fetch_info_.size());
597 const auto& col_lazy_fetch = result_set_->lazy_fetch_info_[target_logical_idx];
598 if (col_lazy_fetch.is_lazily_fetched) {
602 if (result_set_->separate_varlen_storage_valid_) {
608 result_set_->serialized_varlen_buffer_.size());
609 const auto& varlen_buffer_for_fragment =
610 result_set_->serialized_varlen_buffer_[storage_lookup_result.
storage_idx];
611 CHECK_LT(static_cast<size_t>(i1), varlen_buffer_for_fragment.size());
614 CHECK(offsets_for_target.ptr2);
617 entry_idx, offsets_for_target.ptr2, offsets_for_target.compact_sz2),
618 offsets_for_target.compact_sz2);
620 return result_set_->getVarlenOrderEntry(i1, i2);
623 type_info.is_fp() ? i1 :
int_resize_cast(i1, type_info.get_logical_size()));
628 const size_t str_len)
const {
629 char* host_str_ptr{
nullptr};
630 std::vector<int8_t> cpu_buffer;
632 cpu_buffer.resize(str_len);
635 auto data_mgr = executor->getDataMgr();
636 auto allocator = std::make_unique<CudaAllocator>(
638 allocator->copyFromDevice(
639 &cpu_buffer[0], reinterpret_cast<int8_t*>(str_ptr), str_len);
640 host_str_ptr =
reinterpret_cast<char*
>(&cpu_buffer[0]);
643 host_str_ptr =
reinterpret_cast<char*
>(str_ptr);
645 std::string str(host_str_ptr, str_len);
650 const size_t target_logical_idx,
655 if (col_lazy_fetch.is_lazily_fetched) {
658 int64_t ival_copy = ival;
659 auto& frag_col_buffers =
663 auto& frag_col_buffer = frag_col_buffers[col_lazy_fetch.local_col_id];
666 CHECK(!target_info.is_agg);
667 if (target_info.sql_type.is_string() &&
672 reinterpret_cast<ChunkIter*>(const_cast<int8_t*>(frag_col_buffer)),
681 std::string fetched_str(reinterpret_cast<char*>(vd.
pointer), vd.
length);
701 const auto storage_lookup_result =
findStorage(entry_idx);
702 const auto storage = storage_lookup_result.storage_ptr;
703 const auto fixedup_entry_idx = storage_lookup_result.fixedup_entry_idx;
704 if (!storage->isEmptyEntry(fixedup_entry_idx)) {
734 const auto entry_idx =
736 const auto storage_lookup_result =
findStorage(entry_idx);
737 const auto storage = storage_lookup_result.storage_ptr;
738 const auto fixedup_entry_idx = storage_lookup_result.fixedup_entry_idx;
739 if (!storage->isEmptyEntry(fixedup_entry_idx)) {
758 return storage_->query_mem_desc_.getBufferSizeBytes(device_type);
781 const size_t buff_sz,
782 std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner) {
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]));
795 const size_t buff_sz,
797 const bool translate_strings,
798 std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner) {
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];
811 values.emplace_back(sdp->
getString(string_id));
815 ->getOrAddStringDictProxy(dict_key,
false)
821 for (
size_t i = 0; i < num_elems; i++) {
822 values.emplace_back(static_cast<int64_t>(buff[i]));
831 const size_t buff_sz,
832 const bool translate_strings,
833 std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner) {
836 if (elem_ti.is_string()) {
839 elem_ti.getStringDictKey(),
843 switch (elem_ti.get_size()) {
845 return build_array_target_value<int8_t>(buff, buff_sz, row_set_mem_owner);
847 return build_array_target_value<int16_t>(buff, buff_sz, row_set_mem_owner);
849 if (elem_ti.is_fp()) {
850 return build_array_target_value<float>(buff, buff_sz, row_set_mem_owner);
852 return build_array_target_value<int32_t>(buff, buff_sz, row_set_mem_owner);
855 if (elem_ti.is_fp()) {
856 return build_array_target_value<double>(buff, buff_sz, row_set_mem_owner);
858 return build_array_target_value<int64_t>(buff, buff_sz, row_set_mem_owner);
867 template <
class Tuple,
size_t... indices>
869 std::index_sequence<indices...>,
870 const Tuple& tuple) {
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))...};
876 const int64_t varlen_ptr) {
877 auto ad = std::make_unique<ArrayDatum>();
888 template <
typename...
T>
892 constexpr
int num_vals =
sizeof...(vals);
895 "Must have consistent pointer/size pairs for lazy fetch of geo target values.");
896 const auto vals_vector =
make_vals_vector(std::make_index_sequence<num_vals / 2>{},
897 std::make_tuple(vals...));
900 for (
const auto& col_pair : vals_vector) {
911 ad_arr[ctr]->is_null =
false;
915 if (ad_arr[ctr]->length == 0 || ad_arr[ctr]->pointer == NULL ||
917 is_null_point(geo_ti, ad_arr[ctr]->pointer, ad_arr[ctr]->length))) {
918 ad_arr[ctr]->is_null =
true;
928 const int64_t length,
930 const int device_id) {
932 std::shared_ptr<int8_t>(
new int8_t[length], std::default_delete<int8_t[]>());
933 auto allocator = std::make_unique<CudaAllocator>(
935 allocator->copyFromDevice(cpu_buf.get(),
reinterpret_cast<int8_t*
>(varlen_ptr), length);
937 return std::make_unique<ArrayDatum>(length, cpu_buf,
false);
942 return [](
const int64_t ptr,
const int64_t length) ->
VarlenDatumPtr {
944 return std::make_unique<VarlenDatum>(length,
reinterpret_cast<int8_t*
>(ptr),
false);
949 const int device_id) {
950 return [data_mgr_ptr, device_id](
const int64_t ptr,
957 return [](
const int64_t ptr,
const int64_t length) ->
VarlenDatumPtr {
959 return std::make_unique<VarlenDatum>(length,
reinterpret_cast<int8_t*
>(ptr),
false);
963 template <
typename...
T>
970 auto ad_arr_generator = [&](
auto datum_fetcher) {
971 constexpr
int num_vals =
sizeof...(vals);
974 "Must have consistent pointer/size pairs for lazy fetch of geo target values.");
975 const auto vals_vector = std::vector<int64_t>{vals...};
979 for (
size_t i = 0; i < vals_vector.size(); i += 2, ctr++) {
980 if (vals_vector[i] == 0) {
983 ad_arr[ctr] = std::make_unique<ArrayDatum>(0,
nullptr,
true);
986 ad_arr[ctr] = datum_fetcher(vals_vector[i], vals_vector[i + 1]);
991 if (ad_arr[ctr]->length == 0 || ad_arr[ctr]->pointer == NULL) {
994 is_null_point(geo_ti, ad_arr[ctr]->pointer, ad_arr[ctr]->length)) {
996 }
else if (ad_arr[ctr]->length == 4 *
sizeof(
double)) {
999 is_null = dti.is_null_fixlen_array(ad_arr[ctr]->pointer, ad_arr[ctr]->length);
1001 ad_arr[ctr]->is_null =
is_null;
1007 if (fetch_data_from_gpu) {
1009 return ad_arr_generator(yieldGpuPtrFetcher());
1011 return ad_arr_generator(yieldGpuDatumFetcher(data_mgr, device_id));
1014 return ad_arr_generator(yieldCpuDatumFetcher());
1019 template <SQLTypes GEO_SOURCE_TYPE,
typename GeoTargetFetcher>
1021 template <
typename...
T>
1025 auto ad_arr = GeoTargetFetcher::fetch(geo_ti, return_type, std::forward<T>(vals)...);
1026 static_assert(std::tuple_size<decltype(ad_arr)>::value > 0,
1027 "ArrayDatum array for Geo Target must contain at least one value.");
1031 switch (return_type) {
1033 if (!geo_ti.
get_notnull() && ad_arr[0]->is_null) {
1041 if (!geo_ti.
get_notnull() && ad_arr[0]->is_null) {
1051 if (!geo_ti.
get_notnull() && ad_arr[0]->is_null) {
1068 template <
typename T>
1070 const std::vector<std::vector<T>>& frag_offsets,
1071 const size_t tab_or_col_idx,
1072 const int64_t global_idx) {
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};
1089 bool const translate_strings,
1090 int64_t
const val)
const {
1102 bool const translate_strings) {
1113 int64_t
const rhs)
const {
1127 bool const translate_strings,
1128 int64_t
const ival) {
1137 const size_t col_logical_idx,
1138 int64_t& global_idx)
const {
1141 int64_t frag_id = 0;
1142 int64_t local_idx = global_idx;
1153 global_idx = local_idx;
1162 auto storage_lookup_result =
findStorage(entry_idx);
1163 CHECK(storage_lookup_result.storage_ptr);
1164 return storage_lookup_result.storage_ptr->getVarlenOutputInfo();
1172 int8_t* output_buffer,
1173 const size_t output_buffer_size)
const {
1176 CHECK(output_buffer_size > 0);
1177 CHECK(output_buffer);
1179 size_t out_buff_offset = 0;
1182 const size_t crt_storage_row_count =
storage_->query_mem_desc_.getEntryCount();
1183 const size_t crt_buffer_size = crt_storage_row_count * column_width_size;
1184 const size_t column_offset =
storage_->query_mem_desc_.getColOffInBytes(column_idx);
1185 const int8_t* storage_buffer =
storage_->getUnderlyingBuffer() + column_offset;
1186 CHECK(crt_buffer_size <= output_buffer_size);
1187 std::memcpy(output_buffer, storage_buffer, crt_buffer_size);
1189 out_buff_offset += crt_buffer_size;
1193 const size_t crt_storage_row_count =
1195 if (crt_storage_row_count == 0) {
1199 CHECK_LT(out_buff_offset, output_buffer_size);
1200 const size_t crt_buffer_size = crt_storage_row_count * column_width_size;
1201 const size_t column_offset =
1203 const int8_t* storage_buffer =
1205 CHECK(out_buff_offset + crt_buffer_size <= output_buffer_size);
1206 std::memcpy(output_buffer + out_buff_offset, storage_buffer, crt_buffer_size);
1208 out_buff_offset += crt_buffer_size;
1212 template <
typename ENTRY_TYPE, QueryDescriptionType QUERY_TYPE,
bool COLUMNAR_FORMAT>
1214 const size_t target_idx,
1215 const size_t slot_idx)
const {
1217 if constexpr (COLUMNAR_FORMAT) {
1218 return getColumnarPerfectHashEntryAt<ENTRY_TYPE>(row_idx, target_idx, slot_idx);
1220 return getRowWisePerfectHashEntryAt<ENTRY_TYPE>(row_idx, target_idx, slot_idx);
1223 if constexpr (COLUMNAR_FORMAT) {
1224 return getColumnarBaselineEntryAt<ENTRY_TYPE>(row_idx, target_idx, slot_idx);
1226 return getRowWiseBaselineEntryAt<ENTRY_TYPE>(row_idx, target_idx, slot_idx);
1234 #define DEF_GET_ENTRY_AT(query_type, columnar_output) \
1235 template DATA_T ResultSet::getEntryAt<DATA_T, query_type, columnar_output>( \
1236 const size_t row_idx, const size_t target_idx, const size_t slot_idx) const;
1238 #define DATA_T int64_t
1245 #define DATA_T int32_t
1252 #define DATA_T int16_t
1259 #define DATA_T int8_t
1266 #define DATA_T float
1273 #define DATA_T double
1280 #undef DEF_GET_ENTRY_AT
1288 template <
typename ENTRY_TYPE>
1290 const size_t target_idx,
1291 const size_t slot_idx)
const {
1292 const size_t column_offset =
storage_->query_mem_desc_.getColOffInBytes(slot_idx);
1293 const int8_t* storage_buffer =
storage_->getUnderlyingBuffer() + column_offset;
1294 return reinterpret_cast<const ENTRY_TYPE*
>(storage_buffer)[row_idx];
1303 template <
typename ENTRY_TYPE>
1305 const size_t target_idx,
1306 const size_t slot_idx)
const {
1307 const size_t row_offset =
storage_->query_mem_desc_.getRowSize() * row_idx;
1308 const size_t column_offset =
storage_->query_mem_desc_.getColOffInBytes(slot_idx);
1309 const int8_t* storage_buffer =
1310 storage_->getUnderlyingBuffer() + row_offset + column_offset;
1311 return *
reinterpret_cast<const ENTRY_TYPE*
>(storage_buffer);
1320 template <
typename ENTRY_TYPE>
1322 const size_t target_idx,
1323 const size_t slot_idx)
const {
1325 const auto key_width =
storage_->query_mem_desc_.getEffectiveKeyWidth();
1328 const auto column_offset =
1329 (
storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) < 0)
1330 ?
storage_->query_mem_desc_.getColOffInBytes(slot_idx)
1331 :
storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) * key_width;
1332 const auto storage_buffer = keys_ptr + column_offset;
1333 return *
reinterpret_cast<const ENTRY_TYPE*
>(storage_buffer);
1342 template <
typename ENTRY_TYPE>
1344 const size_t target_idx,
1345 const size_t slot_idx)
const {
1347 const auto key_width =
storage_->query_mem_desc_.getEffectiveKeyWidth();
1348 const auto column_offset =
1349 (
storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) < 0)
1350 ?
storage_->query_mem_desc_.getColOffInBytes(slot_idx)
1351 :
storage_->query_mem_desc_.getTargetGroupbyIndex(target_idx) * key_width *
1352 storage_->query_mem_desc_.getEntryCount();
1353 const auto column_buffer =
storage_->getUnderlyingBuffer() + column_offset;
1354 return reinterpret_cast<const ENTRY_TYPE*
>(column_buffer)[row_idx];
1359 const int8_t compact_sz1,
1361 const int8_t compact_sz2,
1363 const size_t target_logical_idx,
1364 const bool translate_strings,
1365 const size_t entry_buff_idx)
const {
1368 if (varlen_ptr < 0) {
1379 const auto& varlen_buffer_for_storage =
1381 CHECK_LT(static_cast<size_t>(varlen_ptr), varlen_buffer_for_storage.size());
1382 return varlen_buffer_for_storage[varlen_ptr];
1386 CHECK_LT(static_cast<size_t>(varlen_ptr), varlen_buffer.size());
1390 reinterpret_cast<const int8_t*>(varlen_buffer[varlen_ptr].data()),
1391 varlen_buffer[varlen_ptr].size(),
1401 if (col_lazy_fetch.is_lazily_fetched) {
1404 auto& frag_col_buffers =
1405 getColumnFrag(storage_idx.first, target_logical_idx, varlen_ptr);
1407 auto col_buf =
const_cast<int8_t*
>(frag_col_buffers[col_lazy_fetch.local_col_id]);
1411 std::string fetched_str;
1413 auto status = m.getItem(varlen_ptr, fetched_str,
is_null);
1417 CHECK_EQ(status, FlatBufferManager::Status::Success);
1422 reinterpret_cast<ChunkIter*>(col_buf), varlen_ptr,
false, &vd, &is_end);
1429 std::string fetched_str(reinterpret_cast<char*>(vd.
pointer), vd.
length);
1438 reinterpret_cast<ChunkIter*>(col_buf), varlen_ptr, &ad, &is_end);
1444 if (ad.length > 0) {
1466 std::vector<int8_t> cpu_buffer;
1468 cpu_buffer.resize(length);
1471 auto data_mgr = executor->getDataMgr();
1472 auto allocator = std::make_unique<CudaAllocator>(
1475 allocator->copyFromDevice(
1476 &cpu_buffer[0], reinterpret_cast<int8_t*>(varlen_ptr), length);
1477 varlen_ptr =
reinterpret_cast<int64_t
>(&cpu_buffer[0]);
1481 reinterpret_cast<const int8_t*>(varlen_ptr),
1486 return std::string(reinterpret_cast<char*>(varlen_ptr), length);
1496 throw std::runtime_error(
"Column target at index " +
std::to_string(col_idx) +
1497 " is not a geo column. It is of type " +
1498 targets_[col_idx].sql_type.get_type_name() +
".");
1501 const auto& target_info =
targets_[col_idx];
1516 template <
size_t NDIM,
1517 typename GeospatialGeoType,
1518 typename GeoTypeTargetValue,
1519 typename GeoTypeTargetValuePtr>
1521 const int64_t index,
1533 auto status = m.getItem(index, item);
1534 CHECK_EQ(status, FlatBufferManager::Status::Success);
1539 switch (return_type) {
1544 std::vector<double> coords;
1549 const double* values_buf =
reinterpret_cast<const double*
>(item.
values);
1550 coords.insert(coords.end(), values_buf, values_buf + 2 * item.
nof_values);
1552 if constexpr (NDIM == 1) {
1553 GeospatialGeoType obj(coords);
1555 }
else if constexpr (NDIM == 2) {
1556 std::vector<int32_t> rings;
1557 rings.insert(rings.end(),
1560 GeospatialGeoType obj(coords, rings);
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(),
1568 rings.insert(rings.end(),
1571 GeospatialGeoType obj(coords, rings, poly_rings);
1581 std::vector<double> coords;
1586 const double* values_buf =
reinterpret_cast<const double*
>(item.
values);
1587 coords.insert(coords.end(), values_buf, values_buf + 2 * item.
nof_values);
1589 if constexpr (NDIM == 1) {
1591 }
else if constexpr (NDIM == 2) {
1592 std::vector<int32_t> rings;
1593 rings.insert(rings.end(),
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(),
1603 rings.insert(rings.end(),
1606 return GeoTargetValue(GeoTypeTargetValue(coords, rings, poly_rings));
1614 return GeoTypeTargetValuePtr();
1616 auto coords = std::make_shared<VarlenDatum>(
1619 if constexpr (NDIM == 1) {
1620 return GeoTypeTargetValuePtr({std::move(coords)});
1621 }
else if constexpr (NDIM == 2) {
1622 auto rings = std::make_shared<VarlenDatum>(
1626 return GeoTypeTargetValuePtr({std::move(coords), std::move(rings)});
1627 }
else if constexpr (NDIM == 3) {
1628 auto poly_rings = std::make_shared<VarlenDatum>(
1632 auto rings = std::make_shared<VarlenDatum>(
1636 return GeoTypeTargetValuePtr(
1637 {std::move(coords), std::move(rings), std::move(poly_rings)});
1653 const size_t slot_idx,
1655 const size_t target_logical_idx,
1656 const size_t entry_buff_idx)
const {
1659 auto getNextTargetBufferRowWise = [&](
const size_t slot_idx,
const size_t range) {
1663 auto getNextTargetBufferColWise = [&](
const size_t slot_idx,
const size_t range) {
1664 const auto storage_info =
findStorage(entry_buff_idx);
1665 auto crt_geo_col_ptr = geo_target_ptr;
1666 for (
size_t i = slot_idx; i < slot_idx + range; i++) {
1668 crt_geo_col_ptr, storage_info.storage_ptr->query_mem_desc_, i);
1671 return crt_geo_col_ptr +
1672 storage_info.fixedup_entry_idx *
1673 storage_info.storage_ptr->query_mem_desc_.getPaddedSlotWidthBytes(
1677 auto getNextTargetBuffer = [&](
const size_t slot_idx,
const size_t range) {
1679 ? getNextTargetBufferColWise(slot_idx, range)
1680 : getNextTargetBufferRowWise(slot_idx, range);
1683 auto getCoordsDataPtr = [&](
const int8_t* geo_target_ptr) {
1688 auto getCoordsLength = [&](
const int8_t* geo_target_ptr) {
1693 auto getRingSizesPtr = [&](
const int8_t* geo_target_ptr) {
1698 auto getRingSizesLength = [&](
const int8_t* geo_target_ptr) {
1703 auto getPolyRingsPtr = [&](
const int8_t* geo_target_ptr) {
1708 auto getPolyRingsLength = [&](
const int8_t* geo_target_ptr) {
1713 auto getFragColBuffers = [&]() -> decltype(
auto) {
1716 auto global_idx = getCoordsDataPtr(geo_target_ptr);
1717 return getColumnFrag(storage_idx.first, target_logical_idx, global_idx);
1722 auto getDataMgr = [&]() {
1725 return executor->getDataMgr();
1728 auto getSeparateVarlenStorage = [&]() -> decltype(
auto) {
1732 return varlen_buffer;
1736 CHECK_EQ(-1, getCoordsDataPtr(geo_target_ptr));
1750 CHECK(varlen_output_info);
1754 reinterpret_cast<int64_t
>(varlen_output_info->computeCpuOffset(geo_data_ptr));
1755 return GeoTargetValueBuilder<kPOINT, GeoQueryOutputFetchHandler>::build(
1764 const auto& varlen_buffer = getSeparateVarlenStorage();
1765 CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr)),
1766 varlen_buffer.size());
1768 return GeoTargetValueBuilder<kPOINT, GeoQueryOutputFetchHandler>::build(
1774 reinterpret_cast<int64_t>(
1775 varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1776 static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()));
1778 const auto& frag_col_buffers = getFragColBuffers();
1779 return GeoTargetValueBuilder<kPOINT, GeoLazyFetchHandler>::build(
1783 getCoordsDataPtr(geo_target_ptr));
1785 return GeoTargetValueBuilder<kPOINT, GeoQueryOutputFetchHandler>::build(
1788 is_gpu_fetch ? getDataMgr() :
nullptr,
1791 getCoordsDataPtr(geo_target_ptr),
1792 getCoordsLength(geo_target_ptr));
1798 const auto& varlen_buffer = getSeparateVarlenStorage();
1799 CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr)),
1800 varlen_buffer.size());
1802 return GeoTargetValueBuilder<kMULTIPOINT, GeoQueryOutputFetchHandler>::build(
1808 reinterpret_cast<int64_t>(
1809 varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1810 static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()));
1812 const auto& frag_col_buffers = getFragColBuffers();
1814 auto ptr = frag_col_buffers[col_lazy_fetch->
local_col_id];
1816 int64_t index = getCoordsDataPtr(geo_target_ptr);
1823 return GeoTargetValueBuilder<kMULTIPOINT, GeoLazyFetchHandler>::build(
1827 getCoordsDataPtr(geo_target_ptr));
1829 return GeoTargetValueBuilder<kMULTIPOINT, GeoQueryOutputFetchHandler>::build(
1832 is_gpu_fetch ? getDataMgr() :
nullptr,
1835 getCoordsDataPtr(geo_target_ptr),
1836 getCoordsLength(geo_target_ptr));
1842 const auto& varlen_buffer = getSeparateVarlenStorage();
1843 CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr)),
1844 varlen_buffer.size());
1846 return GeoTargetValueBuilder<kLINESTRING, GeoQueryOutputFetchHandler>::build(
1852 reinterpret_cast<int64_t>(
1853 varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1854 static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()));
1856 const auto& frag_col_buffers = getFragColBuffers();
1858 auto ptr = frag_col_buffers[col_lazy_fetch->
local_col_id];
1860 int64_t index = getCoordsDataPtr(geo_target_ptr);
1867 return GeoTargetValueBuilder<kLINESTRING, GeoLazyFetchHandler>::build(
1871 getCoordsDataPtr(geo_target_ptr));
1873 return GeoTargetValueBuilder<kLINESTRING, GeoQueryOutputFetchHandler>::build(
1876 is_gpu_fetch ? getDataMgr() :
nullptr,
1879 getCoordsDataPtr(geo_target_ptr),
1880 getCoordsLength(geo_target_ptr));
1886 const auto& varlen_buffer = getSeparateVarlenStorage();
1887 CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr) + 1),
1888 varlen_buffer.size());
1890 return GeoTargetValueBuilder<kMULTILINESTRING, GeoQueryOutputFetchHandler>::build(
1896 reinterpret_cast<int64_t>(
1897 varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1898 static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()),
1899 reinterpret_cast<int64_t>(
1900 varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].data()),
1901 static_cast<int64_t>(
1902 varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].size()));
1904 const auto& frag_col_buffers = getFragColBuffers();
1906 auto ptr = frag_col_buffers[col_lazy_fetch->
local_col_id];
1908 int64_t index = getCoordsDataPtr(geo_target_ptr);
1916 return GeoTargetValueBuilder<kMULTILINESTRING, GeoLazyFetchHandler>::build(
1920 getCoordsDataPtr(geo_target_ptr),
1922 getCoordsDataPtr(geo_target_ptr));
1924 return GeoTargetValueBuilder<kMULTILINESTRING, GeoQueryOutputFetchHandler>::build(
1927 is_gpu_fetch ? getDataMgr() :
nullptr,
1930 getCoordsDataPtr(geo_target_ptr),
1931 getCoordsLength(geo_target_ptr),
1932 getRingSizesPtr(geo_target_ptr),
1933 getRingSizesLength(geo_target_ptr) * 4);
1939 const auto& varlen_buffer = getSeparateVarlenStorage();
1940 CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr) + 1),
1941 varlen_buffer.size());
1943 return GeoTargetValueBuilder<kPOLYGON, GeoQueryOutputFetchHandler>::build(
1949 reinterpret_cast<int64_t>(
1950 varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
1951 static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()),
1952 reinterpret_cast<int64_t>(
1953 varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].data()),
1954 static_cast<int64_t>(
1955 varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].size()));
1957 const auto& frag_col_buffers = getFragColBuffers();
1958 auto ptr = frag_col_buffers[col_lazy_fetch->
local_col_id];
1960 int64_t index = getCoordsDataPtr(geo_target_ptr);
1968 return GeoTargetValueBuilder<kPOLYGON, GeoLazyFetchHandler>::build(
1972 getCoordsDataPtr(geo_target_ptr),
1974 getCoordsDataPtr(geo_target_ptr));
1976 return GeoTargetValueBuilder<kPOLYGON, GeoQueryOutputFetchHandler>::build(
1979 is_gpu_fetch ? getDataMgr() :
nullptr,
1982 getCoordsDataPtr(geo_target_ptr),
1983 getCoordsLength(geo_target_ptr),
1984 getRingSizesPtr(geo_target_ptr),
1985 getRingSizesLength(geo_target_ptr) * 4);
1991 const auto& varlen_buffer = getSeparateVarlenStorage();
1992 CHECK_LT(static_cast<size_t>(getCoordsDataPtr(geo_target_ptr) + 2),
1993 varlen_buffer.size());
1995 return GeoTargetValueBuilder<kMULTIPOLYGON, GeoQueryOutputFetchHandler>::build(
2001 reinterpret_cast<int64_t>(
2002 varlen_buffer[getCoordsDataPtr(geo_target_ptr)].data()),
2003 static_cast<int64_t>(varlen_buffer[getCoordsDataPtr(geo_target_ptr)].size()),
2004 reinterpret_cast<int64_t>(
2005 varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].data()),
2006 static_cast<int64_t>(
2007 varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 1].size()),
2008 reinterpret_cast<int64_t>(
2009 varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 2].data()),
2010 static_cast<int64_t>(
2011 varlen_buffer[getCoordsDataPtr(geo_target_ptr) + 2].size()));
2013 const auto& frag_col_buffers = getFragColBuffers();
2014 auto ptr = frag_col_buffers[col_lazy_fetch->
local_col_id];
2016 int64_t index = getCoordsDataPtr(geo_target_ptr);
2024 return GeoTargetValueBuilder<kMULTIPOLYGON, GeoLazyFetchHandler>::build(
2028 getCoordsDataPtr(geo_target_ptr),
2030 getCoordsDataPtr(geo_target_ptr),
2032 getCoordsDataPtr(geo_target_ptr));
2034 return GeoTargetValueBuilder<kMULTIPOLYGON, GeoQueryOutputFetchHandler>::build(
2037 is_gpu_fetch ? getDataMgr() :
nullptr,
2040 getCoordsDataPtr(geo_target_ptr),
2041 getCoordsLength(geo_target_ptr),
2042 getRingSizesPtr(geo_target_ptr),
2043 getRingSizesLength(geo_target_ptr) * 4,
2044 getPolyRingsPtr(geo_target_ptr),
2045 getPolyRingsLength(geo_target_ptr) * 4);
2050 throw std::runtime_error(
"Unknown Geometry type encountered: " +
2060 if (dict_key.dict_id) {
2061 constexpr
bool with_generation =
false;
2062 sdp = dict_key.db_id > 0
2073 bool const translate_strings,
2074 int64_t
const ival)
const {
2075 if (translate_strings) {
2076 if (static_cast<int32_t>(ival) ==
NULL_INT) {
2082 return static_cast<int64_t
>(
static_cast<int32_t
>(ival));
2088 const int8_t compact_sz,
2090 const size_t target_logical_idx,
2091 const bool translate_strings,
2092 const bool decimal_to_double,
2093 const size_t entry_buff_idx)
const {
2094 auto actual_compact_sz = compact_sz;
2095 const auto& type_info = target_info.
sql_type;
2098 actual_compact_sz =
sizeof(float);
2100 actual_compact_sz =
sizeof(double);
2102 if (target_info.
is_agg &&
2108 actual_compact_sz =
sizeof(float);
2113 actual_compact_sz =
sizeof(int64_t);
2117 if (type_info.is_string() && type_info.get_compression() ==
kENCODING_DICT &&
2118 type_info.getStringDictKey().dict_id) {
2119 actual_compact_sz =
sizeof(int32_t);
2127 if (col_lazy_fetch.is_lazily_fetched) {
2131 auto& frag_col_buffers =
getColumnFrag(storage_idx.first, target_logical_idx, ival);
2132 CHECK_LT(
size_t(col_lazy_fetch.local_col_id), frag_col_buffers.size());
2134 col_lazy_fetch, frag_col_buffers[col_lazy_fetch.local_col_id], ival);
2135 if (chosen_type.is_fp()) {
2136 const auto dval = *
reinterpret_cast<const double*
>(may_alias_ptr(&ival));
2137 if (chosen_type.get_type() ==
kFLOAT) {
2146 if (!
isNullIval(chosen_type, translate_strings, ival)) {
2147 auto const*
const*
const agg_mode =
reinterpret_cast<AggMode const* const*
>(ptr);
2148 if (std::optional<int64_t>
const mode = (*agg_mode)->mode()) {
2154 if (chosen_type.is_fp()) {
2156 return *
reinterpret_cast<double const*
>(ptr) ==
NULL_DOUBLE
2160 switch (actual_compact_sz) {
2162 const auto dval = *
reinterpret_cast<const double*
>(ptr);
2163 return chosen_type.get_type() ==
kFLOAT
2169 return *
reinterpret_cast<const float*
>(ptr);
2175 if (chosen_type.is_integer() || chosen_type.is_boolean() || chosen_type.is_time() ||
2176 chosen_type.is_timeinterval()) {
2189 if (chosen_type.is_string() && chosen_type.get_compression() ==
kENCODING_DICT) {
2192 if (chosen_type.is_decimal()) {
2193 if (decimal_to_double) {
2194 if (target_info.
is_agg &&
2201 if (!chosen_type.get_notnull() &&
2206 return static_cast<double>(ival) /
exp_to_scale(chosen_type.get_scale());
2215 const int8_t* col_ptr,
2217 const size_t slot_idx,
2218 const size_t target_logical_idx,
2219 const size_t global_entry_idx,
2220 const size_t local_entry_idx,
2221 const bool translate_strings,
2226 CHECK(m.isNestedArray());
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;
2240 CHECK_EQ(status, FlatBufferManager::Status::ItemUnspecifiedError);
2246 if (ad.length > 0) {
2253 row_set_mem_owner_);
2267 const int8_t* col_ptr,
2268 const int8_t* keys_ptr,
2270 const size_t local_entry_idx,
2271 const size_t global_entry_idx,
2273 const size_t target_logical_idx,
2274 const size_t slot_idx,
2275 const bool translate_strings,
2276 const bool decimal_to_double)
const {
2278 const auto col1_ptr = col_ptr;
2281 <<
"target_info.sql_type=" << target_info.
sql_type;
2289 row_set_mem_owner_);
2292 const auto next_col_ptr =
2306 col1_ptr, slot_idx, target_info, target_logical_idx, global_entry_idx);
2351 int8_t* rowwise_target_ptr,
2353 const size_t entry_buff_idx,
2355 const size_t target_logical_idx,
2356 const size_t slot_idx,
2357 const bool translate_strings,
2358 const bool decimal_to_double,
2359 const bool fixup_count_distinct_pointers)
const {
2365 if (
UNLIKELY(fixup_count_distinct_pointers)) {
2367 auto count_distinct_ptr_ptr =
reinterpret_cast<int64_t*
>(rowwise_target_ptr);
2368 const auto remote_ptr = *count_distinct_ptr_ptr;
2370 const auto ptr =
storage_->mappedPtr(remote_ptr);
2372 *count_distinct_ptr_ptr = ptr;
2375 const auto& count_distinct_desc =
2377 const auto bitmap_byte_sz = count_distinct_desc.sub_bitmap_count == 1
2378 ? count_distinct_desc.bitmapSizeBytes()
2379 : count_distinct_desc.bitmapPaddedSizeBytes();
2380 constexpr
size_t thread_idx{0};
2381 row_set_mem_owner_->initCountDistinctBufferAllocator(bitmap_byte_sz,
2383 auto count_distinct_buffer =
2384 row_set_mem_owner_->allocateCountDistinctBuffer(bitmap_byte_sz, thread_idx);
2385 *count_distinct_ptr_ptr =
reinterpret_cast<int64_t
>(count_distinct_buffer);
2393 rowwise_target_ptr, slot_idx, target_info, target_logical_idx, entry_buff_idx);
2396 auto ptr1 = rowwise_target_ptr;
2411 int8_t compact_sz2 = 0;
2463 return isEmptyEntryColumnar(entry_idx, buff);
2470 target_init_vals_.size());
2484 return *
reinterpret_cast<const int32_t*
>(keys_ptr) ==
EMPTY_KEY_32;
2486 return *
reinterpret_cast<const int64_t*
>(keys_ptr) ==
EMPTY_KEY_64;
2499 const int8_t* buff)
const {
2508 CHECK_LT(entry_idx, getEntryCount());
2516 target_init_vals_.size());
2519 const auto entry_buff =
2529 return reinterpret_cast<const int64_t*
>(buff)[entry_idx] ==
EMPTY_KEY_64;
2535 return reinterpret_cast<const int64_t*
>(target_buff)[entry_idx] ==
EMPTY_KEY_64;
2537 return reinterpret_cast<const int32_t*
>(target_buff)[entry_idx] ==
EMPTY_KEY_32;
2539 return reinterpret_cast<const int16_t*
>(target_buff)[entry_idx] ==
EMPTY_KEY_16;
2541 return reinterpret_cast<const int8_t*
>(target_buff)[entry_idx] ==
EMPTY_KEY_8;
2553 template <
typename T>
2556 if (!is_empty_fn(r - 1)) {
2562 size_t c = (l + r) / 2;
2563 if (is_empty_fn(c)) {
2587 return reinterpret_cast<const int64_t*
>(buff_)[idx] ==
EMPTY_KEY_64;
2592 return *
reinterpret_cast<const int64_t*
>(keys_ptr) ==
EMPTY_KEY_64;
2598 return isEmptyEntry(entry_idx, buff_);
2603 const bool float_argument_input) {
InternalTargetValue getColumnInternal(const int8_t *buff, const size_t entry_idx, const size_t target_logical_idx, const StorageLookupResult &storage_lookup_result) const
size_t getSlotCount() const
bool slotIsVarlenOutput(const size_t slot_idx) const
std::pair< size_t, size_t > getStorageIndex(const size_t entry_idx) const
size_t getEntryCount() const
bool isEmptyEntry(const size_t entry_idx, const int8_t *buff) const
ENTRY_TYPE getRowWisePerfectHashEntryAt(const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
static ScalarTargetValue nullScalarTargetValue(SQLTypeInfo const &, bool const translate_strings)
AppendedStorage appended_storage_
ENTRY_TYPE getColumnarPerfectHashEntryAt(const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
int64_t getTargetGroupbyIndex(const size_t target_idx) const
GeoReturnType geo_return_type_
bool isEmptyEntryColumnar(const size_t entry_idx, const int8_t *buff) const
bool isLogicalSizedColumnsAllowed() const
T advance_to_next_columnar_target_buff(T target_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t target_slot_idx)
size_t make_bin_search(size_t l, size_t r, T &&is_empty_fn)
std::unique_ptr< ArrayDatum > lazy_fetch_chunk(const int8_t *ptr, const int64_t varlen_ptr)
TargetValue NestedArrayToGeoTargetValue(const int8_t *buf, const int64_t index, const SQLTypeInfo &ti, const ResultSet::GeoReturnType return_type)
std::vector< TargetValue > getNextRow(const bool translate_strings, const bool decimal_to_double) const
static bool isNull(const SQLTypeInfo &ti, const InternalTargetValue &val, const bool float_argument_input)
QueryMemoryDescriptor query_mem_desc_
bool hasKeylessHash() const
std::unique_ptr< ResultSetStorage > storage_
bool is_null_point(const SQLTypeInfo &geo_ti, const int8_t *coords, const size_t coords_sz)
std::string getString(int32_t string_id) const
High-level representation of SQL values.
ENTRY_TYPE getEntryAt(const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
size_t getEffectiveKeyWidth() const
Constants for Builtin SQL Types supported by HEAVY.AI.
TargetValue makeGeoTargetValue(const int8_t *geo_target_ptr, const size_t slot_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t entry_buff_idx) const
TargetValue getTargetValueFromBufferRowwise(int8_t *rowwise_target_ptr, int8_t *keys_ptr, const size_t entry_buff_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t slot_idx, const bool translate_strings, const bool decimal_to_double, const bool fixup_count_distinct_pointers) const
int64_t read_int_from_buff(const int8_t *ptr, const int8_t compact_sz)
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)
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)
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_)
std::vector< SerializedVarlenBufferStorage > serialized_varlen_buffer_
int64_t lazyReadInt(const int64_t ival, const size_t target_logical_idx, const StorageLookupResult &storage_lookup_result) const
HOST DEVICE SQLTypes get_type() const
OneIntegerColumnRow getOneColRow(const size_t index) const
static bool isNullIval(SQLTypeInfo const &, bool const translate_strings, int64_t const ival)
TargetValue getTargetValueFromBufferColwise(const int8_t *col_ptr, const int8_t *keys_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t local_entry_idx, const size_t global_entry_idx, const TargetInfo &target_info, const size_t target_logical_idx, const size_t slot_idx, const bool translate_strings, const bool decimal_to_double) const
T advance_target_ptr_row_wise(T target_ptr, const TargetInfo &target_info, const size_t slot_idx, const QueryMemoryDescriptor &query_mem_desc, const bool separate_varlen_storage)
int64_t null_val_bit_pattern(const SQLTypeInfo &ti, const bool float_argument_input)
DEVICE void ChunkIter_get_nth(ChunkIter *it, int n, bool uncompress, VarlenDatum *result, bool *is_end)
TargetValue build_array_target_value(const int8_t *buff, const size_t buff_sz, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
ScalarTargetValue makeStringTargetValue(SQLTypeInfo const &chosen_type, bool const translate_strings, int64_t const ival) const
const ResultSet * result_set_
std::vector< TargetValue > getRowAtNoTranslations(const size_t index, const std::vector< bool > &targets_to_skip={}) const
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)
Serialization routines for geospatial types.
std::conditional_t< is_cuda_compiler(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
const SQLTypeInfo get_compact_type(const TargetInfo &target)
bool forceFourByteFloat() const
InternalTargetValue getVarlenOrderEntry(const int64_t str_ptr, const size_t str_len) const
std::shared_ptr< std::vector< double > > decompress_coords< double, SQLTypeInfo >(const SQLTypeInfo &geo_ti, const int8_t *coords, const size_t coords_sz)
const std::vector< TargetInfo > targets_
int8_t groupColWidth(const size_t key_idx) const
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
size_t get_byteoff_of_slot(const size_t slot_idx, const QueryMemoryDescriptor &query_mem_desc)
size_t advance_slot(const size_t j, const TargetInfo &target_info, const bool separate_varlen_storage)
CONSTEXPR DEVICE bool is_null(const T &value)
static TargetValue build(const SQLTypeInfo &geo_ti, const ResultSet::GeoReturnType return_type, T &&...vals)
Classes representing a parse tree.
static auto yieldGpuPtrFetcher()
int64_t count_distinct_set_size(const int64_t set_handle, const CountDistinctDescriptor &count_distinct_desc)
size_t getGroupbyColCount() const
size_t targetGroupbyIndicesSize() const
size_t binSearchRowCount() const
boost::optional< std::vector< ScalarTargetValue >> ArrayTargetValue
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)
int64_t lazy_decode(const ColumnLazyFetchInfo &col_lazy_fetch, const int8_t *byte_stream, const int64_t pos)
ScalarTargetValue convertToScalarTargetValue(SQLTypeInfo const &, bool const translate_strings, int64_t const val) const
CountDistinctDescriptors count_distinct_descriptors_
size_t getPaddedColWidthForRange(const size_t offset, const size_t range) const
StorageLookupResult findStorage(const size_t entry_idx) const
boost::optional< boost::variant< GeoPointTargetValue, GeoMultiPointTargetValue, GeoLineStringTargetValue, GeoMultiLineStringTargetValue, GeoPolyTargetValue, GeoMultiPolyTargetValue >> GeoTargetValue
bool is_distinct_target(const TargetInfo &target_info)
bool usesFlatBuffer() const
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
void copyColumnIntoBuffer(const size_t column_idx, int8_t *output_buffer, const size_t output_buffer_size) const
bool g_enable_smem_group_by true
static double calculateQuantile(quantile::TDigest *const t_digest)
T row_ptr_rowwise(T buff, const QueryMemoryDescriptor &query_mem_desc, const size_t entry_idx)
const VarlenOutputInfo * getVarlenOutputInfo(const size_t entry_idx) const
QueryDescriptionType getQueryDescriptionType() const
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
std::vector< TargetValue > getRowAt(const size_t index) const
const CountDistinctDescriptor & getCountDistinctDescriptor(const size_t idx) const
bool is_real_str_or_array(const TargetInfo &target_info)
bool isSingleColumnGroupByWithPerfectHash() const
void serialize(Archive &ar, RegisteredQueryHint &query_hint, const unsigned int version)
HOST DEVICE EncodingType get_compression() const
bool is_date_in_days() const
int64_t int_resize_cast(const int64_t ival, const size_t sz)
int get_array_context_logical_size() const
bool isGeoColOnGpu(const size_t col_idx) const
int32_t * sizes_buffers[NDIM]
void initializeOffsetsForStorage()
std::vector< std::vector< std::vector< const int8_t * > > > col_buffers_
#define DEF_GET_ENTRY_AT(query_type, columnar_output)
bool isRowAtEmpty(const size_t index) const
size_t entryCount() const
Returns the number of entries the result set is allocated to hold.
static auto fetch(const SQLTypeInfo &geo_ti, const ResultSet::GeoReturnType return_type, Data_Namespace::DataMgr *data_mgr, const bool fetch_data_from_gpu, const int device_id, T &&...vals)
std::string get_type_name() const
boost::variant< std::string, void * > NullableString
CUstream getQueryEngineCudaStreamForDevice(int device_num)
TargetValue makeTargetValue(const int8_t *ptr, const int8_t compact_sz, const TargetInfo &target_info, const size_t target_logical_idx, const bool translate_strings, const bool decimal_to_double, const size_t entry_buff_idx) const
static auto yieldGpuDatumFetcher(Data_Namespace::DataMgr *data_mgr_ptr, const int device_id)
const bool is_lazily_fetched
std::vector< std::vector< int64_t > > consistent_frag_sizes_
bool didOutputColumnar() const
std::string getString(SQLTypeInfo const &, int64_t const ival) const
const ExecutorDeviceType device_type_
std::vector< TargetValue > getNextRowImpl(const bool translate_strings, const bool decimal_to_double) const
bool g_enable_watchdog false
static auto fetch(const SQLTypeInfo &geo_ti, const ResultSet::GeoReturnType return_type, T &&...vals)
ScalarTargetValue make_scalar_tv(const T val)
size_t getBufferSizeBytes(const ExecutorDeviceType device_type) const
std::vector< ColumnLazyFetchInfo > lazy_fetch_info_
uint64_t exp_to_scale(const unsigned exp)
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
std::vector< std::vector< std::vector< int64_t > > > frag_offsets_
Basic constructors and methods of the row set interface.
bool separate_varlen_storage_valid_
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
std::vector< TargetValue > getNextRowUnlocked(const bool translate_strings, const bool decimal_to_double) const
std::vector< std::pair< const int8_t *, const int64_t > > make_vals_vector(std::index_sequence< indices...>, const Tuple &tuple)
static auto yieldCpuDatumFetcher()
T advance_target_ptr_col_wise(T target_ptr, const TargetInfo &target_info, const size_t slot_idx, const QueryMemoryDescriptor &query_mem_desc, const bool separate_varlen_storage)
size_t advanceCursorToNextEntry() const
HOST DEVICE bool get_notnull() const
ENTRY_TYPE getColumnarBaselineEntryAt(const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
HOST static DEVICE bool isFlatBuffer(const void *buffer)
int32_t sizes_lengths[NDIM]
InternalTargetValue getColumnInternal(const int8_t *buff, const size_t entry_idx, const size_t target_logical_idx, const StorageLookupResult &storage_lookup_result) const
bool isLessThan(SQLTypeInfo const &, int64_t const lhs, int64_t const rhs) const
std::vector< std::vector< TargetOffsets > > offsets_for_storage_
SQLTypeInfo get_elem_type() const
size_t getBufferColSlotCount() const
T get_cols_ptr(T buff, const QueryMemoryDescriptor &query_mem_desc)
const int8_t getLogicalSlotWidthBytes(const size_t slot_idx) const
void initializeOffsetsForStorage()
bool global_entry_idx_valid_
std::unique_ptr< VarlenDatum > VarlenDatumPtr
bool isDirectColumnarConversionPossible() const
size_t get_key_bytes_rowwise(const QueryMemoryDescriptor &query_mem_desc)
const int8_t * columnar_elem_ptr(const size_t entry_idx, const int8_t *col1_ptr, const int8_t compact_sz1)
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)
TargetValue makeVarlenTargetValue(const int8_t *ptr1, const int8_t compact_sz1, const int8_t *ptr2, const int8_t compact_sz2, const TargetInfo &target_info, const size_t target_logical_idx, const bool translate_strings, const size_t entry_buff_idx) const
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)
const std::vector< const int8_t * > & getColumnFrag(const size_t storge_idx, const size_t col_logical_idx, int64_t &global_idx) const
const Executor * getExecutor() const
std::unique_ptr< ArrayDatum > fetch_data_from_gpu(int64_t varlen_ptr, const int64_t length, Data_Namespace::DataMgr *data_mgr, const int device_id)
DEVICE void VarlenArray_get_nth(int8_t *buf, int n, ArrayDatum *result, bool *is_end)
ENTRY_TYPE getRowWiseBaselineEntryAt(const size_t row_idx, const size_t target_idx, const size_t slot_idx) const
const shared::StringDictKey & getStringDictKey() const
boost::variant< int64_t, double, float, NullableString > ScalarTargetValue
int32_t getTargetIdxForKey() const
const size_t fixedup_entry_idx
size_t getPrependedGroupColOffInBytes(const size_t group_idx) const