40 template<
class ReturnType>
54 std::shared_ptr<DereferenceLambda<ReturnType>> newRoot = std::make_shared<DereferenceLambda<ReturnType>>(treeWithPointer);
65 return tree->getInputIndex();
73 void toMap(std::map<std::string, GenericLambdaObjectPtr> &returnVal,
int &suffix) {
78 std::vector<std::string> ret;
102 std::vector<std::string> &inputColumnNames,
103 std::vector<std::string> &inputColumnsToApply,
104 std::vector<std::string> &childrenLambdaNames,
106 std::string computationName,
107 int computationLabel,
108 std::string &outputTupleSetName,
109 std::vector<std::string> &outputColumnNames,
110 std::string &addedOutputColumnName,
111 std::string &myLambdaName,
112 bool whetherToRemoveUnusedOutputColumns,
114 bool amIPartOfJoinPredicate =
false) {
115 std::vector<std::string> tcapStrings;
116 std::string outputTCAPString;
117 std::vector<std::string> inputTupleSetNames;
118 inputTupleSetNames.push_back(inputTupleSetName);
119 std::vector<std::string> columnNames;
121 for (
const auto &inputColumnName : inputColumnNames) {
122 columnNames.push_back(inputColumnName);
125 std::vector<std::string> columnsToApply;
126 for (
const auto &i : inputColumnsToApply) {
127 columnsToApply.push_back(i);
130 std::vector<std::string> childrenLambdas;
131 for (
const auto &childrenLambdaName : childrenLambdaNames) {
132 childrenLambdas.push_back(childrenLambdaName);
144 addedOutputColumnName,
148 amIPartOfJoinPredicate);
149 PDB_COUT <<
"Lambda: lambdaLabel=" << lambdaLabel << std::endl;
150 bool isOutputInInput =
false;
151 outputColumnNames.clear();
153 if (!whetherToRemoveUnusedOutputColumns) {
155 for (
const auto &columnName : columnNames) {
156 outputColumnNames.push_back(columnName);
157 if (addedOutputColumnName == columnName) {
158 isOutputInInput =
true;
162 if (!isOutputInInput) {
163 outputColumnNames.push_back(addedOutputColumnName);
167 outputColumnNames.push_back(addedOutputColumnName);
171 if (whetherToRemoveUnusedOutputColumns) {
174 unsigned long last = tcapStrings.size() - 1;
176 PDB_COUT <<
"tcapStrings[" << last <<
"]=" << tcapStrings[last] << std::endl;
177 std::string right = tcapStrings[last].substr(tcapStrings[last].find(
"<="));
183 if (right.find(
'[') != std::string::npos) {
184 end = right.substr(right.find(
'['));
185 right = right.substr(0, right.find(
'['));
189 unsigned long pos1 = right.find_last_of(
'(');
190 unsigned long pos2 = right.rfind(
"),");
193 right.replace(pos1 + 1, pos2 - 1 - (pos1 + 1) + 1,
"");
196 tcapStrings[last] = outputTupleSetName +
" (" + addedOutputColumnName +
") " + right + end;
200 for (
const auto &tcapString : tcapStrings) {
201 outputTCAPString.append(tcapString);
204 return outputTCAPString;
212 std::shared_ptr<TypedLambdaObject<ReturnType>>
tree;
222 static void traverse(std::map<std::string, GenericLambdaObjectPtr> &fillMe,
226 for (
int i = 0; i < root->getNumChildren(); i++) {
228 traverse(fillMe, child, startLabel);
231 std::string myName = root->getTypeOfLambda();
232 myName = myName +
"_" + std::to_string(startLabel);
234 fillMe[myName] = root;
245 for (
int i = 0; i < root->getNumChildren(); i++) {
248 getInputs(allInputs, child, multiInputsBase);
251 if (root->getNumChildren() == 0) {
252 for (
int i = 0; i < root->getNumInputs(); i++) {
254 auto iter = std::find(allInputs.begin(), allInputs.end(), myName);
256 if (iter == allInputs.end()) {
257 allInputs.push_back(myName);
285 std::vector<std::string> &inputTupleSetNames,
286 std::vector<std::string> &inputColumnNames,
287 std::vector<std::string> &inputColumnsToApply,
288 std::vector<std::string> &childrenLambdaNames,
291 std::string computationName,
292 int computationLabel,
293 std::string &addedOutputColumnName,
294 std::string &myLambdaName,
295 std::string &outputTupleSetName,
297 bool amIPartOfJoinPredicate =
false,
298 bool amILeftChildOfEqualLambda =
false,
299 bool amIRightChildOfEqualLambda =
false,
300 std::string parentLambdaName =
"",
301 bool isSelfJoin =
false) {
303 std::vector<std::string> columnsToApply;
304 std::vector<std::string> childrenLambdas;
305 std::vector<std::string> inputNames;
306 std::vector<std::string> inputColumns;
308 if (root->getNumChildren() > 0) {
310 for (
const auto &i : inputColumnsToApply) {
311 columnsToApply.push_back(i);
314 inputColumnsToApply.clear();
316 for (
const auto &childrenLambdaName : childrenLambdaNames) {
317 childrenLambdas.push_back(childrenLambdaName);
320 childrenLambdaNames.clear();
322 for (
const auto &inputTupleSetName : inputTupleSetNames) {
323 auto iter = std::find(inputNames.begin(), inputNames.end(), inputTupleSetName);
324 if (iter == inputNames.end()) {
325 inputNames.push_back(inputTupleSetName);
329 inputTupleSetNames.clear();
331 for (
const auto &inputColumnName : inputColumnNames) {
332 inputColumns.push_back(inputColumnName);
335 inputColumnNames.clear();
338 std::string myTypeName = root->getTypeOfLambda();
339 PDB_COUT <<
"\tExtracted lambda named: " << myTypeName <<
"\n";
340 std::string myName = myTypeName +
"_" + std::to_string(lambdaLabel + root->getNumChildren());
342 bool isLeftChildOfEqualLambda =
false;
343 bool isRightChildOfEqualLambda =
false;
344 bool isChildSelfJoin =
false;
347 for (
int i = 0; i < root->getNumChildren(); i++) {
350 if ((i + 1) < root->getNumChildren()) {
351 nextChild = root->getChild(i + 1);
354 if (myTypeName ==
"==") {
357 isLeftChildOfEqualLambda =
true;
361 isRightChildOfEqualLambda =
true;
366 if ((isLeftChildOfEqualLambda || isRightChildOfEqualLambda) && (multiInputsComp !=
nullptr)) {
368 std::string nextInputName;
370 if (nextChild !=
nullptr) {
371 nextInputName = multiInputsComp->getNameForIthInput(nextChild->getInputIndex(0));
374 std::string myInputName = multiInputsComp->getNameForIthInput(child->getInputIndex(0));
376 if (nextInputName == myInputName) {
377 isChildSelfJoin =
true;
390 addedOutputColumnName,
394 amIPartOfJoinPredicate,
395 isLeftChildOfEqualLambda,
396 isRightChildOfEqualLambda,
400 inputColumnsToApply.push_back(addedOutputColumnName);
401 childrenLambdaNames.push_back(myLambdaName);
403 if (multiInputsComp !=
nullptr) {
404 auto iter = std::find(inputTupleSetNames.begin(), inputTupleSetNames.end(), outputTupleSetName);
406 if (iter == inputTupleSetNames.end()) {
407 inputTupleSetNames.push_back(outputTupleSetName);
412 inputTupleSetNames.clear();
413 inputTupleSetNames.push_back(outputTupleSetName);
414 inputColumnNames.clear();
417 for (
const auto &inputColumn : inputColumns) {
419 std::find(inputColumnNames.begin(), inputColumnNames.end(), inputColumn);
420 if (iter == inputColumnNames.end()) {
421 inputColumnNames.push_back(inputColumn);
425 isLeftChildOfEqualLambda =
false;
426 isRightChildOfEqualLambda =
false;
427 isChildSelfJoin =
false;
431 std::vector<std::string> outputColumns;
432 std::string tcapString = root->toTCAPString(inputTupleSetNames,
441 addedOutputColumnName,
444 amIPartOfJoinPredicate,
445 amILeftChildOfEqualLambda,
446 amIRightChildOfEqualLambda,
450 tcapStrings.push_back(tcapString);
453 if (multiInputsComp ==
nullptr) {
454 inputTupleSetNames.clear();
455 inputTupleSetNames.push_back(outputTupleSetName);
458 inputColumnNames.clear();
459 for (
const auto &outputColumn : outputColumns) {
460 inputColumnNames.push_back(outputColumn);
unsigned int getInputIndex()
std::shared_ptr< TypedLambdaObject< ReturnType > > tree
static void getTCAPString(std::vector< std::string > &tcapStrings, std::vector< std::string > &inputTupleSetNames, std::vector< std::string > &inputColumnNames, std::vector< std::string > &inputColumnsToApply, std::vector< std::string > &childrenLambdaNames, GenericLambdaObjectPtr root, int &lambdaLabel, std::string computationName, int computationLabel, std::string &addedOutputColumnName, std::string &myLambdaName, std::string &outputTupleSetName, MultiInputsBase *multiInputsComp=nullptr, bool amIPartOfJoinPredicate=false, bool amILeftChildOfEqualLambda=false, bool amIRightChildOfEqualLambda=false, std::string parentLambdaName="", bool isSelfJoin=false)
void getInputs(std::vector< std::string > &allInputs, GenericLambdaObjectPtr root, MultiInputsBase *multiInputsBase)
void toMap(std::map< std::string, GenericLambdaObjectPtr > &returnVal, int &suffix)
std::shared_ptr< GenericLambdaObject > GenericLambdaObjectPtr
static void traverse(std::map< std::string, GenericLambdaObjectPtr > &fillMe, GenericLambdaObjectPtr root, int &startLabel)
std::vector< std::string > getAllInputs(MultiInputsBase *multiInputsBase)
Lambda(LambdaTree< ReturnType > tree)
std::string toTCAPString(std::string inputTupleSetName, std::vector< std::string > &inputColumnNames, std::vector< std::string > &inputColumnsToApply, std::vector< std::string > &childrenLambdaNames, int &lambdaLabel, std::string computationName, int computationLabel, std::string &outputTupleSetName, std::vector< std::string > &outputColumnNames, std::string &addedOutputColumnName, std::string &myLambdaName, bool whetherToRemoveUnusedOutputColumns, MultiInputsBase *multiInputsComp=nullptr, bool amIPartOfJoinPredicate=false)
Lambda(LambdaTree< Ptr< ReturnType >> treeWithPointer)