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

#include <ParserNode.h>

+ Inheritance diagram for Parser::ColumnRef:
+ Collaboration diagram for Parser::ColumnRef:

Public Member Functions

 ColumnRef (std::string *n1)
 
 ColumnRef (std::string *n1, std::string *n2)
 
const std::string * get_table () const
 
const std::string * get_column () const
 
std::shared_ptr< Analyzer::Expranalyze (const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
 
std::string to_string () const override
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Private Attributes

std::unique_ptr< std::string > table_
 
std::unique_ptr< std::string > column_
 

Additional Inherited Members

- Public Types inherited from Parser::Expr
enum  TlistRefType { TLIST_NONE, TLIST_REF, TLIST_COPY }
 

Detailed Description

Definition at line 627 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::ColumnRef::ColumnRef ( std::string *  n1)
inlineexplicit

Definition at line 629 of file ParserNode.h.

629 : table_(nullptr), column_(n1) {}
std::unique_ptr< std::string > table_
Definition: ParserNode.h:640
std::unique_ptr< std::string > column_
Definition: ParserNode.h:641
Parser::ColumnRef::ColumnRef ( std::string *  n1,
std::string *  n2 
)
inline

Definition at line 630 of file ParserNode.h.

630 : table_(n1), column_(n2) {}
std::unique_ptr< std::string > table_
Definition: ParserNode.h:640
std::unique_ptr< std::string > column_
Definition: ParserNode.h:641

Member Function Documentation

std::shared_ptr< Analyzer::Expr > Parser::ColumnRef::analyze ( const Catalog_Namespace::Catalog catalog,
Analyzer::Query query,
TlistRefType  allow_tlist_ref = TLIST_NONE 
) const
overridevirtual

Implements Parser::Expr.

Definition at line 882 of file ParserNode.cpp.

References Analyzer::Var::deep_copy(), Analyzer::RangeTableEntry::get_column_desc(), Analyzer::Query::get_rangetable(), Analyzer::Query::get_rte(), Analyzer::Query::get_rte_idx(), Analyzer::RangeTableEntry::get_table_id(), Analyzer::Query::get_targetlist(), Analyzer::Var::get_which_row(), Catalog_Namespace::Catalog::getDatabaseId(), Analyzer::Var::kGROUPBY, and Analyzer::Var::kOUTPUT.

885  {
886  int table_id{0};
887  int rte_idx{0};
888  const ColumnDescriptor* cd{nullptr};
889  if (column_ == nullptr) {
890  throw std::runtime_error("invalid column name *.");
891  }
892  if (table_ != nullptr) {
893  rte_idx = query.get_rte_idx(*table_);
894  if (rte_idx < 0) {
895  throw std::runtime_error("range variable or table name " + *table_ +
896  " does not exist.");
897  }
898  Analyzer::RangeTableEntry* rte = query.get_rte(rte_idx);
899  cd = rte->get_column_desc(catalog, *column_);
900  if (cd == nullptr) {
901  throw std::runtime_error("Column name " + *column_ + " does not exist.");
902  }
903  table_id = rte->get_table_id();
904  } else {
905  bool found = false;
906  int i = 0;
907  for (auto rte : query.get_rangetable()) {
908  cd = rte->get_column_desc(catalog, *column_);
909  if (cd != nullptr && !found) {
910  found = true;
911  rte_idx = i;
912  table_id = rte->get_table_id();
913  } else if (cd != nullptr && found) {
914  throw std::runtime_error("Column name " + *column_ + " is ambiguous.");
915  }
916  i++;
917  }
918  if (cd == nullptr && allow_tlist_ref != TlistRefType::TLIST_NONE) {
919  // check if this is a reference to a targetlist entry
920  bool found = false;
921  int varno = -1;
922  int i = 1;
923  std::shared_ptr<Analyzer::TargetEntry> tle;
924  for (auto p : query.get_targetlist()) {
925  if (*column_ == p->get_resname() && !found) {
926  found = true;
927  varno = i;
928  tle = p;
929  } else if (*column_ == p->get_resname() && found) {
930  throw std::runtime_error("Output alias " + *column_ + " is ambiguous.");
931  }
932  i++;
933  }
934  if (found) {
935  if (dynamic_cast<Analyzer::Var*>(tle->get_expr())) {
936  Analyzer::Var* v = static_cast<Analyzer::Var*>(tle->get_expr());
938  return v->deep_copy();
939  }
940  }
941  if (allow_tlist_ref == TlistRefType::TLIST_COPY) {
942  return tle->get_expr()->deep_copy();
943  } else {
944  return makeExpr<Analyzer::Var>(
945  tle->get_expr()->get_type_info(), Analyzer::Var::kOUTPUT, varno);
946  }
947  }
948  }
949  if (cd == nullptr) {
950  throw std::runtime_error("Column name " + *column_ + " does not exist.");
951  }
952  }
953  return makeExpr<Analyzer::ColumnVar>(
954  cd->columnType,
955  shared::ColumnKey{catalog.getDatabaseId(), table_id, cd->columnId},
956  rte_idx);
957 }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:640
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:87
int32_t get_table_id() const
int get_rte_idx(const std::string &range_var_name) const
Definition: Analyzer.cpp:1468
RangeTableEntry * get_rte(int rte_idx) const
Definition: Analyzer.h:2831
WhichRow get_which_row() const
Definition: Analyzer.h:286
int getDatabaseId() const
Definition: Catalog.h:304
specifies the content in-memory of a row in the column metadata table
const ColumnDescriptor * get_column_desc(const Catalog_Namespace::Catalog &catalog, const std::string &name)
std::unique_ptr< std::string > column_
Definition: ParserNode.h:641
const std::vector< std::shared_ptr< TargetEntry > > & get_targetlist() const
Definition: Analyzer.h:2795
const std::vector< RangeTableEntry * > & get_rangetable() const
Definition: Analyzer.h:2807

+ Here is the call graph for this function:

const std::string* Parser::ColumnRef::get_column ( ) const
inline

Definition at line 632 of file ParserNode.h.

References column_.

632 { return column_.get(); }
std::unique_ptr< std::string > column_
Definition: ParserNode.h:641
const std::string* Parser::ColumnRef::get_table ( ) const
inline

Definition at line 631 of file ParserNode.h.

References table_.

631 { return table_.get(); }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:640
std::string Parser::ColumnRef::to_string ( ) const
overridevirtual

Implements Parser::Expr.

Definition at line 2111 of file ParserNode.cpp.

2111  {
2112  std::string str;
2113  if (table_ == nullptr) {
2114  str = *column_;
2115  } else if (column_ == nullptr) {
2116  str = *table_ + ".*";
2117  } else {
2118  str = *table_ + "." + *column_;
2119  }
2120  return str;
2121 }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:640
std::unique_ptr< std::string > column_
Definition: ParserNode.h:641

Member Data Documentation

std::unique_ptr<std::string> Parser::ColumnRef::column_
private

Definition at line 641 of file ParserNode.h.

Referenced by get_column().

std::unique_ptr<std::string> Parser::ColumnRef::table_
private

Definition at line 640 of file ParserNode.h.

Referenced by get_table().


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