OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 1702 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 1704 of file ParserNode.h.

References orderby_clause.

1705  : query_expr(q), limit(l), offset(f) {
1706  if (o) {
1707  for (const auto e : *o) {
1708  orderby_clause.emplace_back(e);
1709  }
1710  delete o;
1711  }
1712  }
std::unique_ptr< QueryExpr > query_expr
Definition: ParserNode.h:1721
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1722

Member Function Documentation

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

Implements Parser::DMLStmt.

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

1183  {
1184  query.set_stmt_type(kSELECT);
1185  query.set_limit(limit);
1186  if (offset < 0) {
1187  throw std::runtime_error("OFFSET cannot be negative.");
1188  }
1189  query.set_offset(offset);
1190  query_expr->analyze(catalog, query);
1191  if (orderby_clause.empty() && !query.get_is_distinct()) {
1192  query.set_order_by(nullptr);
1193  return;
1194  }
1195  const std::vector<std::shared_ptr<Analyzer::TargetEntry>>& tlist =
1196  query.get_targetlist();
1197  std::list<Analyzer::OrderEntry>* order_by = new std::list<Analyzer::OrderEntry>();
1198  if (!orderby_clause.empty()) {
1199  for (auto& p : orderby_clause) {
1200  int tle_no = p->get_colno();
1201  if (tle_no == 0) {
1202  // use column name
1203  // search through targetlist for matching name
1204  const std::string* name = p->get_column()->get_column();
1205  tle_no = 1;
1206  bool found = false;
1207  for (auto tle : tlist) {
1208  if (tle->get_resname() == *name) {
1209  found = true;
1210  break;
1211  }
1212  tle_no++;
1213  }
1214  if (!found) {
1215  throw std::runtime_error("invalid name in order by: " + *name);
1216  }
1217  }
1218  order_by->push_back(
1219  Analyzer::OrderEntry(tle_no, p->get_is_desc(), p->get_nulls_first()));
1220  }
1221  }
1222  if (query.get_is_distinct()) {
1223  // extend order_by to include all targetlist entries.
1224  for (int i = 1; i <= static_cast<int>(tlist.size()); i++) {
1225  bool in_orderby = false;
1226  std::for_each(order_by->begin(),
1227  order_by->end(),
1228  [&in_orderby, i](const Analyzer::OrderEntry& oe) {
1229  in_orderby = in_orderby || (i == oe.tle_no);
1230  });
1231  if (!in_orderby) {
1232  order_by->push_back(Analyzer::OrderEntry(i, false, false));
1233  }
1234  }
1235  }
1236  query.set_order_by(order_by);
1237 }
void set_order_by(std::list< OrderEntry > *o)
Definition: Analyzer.h:1550
void set_offset(int64_t o)
Definition: Analyzer.h:1562
bool get_is_distinct() const
Definition: Analyzer.h:1524
std::unique_ptr< QueryExpr > query_expr
Definition: ParserNode.h:1721
void set_stmt_type(SQLStmtType t)
Definition: Analyzer.h:1553
Definition: Analyzer.h:1362
void set_limit(int64_t l)
Definition: Analyzer.h:1560
const std::vector< std::shared_ptr< TargetEntry > > & get_targetlist() const
Definition: Analyzer.h:1526
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1722

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

References orderby_clause.

1714  {
1715  return orderby_clause;
1716  }
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1722
const QueryExpr* Parser::SelectStmt::get_query_expr ( ) const
inline

Definition at line 1713 of file ParserNode.h.

References query_expr.

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

Member Data Documentation

int64_t Parser::SelectStmt::limit
private

Definition at line 1723 of file ParserNode.h.

int64_t Parser::SelectStmt::offset
private

Definition at line 1724 of file ParserNode.h.

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

Definition at line 1722 of file ParserNode.h.

Referenced by get_orderby_clause(), and SelectStmt().

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

Definition at line 1721 of file ParserNode.h.

Referenced by get_query_expr().


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