OmniSciDB  c07336695a
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 1601 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 1603 of file ParserNode.h.

1604  : query_expr(q), limit(l), offset(f) {
1605  if (o) {
1606  for (const auto e : *o) {
1607  orderby_clause.emplace_back(e);
1608  }
1609  delete o;
1610  }
1611  }
std::unique_ptr< QueryExpr > query_expr
Definition: ParserNode.h:1620
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1621

Member Function Documentation

◆ analyze()

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

Implements Parser::DMLStmt.

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

1168  {
1169  query.set_stmt_type(kSELECT);
1170  query.set_limit(limit);
1171  if (offset < 0) {
1172  throw std::runtime_error("OFFSET cannot be negative.");
1173  }
1174  query.set_offset(offset);
1175  query_expr->analyze(catalog, query);
1176  if (orderby_clause.empty() && !query.get_is_distinct()) {
1177  query.set_order_by(nullptr);
1178  return;
1179  }
1180  const std::vector<std::shared_ptr<Analyzer::TargetEntry>>& tlist =
1181  query.get_targetlist();
1182  std::list<Analyzer::OrderEntry>* order_by = new std::list<Analyzer::OrderEntry>();
1183  if (!orderby_clause.empty()) {
1184  for (auto& p : orderby_clause) {
1185  int tle_no = p->get_colno();
1186  if (tle_no == 0) {
1187  // use column name
1188  // search through targetlist for matching name
1189  const std::string* name = p->get_column()->get_column();
1190  tle_no = 1;
1191  bool found = false;
1192  for (auto tle : tlist) {
1193  if (tle->get_resname() == *name) {
1194  found = true;
1195  break;
1196  }
1197  tle_no++;
1198  }
1199  if (!found) {
1200  throw std::runtime_error("invalid name in order by: " + *name);
1201  }
1202  }
1203  order_by->push_back(
1204  Analyzer::OrderEntry(tle_no, p->get_is_desc(), p->get_nulls_first()));
1205  }
1206  }
1207  if (query.get_is_distinct()) {
1208  // extend order_by to include all targetlist entries.
1209  for (int i = 1; i <= static_cast<int>(tlist.size()); i++) {
1210  bool in_orderby = false;
1211  std::for_each(order_by->begin(),
1212  order_by->end(),
1213  [&in_orderby, i](const Analyzer::OrderEntry& oe) {
1214  in_orderby = in_orderby || (i == oe.tle_no);
1215  });
1216  if (!in_orderby) {
1217  order_by->push_back(Analyzer::OrderEntry(i, false, false));
1218  }
1219  }
1220  }
1221  query.set_order_by(order_by);
1222 }
const std::vector< std::shared_ptr< TargetEntry > > & get_targetlist() const
Definition: Analyzer.h:1449
void set_order_by(std::list< OrderEntry > *o)
Definition: Analyzer.h:1473
void set_offset(int64_t o)
Definition: Analyzer.h:1485
bool get_is_distinct() const
Definition: Analyzer.h:1447
std::unique_ptr< QueryExpr > query_expr
Definition: ParserNode.h:1620
void set_stmt_type(SQLStmtType t)
Definition: Analyzer.h:1476
Definition: Analyzer.h:1305
void set_limit(int64_t l)
Definition: Analyzer.h:1483
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1621
+ 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 1613 of file ParserNode.h.

References anonymous_namespace{UpdateMetadataTest.cpp}::query.

1613  {
1614  return orderby_clause;
1615  }
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1621

◆ get_query_expr()

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

Definition at line 1612 of file ParserNode.h.

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

Member Data Documentation

◆ limit

int64_t Parser::SelectStmt::limit
private

Definition at line 1622 of file ParserNode.h.

◆ offset

int64_t Parser::SelectStmt::offset
private

Definition at line 1623 of file ParserNode.h.

◆ orderby_clause

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

Definition at line 1621 of file ParserNode.h.

◆ query_expr

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

Definition at line 1620 of file ParserNode.h.


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