OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RelSort Class Reference

#include <RelAlgDag.h>

+ Inheritance diagram for RelSort:
+ Collaboration diagram for RelSort:

Public Member Functions

 RelSort ()
 
 RelSort (const std::vector< SortField > &collation, std::optional< size_t > limit, const size_t offset, std::shared_ptr< const RelAlgNode > input)
 
virtual void acceptChildren (Visitor &v) const override
 
virtual void accept (Visitor &v, std::string name) const override
 
bool operator== (const RelSort &that) const
 
size_t collationCount () const
 
SortField getCollation (const size_t i) const
 
void setCollation (std::vector< SortField > &&collation)
 
bool isEmptyResult () const
 
bool isLimitDelivered () const
 
std::optional< size_t > getLimit () const
 
size_t getOffset () const
 
std::string toString (RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
 
size_t size () const override
 
std::shared_ptr< RelAlgNodedeepCopy () const override
 
virtual size_t toHash () const override
 
std::list< Analyzer::OrderEntrygetOrderEntries () const
 
- Public Member Functions inherited from RelAlgNode
 RelAlgNode (RelAlgInputs inputs={})
 
virtual ~RelAlgNode ()
 
void resetQueryExecutionState ()
 
void setContextData (const RaExecutionDesc *context_data) const
 
void setOutputMetainfo (std::vector< TargetMetaInfo > targets_metainfo) const
 
void setQueryPlanDag (const std::string &extracted_query_plan_dag) const
 
std::string getQueryPlanDag () const
 
size_t getQueryPlanDagHash () const
 
const std::vector
< TargetMetaInfo > & 
getOutputMetainfo () const
 
unsigned getId () const
 
bool hasContextData () const
 
const RaExecutionDescgetContextData () const
 
const size_t inputCount () const
 
const RelAlgNodegetInput (const size_t idx) const
 
const std::vector< RelAlgNode
const * > 
getInputs () const
 
std::shared_ptr< const RelAlgNodegetAndOwnInput (const size_t idx) const
 
void addManagedInput (std::shared_ptr< const RelAlgNode > input)
 
bool hasInput (const RelAlgNode *needle) const
 
virtual void replaceInput (std::shared_ptr< const RelAlgNode > old_input, std::shared_ptr< const RelAlgNode > input)
 
void setRelNodeDagId (const size_t id) const
 
size_t getRelNodeDagId () const
 
bool isNop () const
 
void markAsNop ()
 
void clearContextData () const
 
- Public Member Functions inherited from RelAlgDagNode
 RelAlgDagNode ()
 
virtual size_t getStepNumber () const
 
virtual void setStepNumber (size_t step) const
 
std::optional< size_t > getIdInPlanTree () const
 
void setIdInPlanTree (size_t id) const
 

Private Member Functions

bool hasEquivCollationOf (const RelSort &that) const
 

Private Attributes

std::vector< SortFieldcollation_
 
std::optional< size_t > limit_
 
size_t offset_
 

Friends

struct RelAlgDagSerializer
 
std::size_t hash_value (RelSort const &)
 

Additional Inherited Members

- Static Public Member Functions inherited from RelAlgNode
static void resetRelAlgFirstId () noexcept
 
- Protected Attributes inherited from RelAlgNode
RelAlgInputs inputs_
 
unsigned id_
 
std::optional< size_t > hash_
 
- Protected Attributes inherited from RelAlgDagNode
size_t step_ {0}
 
std::optional< size_t > id_in_plan_tree_
 

Detailed Description

Definition at line 2181 of file RelAlgDag.h.

Constructor & Destructor Documentation

RelSort::RelSort ( )
inline

Definition at line 2184 of file RelAlgDag.h.

2184 : limit_(std::nullopt), offset_(0) {}
size_t offset_
Definition: RelAlgDag.h:2280
std::optional< size_t > limit_
Definition: RelAlgDag.h:2279
RelSort::RelSort ( const std::vector< SortField > &  collation,
std::optional< size_t >  limit,
const size_t  offset,
std::shared_ptr< const RelAlgNode input 
)
inline

Definition at line 2186 of file RelAlgDag.h.

References RelAlgNode::inputs_.

2190  : collation_(collation), limit_(limit), offset_(offset) {
2191  inputs_.push_back(input);
2192  }
std::vector< SortField > collation_
Definition: RelAlgDag.h:2278
size_t offset_
Definition: RelAlgDag.h:2280
std::optional< size_t > limit_
Definition: RelAlgDag.h:2279
RelAlgInputs inputs_
Definition: RelAlgDag.h:945

Member Function Documentation

virtual void RelSort::accept ( Visitor v,
std::string  name 
) const
inlineoverridevirtual

Implements RelAlgDagNode.

Definition at line 2201 of file RelAlgDag.h.

References acceptChildren(), and RelAlgDagNode::Visitor::visit().

Referenced by TableFunctionsFactory_node.PrintNode::__str__().

2201  {
2202  if (v.visit(this, std::move(name))) {
2203  acceptChildren(v);
2204  }
2205  }
string name
Definition: setup.in.py:72
virtual void acceptChildren(Visitor &v) const override
Definition: RelAlgDag.h:2194

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual void RelSort::acceptChildren ( Visitor v) const
inlineoverridevirtual

Implements RelAlgDagNode.

Definition at line 2194 of file RelAlgDag.h.

References RelAlgNode::getInputs(), and anonymous_namespace{Utm.h}::n.

Referenced by accept().

2194  {
2195  for (auto& n : getInputs()) {
2196  if (n) {
2197  n->accept(v, "input");
2198  }
2199  }
2200  }
const std::vector< RelAlgNode const * > getInputs() const
Definition: RelAlgDag.h:882
constexpr double n
Definition: Utm.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t RelSort::collationCount ( ) const
inline

Definition at line 2211 of file RelAlgDag.h.

References collation_.

Referenced by RelAlgExecutor::createSortInputWorkUnit(), and RelAlgExecutor::executeSort().

2211 { return collation_.size(); }
std::vector< SortField > collation_
Definition: RelAlgDag.h:2278

+ Here is the caller graph for this function:

std::shared_ptr<RelAlgNode> RelSort::deepCopy ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 2258 of file RelAlgDag.h.

2258  {
2259  return std::make_shared<RelSort>(*this);
2260  }
SortField RelSort::getCollation ( const size_t  i) const
inline

Definition at line 2213 of file RelAlgDag.h.

References CHECK_LT, and collation_.

2213  {
2214  CHECK_LT(i, collation_.size());
2215  return collation_[i];
2216  }
std::vector< SortField > collation_
Definition: RelAlgDag.h:2278
#define CHECK_LT(x, y)
Definition: Logger.h:303
std::optional<size_t> RelSort::getLimit ( ) const
inline

Definition at line 2226 of file RelAlgDag.h.

References limit_.

Referenced by SortInfo::createFromSortNode(), RelAlgExecutor::createSortInputWorkUnit(), and RelAlgExecutor::executeSort().

2226 { return limit_; }
std::optional< size_t > limit_
Definition: RelAlgDag.h:2279

+ Here is the caller graph for this function:

size_t RelSort::getOffset ( ) const
inline

Definition at line 2228 of file RelAlgDag.h.

References offset_.

Referenced by SortInfo::createFromSortNode(), RelAlgExecutor::createSortInputWorkUnit(), and RelAlgExecutor::executeSort().

2228 { return offset_; }
size_t offset_
Definition: RelAlgDag.h:2280

+ Here is the caller graph for this function:

std::list<Analyzer::OrderEntry> RelSort::getOrderEntries ( ) const
inline

Definition at line 2264 of file RelAlgDag.h.

References collation_, Descending, First, and run_benchmark_import::result.

Referenced by SortInfo::createFromSortNode(), and RelAlgExecutor::executeSort().

2264  {
2265  std::list<Analyzer::OrderEntry> result;
2266  for (size_t i = 0; i < collation_.size(); ++i) {
2267  const auto sort_field = collation_[i];
2268  result.emplace_back(sort_field.getField() + 1,
2269  sort_field.getSortDir() == SortDirection::Descending,
2270  sort_field.getNullsPosition() == NullSortedPosition::First);
2271  }
2272  return result;
2273  }
std::vector< SortField > collation_
Definition: RelAlgDag.h:2278

+ Here is the caller graph for this function:

bool RelSort::hasEquivCollationOf ( const RelSort that) const
private

Definition at line 803 of file RelAlgDag.cpp.

References collation_, and anonymous_namespace{RelAlgDag.cpp}::get_equiv_cols().

Referenced by operator==().

803  {
804  if (collation_.size() != that.collation_.size()) {
805  return false;
806  }
807 
808  for (size_t i = 0, e = collation_.size(); i < e; ++i) {
809  auto this_sort_key = collation_[i];
810  auto that_sort_key = that.collation_[i];
811  if (this_sort_key.getSortDir() != that_sort_key.getSortDir()) {
812  return false;
813  }
814  if (this_sort_key.getNullsPosition() != that_sort_key.getNullsPosition()) {
815  return false;
816  }
817  auto this_equiv_keys = get_equiv_cols(this, this_sort_key.getField());
818  auto that_equiv_keys = get_equiv_cols(&that, that_sort_key.getField());
819  std::vector<std::pair<const RelAlgNode*, int>> intersect;
820  std::set_intersection(this_equiv_keys.begin(),
821  this_equiv_keys.end(),
822  that_equiv_keys.begin(),
823  that_equiv_keys.end(),
824  std::back_inserter(intersect));
825  if (intersect.empty()) {
826  return false;
827  }
828  }
829  return true;
830 }
std::vector< SortField > collation_
Definition: RelAlgDag.h:2278
std::set< std::pair< const RelAlgNode *, int > > get_equiv_cols(const RelAlgNode *node, const size_t which_col)
Definition: RelAlgDag.cpp:764

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool RelSort::isEmptyResult ( ) const
inline

Definition at line 2222 of file RelAlgDag.h.

References limit_.

Referenced by RelAlgExecutor::executeSort().

2222 { return limit_.value_or(-1) == 0; }
std::optional< size_t > limit_
Definition: RelAlgDag.h:2279

+ Here is the caller graph for this function:

bool RelSort::isLimitDelivered ( ) const
inline

Definition at line 2224 of file RelAlgDag.h.

References limit_.

2224 { return limit_.has_value(); }
std::optional< size_t > limit_
Definition: RelAlgDag.h:2279
bool RelSort::operator== ( const RelSort that) const
inline

Definition at line 2207 of file RelAlgDag.h.

References hasEquivCollationOf(), limit_, and offset_.

2207  {
2208  return limit_ == that.limit_ && offset_ == that.offset_ && hasEquivCollationOf(that);
2209  }
bool hasEquivCollationOf(const RelSort &that) const
Definition: RelAlgDag.cpp:803
size_t offset_
Definition: RelAlgDag.h:2280
std::optional< size_t > limit_
Definition: RelAlgDag.h:2279

+ Here is the call graph for this function:

void RelSort::setCollation ( std::vector< SortField > &&  collation)
inline

Definition at line 2218 of file RelAlgDag.h.

References collation_.

2218  {
2219  collation_ = std::move(collation);
2220  }
std::vector< SortField > collation_
Definition: RelAlgDag.h:2278
size_t RelSort::size ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 2256 of file RelAlgDag.h.

References RelAlgNode::inputs_.

2256 { return inputs_[0]->size(); }
RelAlgInputs inputs_
Definition: RelAlgDag.h:945
virtual size_t RelSort::toHash ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 2262 of file RelAlgDag.h.

References hash_value.

2262 { return hash_value(*this); }
friend std::size_t hash_value(RelSort const &)
Definition: RelAlgDag.cpp:3791
std::string RelSort::toString ( RelRexToStringConfig  config = RelRexToStringConfig::defaults()) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 2230 of file RelAlgDag.h.

References cat(), collation_, RelAlgNode::inputs_, limit_, offset_, to_string(), and typeName().

2231  {
2232  const std::string limit_info = limit_ ? std::to_string(*limit_) : "N/A";
2233  auto ret = cat(::typeName(this),
2234  "(",
2235  "collation=",
2236  ::toString(collation_),
2237  ", limit=",
2238  limit_info,
2239  ", offset",
2240  std::to_string(offset_));
2241  if (!config.skip_input_nodes) {
2242  ret += ", inputs=", ::toString(inputs_);
2243  } else {
2244  ret += ", input node id={";
2245  for (auto& input : inputs_) {
2246  auto node_id_in_plan = input->getIdInPlanTree();
2247  auto node_id_str = node_id_in_plan ? std::to_string(*node_id_in_plan)
2248  : std::to_string(input->getId());
2249  ret += node_id_str + " ";
2250  }
2251  ret += "}";
2252  }
2253  return cat(ret, ")");
2254  }
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
Definition: RelAlgDag.h:2230
std::string cat(Ts &&...args)
std::string to_string(char const *&&v)
std::vector< SortField > collation_
Definition: RelAlgDag.h:2278
unsigned getId() const
Definition: RelAlgDag.h:869
size_t offset_
Definition: RelAlgDag.h:2280
std::string typeName(const T *v)
Definition: toString.h:106
std::optional< size_t > limit_
Definition: RelAlgDag.h:2279
RelAlgInputs inputs_
Definition: RelAlgDag.h:945

+ Here is the call graph for this function:

Friends And Related Function Documentation

std::size_t hash_value ( RelSort const &  rel_sort)
friend

Definition at line 3791 of file RelAlgDag.cpp.

Referenced by toHash().

3791  {
3792  if (rel_sort.hash_) {
3793  return *rel_sort.hash_;
3794  }
3795  rel_sort.hash_ = typeid(RelSort).hash_code();
3796  boost::hash_combine(*rel_sort.hash_, rel_sort.collation_);
3797  boost::hash_combine(*rel_sort.hash_, rel_sort.limit_.has_value());
3798  boost::hash_combine(*rel_sort.hash_, rel_sort.limit_.value_or(0));
3799  boost::hash_combine(*rel_sort.hash_, rel_sort.offset_);
3800  boost::hash_combine(*rel_sort.hash_, rel_sort.inputs_);
3801  return *rel_sort.hash_;
3802 }
friend struct RelAlgDagSerializer
friend

Definition at line 2284 of file RelAlgDag.h.

Member Data Documentation

std::vector<SortField> RelSort::collation_
private
std::optional<size_t> RelSort::limit_
private
size_t RelSort::offset_
private

Definition at line 2280 of file RelAlgDag.h.

Referenced by getOffset(), hash_value(), operator==(), and toString().


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