OmniSciDB  ba1bac9284
 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 1816 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 1818 of file ParserNode.h.

References orderby_clause.

1819  : query_expr(q), limit(l), offset(f) {
1820  if (o) {
1821  for (const auto e : *o) {
1822  orderby_clause.emplace_back(e);
1823  }
1824  delete o;
1825  }
1826  }
std::unique_ptr< QueryExpr > query_expr
Definition: ParserNode.h:1835
char * f
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1836

Member Function Documentation

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

Implements Parser::DMLStmt.

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

1236  {
1237  query.set_stmt_type(kSELECT);
1238  query.set_limit(limit);
1239  if (offset < 0) {
1240  throw std::runtime_error("OFFSET cannot be negative.");
1241  }
1242  query.set_offset(offset);
1243  query_expr->analyze(catalog, query);
1244  if (orderby_clause.empty() && !query.get_is_distinct()) {
1245  query.set_order_by(nullptr);
1246  return;
1247  }
1248  const std::vector<std::shared_ptr<Analyzer::TargetEntry>>& tlist =
1249  query.get_targetlist();
1250  std::list<Analyzer::OrderEntry>* order_by = new std::list<Analyzer::OrderEntry>();
1251  if (!orderby_clause.empty()) {
1252  for (auto& p : orderby_clause) {
1253  int tle_no = p->get_colno();
1254  if (tle_no == 0) {
1255  // use column name
1256  // search through targetlist for matching name
1257  const std::string* name = p->get_column()->get_column();
1258  tle_no = 1;
1259  bool found = false;
1260  for (auto tle : tlist) {
1261  if (tle->get_resname() == *name) {
1262  found = true;
1263  break;
1264  }
1265  tle_no++;
1266  }
1267  if (!found) {
1268  throw std::runtime_error("invalid name in order by: " + *name);
1269  }
1270  }
1271  order_by->push_back(
1272  Analyzer::OrderEntry(tle_no, p->get_is_desc(), p->get_nulls_first()));
1273  }
1274  }
1275  if (query.get_is_distinct()) {
1276  // extend order_by to include all targetlist entries.
1277  for (int i = 1; i <= static_cast<int>(tlist.size()); i++) {
1278  bool in_orderby = false;
1279  std::for_each(order_by->begin(),
1280  order_by->end(),
1281  [&in_orderby, i](const Analyzer::OrderEntry& oe) {
1282  in_orderby = in_orderby || (i == oe.tle_no);
1283  });
1284  if (!in_orderby) {
1285  order_by->push_back(Analyzer::OrderEntry(i, false, false));
1286  }
1287  }
1288  }
1289  query.set_order_by(order_by);
1290 }
string name
Definition: setup.in.py:72
void set_order_by(std::list< OrderEntry > *o)
Definition: Analyzer.h:1640
void set_offset(int64_t o)
Definition: Analyzer.h:1652
bool get_is_distinct() const
Definition: Analyzer.h:1614
std::unique_ptr< QueryExpr > query_expr
Definition: ParserNode.h:1835
void set_stmt_type(SQLStmtType t)
Definition: Analyzer.h:1643
Definition: Analyzer.h:1413
void set_limit(int64_t l)
Definition: Analyzer.h:1650
const std::vector< std::shared_ptr< TargetEntry > > & get_targetlist() const
Definition: Analyzer.h:1616
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1836

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

References orderby_clause.

1828  {
1829  return orderby_clause;
1830  }
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1836
const QueryExpr* Parser::SelectStmt::get_query_expr ( ) const
inline

Definition at line 1827 of file ParserNode.h.

References query_expr.

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

Member Data Documentation

int64_t Parser::SelectStmt::limit
private

Definition at line 1837 of file ParserNode.h.

int64_t Parser::SelectStmt::offset
private

Definition at line 1838 of file ParserNode.h.

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

Definition at line 1836 of file ParserNode.h.

Referenced by get_orderby_clause(), and SelectStmt().

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

Definition at line 1835 of file ParserNode.h.

Referenced by get_query_expr().


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