OmniSciDB  cde582ebc3
 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 1863 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 1865 of file ParserNode.h.

References orderby_clause_.

1866  : query_expr_(q), limit_(l), offset_(f) {
1867  if (o) {
1868  for (const auto e : *o) {
1869  orderby_clause_.emplace_back(e);
1870  }
1871  delete o;
1872  }
1873  }
constexpr double f
Definition: Utm.h:31
std::list< std::unique_ptr< OrderSpec > > orderby_clause_
Definition: ParserNode.h:1883
std::unique_ptr< QueryExpr > query_expr_
Definition: ParserNode.h:1882

Member Function Documentation

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

Implements Parser::DMLStmt.

Definition at line 2016 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().

2017  {
2018  query.set_stmt_type(kSELECT);
2019  query.set_limit(limit_);
2020  if (offset_ < 0) {
2021  throw std::runtime_error("OFFSET cannot be negative.");
2022  }
2023  query.set_offset(offset_);
2024  query_expr_->analyze(catalog, query);
2025  if (orderby_clause_.empty() && !query.get_is_distinct()) {
2026  query.set_order_by(nullptr);
2027  return;
2028  }
2029  const std::vector<std::shared_ptr<Analyzer::TargetEntry>>& tlist =
2030  query.get_targetlist();
2031  std::list<Analyzer::OrderEntry>* order_by = new std::list<Analyzer::OrderEntry>();
2032  if (!orderby_clause_.empty()) {
2033  for (auto& p : orderby_clause_) {
2034  int tle_no = p->get_colno();
2035  if (tle_no == 0) {
2036  // use column name
2037  // search through targetlist for matching name
2038  const std::string* name = p->get_column()->get_column();
2039  tle_no = 1;
2040  bool found = false;
2041  for (auto tle : tlist) {
2042  if (tle->get_resname() == *name) {
2043  found = true;
2044  break;
2045  }
2046  tle_no++;
2047  }
2048  if (!found) {
2049  throw std::runtime_error("invalid name in order by: " + *name);
2050  }
2051  }
2052  order_by->push_back(
2053  Analyzer::OrderEntry(tle_no, p->get_is_desc(), p->get_nulls_first()));
2054  }
2055  }
2056  if (query.get_is_distinct()) {
2057  // extend order_by to include all targetlist entries.
2058  for (int i = 1; i <= static_cast<int>(tlist.size()); i++) {
2059  bool in_orderby = false;
2060  std::for_each(order_by->begin(),
2061  order_by->end(),
2062  [&in_orderby, i](const Analyzer::OrderEntry& oe) {
2063  in_orderby = in_orderby || (i == oe.tle_no);
2064  });
2065  if (!in_orderby) {
2066  order_by->push_back(Analyzer::OrderEntry(i, false, false));
2067  }
2068  }
2069  }
2070  query.set_order_by(order_by);
2071 }
void set_order_by(std::list< OrderEntry > *o)
Definition: Analyzer.h:2523
void set_offset(int64_t o)
Definition: Analyzer.h:2535
bool get_is_distinct() const
Definition: Analyzer.h:2491
void set_stmt_type(SQLStmtType t)
Definition: Analyzer.h:2526
std::list< std::unique_ptr< OrderSpec > > orderby_clause_
Definition: ParserNode.h:1883
std::unique_ptr< QueryExpr > query_expr_
Definition: ParserNode.h:1882
string name
Definition: setup.in.py:72
Definition: Analyzer.h:2227
void set_limit(int64_t l)
Definition: Analyzer.h:2533
const std::vector< std::shared_ptr< TargetEntry > > & get_targetlist() const
Definition: Analyzer.h:2493

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

References orderby_clause_.

1875  {
1876  return orderby_clause_;
1877  }
std::list< std::unique_ptr< OrderSpec > > orderby_clause_
Definition: ParserNode.h:1883
const QueryExpr* Parser::SelectStmt::get_query_expr ( ) const
inline

Definition at line 1874 of file ParserNode.h.

References query_expr_.

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

Member Data Documentation

int64_t Parser::SelectStmt::limit_
private

Definition at line 1884 of file ParserNode.h.

int64_t Parser::SelectStmt::offset_
private

Definition at line 1885 of file ParserNode.h.

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

Definition at line 1883 of file ParserNode.h.

Referenced by get_orderby_clause(), and SelectStmt().

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

Definition at line 1882 of file ParserNode.h.

Referenced by get_query_expr().


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