OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE > Struct Template Reference
+ Collaboration diagram for ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >:

Public Types

using BufferIteratorType = BUFFER_ITERATOR_TYPE
 

Public Member Functions

 ResultSetComparator (const std::list< Analyzer::OrderEntry > &order_entries, const bool use_heap, const ResultSet *result_set)
 
bool operator() (const uint32_t lhs, const uint32_t rhs) const
 

Public Attributes

const std::list
< Analyzer::OrderEntry
order_entries_
 
const bool use_heap_
 
const ResultSetresult_set_
 
const BufferIteratorType buffer_itr_
 

Detailed Description

template<typename BUFFER_ITERATOR_TYPE>
struct ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >

Definition at line 719 of file ResultSet.h.

Member Typedef Documentation

template<typename BUFFER_ITERATOR_TYPE >
using ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::BufferIteratorType = BUFFER_ITERATOR_TYPE

Definition at line 720 of file ResultSet.h.

Constructor & Destructor Documentation

template<typename BUFFER_ITERATOR_TYPE >
ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::ResultSetComparator ( const std::list< Analyzer::OrderEntry > &  order_entries,
const bool  use_heap,
const ResultSet result_set 
)
inline

Definition at line 722 of file ResultSet.h.

725  : order_entries_(order_entries)
726  , use_heap_(use_heap)
727  , result_set_(result_set)
728  , buffer_itr_(result_set) {}
const std::list< Analyzer::OrderEntry > order_entries_
Definition: ResultSet.h:733
const BufferIteratorType buffer_itr_
Definition: ResultSet.h:736
const ResultSet * result_set_
Definition: ResultSet.h:735

Member Function Documentation

template<typename BUFFER_ITERATOR_TYPE >
bool ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::operator() ( const uint32_t  lhs,
const uint32_t  rhs 
) const

Definition at line 626 of file ResultSet.cpp.

References CHECK(), CHECK_EQ, CHECK_GE, count_distinct_set_size(), get_compact_type(), is_distinct_target(), kENCODING_DICT, kFLOAT, LIKELY, pair_to_double(), takes_float_argument(), and UNLIKELY.

628  {
629  // NB: The compare function must define a strict weak ordering, otherwise
630  // std::sort will trigger a segmentation fault (or corrupt memory).
631  const auto lhs_storage_lookup_result = result_set_->findStorage(lhs);
632  const auto rhs_storage_lookup_result = result_set_->findStorage(rhs);
633  const auto lhs_storage = lhs_storage_lookup_result.storage_ptr;
634  const auto rhs_storage = rhs_storage_lookup_result.storage_ptr;
635  const auto fixedup_lhs = lhs_storage_lookup_result.fixedup_entry_idx;
636  const auto fixedup_rhs = rhs_storage_lookup_result.fixedup_entry_idx;
637  for (const auto order_entry : order_entries_) {
638  CHECK_GE(order_entry.tle_no, 1);
639  const auto& agg_info = result_set_->targets_[order_entry.tle_no - 1];
640  const auto entry_ti = get_compact_type(agg_info);
641  bool float_argument_input = takes_float_argument(agg_info);
642  // Need to determine if the float value has been stored as float
643  // or if it has been compacted to a different (often larger 8 bytes)
644  // in distributed case the floats are actually 4 bytes
645  // TODO the above takes_float_argument() is widely used wonder if this problem
646  // exists elsewhere
647  if (entry_ti.get_type() == kFLOAT) {
648  const auto is_col_lazy =
649  !result_set_->lazy_fetch_info_.empty() &&
650  result_set_->lazy_fetch_info_[order_entry.tle_no - 1].is_lazily_fetched;
651  if (result_set_->query_mem_desc_.getPaddedSlotWidthBytes(order_entry.tle_no - 1) ==
652  sizeof(float)) {
653  float_argument_input =
654  result_set_->query_mem_desc_.didOutputColumnar() ? !is_col_lazy : true;
655  }
656  }
657  const auto lhs_v = buffer_itr_.getColumnInternal(lhs_storage->buff_,
658  fixedup_lhs,
659  order_entry.tle_no - 1,
660  lhs_storage_lookup_result);
661  const auto rhs_v = buffer_itr_.getColumnInternal(rhs_storage->buff_,
662  fixedup_rhs,
663  order_entry.tle_no - 1,
664  rhs_storage_lookup_result);
665  if (UNLIKELY(isNull(entry_ti, lhs_v, float_argument_input) &&
666  isNull(entry_ti, rhs_v, float_argument_input))) {
667  return false;
668  }
669  if (UNLIKELY(isNull(entry_ti, lhs_v, float_argument_input) &&
670  !isNull(entry_ti, rhs_v, float_argument_input))) {
671  return use_heap_ ? !order_entry.nulls_first : order_entry.nulls_first;
672  }
673  if (UNLIKELY(isNull(entry_ti, rhs_v, float_argument_input) &&
674  !isNull(entry_ti, lhs_v, float_argument_input))) {
675  return use_heap_ ? order_entry.nulls_first : !order_entry.nulls_first;
676  }
677  const bool use_desc_cmp = use_heap_ ? !order_entry.is_desc : order_entry.is_desc;
678  if (LIKELY(lhs_v.isInt())) {
679  CHECK(rhs_v.isInt());
680  if (UNLIKELY(entry_ti.is_string() &&
681  entry_ti.get_compression() == kENCODING_DICT)) {
682  CHECK_EQ(4, entry_ti.get_logical_size());
683  const auto string_dict_proxy = result_set_->executor_->getStringDictionaryProxy(
684  entry_ti.get_comp_param(), result_set_->row_set_mem_owner_, false);
685  auto lhs_str = string_dict_proxy->getString(lhs_v.i1);
686  auto rhs_str = string_dict_proxy->getString(rhs_v.i1);
687  if (lhs_str == rhs_str) {
688  continue;
689  }
690  return use_desc_cmp ? lhs_str > rhs_str : lhs_str < rhs_str;
691  }
692  if (UNLIKELY(is_distinct_target(result_set_->targets_[order_entry.tle_no - 1]))) {
693  const auto lhs_sz = count_distinct_set_size(
694  lhs_v.i1,
695  result_set_->query_mem_desc_.getCountDistinctDescriptor(order_entry.tle_no -
696  1));
697  const auto rhs_sz = count_distinct_set_size(
698  rhs_v.i1,
699  result_set_->query_mem_desc_.getCountDistinctDescriptor(order_entry.tle_no -
700  1));
701  if (lhs_sz == rhs_sz) {
702  continue;
703  }
704  return use_desc_cmp ? lhs_sz > rhs_sz : lhs_sz < rhs_sz;
705  }
706  if (lhs_v.i1 == rhs_v.i1) {
707  continue;
708  }
709  if (entry_ti.is_fp()) {
710  if (float_argument_input) {
711  const auto lhs_dval = *reinterpret_cast<const float*>(may_alias_ptr(&lhs_v.i1));
712  const auto rhs_dval = *reinterpret_cast<const float*>(may_alias_ptr(&rhs_v.i1));
713  return use_desc_cmp ? lhs_dval > rhs_dval : lhs_dval < rhs_dval;
714  } else {
715  const auto lhs_dval =
716  *reinterpret_cast<const double*>(may_alias_ptr(&lhs_v.i1));
717  const auto rhs_dval =
718  *reinterpret_cast<const double*>(may_alias_ptr(&rhs_v.i1));
719  return use_desc_cmp ? lhs_dval > rhs_dval : lhs_dval < rhs_dval;
720  }
721  }
722  return use_desc_cmp ? lhs_v.i1 > rhs_v.i1 : lhs_v.i1 < rhs_v.i1;
723  } else {
724  if (lhs_v.isPair()) {
725  CHECK(rhs_v.isPair());
726  const auto lhs =
727  pair_to_double({lhs_v.i1, lhs_v.i2}, entry_ti, float_argument_input);
728  const auto rhs =
729  pair_to_double({rhs_v.i1, rhs_v.i2}, entry_ti, float_argument_input);
730  if (lhs == rhs) {
731  continue;
732  }
733  return use_desc_cmp ? lhs > rhs : lhs < rhs;
734  } else {
735  CHECK(lhs_v.isStr() && rhs_v.isStr());
736  const auto lhs = lhs_v.strVal();
737  const auto rhs = rhs_v.strVal();
738  if (lhs == rhs) {
739  continue;
740  }
741  return use_desc_cmp ? lhs > rhs : lhs < rhs;
742  }
743  }
744  }
745  return false;
746 }
const std::list< Analyzer::OrderEntry > order_entries_
Definition: ResultSet.h:733
#define CHECK_EQ(x, y)
Definition: Logger.h:198
const BufferIteratorType buffer_itr_
Definition: ResultSet.h:736
static bool isNull(const SQLTypeInfo &ti, const InternalTargetValue &val, const bool float_argument_input)
#define CHECK_GE(x, y)
Definition: Logger.h:203
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:120
const SQLTypeInfo get_compact_type(const TargetInfo &target)
CHECK(cgen_state)
int64_t count_distinct_set_size(const int64_t set_handle, const CountDistinctDescriptor &count_distinct_desc)
Definition: CountDistinct.h:75
const ResultSet * result_set_
Definition: ResultSet.h:735
#define LIKELY(x)
Definition: likely.h:19
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:116
#define UNLIKELY(x)
Definition: likely.h:20

+ Here is the call graph for this function:

Member Data Documentation

template<typename BUFFER_ITERATOR_TYPE >
const BufferIteratorType ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::buffer_itr_

Definition at line 736 of file ResultSet.h.

template<typename BUFFER_ITERATOR_TYPE >
const std::list<Analyzer::OrderEntry> ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::order_entries_

Definition at line 733 of file ResultSet.h.

template<typename BUFFER_ITERATOR_TYPE >
const ResultSet* ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::result_set_

Definition at line 735 of file ResultSet.h.

template<typename BUFFER_ITERATOR_TYPE >
const bool ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::use_heap_

Definition at line 734 of file ResultSet.h.


The documentation for this struct was generated from the following files: