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
FilterExecutor.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 FILTER_QUERY_EXEC_H
20 #define FILTER_QUERY_EXEC_H
21 
22 #include "ComputeExecutor.h"
23 #include "TupleSetMachine.h"
24 #include "TupleSet.h"
25 #include <vector>
26 
27 namespace pdb {
28 
29 // runs a filter operation
31 
32 private:
33  // this is the output TupleSet that we return
35 
36  // the attribute to operate on
37  int whichAtt;
38 
39  // to setup the output tuple set
41 
42 public:
43  // currently, we just ignore the extra parameter to the filter if we get it
44  FilterExecutor(TupleSpec& inputSchema,
45  TupleSpec& attsToOperateOn,
46  TupleSpec& attsToIncludeInOutput,
48  : myMachine(inputSchema, attsToIncludeInOutput) {
49 
50  // this is the input attribute that we will process
51  output = std::make_shared<TupleSet>();
52  std::vector<int> matches = myMachine.match(attsToOperateOn);
53  whichAtt = matches[0];
54  }
55 
56  FilterExecutor(TupleSpec& inputSchema,
57  TupleSpec& attsToOperateOn,
58  TupleSpec& attsToIncludeInOutput)
59  : myMachine(inputSchema, attsToIncludeInOutput) {
60 
61  // this is the input attribute that we will process
62  output = std::make_shared<TupleSet>();
63  std::vector<int> matches = myMachine.match(attsToOperateOn);
64  whichAtt = matches[0];
65  }
66 
67  TupleSetPtr process(TupleSetPtr input) override {
68 
69  // set up the output tuple set
70  myMachine.setup(input, output);
71 
72  // get the input column to use as a filter
73  std::vector<bool>& inputColumn = input->getColumn<bool>(whichAtt);
74 
75  // loop over the columns and filter
76  int numColumns = output->getNumColumns();
77  for (int i = 0; i < numColumns; i++) {
78  output->filterColumn(i, inputColumn);
79  }
80 
81  return output;
82  }
83 
84  std::string getType() override {
85  return "FILTER";
86  }
87 };
88 }
89 
90 #endif
FilterExecutor(TupleSpec &inputSchema, TupleSpec &attsToOperateOn, TupleSpec &attsToIncludeInOutput, ComputeInfoPtr)
std::string getType() override
std::shared_ptr< ComputeInfo > ComputeInfoPtr
Definition: ComputeInfo.h:33
std::vector< int > match(TupleSpec &attsToMatch)
FilterExecutor(TupleSpec &inputSchema, TupleSpec &attsToOperateOn, TupleSpec &attsToIncludeInOutput)
TupleSetPtr process(TupleSetPtr input) override
void setup(TupleSetPtr input, TupleSetPtr output)
std::shared_ptr< TupleSet > TupleSetPtr
Definition: TupleSet.h:64
TupleSetSetupMachine myMachine