OmniSciDB  d2f719934e
 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 1805 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 1807 of file ParserNode.h.

References orderby_clause_.

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

Member Function Documentation

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

Implements Parser::DMLStmt.

Definition at line 1349 of file ParserNode.cpp.

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

1350  {
1351  query.set_stmt_type(kSELECT);
1352  query.set_limit(limit_);
1353  if (offset_ < 0) {
1354  throw std::runtime_error("OFFSET cannot be negative.");
1355  }
1356  query.set_offset(offset_);
1357  query_expr_->analyze(catalog, query);
1358  if (orderby_clause_.empty() && !query.get_is_distinct()) {
1359  query.set_order_by(nullptr);
1360  return;
1361  }
1362  const std::vector<std::shared_ptr<Analyzer::TargetEntry>>& tlist =
1363  query.get_targetlist();
1364  std::list<Analyzer::OrderEntry>* order_by = new std::list<Analyzer::OrderEntry>();
1365  if (!orderby_clause_.empty()) {
1366  for (auto& p : orderby_clause_) {
1367  int tle_no = p->get_colno();
1368  if (tle_no == 0) {
1369  // use column name
1370  // search through targetlist for matching name
1371  const std::string* name = p->get_column()->get_column();
1372  tle_no = 1;
1373  bool found = false;
1374  for (auto tle : tlist) {
1375  if (tle->get_resname() == *name) {
1376  found = true;
1377  break;
1378  }
1379  tle_no++;
1380  }
1381  if (!found) {
1382  throw std::runtime_error("invalid name in order by: " + *name);
1383  }
1384  }
1385  order_by->push_back(
1386  Analyzer::OrderEntry(tle_no, p->get_is_desc(), p->get_nulls_first()));
1387  }
1388  }
1389  if (query.get_is_distinct()) {
1390  // extend order_by to include all targetlist entries.
1391  for (int i = 1; i <= static_cast<int>(tlist.size()); i++) {
1392  bool in_orderby = false;
1393  std::for_each(order_by->begin(),
1394  order_by->end(),
1395  [&in_orderby, i](const Analyzer::OrderEntry& oe) {
1396  in_orderby = in_orderby || (i == oe.tle_no);
1397  });
1398  if (!in_orderby) {
1399  order_by->push_back(Analyzer::OrderEntry(i, false, false));
1400  }
1401  }
1402  }
1403  query.set_order_by(order_by);
1404 }
string name
Definition: setup.in.py:72
void set_order_by(std::list< OrderEntry > *o)
Definition: Analyzer.h:1800
void set_offset(int64_t o)
Definition: Analyzer.h:1812
bool get_is_distinct() const
Definition: Analyzer.h:1774
void set_stmt_type(SQLStmtType t)
Definition: Analyzer.h:1803
std::list< std::unique_ptr< OrderSpec > > orderby_clause_
Definition: ParserNode.h:1825
std::unique_ptr< QueryExpr > query_expr_
Definition: ParserNode.h:1824
Definition: Analyzer.h:1573
void set_limit(int64_t l)
Definition: Analyzer.h:1810
const std::vector< std::shared_ptr< TargetEntry > > & get_targetlist() const
Definition: Analyzer.h:1776

+ 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 1817 of file ParserNode.h.

References orderby_clause_.

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

Definition at line 1816 of file ParserNode.h.

References query_expr_.

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

Member Data Documentation

int64_t Parser::SelectStmt::limit_
private

Definition at line 1826 of file ParserNode.h.

int64_t Parser::SelectStmt::offset_
private

Definition at line 1827 of file ParserNode.h.

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

Definition at line 1825 of file ParserNode.h.

Referenced by get_orderby_clause(), and SelectStmt().

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

Definition at line 1824 of file ParserNode.h.

Referenced by get_query_expr().


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