OmniSciDB  04ee39c94c
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 601 of file ParserNode.h.

Constructor & Destructor Documentation

◆ ColumnRef() [1/2]

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

Definition at line 603 of file ParserNode.h.

603 : table(nullptr), column(n1) {}
std::unique_ptr< std::string > column
Definition: ParserNode.h:615
std::unique_ptr< std::string > table
Definition: ParserNode.h:614

◆ ColumnRef() [2/2]

Parser::ColumnRef::ColumnRef ( std::string *  n1,
std::string *  n2 
)
inline

Definition at line 604 of file ParserNode.h.

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

Member Function Documentation

◆ analyze()

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

695  {
696  int table_id{0};
697  int rte_idx{0};
698  const ColumnDescriptor* cd{nullptr};
699  if (column == nullptr) {
700  throw std::runtime_error("invalid column name *.");
701  }
702  if (table != nullptr) {
703  rte_idx = query.get_rte_idx(*table);
704  if (rte_idx < 0) {
705  throw std::runtime_error("range variable or table name " + *table +
706  " does not exist.");
707  }
708  Analyzer::RangeTableEntry* rte = query.get_rte(rte_idx);
709  cd = rte->get_column_desc(catalog, *column);
710  if (cd == nullptr) {
711  throw std::runtime_error("Column name " + *column + " does not exist.");
712  }
713  table_id = rte->get_table_id();
714  } else {
715  bool found = false;
716  int i = 0;
717  for (auto rte : query.get_rangetable()) {
718  cd = rte->get_column_desc(catalog, *column);
719  if (cd != nullptr && !found) {
720  found = true;
721  rte_idx = i;
722  table_id = rte->get_table_id();
723  } else if (cd != nullptr && found) {
724  throw std::runtime_error("Column name " + *column + " is ambiguous.");
725  }
726  i++;
727  }
728  if (cd == nullptr && allow_tlist_ref != TlistRefType::TLIST_NONE) {
729  // check if this is a reference to a targetlist entry
730  bool found = false;
731  int varno = -1;
732  int i = 1;
733  std::shared_ptr<Analyzer::TargetEntry> tle;
734  for (auto p : query.get_targetlist()) {
735  if (*column == p->get_resname() && !found) {
736  found = true;
737  varno = i;
738  tle = p;
739  } else if (*column == p->get_resname() && found) {
740  throw std::runtime_error("Output alias " + *column + " is ambiguous.");
741  }
742  i++;
743  }
744  if (found) {
745  if (dynamic_cast<Analyzer::Var*>(tle->get_expr())) {
746  Analyzer::Var* v = static_cast<Analyzer::Var*>(tle->get_expr());
748  return v->deep_copy();
749  }
750  }
751  if (allow_tlist_ref == TlistRefType::TLIST_COPY) {
752  return tle->get_expr()->deep_copy();
753  } else {
754  return makeExpr<Analyzer::Var>(
755  tle->get_expr()->get_type_info(), Analyzer::Var::kOUTPUT, varno);
756  }
757  }
758  }
759  if (cd == nullptr) {
760  throw std::runtime_error("Column name " + *column + " does not exist.");
761  }
762  }
763  return makeExpr<Analyzer::ColumnVar>(cd->columnType, table_id, cd->columnId, rte_idx);
764 }
int32_t get_table_id() const
const std::vector< std::shared_ptr< TargetEntry > > & get_targetlist() const
Definition: Analyzer.h:1449
std::unique_ptr< std::string > column
Definition: ParserNode.h:615
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:80
std::unique_ptr< std::string > table
Definition: ParserNode.h:614
WhichRow get_which_row() const
Definition: Analyzer.h:272
RangeTableEntry * get_rte(int rte_idx) const
Definition: Analyzer.h:1479
T v(const TargetValue &r)
specifies the content in-memory of a row in the column metadata table
int get_rte_idx(const std::string &range_var_name) const
Definition: Analyzer.cpp:1255
const ColumnDescriptor * get_column_desc(const Catalog_Namespace::Catalog &catalog, const std::string &name)
const std::vector< RangeTableEntry * > & get_rangetable() const
Definition: Analyzer.h:1455
+ Here is the call graph for this function:

◆ get_column()

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

Definition at line 606 of file ParserNode.h.

References anonymous_namespace{UpdateMetadataTest.cpp}::query, and to_string().

606 { return column.get(); }
std::unique_ptr< std::string > column
Definition: ParserNode.h:615
+ Here is the call graph for this function:

◆ get_table()

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

Definition at line 605 of file ParserNode.h.

605 { return table.get(); }
std::unique_ptr< std::string > table
Definition: ParserNode.h:614

◆ to_string()

std::string Parser::ColumnRef::to_string ( ) const
overridevirtual

Implements Parser::Expr.

Definition at line 1316 of file ParserNode.cpp.

1316  {
1317  std::string str;
1318  if (table == nullptr) {
1319  str = *column;
1320  } else if (column == nullptr) {
1321  str = *table + ".*";
1322  } else {
1323  str = *table + "." + *column;
1324  }
1325  return str;
1326 }
std::unique_ptr< std::string > column
Definition: ParserNode.h:615
std::unique_ptr< std::string > table
Definition: ParserNode.h:614

Member Data Documentation

◆ column

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

Definition at line 615 of file ParserNode.h.

◆ table

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

Definition at line 614 of file ParserNode.h.


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