A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ParserHelperFunctions.cc
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 
19 #ifndef SQL_PARSER_C
20 #define SQL_PARSER_C
21 
22 #include <iostream>
23 #include <stdlib.h>
24 #include "Parser.h"
25 #include "ParserHelperFunctions.h"
26 #include "AttList.h"
27 #include "KeyValueList.h"
28 #include "TupleSpec.h"
29 #include "AtomicComputationList.h"
31 #include <string>
32 #include <map>
33 #include <vector>
34 #include <utility>
35 
36 /*************************************************/
39 /*************************************************/
40 
41 extern "C" {
42 
43 // ss107: Newer functions for updating TCAP:
45  auto *returnVal = new KeyValueList ();
46  return returnVal;
47 }
48 
49 struct KeyValueList *makeKeyValueList (char *keyName, char *valueName) {
50  auto * returnVal = new KeyValueList ();
51  returnVal->appendkeyValuePair (std::string(keyName), std::string(valueName));
52  free (keyName);
53  free (valueName);
54  return returnVal;
55 }
56 
57 struct KeyValueList *pushBackKeyValue (struct KeyValueList *addToMe, char *keyName, char *valueName) {
58  addToMe->appendkeyValuePair (keyName, valueName);
59  free (keyName);
60  free (valueName);
61  return addToMe;
62 }
63 
64 struct AtomicComputation *makeFilterWithList (struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, struct KeyValueList *useMe) {
65  AtomicComputationPtr returnVal = std :: make_shared <ApplyFilter> (*input, *output, *projection, std :: string (nodeName), *useMe);
66  returnVal->setShared (returnVal);
67  delete output;
68  delete input;
69  delete projection;
70  delete useMe;
71  free (nodeName);
72  return returnVal.get ();
73 }
74 
75 struct AtomicComputation *makeApplyWithList (struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, char *opName, struct KeyValueList *useMe) {
76  AtomicComputationPtr returnVal = std::make_shared<ApplyLambda>(*input, *output, *projection, std::string(nodeName), std::string(opName), *useMe);
77  returnVal->setShared (returnVal);
78  delete output;
79  delete input;
80  delete projection;
81  delete useMe;
82  free (nodeName);
83  free (opName);
84  return returnVal.get ();
85 }
86 
87 struct AtomicComputation *makeAggWithList (struct TupleSpec *output, struct TupleSpec *input, char *nodeName, struct KeyValueList *useMe) {
88  AtomicComputationPtr returnVal = std :: make_shared <ApplyAgg> (*input, *output, *input, std :: string (nodeName), *useMe);
89  returnVal->setShared (returnVal);
90  delete output;
91  delete input;
92  delete useMe;
93  free (nodeName);
94  return returnVal.get ();
95 }
96 
97 struct AtomicComputation *makePartitionWithList (struct TupleSpec *output, struct TupleSpec *input, char *nodeName, struct KeyValueList *useMe) {
98  AtomicComputationPtr returnVal = std :: make_shared <ApplyPartition> (*input, *output, *input, std :: string (nodeName), *useMe);
99  returnVal->setShared (returnVal);
100  delete output;
101  delete input;
102  delete useMe;
103  free (nodeName);
104  return returnVal.get ();
105 }
106 
107 
108 struct AtomicComputation *makeJoinWithList (struct TupleSpec *output, struct TupleSpec *lInput, struct TupleSpec *lProjection,
109  struct TupleSpec *rInput, struct TupleSpec *rProjection, char *opName, struct KeyValueList *useMe) {
110  AtomicComputationPtr returnVal = std :: make_shared <ApplyJoin> (*output, *lInput, *rInput, *lProjection,
111  *rProjection, std :: string (opName), *useMe);
112  returnVal->setShared (returnVal);
113  free (opName);
114  delete output;
115  delete lInput;
116  delete rInput;
117  delete useMe;
118  delete lProjection;
119  delete rProjection;
120  return returnVal.get ();
121 }
122 
123 struct AtomicComputation *makeHashLeftWithList (struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, char *opName, struct KeyValueList *useMe) {
124  AtomicComputationPtr returnVal = std :: make_shared <HashLeft> (*input, *output, *projection, std :: string (nodeName), std :: string (opName), *useMe);
125  returnVal->setShared (returnVal);
126  delete output;
127  delete input;
128  delete projection;
129  delete useMe;
130  free (nodeName);
131  free (opName);
132  return returnVal.get ();
133 }
134 
135 struct AtomicComputation *makeHashRightWithList (struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, char *opName, struct KeyValueList *useMe) {
136  AtomicComputationPtr returnVal = std :: make_shared <HashRight> (*input, *output, *projection, std :: string (nodeName), std :: string (opName), *useMe);
137  returnVal->setShared (returnVal);
138  delete output;
139  delete input;
140  delete projection;
141  delete useMe;
142  free (nodeName);
143  free (opName);
144  return returnVal.get ();
145 }
146 
147 
148 
149 struct AtomicComputation *makeHashOneWithList (struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, struct KeyValueList *useMe) {
150  AtomicComputationPtr returnVal = std :: make_shared <HashOne> (*input, *output, *projection, std :: string (nodeName), *useMe);
151  returnVal->setShared (returnVal);
152  delete output;
153  delete input;
154  delete projection;
155  delete useMe;
156  free (nodeName);
157  return returnVal.get ();
158 }
159 
160 struct AtomicComputation *makeFlattenWithList (struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, struct KeyValueList *useMe) {
161  AtomicComputationPtr returnVal = std :: make_shared <Flatten> (*input, *output, *projection, std :: string (nodeName), *useMe);
162  returnVal->setShared (returnVal);
163  delete output;
164  delete input;
165  delete projection;
166  delete useMe;
167  free (nodeName);
168  return returnVal.get ();
169 }
170 
171 
172 
173 struct AtomicComputation *makeScanWithList (struct TupleSpec *output, char *dbName, char *setName, char *nodeName, struct KeyValueList *useMe) {
174  AtomicComputationPtr returnVal = std :: make_shared <ScanSet> (*output, std :: string (dbName), std :: string (setName), std :: string (nodeName), *useMe);
175  returnVal->setShared (returnVal);
176  free (dbName);
177  free (setName);
178  free (nodeName);
179  delete useMe;
180  delete output;
181  return returnVal.get ();
182 }
183 
185  char *dbName, char *setName, char *nodeName, struct KeyValueList *useMe) {
186  AtomicComputationPtr returnVal = std :: make_shared <WriteSet> (*input, *output, *input,
187  std :: string (dbName), std :: string (setName), std :: string (nodeName), *useMe);
188  returnVal->setShared (returnVal);
189  free (dbName);
190  free (setName);
191  free (nodeName);
192  delete useMe;
193  delete output;
194  delete input;
195  return returnVal.get ();
196 }
197 
198 
199 // Older functions that were here:
200 struct AttList* makeAttList(char* fromMe) {
201  auto* returnVal = new AttList();
202  returnVal->appendAttribute(fromMe);
203  free(fromMe);
204  return returnVal;
205 }
206 
207 struct AttList* pushBackAttribute(struct AttList* addToMe, char* fromMe) {
208  addToMe->appendAttribute(fromMe);
209  free(fromMe);
210  return addToMe;
211 }
212 
213 struct TupleSpec* makeTupleSpec(char* setName, struct AttList* useMe) {
214  TupleSpec* returnVal = new TupleSpec(std::string(setName), *useMe);
215  delete useMe;
216  free(setName);
217  return returnVal;
218 }
219 
221  auto* returnVal = new AtomicComputationList();
222  returnVal->addAtomicComputation(fromMe->getShared());
223  return returnVal;
224 }
225 
227  struct AtomicComputation* addMe) {
228  input->addAtomicComputation(addMe->getShared());
229  return input;
230 }
231 
233  TupleSpec* returnVal = new TupleSpec(std::string(setName));
234  free(setName);
235  return returnVal;
236 }
237 
239  struct TupleSpec* input,
240  struct TupleSpec* projection,
241  char* nodeName) {
242  AtomicComputationPtr returnVal =
243  std::make_shared<ApplyFilter>(*input, *output, *projection, std::string(nodeName));
244  returnVal->setShared(returnVal);
245  delete output;
246  delete input;
247  delete projection;
248  free(nodeName);
249  return returnVal.get();
250 }
251 
253  struct TupleSpec* input,
254  struct TupleSpec* projection,
255  char* nodeName,
256  char* opName) {
257  AtomicComputationPtr returnVal = std::make_shared<ApplyLambda>(*input, *output, *projection, std::string(nodeName), std::string(opName));
258  returnVal->setShared(returnVal);
259  delete output;
260  delete input;
261  delete projection;
262  free(nodeName);
263  free(opName);
264  return returnVal.get();
265 }
266 
268  struct TupleSpec* input,
269  char* nodeName) {
270  AtomicComputationPtr returnVal =
271  std::make_shared<ApplyAgg>(*input, *output, *input, std::string(nodeName));
272  returnVal->setShared(returnVal);
273  delete output;
274  delete input;
275  free(nodeName);
276  return returnVal.get();
277 }
278 
280  struct TupleSpec* input,
281  char* nodeName) {
282  AtomicComputationPtr returnVal =
283  std::make_shared<ApplyPartition>(*input, *output, *input, std::string(nodeName));
284  returnVal->setShared(returnVal);
285  delete output;
286  delete input;
287  free(nodeName);
288  return returnVal.get();
289 }
290 
291 
292 
294  struct TupleSpec* lInput,
295  struct TupleSpec* lProjection,
296  struct TupleSpec* rInput,
297  struct TupleSpec* rProjection,
298  char* opName) {
299  AtomicComputationPtr returnVal = std::make_shared<ApplyJoin>(
300  *output, *lInput, *rInput, *lProjection, *rProjection, std::string(opName));
301  returnVal->setShared(returnVal);
302  free(opName);
303  delete output;
304  delete lInput;
305  delete rInput;
306  delete lProjection;
307  delete rProjection;
308  return returnVal.get();
309 }
310 
312  struct TupleSpec* input,
313  struct TupleSpec* projection,
314  char* nodeName,
315  char* opName) {
316  AtomicComputationPtr returnVal = std::make_shared<HashLeft>(
317  *input, *output, *projection, std::string(nodeName), std::string(opName));
318  returnVal->setShared(returnVal);
319  delete output;
320  delete input;
321  delete projection;
322  free(nodeName);
323  free(opName);
324  return returnVal.get();
325 }
326 
328  struct TupleSpec* input,
329  struct TupleSpec* projection,
330  char* nodeName,
331  char* opName) {
332  AtomicComputationPtr returnVal = std::make_shared<HashRight>(
333  *input, *output, *projection, std::string(nodeName), std::string(opName));
334  returnVal->setShared(returnVal);
335  delete output;
336  delete input;
337  delete projection;
338  free(nodeName);
339  free(opName);
340  return returnVal.get();
341 }
342 
344  struct TupleSpec* input,
345  struct TupleSpec* projection,
346  char* nodeName) {
347  AtomicComputationPtr returnVal =
348  std::make_shared<HashOne>(*input, *output, *projection, std::string(nodeName));
349  returnVal->setShared(returnVal);
350  delete output;
351  delete input;
352  delete projection;
353  free(nodeName);
354  return returnVal.get();
355 }
356 
358  struct TupleSpec* input,
359  struct TupleSpec* projection,
360  char* nodeName) {
361  AtomicComputationPtr returnVal =
362  std::make_shared<Flatten>(*input, *output, *projection, std::string(nodeName));
363  returnVal->setShared(returnVal);
364  delete output;
365  delete input;
366  delete projection;
367  free(nodeName);
368  return returnVal.get();
369 }
370 
371 
373  char* dbName,
374  char* setName,
375  char* nodeName) {
376  AtomicComputationPtr returnVal = std::make_shared<ScanSet>(
377  *output, std::string(dbName), std::string(setName), std::string(nodeName));
378  returnVal->setShared(returnVal);
379  free(dbName);
380  free(setName);
381  free(nodeName);
382  delete output;
383  return returnVal.get();
384 }
385 
387  struct TupleSpec* input,
388  char* dbName,
389  char* setName,
390  char* nodeName) {
391  AtomicComputationPtr returnVal = std::make_shared<WriteSet>(
392  *input, *output, *input, std::string(dbName), std::string(setName), std::string(nodeName));
393  returnVal->setShared(returnVal);
394  free(dbName);
395  free(setName);
396  free(nodeName);
397  delete output;
398  delete input;
399  return returnVal.get();
400 }
401 
402 // structure that stores a list of aliases from a FROM clause
403 } // extern
404 
405 #endif
struct AtomicComputation * makeOutputWithList(struct TupleSpec *output, struct TupleSpec *input, char *dbName, char *setName, char *nodeName, struct KeyValueList *useMe)
struct AttList * makeAttList(char *fromMe)
AtomicComputationPtr getShared()
struct AtomicComputation * makeOutput(struct TupleSpec *output, struct TupleSpec *input, char *dbName, char *setName, char *nodeName)
struct AtomicComputation * makeFilter(struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName)
struct KeyValueList * makeKeyValueList(char *keyName, char *valueName)
struct TupleSpec * makeEmptyTupleSpec(char *setName)
struct AtomicComputation * makeApply(struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, char *opName)
struct AtomicComputation * makeJoinWithList(struct TupleSpec *output, struct TupleSpec *lInput, struct TupleSpec *lProjection, struct TupleSpec *rInput, struct TupleSpec *rProjection, char *opName, struct KeyValueList *useMe)
struct AtomicComputation * makeFlattenWithList(struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, struct KeyValueList *useMe)
struct AtomicComputation * makeHashOne(struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName)
struct AtomicComputation * makeScan(struct TupleSpec *output, char *dbName, char *setName, char *nodeName)
struct TupleSpec * makeTupleSpec(char *setName, struct AttList *useMe)
struct AtomicComputation * makeFlatten(struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName)
struct AtomicComputation * makeHashLeft(struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, char *opName)
struct KeyValueList * pushBackKeyValue(struct KeyValueList *addToMe, char *keyName, char *valueName)
struct AtomicComputation * makeFilterWithList(struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, struct KeyValueList *useMe)
struct AtomicComputationList * pushBackAtomicComputation(struct AtomicComputationList *input, struct AtomicComputation *addMe)
void appendAttribute(char *appendMe)
Definition: AttList.h:40
void appendkeyValuePair(std::string keyName, std::string valueName)
Definition: KeyValueList.h:47
void setShared(AtomicComputationPtr meIn)
struct AtomicComputationList * makeAtomicComputationList(struct AtomicComputation *fromMe)
struct AtomicComputation * makeHashRightWithList(struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, char *opName, struct KeyValueList *useMe)
struct AtomicComputation * makeJoin(struct TupleSpec *output, struct TupleSpec *lInput, struct TupleSpec *lProjection, struct TupleSpec *rInput, struct TupleSpec *rProjection, char *opName)
struct AtomicComputation * makeAgg(struct TupleSpec *output, struct TupleSpec *input, char *nodeName)
void addAtomicComputation(AtomicComputationPtr addMe)
struct AtomicComputation * makePartition(struct TupleSpec *output, struct TupleSpec *input, char *nodeName)
struct AtomicComputation * makeHashLeftWithList(struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, char *opName, struct KeyValueList *useMe)
std::string setName
Definition: TupleSpec.h:37
struct AttList * pushBackAttribute(struct AttList *addToMe, char *fromMe)
std::shared_ptr< struct AtomicComputation > AtomicComputationPtr
struct AtomicComputation * makeApplyWithList(struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, char *opName, struct KeyValueList *useMe)
AttList()
Definition: AttList.h:38
TupleSpec()
Definition: TupleSpec.h:41
struct KeyValueList * makeEmptyKeyValueList()
struct AtomicComputation * makeScanWithList(struct TupleSpec *output, char *dbName, char *setName, char *nodeName, struct KeyValueList *useMe)
struct AtomicComputation * makeHashOneWithList(struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, struct KeyValueList *useMe)
struct AtomicComputation * makePartitionWithList(struct TupleSpec *output, struct TupleSpec *input, char *nodeName, struct KeyValueList *useMe)
struct AtomicComputation * makeAggWithList(struct TupleSpec *output, struct TupleSpec *input, char *nodeName, struct KeyValueList *useMe)
struct AtomicComputation * makeHashRight(struct TupleSpec *output, struct TupleSpec *input, struct TupleSpec *projection, char *nodeName, char *opName)