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
SelfLambda.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 
19 #ifndef SELF_LAM_H
20 #define SELF_LAM_H
21 
22 #include "Handle.h"
23 #include <string>
24 #include "Ptr.h"
25 #include "TupleSet.h"
26 #include <vector>
27 #include "SimpleComputeExecutor.h"
28 #include "TupleSetMachine.h"
29 
30 namespace pdb {
31 
32 template<class ClassType>
33 class SelfLambda : public TypedLambdaObject<pdb::Ptr<ClassType>> {
34 
35  public:
36  std::string inputTypeName;
37 
38  public:
39  // create an att access lambda; offset is the position in the input object where we are going to
40  // find the input att
42  inputTypeName = getTypeName<ClassType>();
43  this->setInputIndex(0, -((input.getExactTypeInfoValue() + 1)));
44  }
45 
46  std::string getTypeOfLambda() override {
47  return std::string("self");
48  }
49 
50  std::string typeOfAtt() {
51  return inputTypeName;
52  }
53 
54  std::string getInputType() {
55  return inputTypeName;
56  }
57 
58  unsigned int getNumInputs() override {
59  return 1;
60  }
61 
62  int getNumChildren() override {
63  return 0;
64  }
65 
66  GenericLambdaObjectPtr getChild(int which) override {
67  return nullptr;
68  }
69 
74  std::map<std::string, std::string> getInfo() override {
75 
76  // fill in the info
77  return std::map<std::string, std::string>{
78  std::make_pair ("lambdaType", getTypeOfLambda()),
79  };
80  };
81 
83  TupleSpec &attsToOperateOn,
84  TupleSpec &attsToIncludeInOutput) override {
85 
86  // create the output tuple set
87  TupleSetPtr output = std::make_shared<TupleSet>();
88 
89  // create the machine that is going to setup the output tuple set, using the input tuple set
90  TupleSetSetupMachinePtr myMachine =
91  std::make_shared<TupleSetSetupMachine>(inputSchema, attsToIncludeInOutput);
92 
93  // this is the input attribute that we will process
94  std::vector<int> matches = myMachine->match(attsToOperateOn);
95  int whichAtt = matches[0];
96 
97  // this is the output attribute
98  int outAtt = attsToIncludeInOutput.getAtts().size();
99 
100  return std::make_shared<SimpleComputeExecutor>(
101  output,
102  [=](TupleSetPtr input) {
103 
104  // set up the output tuple set
105  myMachine->setup(input, output);
106 
107  // get the columns to operate on
108  std::vector<Handle<ClassType>> &inputColumn =
109  input->getColumn<Handle<ClassType>>(whichAtt);
110 
111  // setup the output column, if it is not already set up
112  if (!output->hasColumn(outAtt)) {
113  std::vector<Ptr<ClassType>> *outputCol = new std::vector<Ptr<ClassType>>;
114  output->addColumn(outAtt, outputCol, true);
115  }
116 
117  // get the output column
118  std::vector<Ptr<ClassType>> &outColumn = output->getColumn<Ptr<ClassType>>(outAtt);
119 
120  // loop down the columns, setting the output
121  int numTuples = inputColumn.size();
122  outColumn.resize(numTuples);
123  for (int i = 0; i < numTuples; i++) {
124  outColumn[i] = (ClassType *) &(*(inputColumn[i]));
125  }
126 
127  return output;
128  },
129  "selfLambda");
130  }
131 };
132 }
133 
134 #endif
ComputeExecutorPtr getExecutor(TupleSpec &inputSchema, TupleSpec &attsToOperateOn, TupleSpec &attsToIncludeInOutput) override
Definition: SelfLambda.h:82
unsigned int getNumInputs() override
Definition: SelfLambda.h:58
std::vector< std::string > & getAtts()
Definition: TupleSpec.h:60
std::shared_ptr< TupleSetSetupMachine > TupleSetSetupMachinePtr
std::string getInputType()
Definition: SelfLambda.h:54
SelfLambda(Handle< ClassType > &input)
Definition: SelfLambda.h:41
std::shared_ptr< GenericLambdaObject > GenericLambdaObjectPtr
std::map< std::string, std::string > getInfo() override
Definition: SelfLambda.h:74
std::shared_ptr< TupleSet > TupleSetPtr
Definition: TupleSet.h:64
std::string inputTypeName
Definition: SelfLambda.h:36
std::string typeOfAtt()
Definition: SelfLambda.h:50
std::shared_ptr< ComputeExecutor > ComputeExecutorPtr
int getNumChildren() override
Definition: SelfLambda.h:62
GenericLambdaObjectPtr getChild(int which) override
Definition: SelfLambda.h:66
std::string getTypeOfLambda() override
Definition: SelfLambda.h:46
void setInputIndex(int i, unsigned int index)
Definition: Ptr.h:32