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
MultiInputsBase.h
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 #ifndef MULTI_INPUTS_BASE
19 #define MULTI_INPUTS_BASE
20 
21 
22 namespace pdb {
23 
24 
25 // this class represents all inputs for a multi-input computation like Join
26 // this is used in query graph analysis
28 
29 private:
30  // tuple set names for each input
31  std::vector<std::string> tupleSetNamesForInputs;
32 
33  // input columns for each input
34  std::vector<std::vector<std::string>> inputColumnsForInputs;
35 
36  // input column to apply for each input
37  std::vector<std::vector<std::string>> inputColumnsToApplyForInputs;
38 
39  // lambda names to extract for each input and each predicate
40  std::vector<std::map<std::string, std::vector<std::string>>> lambdaNamesForInputs;
41 
42 
43  // input names for this join operation
44  std::vector<std::string> inputNames;
45 
46  // input names show up in join predicates
47  std::vector<std::string> inputNamesInPredicates;
48 
49  // input names show up in join projection
50  std::vector<std::string> inputNamesInProjection;
51 
52 
54 
55 
56  int numInputs;
57 
58 public:
59  void setNumInputs(int numInputs) {
60  this->numInputs = numInputs;
61  }
62 
63  int getNumInputs() {
64  return this->numInputs;
65  }
66 
68  this->numPredicates = numPredicates;
69  }
70 
72  return this->numPredicates;
73  }
74 
75  // returns the latest tuple set name that contains the i-th input
76  std::string getTupleSetNameForIthInput(int i) {
77  if (i >= this->getNumInputs()) {
78  return "";
79  }
80  return tupleSetNamesForInputs[i];
81  }
82 
83  // set the latest tuple set name that contains the i-th input
84  void setTupleSetNameForIthInput(int i, std::string name) {
85  int numInputs = this->getNumInputs();
86  if (tupleSetNamesForInputs.size() != numInputs) {
87  tupleSetNamesForInputs.resize(numInputs);
88  }
89  if (i < numInputs) {
90  tupleSetNamesForInputs[i] = name;
91  }
92  }
93 
94  // get latest input columns for the tupleset for the i-th input
95  std::vector<std::string> getInputColumnsForIthInput(int i) {
96  if (i >= this->getNumInputs()) {
97  std::vector<std::string> ret;
98  return ret;
99  }
100  return inputColumnsForInputs[i];
101  }
102 
103  // set latest input columns for the tupleset for the i-th input
104  void setInputColumnsForIthInput(int i, std::vector<std::string>& columns) {
105  int numInputs = this->getNumInputs();
106  if (inputColumnsForInputs.size() != numInputs) {
107  inputColumnsForInputs.resize(numInputs);
108  }
109  if (i < numInputs) {
110  inputColumnsForInputs[i] = columns;
111  }
112  }
113 
114  // get latest input column to apply for the tupleset for the i-th input
115  std::vector<std::string> getInputColumnsToApplyForIthInput(int i) {
116  if (i >= this->getNumInputs()) {
117  std::vector<std::string> ret;
118  return ret;
119  }
121  }
122 
123 
124  // set latest input column to apply for the tupleset for the i-th input
125  void setInputColumnsToApplyForIthInput(int i, std::vector<std::string>& columnsToApply) {
126  int numInputs = this->getNumInputs();
127  if (inputColumnsToApplyForInputs.size() != numInputs) {
128  inputColumnsToApplyForInputs.resize(numInputs);
129  }
130  if (i < numInputs) {
131  inputColumnsToApplyForInputs[i] = columnsToApply;
132  }
133  }
134 
135  // set latest input column to apply for the tupleset for the i-th input
136  void setInputColumnsToApplyForIthInput(int i, std::string columnToApply) {
137  int numInputs = this->getNumInputs();
138  if (inputColumnsToApplyForInputs.size() != numInputs) {
139  inputColumnsToApplyForInputs.resize(numInputs);
140  }
141  if (i < numInputs) {
142  inputColumnsToApplyForInputs[i].clear();
143  inputColumnsToApplyForInputs[i].push_back(columnToApply);
144  }
145  }
146 
147  // get lambdas to extract for the i-th input, and j-th predicate
148  std::vector<std::string> getLambdasForIthInputAndPredicate(int i, std::string predicateLambda) {
149  if (i >= this->getNumInputs()) {
150  std::vector<std::string> ret;
151  return ret;
152  }
153  return lambdaNamesForInputs[i][predicateLambda];
154  }
155 
156  // set lambdas for the i-th input, and j-th predicate
158  std::string predicateLambda,
159  std::string lambdaName) {
160  int numInputs = this->getNumInputs();
161  if (lambdaNamesForInputs.size() != numInputs) {
162  lambdaNamesForInputs.resize(numInputs);
163  }
164  if (i < numInputs) {
165  lambdaNamesForInputs[i][predicateLambda].push_back(lambdaName);
166  }
167  }
168 
169  // get the name for the i-th input
170  std::string getNameForIthInput(int i) {
171  if (i >= this->getNumInputs()) {
172  return "";
173  }
174  return inputNames[i];
175  }
176 
177 
178  // set the name for the i-th input
179  void setNameForIthInput(int i, std::string name) {
180  int numInputs = this->getNumInputs();
181  if (inputNames.size() != numInputs) {
182  inputNames.resize(numInputs);
183  }
184  if (i < numInputs) {
185  inputNames[i] = name;
186  }
187  }
188 
189  // get the input names in predicates
190  std::vector<std::string> getInputsInPredicates() {
191  return this->inputNamesInPredicates;
192  }
193 
194 
195  // add name to names in predicates
196  void addInputNameToPredicates(std::string name) {
197 
198  auto iter = std::find(inputNamesInPredicates.begin(), inputNamesInPredicates.end(), name);
199  if (iter == inputNamesInPredicates.end()) {
200  inputNamesInPredicates.push_back(name);
201  }
202  }
203 
204  // get the input names in projection
205  std::vector<std::string> getInputsInProjection() {
206  return inputNamesInProjection;
207  }
208 
209 
210  // set the name for the i-th input
211  void addInputNameToProjection(std::string name) {
212 
213  auto iter = std::find(inputNamesInProjection.begin(), inputNamesInProjection.end(), name);
214  if (iter == inputNamesInProjection.end()) {
215  inputNamesInProjection.push_back(name);
216  }
217  }
218 
219 
220  // get a vector of inputs that are not in join predicates
221  std::vector<std::string> getNamesNotInPredicates() {
222  std::vector<std::string> ret;
223  for (int i = 0; i < inputNames.size(); i++) {
224  auto iter = std::find(
226  if (iter == inputNamesInPredicates.end()) {
227  ret.push_back(inputNames[i]);
228  }
229  }
230  return ret;
231  }
232 
233  // get a vector of inputs that are not in projection
234  std::vector<std::string> getNamesNotInProjection() {
235  std::vector<std::string> ret;
236  for (int i = 0; i < inputNames.size(); i++) {
237  auto iter = std::find(
239  if (iter == inputNamesInProjection.end()) {
240  ret.push_back(inputNames[i]);
241  }
242  }
243  return ret;
244  }
245 
246  // check whether an input name is in projection
247  bool isInputInProjection(std::string name) {
248  auto iter = std::find(inputNamesInProjection.begin(), inputNamesInProjection.end(), name);
249  if (iter != inputNamesInProjection.end()) {
250  return true;
251  } else {
252  return false;
253  }
254  }
255 };
256 }
257 
258 #endif
void setNumInputs(int numInputs)
void setInputColumnsForIthInput(int i, std::vector< std::string > &columns)
std::vector< std::string > getLambdasForIthInputAndPredicate(int i, std::string predicateLambda)
std::vector< std::string > tupleSetNamesForInputs
void setNumPredicates(int numPredicates)
std::string getTupleSetNameForIthInput(int i)
void setInputColumnsToApplyForIthInput(int i, std::vector< std::string > &columnsToApply)
void setTupleSetNameForIthInput(int i, std::string name)
void addInputNameToProjection(std::string name)
std::vector< std::string > getInputColumnsForIthInput(int i)
std::vector< std::string > inputNamesInPredicates
std::vector< std::vector< std::string > > inputColumnsToApplyForInputs
std::vector< std::string > inputNamesInProjection
void setInputColumnsToApplyForIthInput(int i, std::string columnToApply)
std::vector< std::vector< std::string > > inputColumnsForInputs
std::vector< std::string > getInputsInPredicates()
std::vector< std::string > getNamesNotInPredicates()
void addInputNameToPredicates(std::string name)
std::vector< std::map< std::string, std::vector< std::string > > > lambdaNamesForInputs
bool isInputInProjection(std::string name)
void setNameForIthInput(int i, std::string name)
std::vector< std::string > inputNames
void setLambdasForIthInputAndPredicate(int i, std::string predicateLambda, std::string lambdaName)
std::vector< std::string > getInputColumnsToApplyForIthInput(int i)
std::string getNameForIthInput(int i)
std::vector< std::string > getNamesNotInProjection()
std::vector< std::string > getInputsInProjection()