OmniSciDB  f632821e96
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 1762 of file ParserNode.h.

Constructor & Destructor Documentation

◆ SelectStmt()

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

Definition at line 1764 of file ParserNode.h.

1765  : query_expr(q), limit(l), offset(f) {
1766  if (o) {
1767  for (const auto e : *o) {
1768  orderby_clause.emplace_back(e);
1769  }
1770  delete o;
1771  }
1772  }
std::unique_ptr< QueryExpr > query_expr
Definition: ParserNode.h:1781
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1782

Member Function Documentation

◆ analyze()

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

Implements Parser::DMLStmt.

Definition at line 1200 of file ParserNode.cpp.

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

1201  {
1202  query.set_stmt_type(kSELECT);
1203  query.set_limit(limit);
1204  if (offset < 0) {
1205  throw std::runtime_error("OFFSET cannot be negative.");
1206  }
1207  query.set_offset(offset);
1208  query_expr->analyze(catalog, query);
1209  if (orderby_clause.empty() && !query.get_is_distinct()) {
1210  query.set_order_by(nullptr);
1211  return;
1212  }
1213  const std::vector<std::shared_ptr<Analyzer::TargetEntry>>& tlist =
1214  query.get_targetlist();
1215  std::list<Analyzer::OrderEntry>* order_by = new std::list<Analyzer::OrderEntry>();
1216  if (!orderby_clause.empty()) {
1217  for (auto& p : orderby_clause) {
1218  int tle_no = p->get_colno();
1219  if (tle_no == 0) {
1220  // use column name
1221  // search through targetlist for matching name
1222  const std::string* name = p->get_column()->get_column();
1223  tle_no = 1;
1224  bool found = false;
1225  for (auto tle : tlist) {
1226  if (tle->get_resname() == *name) {
1227  found = true;
1228  break;
1229  }
1230  tle_no++;
1231  }
1232  if (!found) {
1233  throw std::runtime_error("invalid name in order by: " + *name);
1234  }
1235  }
1236  order_by->push_back(
1237  Analyzer::OrderEntry(tle_no, p->get_is_desc(), p->get_nulls_first()));
1238  }
1239  }
1240  if (query.get_is_distinct()) {
1241  // extend order_by to include all targetlist entries.
1242  for (int i = 1; i <= static_cast<int>(tlist.size()); i++) {
1243  bool in_orderby = false;
1244  std::for_each(order_by->begin(),
1245  order_by->end(),
1246  [&in_orderby, i](const Analyzer::OrderEntry& oe) {
1247  in_orderby = in_orderby || (i == oe.tle_no);
1248  });
1249  if (!in_orderby) {
1250  order_by->push_back(Analyzer::OrderEntry(i, false, false));
1251  }
1252  }
1253  }
1254  query.set_order_by(order_by);
1255 }
const std::vector< std::shared_ptr< TargetEntry > > & get_targetlist() const
Definition: Analyzer.h:1610
void set_order_by(std::list< OrderEntry > *o)
Definition: Analyzer.h:1634
void set_offset(int64_t o)
Definition: Analyzer.h:1646
bool get_is_distinct() const
Definition: Analyzer.h:1608
std::unique_ptr< QueryExpr > query_expr
Definition: ParserNode.h:1781
void set_stmt_type(SQLStmtType t)
Definition: Analyzer.h:1637
Definition: Analyzer.h:1413
void set_limit(int64_t l)
Definition: Analyzer.h:1644
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1782
+ Here is the call graph for this function:

◆ get_orderby_clause()

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

Definition at line 1774 of file ParserNode.h.

1774  {
1775  return orderby_clause;
1776  }
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1782

◆ get_query_expr()

const QueryExpr* Parser::SelectStmt::get_query_expr ( ) const
inline

Definition at line 1773 of file ParserNode.h.

1773 { return query_expr.get(); }
std::unique_ptr< QueryExpr > query_expr
Definition: ParserNode.h:1781

Member Data Documentation

◆ limit

int64_t Parser::SelectStmt::limit
private

Definition at line 1783 of file ParserNode.h.

◆ offset

int64_t Parser::SelectStmt::offset
private

Definition at line 1784 of file ParserNode.h.

◆ orderby_clause

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

Definition at line 1782 of file ParserNode.h.

◆ query_expr

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

Definition at line 1781 of file ParserNode.h.


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