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

#include <ParserNode.h>

+ Inheritance diagram for Parser::SelectStmt:
+ Collaboration diagram for Parser::SelectStmt:

Public Member Functions

 SelectStmt (QueryExpr *q, std::list< OrderSpec * > *o, int64_t l, int64_t f)
 
const QueryExprget_query_expr () const
 
const std::list
< std::unique_ptr< OrderSpec > > & 
get_orderby_clause () const
 
void analyze (const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const override
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Private Attributes

std::unique_ptr< QueryExprquery_expr_
 
std::list< std::unique_ptr
< OrderSpec > > 
orderby_clause_
 
int64_t limit_
 
int64_t offset_
 

Detailed Description

Definition at line 1806 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::SelectStmt::SelectStmt ( QueryExpr q,
std::list< OrderSpec * > *  o,
int64_t  l,
int64_t  f 
)
inline

Definition at line 1808 of file ParserNode.h.

References orderby_clause_.

1809  : query_expr_(q), limit_(l), offset_(f) {
1810  if (o) {
1811  for (const auto e : *o) {
1812  orderby_clause_.emplace_back(e);
1813  }
1814  delete o;
1815  }
1816  }
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
std::list< std::unique_ptr< OrderSpec > > orderby_clause_
Definition: ParserNode.h:1826
std::unique_ptr< QueryExpr > query_expr_
Definition: ParserNode.h:1825

Member Function Documentation

void Parser::SelectStmt::analyze ( const Catalog_Namespace::Catalog catalog,
Analyzer::Query query 
) const
overridevirtual

Implements Parser::DMLStmt.

Definition at line 2070 of file ParserNode.cpp.

References Analyzer::Query::get_is_distinct(), Analyzer::Query::get_targetlist(), kSELECT, setup::name, Analyzer::Query::set_limit(), Analyzer::Query::set_offset(), Analyzer::Query::set_order_by(), and Analyzer::Query::set_stmt_type().

2071  {
2072  query.set_stmt_type(kSELECT);
2073  query.set_limit(limit_);
2074  if (offset_ < 0) {
2075  throw std::runtime_error("OFFSET cannot be negative.");
2076  }
2077  query.set_offset(offset_);
2078  query_expr_->analyze(catalog, query);
2079  if (orderby_clause_.empty() && !query.get_is_distinct()) {
2080  query.set_order_by(nullptr);
2081  return;
2082  }
2083  const std::vector<std::shared_ptr<Analyzer::TargetEntry>>& tlist =
2084  query.get_targetlist();
2085  std::list<Analyzer::OrderEntry>* order_by = new std::list<Analyzer::OrderEntry>();
2086  if (!orderby_clause_.empty()) {
2087  for (auto& p : orderby_clause_) {
2088  int tle_no = p->get_colno();
2089  if (tle_no == 0) {
2090  // use column name
2091  // search through targetlist for matching name
2092  const std::string* name = p->get_column()->get_column();
2093  tle_no = 1;
2094  bool found = false;
2095  for (auto tle : tlist) {
2096  if (tle->get_resname() == *name) {
2097  found = true;
2098  break;
2099  }
2100  tle_no++;
2101  }
2102  if (!found) {
2103  throw std::runtime_error("invalid name in order by: " + *name);
2104  }
2105  }
2106  order_by->push_back(
2107  Analyzer::OrderEntry(tle_no, p->get_is_desc(), p->get_nulls_first()));
2108  }
2109  }
2110  if (query.get_is_distinct()) {
2111  // extend order_by to include all targetlist entries.
2112  for (int i = 1; i <= static_cast<int>(tlist.size()); i++) {
2113  bool in_orderby = false;
2114  std::for_each(order_by->begin(),
2115  order_by->end(),
2116  [&in_orderby, i](const Analyzer::OrderEntry& oe) {
2117  in_orderby = in_orderby || (i == oe.tle_no);
2118  });
2119  if (!in_orderby) {
2120  order_by->push_back(Analyzer::OrderEntry(i, false, false));
2121  }
2122  }
2123  }
2124  query.set_order_by(order_by);
2125 }
void set_order_by(std::list< OrderEntry > *o)
Definition: Analyzer.h:3181
void set_offset(int64_t o)
Definition: Analyzer.h:3193
bool get_is_distinct() const
Definition: Analyzer.h:3149
void set_stmt_type(SQLStmtType t)
Definition: Analyzer.h:3184
std::list< std::unique_ptr< OrderSpec > > orderby_clause_
Definition: ParserNode.h:1826
std::unique_ptr< QueryExpr > query_expr_
Definition: ParserNode.h:1825
string name
Definition: setup.in.py:72
Definition: Analyzer.h:2806
void set_limit(int64_t l)
Definition: Analyzer.h:3191
const std::vector< std::shared_ptr< TargetEntry > > & get_targetlist() const
Definition: Analyzer.h:3151

+ Here is the call graph for this function:

const std::list<std::unique_ptr<OrderSpec> >& Parser::SelectStmt::get_orderby_clause ( ) const
inline

Definition at line 1818 of file ParserNode.h.

References orderby_clause_.

1818  {
1819  return orderby_clause_;
1820  }
std::list< std::unique_ptr< OrderSpec > > orderby_clause_
Definition: ParserNode.h:1826
const QueryExpr* Parser::SelectStmt::get_query_expr ( ) const
inline

Definition at line 1817 of file ParserNode.h.

References query_expr_.

1817 { return query_expr_.get(); }
std::unique_ptr< QueryExpr > query_expr_
Definition: ParserNode.h:1825

Member Data Documentation

int64_t Parser::SelectStmt::limit_
private

Definition at line 1827 of file ParserNode.h.

int64_t Parser::SelectStmt::offset_
private

Definition at line 1828 of file ParserNode.h.

std::list<std::unique_ptr<OrderSpec> > Parser::SelectStmt::orderby_clause_
private

Definition at line 1826 of file ParserNode.h.

Referenced by get_orderby_clause(), and SelectStmt().

std::unique_ptr<QueryExpr> Parser::SelectStmt::query_expr_
private

Definition at line 1825 of file ParserNode.h.

Referenced by get_query_expr().


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