OmniSciDB  e465130ba1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 612 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 614 of file ParserNode.h.

614 : table(nullptr), column(n1) {}
std::unique_ptr< std::string > column
Definition: ParserNode.h:626
std::unique_ptr< std::string > table
Definition: ParserNode.h:625
Parser::ColumnRef::ColumnRef ( std::string *  n1,
std::string *  n2 
)
inline

Definition at line 615 of file ParserNode.h.

615 : table(n1), column(n2) {}
std::unique_ptr< std::string > column
Definition: ParserNode.h:626
std::unique_ptr< std::string > table
Definition: ParserNode.h:625

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 698 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(), Analyzer::Var::kGROUPBY, and Analyzer::Var::kOUTPUT.

701  {
702  int table_id{0};
703  int rte_idx{0};
704  const ColumnDescriptor* cd{nullptr};
705  if (column == nullptr) {
706  throw std::runtime_error("invalid column name *.");
707  }
708  if (table != nullptr) {
709  rte_idx = query.get_rte_idx(*table);
710  if (rte_idx < 0) {
711  throw std::runtime_error("range variable or table name " + *table +
712  " does not exist.");
713  }
714  Analyzer::RangeTableEntry* rte = query.get_rte(rte_idx);
715  cd = rte->get_column_desc(catalog, *column);
716  if (cd == nullptr) {
717  throw std::runtime_error("Column name " + *column + " does not exist.");
718  }
719  table_id = rte->get_table_id();
720  } else {
721  bool found = false;
722  int i = 0;
723  for (auto rte : query.get_rangetable()) {
724  cd = rte->get_column_desc(catalog, *column);
725  if (cd != nullptr && !found) {
726  found = true;
727  rte_idx = i;
728  table_id = rte->get_table_id();
729  } else if (cd != nullptr && found) {
730  throw std::runtime_error("Column name " + *column + " is ambiguous.");
731  }
732  i++;
733  }
734  if (cd == nullptr && allow_tlist_ref != TlistRefType::TLIST_NONE) {
735  // check if this is a reference to a targetlist entry
736  bool found = false;
737  int varno = -1;
738  int i = 1;
739  std::shared_ptr<Analyzer::TargetEntry> tle;
740  for (auto p : query.get_targetlist()) {
741  if (*column == p->get_resname() && !found) {
742  found = true;
743  varno = i;
744  tle = p;
745  } else if (*column == p->get_resname() && found) {
746  throw std::runtime_error("Output alias " + *column + " is ambiguous.");
747  }
748  i++;
749  }
750  if (found) {
751  if (dynamic_cast<Analyzer::Var*>(tle->get_expr())) {
752  Analyzer::Var* v = static_cast<Analyzer::Var*>(tle->get_expr());
754  return v->deep_copy();
755  }
756  }
757  if (allow_tlist_ref == TlistRefType::TLIST_COPY) {
758  return tle->get_expr()->deep_copy();
759  } else {
760  return makeExpr<Analyzer::Var>(
761  tle->get_expr()->get_type_info(), Analyzer::Var::kOUTPUT, varno);
762  }
763  }
764  }
765  if (cd == nullptr) {
766  throw std::runtime_error("Column name " + *column + " does not exist.");
767  }
768  }
769  return makeExpr<Analyzer::ColumnVar>(cd->columnType, table_id, cd->columnId, rte_idx);
770 }
std::unique_ptr< std::string > column
Definition: ParserNode.h:626
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:80
std::unique_ptr< std::string > table
Definition: ParserNode.h:625
int32_t get_table_id() const
int get_rte_idx(const std::string &range_var_name) const
Definition: Analyzer.cpp:1263
RangeTableEntry * get_rte(int rte_idx) const
Definition: Analyzer.h:1560
WhichRow get_which_row() const
Definition: Analyzer.h:273
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)
const std::vector< std::shared_ptr< TargetEntry > > & get_targetlist() const
Definition: Analyzer.h:1530
const std::vector< RangeTableEntry * > & get_rangetable() const
Definition: Analyzer.h:1536

+ Here is the call graph for this function:

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

Definition at line 617 of file ParserNode.h.

References column.

617 { return column.get(); }
std::unique_ptr< std::string > column
Definition: ParserNode.h:626
const std::string* Parser::ColumnRef::get_table ( ) const
inline

Definition at line 616 of file ParserNode.h.

References table.

616 { return table.get(); }
std::unique_ptr< std::string > table
Definition: ParserNode.h:625
std::string Parser::ColumnRef::to_string ( ) const
overridevirtual

Implements Parser::Expr.

Definition at line 1333 of file ParserNode.cpp.

1333  {
1334  std::string str;
1335  if (table == nullptr) {
1336  str = *column;
1337  } else if (column == nullptr) {
1338  str = *table + ".*";
1339  } else {
1340  str = *table + "." + *column;
1341  }
1342  return str;
1343 }
std::unique_ptr< std::string > column
Definition: ParserNode.h:626
std::unique_ptr< std::string > table
Definition: ParserNode.h:625

Member Data Documentation

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

Definition at line 626 of file ParserNode.h.

Referenced by get_column().

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

Definition at line 625 of file ParserNode.h.

Referenced by get_table().


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