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

#include <RelAlgDag.h>

+ Inheritance diagram for RelLogicalUnion:
+ Collaboration diagram for RelLogicalUnion:

Public Member Functions

 RelLogicalUnion ()
 
 RelLogicalUnion (RelAlgInputs, bool is_all)
 
virtual void acceptChildren (Visitor &v) const override
 
virtual void accept (Visitor &v, std::string name) const override
 
std::shared_ptr< RelAlgNodedeepCopy () const override
 
size_t size () const override
 
std::string toString (RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
 
std::string getFieldName (const size_t i) const
 
bool isAll () const
 
std::vector< TargetMetaInfogetCompatibleMetainfoTypes () const
 
RexScalar const * copyAndRedirectSource (RexScalar const *, size_t input_idx) const
 
virtual size_t toHash () const override
 
- 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
 

Public Attributes

std::vector< std::shared_ptr
< const RexScalar > > 
scalar_exprs_
 

Private Member Functions

bool allStringCastsAreToDictionaryEncodedStrings () const
 

Private Attributes

bool is_all_
 

Friends

struct RelAlgDagSerializer
 
std::size_t hash_value (RelLogicalUnion 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 2741 of file RelAlgDag.h.

Constructor & Destructor Documentation

RelLogicalUnion::RelLogicalUnion ( )
inline

Definition at line 2744 of file RelAlgDag.h.

2744 : is_all_{false} {}
RelLogicalUnion::RelLogicalUnion ( RelAlgInputs  inputs,
bool  is_all 
)

Definition at line 834 of file RelAlgDag.cpp.

References allStringCastsAreToDictionaryEncodedStrings(), CHECK_LE, g_enable_union, RelAlgNode::inputs_, and is_all_.

835  : RelAlgNode(std::move(inputs)), is_all_(is_all) {
836  if (!g_enable_union) {
837  throw QueryNotSupported(
838  "The DEPRECATED enable-union option is set to off. Please remove this option as "
839  "it may be disabled in the future.");
840  }
841  CHECK_LE(2u, inputs_.size());
842  if (!is_all_) {
843  throw QueryNotSupported("UNION without ALL is not supported yet.");
844  }
846  throw QueryNotSupported(
847  "Unsupported CAST in UNION: Currently, we only allow casting text type to "
848  "dictionary-encoded strings.");
849  }
850 }
RelAlgNode(RelAlgInputs inputs={})
Definition: RelAlgDag.h:830
bool allStringCastsAreToDictionaryEncodedStrings() const
Definition: RelAlgDag.cpp:955
#define CHECK_LE(x, y)
Definition: Logger.h:304
bool g_enable_union
RelAlgInputs inputs_
Definition: RelAlgDag.h:945

+ Here is the call graph for this function:

Member Function Documentation

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

Implements RelAlgDagNode.

Definition at line 2755 of file RelAlgDag.h.

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

Referenced by TableFunctionsFactory_node.PrintNode::__str__().

2755  {
2756  if (v.visit(this, std::move(name))) {
2757  acceptChildren(v);
2758  }
2759  }
virtual void acceptChildren(Visitor &v) const override
Definition: RelAlgDag.h:2748
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Implements RelAlgDagNode.

Definition at line 2748 of file RelAlgDag.h.

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

Referenced by accept().

2748  {
2749  for (auto& n : getInputs()) {
2750  if (n) {
2751  n->accept(v, "input");
2752  }
2753  }
2754  }
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:

bool RelLogicalUnion::allStringCastsAreToDictionaryEncodedStrings ( ) const
private

Definition at line 955 of file RelAlgDag.cpp.

References RelAlgNode::inputs_, and kCAST.

Referenced by RelLogicalUnion().

955  {
956  for (auto const& input : inputs_) {
957  if (auto* proj_node = dynamic_cast<RelProject const*>(input.get())) {
958  for (size_t i = 0; i < proj_node->size(); i++) {
959  if (auto* oper = dynamic_cast<RexOperator const*>(proj_node->getProjectAt(i))) {
960  if (oper->getOperator() == SQLOps::kCAST && oper->getType().is_string() &&
961  !oper->getType().is_dict_encoded_string()) {
962  return false;
963  }
964  }
965  }
966  }
967  }
968  return true;
969 }
Definition: sqldefs.h:51
RelAlgInputs inputs_
Definition: RelAlgDag.h:945

+ Here is the caller graph for this function:

RexScalar const * RelLogicalUnion::copyAndRedirectSource ( RexScalar const *  rex_scalar,
size_t  input_idx 
) const

Definition at line 944 of file RelAlgDag.cpp.

References RelAlgNode::getInput(), scalar_exprs_, and RexInput::setSourceNode().

945  {
946  if (auto const* rex_input_ptr = dynamic_cast<RexInput const*>(rex_scalar)) {
947  RexInput rex_input(*rex_input_ptr);
948  rex_input.setSourceNode(getInput(input_idx));
949  scalar_exprs_.emplace_back(std::make_shared<RexInput const>(std::move(rex_input)));
950  return scalar_exprs_.back().get();
951  }
952  return rex_scalar;
953 }
std::vector< std::shared_ptr< const RexScalar > > scalar_exprs_
Definition: RelAlgDag.h:2776
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:877

+ Here is the call graph for this function:

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

Implements RelAlgNode.

Definition at line 2761 of file RelAlgDag.h.

2761  {
2762  return std::make_shared<RelLogicalUnion>(*this);
2763  }
std::vector< TargetMetaInfo > RelLogicalUnion::getCompatibleMetainfoTypes ( ) const

Definition at line 911 of file RelAlgDag.cpp.

References SQLTypeInfo::get_notnull(), anonymous_namespace{RelAlgDag.cpp}::get_notnulls(), logger::INFO, RelAlgNode::inputs_, SQLTypeInfo::is_dict_encoded_string(), LOG, anonymous_namespace{RelAlgDag.cpp}::same_ignoring_notnull(), anonymous_namespace{RelAlgDag.cpp}::set_notnulls(), and SQLTypeInfo::to_string().

Referenced by RelAlgExecutor::executeUnion().

911  {
912  std::vector<TargetMetaInfo> tmis0 = inputs_[0]->getOutputMetainfo();
913  std::vector<bool> notnulls = get_notnulls(tmis0);
914  for (size_t i = 1; i < inputs_.size(); ++i) {
915  std::vector<TargetMetaInfo> const& tmisi = inputs_[i]->getOutputMetainfo();
916  if (tmis0.size() != tmisi.size()) {
917  LOG(INFO) << "tmis0.size()=" << tmis0.size() << " != " << tmisi.size()
918  << "=tmisi.size() for i=" << i;
919  throw std::runtime_error("Subqueries of a UNION must have matching data types.");
920  }
921  for (size_t j = 0; j < tmis0.size(); ++j) {
922  SQLTypeInfo const& ti0 = tmis0[j].get_type_info();
923  SQLTypeInfo const& ti1 = tmisi[j].get_type_info();
924  // Allow types of different nullability to be UNIONed.
925  if (!same_ignoring_notnull(ti0, ti1)) {
926  LOG(INFO) << "Types do not match for UNION:\n tmis0[" << j
927  << "].get_type_info().to_string() = " << ti0.to_string() << "\n tmis"
928  << i << '[' << j
929  << "].get_type_info().to_string() = " << ti1.to_string();
930  // The only permitted difference is when both columns are dictionary-encoded.
931  if (!(ti0.is_dict_encoded_string() && ti1.is_dict_encoded_string())) {
932  throw std::runtime_error(
933  "Subqueries of a UNION must have the exact same data types.");
934  }
935  }
936  notnulls[j] = notnulls[j] && ti1.get_notnull();
937  }
938  }
939  set_notnulls(&tmis0, notnulls); // Set each SQLTypeInfo::notnull to compatible values.
940  return tmis0;
941 }
void set_notnulls(std::vector< TargetMetaInfo > *tmis0, std::vector< bool > const &notnulls)
Definition: RelAlgDag.cpp:896
std::vector< bool > get_notnulls(std::vector< TargetMetaInfo > const &tmis0)
Definition: RelAlgDag.cpp:882
#define LOG(tag)
Definition: Logger.h:285
std::string to_string() const
Definition: sqltypes.h:528
bool is_dict_encoded_string() const
Definition: sqltypes.h:643
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:398
RelAlgInputs inputs_
Definition: RelAlgDag.h:945
bool same_ignoring_notnull(SQLTypeInfo ti0, SQLTypeInfo ti1)
Definition: RelAlgDag.cpp:890

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string RelLogicalUnion::getFieldName ( const size_t  i) const

Definition at line 860 of file RelAlgDag.cpp.

References RelAlgNode::inputs_, toString(), and UNREACHABLE.

860  {
861  if (auto const* compound = dynamic_cast<RelCompound const*>(inputs_[0].get())) {
862  return compound->getFieldName(i);
863  } else if (auto const* project = dynamic_cast<RelProject const*>(inputs_[0].get())) {
864  return project->getFieldName(i);
865  } else if (auto const* logical_union =
866  dynamic_cast<RelLogicalUnion const*>(inputs_[0].get())) {
867  return logical_union->getFieldName(i);
868  } else if (auto const* aggregate =
869  dynamic_cast<RelAggregate const*>(inputs_[0].get())) {
870  return aggregate->getFieldName(i);
871  } else if (auto const* scan = dynamic_cast<RelScan const*>(inputs_[0].get())) {
872  return scan->getFieldName(i);
873  } else if (auto const* table_func =
874  dynamic_cast<RelTableFunction const*>(inputs_[0].get())) {
875  return table_func->getFieldName(i);
876  }
877  UNREACHABLE() << "Unhandled input type: " << ::toString(inputs_.front());
878  return {};
879 }
#define UNREACHABLE()
Definition: Logger.h:338
std::string toString(RelRexToStringConfig config=RelRexToStringConfig::defaults()) const override
Definition: RelAlgDag.cpp:856
RelAlgInputs inputs_
Definition: RelAlgDag.h:945

+ Here is the call graph for this function:

bool RelLogicalUnion::isAll ( ) const
inline

Definition at line 2770 of file RelAlgDag.h.

References is_all_.

Referenced by RelAlgExecutor::createUnionWorkUnit(), and RelAlgExecutor::executeUnion().

2770 { return is_all_; }

+ Here is the caller graph for this function:

size_t RelLogicalUnion::size ( ) const
overridevirtual

Implements RelAlgNode.

Definition at line 852 of file RelAlgDag.cpp.

References RelAlgNode::inputs_.

852  {
853  return inputs_.front()->size();
854 }
RelAlgInputs inputs_
Definition: RelAlgDag.h:945
virtual size_t RelLogicalUnion::toHash ( ) const
inlineoverridevirtual

Implements RelAlgNode.

Definition at line 2778 of file RelAlgDag.h.

References hash_value.

2778 { return hash_value(*this); }
friend std::size_t hash_value(RelLogicalUnion const &)
Definition: RelAlgDag.cpp:3844
std::string RelLogicalUnion::toString ( RelRexToStringConfig  config = RelRexToStringConfig::defaults()) const
overridevirtual

Implements RelAlgNode.

Definition at line 856 of file RelAlgDag.cpp.

References cat(), is_all_, and typeName().

Referenced by getFieldName().

856  {
857  return cat(::typeName(this), "(is_all(", is_all_, "))");
858 }
std::string cat(Ts &&...args)
std::string typeName(const T *v)
Definition: toString.h:106

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Friends And Related Function Documentation

std::size_t hash_value ( RelLogicalUnion const &  rel_lv)
friend

Definition at line 3844 of file RelAlgDag.cpp.

Referenced by toHash().

3844  {
3845  if (rel_lv.hash_) {
3846  return *rel_lv.hash_;
3847  }
3848  rel_lv.hash_ = typeid(RelLogicalUnion).hash_code();
3849  boost::hash_combine(*rel_lv.hash_, rel_lv.is_all_);
3850  boost::hash_combine(*rel_lv.hash_, rel_lv.inputs_);
3851  return *rel_lv.hash_;
3852 }
friend struct RelAlgDagSerializer
friend

Definition at line 2786 of file RelAlgDag.h.

Member Data Documentation

bool RelLogicalUnion::is_all_
private

Definition at line 2784 of file RelAlgDag.h.

Referenced by hash_value(), isAll(), RelLogicalUnion(), and toString().

std::vector<std::shared_ptr<const RexScalar> > RelLogicalUnion::scalar_exprs_
mutable

Definition at line 2776 of file RelAlgDag.h.

Referenced by copyAndRedirectSource().


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