InfiniSQL  v0.1.2-alpha
Massive Scale Transaction Processing
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Asts.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Mark Travis <mtravis15432+src@gmail.com>
3  * All rights reserved. No warranty, explicit or implicit, provided.
4  *
5  * This file is part of InfiniSQL(tm).
6 
7  * InfiniSQL is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 3
9  * as published by the Free Software Foundation.
10  *
11  * InfiniSQL is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with InfiniSQL. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
29 #ifndef INFINISQLASTS_H
30 #define INFINISQLASTS_H
31 
32 #include <string>
33 #include <vector>
34 #include <boost/unordered_map.hpp>
35 #include "defs.h"
36 #include "larx.h"
37 
38 class ApiInterface;
39 typedef void(ApiInterface::*apifPtr)(int64_t, void *);
40 
41 typedef ApiInterface *(*spclasscreate)(class TransactionAgent *,
42  class ApiInterface *, void *);
43 typedef void(*spclassdestroy)(ApiInterface *);
44 
45 using std::string;
46 using std::vector;
47 
51 class Ast
52 {
53 public:
54  Ast();
61  Ast(class Ast *parentarg , operatortypes_e operatortypearg); // for operators
68  Ast(class Ast *parentarg, std::string &operandarg); // for operands
69  Ast(const Ast &orig);
70  Ast &operator= (const Ast &orig);
76  void cp(const Ast &orig);
77  virtual ~Ast();
78 
93  bool evaluate(class Ast **nextAstNode,
94  class Statement *statementPtr);
95  /* evaluates for setassignment per row. does not get backgrounded */
102  void evaluateAssignment(std::vector<fieldValue_s> &fieldValues,
103  class Statement *statementPtr);
104 
105 
112  void normalizeSetAssignmentOperand(vector<fieldValue_s> &fieldValues,
113  class Statement *statementPtr);
114 
125  static void toFloat(const string &inoperand, fieldValue_s &outField);
136  static void toFloat(const string &inoperand, string &outoperand);
137 
138  class Ast *parent;
139  class Ast *rightchild;
140  class Ast *leftchild;
141 
142  bool isoperator; // false is operand
144  std::string operand; // type and value is embedded
145  boost::unordered_map<uuRecord_s, returnRow_s> predicateResults;
146  //private:
147 };
148 
149 class Statement;
150 typedef void(Statement::*statementfPtr)(int64_t, void *);
151 
157 {
158 public:
164  {
165  bool isasc;
166  std::string operandstr;
167  };
168 
173  struct inobject_s
174  {
175  bool issubquery;
176  int64_t subquery;
177  std::vector<class Ast *> expressionlist;
178  };
179 
184  struct column_s
185  {
187  int64_t fieldid;
188  std::string name;
189  };
190 
196  struct results_s
197  {
198  boost::unordered_map<uuRecord_s, returnRow_s> searchResults;
199  /* each string is a field, with type embedded in 1st char */
200  boost::unordered_map< uuRecord_s,
201  std::vector<fieldValue_s> > selectResults;
202  size_t initerator;
203  std::vector<fieldValue_s> inValues;
204  std::vector<fieldValue_s> insertValues;
205  std::string newrow; // insert
207  int64_t newrowengineid;
209  boost::unordered_map<uuRecord_s,
210  returnRow_s>::const_iterator updateIterator;
211  // setFields[fieldid] = fieldValue
212  boost::unordered_map<int64_t, fieldValue_s> setFields;
213  };
214 
219  struct query_s
220  {
221  ssize_t instance;
222 
225  bool hasnolock;
226  bool haswhere;
228  bool hashaving;
230 
231  std::string table;
232  int64_t tableid;
234  std::vector<std::string> groupByList; // identifiers
235  // fromColumns are operands
236  std::vector<std::string> fromColumns;
237  std::vector<column_s> fromColumnids;
238  std::vector<orderbyitem_s> orderbylist;
240 
242  boost::unordered_map<string, class Ast *> assignments;
243  boost::unordered_map<int64_t, class Ast *> fieldidAssignments;
244  std::vector<class Ast *> insertColumns;
245 
246  std::string storedProcedure;
247  std::vector<std::string> storedProcedureArgs;
248 
250  };
251 
257  {
261  };
262 
267  struct reentry_s
268  {
271  int64_t reentrypoint;
272  void *reentrydata;
273  };
274 
275  Statement();
282  Statement(class TransactionAgent *taPtrarg, class Schema *schemaPtrarg);
283  Statement(const Statement &orig);
284  Statement &operator= (const Statement &orig);
290  void cp(const Statement &orig);
291  virtual ~Statement();
292 
300  query_s cpquery(const query_s &orig);
307  bool resolveTableFields();
315  bool resolveTableFields2();
323  bool resolveFieldNames(class Ast *myPosition);
332  int64_t getfieldid(int64_t tableid, const string &fieldName);
348  bool stagedPredicate(operatortypes_e op, int64_t tableid,
349  string &leftoperand, string &rightoperand,
350  vector<fieldValue_s> &inValues,
351  const boost::unordered_map<uuRecord_s,
352  stagedRow_s> &stagedRows,
353  boost::unordered_map<uuRecord_s, returnRow_s> &results);
357  void andPredicate(operatortypes_e op, int64_t tableid,
358  string &leftoperand, string &rightoperand,
359  vector<fieldValue_s> &inValues,
360  const boost::unordered_map<uuRecord_s,
361  returnRow_s> &andResults,
362  boost::unordered_map<uuRecord_s, returnRow_s> &results);
373  void execute(class ApiInterface *reentryObject, apifPtr reentryfptr,
374  int64_t reentrypoint, void *reentrydata,
375  class Transaction *transactionPtrarg,
376  const vector<string> &parametersarg);
388  void searchExpression(int64_t entrypoint, class Ast *astNode);
393  void branchtotype();
399  void reenter(int64_t status);
406  void continueSelect(int64_t entrypoint, class Ast *ignorethis);
413  void continueDelete(int64_t entrypoint, class Ast *ignorethis);
420  void continueInsert(int64_t entrypoint, class Ast *ignorethis);
427  void continueUpdate(int64_t entrypoint, class Ast *ignorethis);
432  void startQuery();
438  void subqueryScalar(class Ast *astnode);
444  void subqueryUnique(class Ast *astnode);
450  void subqueryExists(class Ast *astnode);
456  void subqueryIn(class Ast *astnode);
462  void abortQuery(int64_t status);
463 
469 
470  std::vector<query_s> queries;
471  std::vector<std::string> parameters;
472 
473  ssize_t queryindex;
474 };
475 
476 #endif /* INFINISQLASTS_H */