OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Analyzer::ColumnVar Class Reference

#include <Analyzer.h>

+ Inheritance diagram for Analyzer::ColumnVar:
+ Collaboration diagram for Analyzer::ColumnVar:

Public Member Functions

 ColumnVar (const SQLTypeInfo &ti, const shared::ColumnKey &column_key, int32_t rte_idx)
 
const shared::ColumnKeygetColumnKey () const
 
shared::TableKey getTableKey () const
 
int32_t get_rte_idx () const
 
void set_rte_idx (int32_t new_rte_idx)
 
EncodingType get_compression () const
 
void check_group_by (const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
 
std::shared_ptr< Analyzer::Exprdeep_copy () const override
 
void group_predicates (std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
 
void collect_rte_idx (std::set< int32_t > &rte_idx_set) const override
 
void collect_column_var (std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
 
std::shared_ptr< Analyzer::Exprrewrite_with_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
 
std::shared_ptr< Analyzer::Exprrewrite_with_child_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
 
std::shared_ptr< Analyzer::Exprrewrite_agg_to_var (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
 
bool operator== (const Expr &rhs) const override
 
std::string toString () const override
 
- Public Member Functions inherited from Analyzer::Expr
 Expr (SQLTypes t, bool notnull)
 
 Expr (SQLTypes t, int d, bool notnull)
 
 Expr (SQLTypes t, int d, int s, bool notnull)
 
 Expr (const SQLTypeInfo &ti, bool has_agg=false)
 
virtual ~Expr ()
 
std::shared_ptr< Analyzer::Exprget_shared_ptr ()
 
const SQLTypeInfoget_type_info () const
 
void set_type_info (const SQLTypeInfo &ti)
 
bool get_contains_agg () const
 
void set_contains_agg (bool a)
 
virtual std::shared_ptr
< Analyzer::Expr
add_cast (const SQLTypeInfo &new_type_info)
 
virtual std::shared_ptr
< Analyzer::Expr
normalize_simple_predicate (int &rte_idx) const
 
virtual void collect_rte_idx (std::set< int > &rte_idx_set) const
 
virtual size_t get_num_column_vars (const bool include_agg) const
 
virtual void print () const
 
virtual void add_unique (std::list< const Expr * > &expr_list) const
 
virtual void find_expr (std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const
 
std::shared_ptr< Analyzer::Exprdecompress ()
 
virtual void get_domain (DomainSet &domain_set) const
 

Static Public Member Functions

static bool colvar_comp (const ColumnVar *l, const ColumnVar *r)
 

Protected Attributes

shared::ColumnKey column_key_
 
int32_t rte_idx_
 
- Protected Attributes inherited from Analyzer::Expr
SQLTypeInfo type_info
 
bool contains_agg
 

Detailed Description

Definition at line 194 of file Analyzer.h.

Constructor & Destructor Documentation

Analyzer::ColumnVar::ColumnVar ( const SQLTypeInfo ti,
const shared::ColumnKey column_key,
int32_t  rte_idx 
)
inline

Definition at line 196 of file Analyzer.h.

197  : Expr(ti), column_key_(column_key), rte_idx_(rte_idx) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
shared::ColumnKey column_key_
Definition: Analyzer.h:239

Member Function Documentation

void Analyzer::ColumnVar::check_group_by ( const std::list< std::shared_ptr< Analyzer::Expr >> &  groupby) const
overridevirtual

Reimplemented from Analyzer::Expr.

Reimplemented in Analyzer::Var.

Definition at line 1483 of file Analyzer.cpp.

References column_key_.

1484  {
1485  if (!groupby.empty()) {
1486  for (auto e : groupby) {
1487  auto c = std::dynamic_pointer_cast<ColumnVar>(e);
1488  if (c && column_key_ == c->getColumnKey()) {
1489  return;
1490  }
1491  }
1492  }
1493  throw std::runtime_error(
1494  "expressions in the SELECT or HAVING clause must be an aggregate function or an "
1495  "expression "
1496  "over GROUP BY columns.");
1497 }
shared::ColumnKey column_key_
Definition: Analyzer.h:239
ColumnVar(const SQLTypeInfo &ti, const shared::ColumnKey &column_key, int32_t rte_idx)
Definition: Analyzer.h:196
void Analyzer::ColumnVar::collect_column_var ( std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &  colvar_set,
bool  include_agg 
) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 222 of file Analyzer.h.

Referenced by anonymous_namespace{GroupByAndAggregate.cpp}::init_count_distinct_descriptors(), and RelAlgTranslator::translateWindowFunction().

225  {
226  colvar_set.insert(this);
227  }

+ Here is the caller graph for this function:

void Analyzer::ColumnVar::collect_rte_idx ( std::set< int32_t > &  rte_idx_set) const
inlineoverride

Definition at line 212 of file Analyzer.h.

References rte_idx_.

212  {
213  rte_idx_set.insert(rte_idx_);
214  }
static bool Analyzer::ColumnVar::colvar_comp ( const ColumnVar l,
const ColumnVar r 
)
inlinestatic

Definition at line 215 of file Analyzer.h.

References CHECK, and column_key_.

Referenced by Analyzer::Expr::get_num_column_vars(), Analyzer::StringOper::hasSingleDictEncodedColInput(), anonymous_namespace{GroupByAndAggregate.cpp}::init_count_distinct_descriptors(), RelAlgTranslator::translateWindowFunction(), and anonymous_namespace{FromTableReordering.cpp}::traverse_join_cost_graph().

215  {
216  CHECK(l);
217  const auto& l_column_key = l->column_key_;
218  CHECK(r);
219  const auto& r_column_key = r->column_key_;
220  return l_column_key < r_column_key;
221  }
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

std::shared_ptr< Analyzer::Expr > Analyzer::ColumnVar::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Reimplemented in Analyzer::Var.

Definition at line 66 of file Analyzer.cpp.

References column_key_, rte_idx_, and Analyzer::Expr::type_info.

Referenced by rewrite_with_targetlist(), DeepCopyVisitor::visitColumnVar(), and anonymous_namespace{ScalarCodeGenerator.cpp}::UsedColumnExpressions::visitColumnVar().

66  {
67  return makeExpr<ColumnVar>(type_info, column_key_, rte_idx_);
68 }
shared::ColumnKey column_key_
Definition: Analyzer.h:239
SQLTypeInfo type_info
Definition: Analyzer.h:180

+ Here is the caller graph for this function:

EncodingType Analyzer::ColumnVar::get_compression ( ) const
inline

Definition at line 204 of file Analyzer.h.

References SQLTypeInfo::get_compression(), and Analyzer::Expr::type_info.

Referenced by anonymous_namespace{ColumnIR.cpp}::get_col_decoder().

204 { return type_info.get_compression(); }
SQLTypeInfo type_info
Definition: Analyzer.h:180
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:389

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const shared::ColumnKey& Analyzer::ColumnVar::getColumnKey ( ) const
inline
shared::TableKey Analyzer::ColumnVar::getTableKey ( ) const
inline

Definition at line 199 of file Analyzer.h.

References column_key_, shared::ColumnKey::db_id, and shared::ColumnKey::table_id.

Referenced by CodeGenerator::codegenRowId(), PerfectJoinHashTable::getInnerQueryInfo(), getLeafColumnRange(), and self_join_not_covered_by_left_deep_tree().

199  {
201  }
shared::ColumnKey column_key_
Definition: Analyzer.h:239

+ Here is the caller graph for this function:

void Analyzer::ColumnVar::group_predicates ( std::list< const Expr * > &  scan_predicates,
std::list< const Expr * > &  join_predicates,
std::list< const Expr * > &  const_predicates 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1593 of file Analyzer.cpp.

References SQLTypeInfo::get_type(), kBOOLEAN, and Analyzer::Expr::type_info.

1595  {
1596  if (type_info.get_type() == kBOOLEAN) {
1597  scan_predicates.push_back(this);
1598  }
1599 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
SQLTypeInfo type_info
Definition: Analyzer.h:180

+ Here is the call graph for this function:

bool Analyzer::ColumnVar::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2203 of file Analyzer.cpp.

References column_key_, get_rte_idx(), Analyzer::Var::get_varno(), Analyzer::Var::get_which_row(), getColumnKey(), and rte_idx_.

2203  {
2204  if (typeid(rhs) != typeid(ColumnVar) && typeid(rhs) != typeid(Var)) {
2205  return false;
2206  }
2207  const ColumnVar& rhs_cv = dynamic_cast<const ColumnVar&>(rhs);
2208  if (rte_idx_ != -1) {
2209  return (column_key_ == rhs_cv.getColumnKey()) && (rte_idx_ == rhs_cv.get_rte_idx());
2210  }
2211  const Var* v = dynamic_cast<const Var*>(this);
2212  if (v == nullptr) {
2213  return false;
2214  }
2215  const Var* rv = dynamic_cast<const Var*>(&rhs);
2216  if (rv == nullptr) {
2217  return false;
2218  }
2219  return (v->get_which_row() == rv->get_which_row()) &&
2220  (v->get_varno() == rv->get_varno());
2221 }
shared::ColumnKey column_key_
Definition: Analyzer.h:239
ColumnVar(const SQLTypeInfo &ti, const shared::ColumnKey &column_key, int32_t rte_idx)
Definition: Analyzer.h:196

+ Here is the call graph for this function:

std::shared_ptr< Analyzer::Expr > Analyzer::ColumnVar::rewrite_agg_to_var ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
overridevirtual

Reimplemented from Analyzer::Expr.

Reimplemented in Analyzer::Var.

Definition at line 1941 of file Analyzer.cpp.

References column_key_, get_rte_idx(), Analyzer::Expr::get_type_info(), getColumnKey(), and Analyzer::Var::kINPUT_OUTER.

1942  {
1943  int varno = 1;
1944  for (auto tle : tlist) {
1945  const Expr* e = tle->get_expr();
1946  if (typeid(*e) != typeid(AggExpr)) {
1947  const ColumnVar* colvar = dynamic_cast<const ColumnVar*>(e);
1948  if (colvar == nullptr) {
1949  throw std::runtime_error(
1950  "Internal Error: targetlist in rewrite_agg_to_var is not all columns and "
1951  "aggregates.");
1952  }
1953  if (column_key_ == colvar->getColumnKey()) {
1954  return makeExpr<Var>(colvar->get_type_info(),
1955  colvar->getColumnKey(),
1956  colvar->get_rte_idx(),
1958  varno);
1959  }
1960  }
1961  varno++;
1962  }
1963  throw std::runtime_error(
1964  "Internal error: cannot find ColumnVar from having clause in targetlist.");
1965 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
shared::ColumnKey column_key_
Definition: Analyzer.h:239
ColumnVar(const SQLTypeInfo &ti, const shared::ColumnKey &column_key, int32_t rte_idx)
Definition: Analyzer.h:196

+ Here is the call graph for this function:

std::shared_ptr< Analyzer::Expr > Analyzer::ColumnVar::rewrite_with_child_targetlist ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
overridevirtual

Reimplemented from Analyzer::Expr.

Reimplemented in Analyzer::Var.

Definition at line 1918 of file Analyzer.cpp.

References column_key_, get_rte_idx(), Analyzer::Expr::get_type_info(), getColumnKey(), and Analyzer::Var::kINPUT_OUTER.

1919  {
1920  int varno = 1;
1921  for (auto tle : tlist) {
1922  const Expr* e = tle->get_expr();
1923  const ColumnVar* colvar = dynamic_cast<const ColumnVar*>(e);
1924  if (colvar == nullptr) {
1925  throw std::runtime_error(
1926  "Internal Error: targetlist in rewrite_with_child_targetlist is not all "
1927  "columns.");
1928  }
1929  if (column_key_ == colvar->getColumnKey()) {
1930  return makeExpr<Var>(colvar->get_type_info(),
1931  colvar->getColumnKey(),
1932  colvar->get_rte_idx(),
1934  varno);
1935  }
1936  varno++;
1937  }
1938  throw std::runtime_error("Internal error: cannot find ColumnVar in child targetlist.");
1939 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
shared::ColumnKey column_key_
Definition: Analyzer.h:239
ColumnVar(const SQLTypeInfo &ti, const shared::ColumnKey &column_key, int32_t rte_idx)
Definition: Analyzer.h:196

+ Here is the call graph for this function:

std::shared_ptr< Analyzer::Expr > Analyzer::ColumnVar::rewrite_with_targetlist ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
overridevirtual

Reimplemented from Analyzer::Expr.

Reimplemented in Analyzer::Var.

Definition at line 1904 of file Analyzer.cpp.

References column_key_, deep_copy(), and getColumnKey().

1905  {
1906  for (auto tle : tlist) {
1907  const Expr* e = tle->get_expr();
1908  const ColumnVar* colvar = dynamic_cast<const ColumnVar*>(e);
1909  if (colvar != nullptr) {
1910  if (column_key_ == colvar->getColumnKey()) {
1911  return colvar->deep_copy();
1912  }
1913  }
1914  }
1915  throw std::runtime_error("Internal error: cannot find ColumnVar in targetlist.");
1916 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
shared::ColumnKey column_key_
Definition: Analyzer.h:239
ColumnVar(const SQLTypeInfo &ti, const shared::ColumnKey &column_key, int32_t rte_idx)
Definition: Analyzer.h:196

+ Here is the call graph for this function:

void Analyzer::ColumnVar::set_rte_idx ( int32_t  new_rte_idx)
inline

Definition at line 203 of file Analyzer.h.

References rte_idx_.

203 { rte_idx_ = new_rte_idx; }
std::string Analyzer::ColumnVar::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Reimplemented in Analyzer::Var.

Definition at line 2614 of file Analyzer.cpp.

References column_key_, Analyzer::Expr::get_type_info(), SQLTypeInfo::get_type_name(), rte_idx_, and to_string().

Referenced by CodeGenerator::codegenColVar(), CodeGenerator::codegenGeoColumnVar(), and PerfectJoinHashTable::getAlternativeCacheKey().

2614  {
2615  std::stringstream ss;
2616  ss << "(ColumnVar " << column_key_ << ", rte: " << std::to_string(rte_idx_) << " "
2617  << get_type_info().get_type_name() << ") ";
2618  return ss.str();
2619 }
shared::ColumnKey column_key_
Definition: Analyzer.h:239
std::string to_string(char const *&&v)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
std::string get_type_name() const
Definition: sqltypes.h:507

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

int32_t Analyzer::ColumnVar::rte_idx_
protected

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