OmniSciDB  06b3bd477c
 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 596 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 598 of file ParserNode.h.

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

Definition at line 599 of file ParserNode.h.

599 : table(n1), column(n2) {}
std::unique_ptr< std::string > column
Definition: ParserNode.h:610
std::unique_ptr< std::string > table
Definition: ParserNode.h:609

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 713 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.

716  {
717  int table_id{0};
718  int rte_idx{0};
719  const ColumnDescriptor* cd{nullptr};
720  if (column == nullptr) {
721  throw std::runtime_error("invalid column name *.");
722  }
723  if (table != nullptr) {
724  rte_idx = query.get_rte_idx(*table);
725  if (rte_idx < 0) {
726  throw std::runtime_error("range variable or table name " + *table +
727  " does not exist.");
728  }
729  Analyzer::RangeTableEntry* rte = query.get_rte(rte_idx);
730  cd = rte->get_column_desc(catalog, *column);
731  if (cd == nullptr) {
732  throw std::runtime_error("Column name " + *column + " does not exist.");
733  }
734  table_id = rte->get_table_id();
735  } else {
736  bool found = false;
737  int i = 0;
738  for (auto rte : query.get_rangetable()) {
739  cd = rte->get_column_desc(catalog, *column);
740  if (cd != nullptr && !found) {
741  found = true;
742  rte_idx = i;
743  table_id = rte->get_table_id();
744  } else if (cd != nullptr && found) {
745  throw std::runtime_error("Column name " + *column + " is ambiguous.");
746  }
747  i++;
748  }
749  if (cd == nullptr && allow_tlist_ref != TlistRefType::TLIST_NONE) {
750  // check if this is a reference to a targetlist entry
751  bool found = false;
752  int varno = -1;
753  int i = 1;
754  std::shared_ptr<Analyzer::TargetEntry> tle;
755  for (auto p : query.get_targetlist()) {
756  if (*column == p->get_resname() && !found) {
757  found = true;
758  varno = i;
759  tle = p;
760  } else if (*column == p->get_resname() && found) {
761  throw std::runtime_error("Output alias " + *column + " is ambiguous.");
762  }
763  i++;
764  }
765  if (found) {
766  if (dynamic_cast<Analyzer::Var*>(tle->get_expr())) {
767  Analyzer::Var* v = static_cast<Analyzer::Var*>(tle->get_expr());
769  return v->deep_copy();
770  }
771  }
772  if (allow_tlist_ref == TlistRefType::TLIST_COPY) {
773  return tle->get_expr()->deep_copy();
774  } else {
775  return makeExpr<Analyzer::Var>(
776  tle->get_expr()->get_type_info(), Analyzer::Var::kOUTPUT, varno);
777  }
778  }
779  }
780  if (cd == nullptr) {
781  throw std::runtime_error("Column name " + *column + " does not exist.");
782  }
783  }
784  return makeExpr<Analyzer::ColumnVar>(cd->columnType, table_id, cd->columnId, rte_idx);
785 }
std::unique_ptr< std::string > column
Definition: ParserNode.h:610
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:80
std::unique_ptr< std::string > table
Definition: ParserNode.h:609
int32_t get_table_id() const
int get_rte_idx(const std::string &range_var_name) const
Definition: Analyzer.cpp:1338
RangeTableEntry * get_rte(int rte_idx) const
Definition: Analyzer.h:1641
WhichRow get_which_row() const
Definition: Analyzer.h:274
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:1611
const std::vector< RangeTableEntry * > & get_rangetable() const
Definition: Analyzer.h:1617

+ Here is the call graph for this function:

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

Definition at line 601 of file ParserNode.h.

References column.

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

Definition at line 600 of file ParserNode.h.

References table.

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

Implements Parser::Expr.

Definition at line 1275 of file ParserNode.cpp.

1275  {
1276  std::string str;
1277  if (table == nullptr) {
1278  str = *column;
1279  } else if (column == nullptr) {
1280  str = *table + ".*";
1281  } else {
1282  str = *table + "." + *column;
1283  }
1284  return str;
1285 }
std::unique_ptr< std::string > column
Definition: ParserNode.h:610
std::unique_ptr< std::string > table
Definition: ParserNode.h:609

Member Data Documentation

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

Definition at line 610 of file ParserNode.h.

Referenced by get_column().

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

Definition at line 609 of file ParserNode.h.

Referenced by get_table().


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