19 #ifndef PDB_MULTISELECTIONCOMPBASE_H
20 #define PDB_MULTISELECTIONCOMPBASE_H
35 template<
class OutputClass,
class InputClass>
58 void extractLambdas(std::map<std::string, GenericLambdaObjectPtr> &returnVal)
override {
63 selectionLambda.
toMap(returnVal, suffix);
64 projectionLambda.
toMap(returnVal, suffix);
72 return std::string(
"MultiSelectionComp");
90 return getTypeName<InputClass>();
109 return getTypeName<OutputClass>();
121 std::string
toTCAPString(std::vector<InputTupleSetSpecifier> &inputTupleSets,
122 int computationLabel,
124 std::vector<std::string> &outputColumnNames,
125 std::string &addedOutputColumnName)
override {
127 if (inputTupleSets.empty()) {
132 std::vector<std::string> childrenLambdaNames;
133 std::string myLambdaName;
141 addedOutputColumnName,
147 std::vector<std::string> &inputColumnNames,
148 std::vector<std::string> &inputColumnsToApply,
149 std::vector<std::string> &childrenLambdaNames,
150 int computationLabel,
152 std::vector<std::string> &outputColumnNames,
153 std::string &addedOutputColumnName,
154 std::string &myLambdaName) {
155 PDB_COUT <<
"To GET TCAP STRING FOR SELECTION" << std::endl;
158 PDB_COUT <<
"TO GET TCAP STRING FOR SELECTION LAMBDA" << std::endl;
160 std::string tupleSetName;
161 std::vector<std::string> columnNames;
162 std::string addedColumnName;
165 std::string tcapString;
166 tcapString +=
"\n/* Apply MultiSelection filtering */\n";
167 tcapString += selectionLambda.
toTCAPString(inputTupleSetName,
180 PDB_COUT <<
"tcapString after parsing selection lambda: " << tcapString << std::endl;
181 PDB_COUT <<
"lambdaLabel=" << lambdaLabel << std::endl;
184 mustache::data inputColumnData = mustache::data::type::list;
185 for(
int i = 0; i < inputColumnNames.size(); i++) {
187 mustache::data columnData;
190 columnData.set(
"columnName", inputColumnNames[i]);
191 columnData.set(
"isLast", i == inputColumnNames.size()-1);
193 inputColumnData.push_back(columnData);
197 mustache::data selectionCompData;
199 selectionCompData.set(
"computationLabel", std::to_string(computationLabel));
200 selectionCompData.set(
"inputColumns", inputColumnData);
201 selectionCompData.set(
"tupleSetName", tupleSetName);
202 selectionCompData.set(
"addedColumnName", addedColumnName);
205 mustache::mustache newTupleSetNameTemplate{
"filteredInputFor{{computationType}}{{computationLabel}}"};
206 std::string newTupleSetName = newTupleSetNameTemplate.render(selectionCompData);
208 mustache::mustache filterTemplate{
"filteredInputFor{{computationType}}{{computationLabel}}"
209 "({{#inputColumns}}{{columnName}}{{^isLast}}, {{/isLast}}{{/inputColumns}}) "
210 "<= FILTER ({{tupleSetName}}({{addedColumnName}}), {{tupleSetName}}"
211 "({{#inputColumns}}{{columnName}}{{^isLast}}, {{/isLast}}{{/inputColumns}}), "
212 "'{{computationType}}_{{computationLabel}}')\n"};
214 tcapString += filterTemplate.render(selectionCompData);
216 PDB_COUT <<
"tcapString after adding filter operation: " << tcapString << std::endl;
217 PDB_COUT <<
"TO GET TCAP STRING FOR PROJECTION LAMBDA" << std::endl;
218 PDB_COUT <<
"lambdaLabel=" << lambdaLabel << std::endl;
221 tcapString +=
"\n/* Apply MultiSelection projection */\n";
222 tcapString += projectionLambda.
toTCAPString(newTupleSetName,
231 addedOutputColumnName,
236 selectionCompData.set(
"addedOutputColumnName", addedOutputColumnName);
238 selectionCompData.set(
"computationLabel", std::to_string(computationLabel));
239 selectionCompData.set(
"outputTupleSetName", outputTupleSetName);
243 newTupleSetNameTemplate = {
"flattenedOutFor{{computationType}}{{computationLabel}}"};
244 newTupleSetName = newTupleSetNameTemplate.render(selectionCompData);
247 mustache::mustache newOutputColumnNameTemplate = {
"flattened_{{addedOutputColumnName}}"};
248 std::string newOutputColumnName = newOutputColumnNameTemplate.render(selectionCompData);
251 mustache::mustache flattenTemplate{
"flattenedOutFor{{computationType}}{{computationLabel}}(flattened_{{addedOutputColumnName}})"
252 " <= FLATTEN ({{outputTupleSetName}}({{addedOutputColumnName}}), "
253 "{{outputTupleSetName}}(), '{{computationType}}_{{computationLabel}}')\n"};
254 tcapString += flattenTemplate.render(selectionCompData);
258 outputTupleSetName = newTupleSetName;
260 addedOutputColumnName = newOutputColumnName;
261 outputColumnNames.clear();
262 outputColumnNames.push_back(addedOutputColumnName);
267 void setOutput(std::string dbName, std::string setName)
override {
307 return std::make_shared<VectorSink<OutputClass>>(consumeMe, projection);
327 #endif //PDB_MULTISELECTIONCOMPBASE_H
std::shared_ptr< ComputeSource > ComputeSourcePtr
virtual pdb::Lambda< bool > getSelection(pdb::Handle< InputClass > checkMe)=0
Handle< ScanUserSet< OutputClass > > & getOutputSetScanner()
void setBatchSize(int batchSize) override
ComputationTypeID getComputationTypeID() override
void setOutput(std::string dbName, std::string setName) override
bool needsMaterializeOutput() override
bool materializeSelectionOut
void toMap(std::map< std::string, GenericLambdaObjectPtr > &returnVal, int &suffix)
ComputeSinkPtr getComputeSink(TupleSpec &consumeMe, TupleSpec &projection, ComputePlan &plan) override
std::string getSetName() override
Handle< ScanUserSet< OutputClass > > outputSetScanner
std::string getOutputType() override
std::shared_ptr< ComputeSink > ComputeSinkPtr
void setOutputColumnToApply(std::string outputColumnToApply)
std::string getComputationType() override
std::string toTCAPString(std::string inputTupleSetName, std::vector< std::string > &inputColumnNames, std::vector< std::string > &inputColumnsToApply, std::vector< std::string > &childrenLambdaNames, int computationLabel, std::string &outputTupleSetName, std::vector< std::string > &outputColumnNames, std::string &addedOutputColumnName, std::string &myLambdaName)
void extractLambdas(std::map< std::string, GenericLambdaObjectPtr > &returnVal) override
std::string getDatabaseName() override
void setTraversed(bool traversed)
std::string getIthInputType(int i) override
virtual pdb::Lambda< pdb::Vector< pdb::Handle< OutputClass > > > getProjection(pdb::Handle< InputClass > checkMe)=0
void setOutputTupleSetName(std::string outputTupleSetName)
int getNumInputs() override
std::string toTCAPString(std::vector< InputTupleSetSpecifier > &inputTupleSets, int computationLabel, std::string &outputTupleSetName, std::vector< std::string > &outputColumnNames, std::string &addedOutputColumnName) override
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)
ComputeSourcePtr getComputeSource(TupleSpec &outputScheme, ComputePlan &plan) override
String outputTupleSetName