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
FilterQueryExecutor.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 "QueryExecutor.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:
44  TupleSpec& attsToOperateOn,
45  TupleSpec& attsToIncludeInOutput)
46  : myMachine(inputSchema, attsToIncludeInOutput) {
47 
48  output = std::make_shared<TupleSet>();
49 
50  // this is the input attribute that we will process
51  std::vector<int> matches = myMachine.match(attsToOperateOn);
52  whichAtt = matches[0];
53  }
54 
55  TupleSetPtr process(TupleSetPtr input) override {
56 
57  // set up the output tuple set
58  myMachine.setup(input, output);
59 
60  // get the input column to use as a filter
61  std::vector<bool>& inputColumn = input->getColumn<bool>(whichAtt);
62 
63  // loop over the columns and filter
64  int numColumns = output->getNumColumns();
65  for (int i = 0; i < numColumns; i++) {
66  output->filterColumn(i, inputColumn);
67  }
68 
69  return output;
70  }
71 };
72 }
73 
74 #endif
TupleSetPtr process(TupleSetPtr input) override
std::vector< int > match(TupleSpec &attsToMatch)
TupleSetSetupMachine< bool > myMachine
void setup(TupleSetPtr input, TupleSetPtr output)
std::shared_ptr< TupleSet > TupleSetPtr
Definition: TupleSet.h:64
FilterQueryExecutor(TupleSpec &inputSchema, TupleSpec &attsToOperateOn, TupleSpec &attsToIncludeInOutput)