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
TupleSetMachine.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 TUPLE_SET_MACHINE_H
20 #define TUPLE_SET_MACHINE_H
21 
22 namespace pdb {
23 
25 
26  // there is one entry here for each item in attsToIncludeInOutput
27  // that entry tells us where to find that attribute in the input
28  std::vector<int> matches;
29 
31 
32 public:
33  TupleSetSetupMachine(TupleSpec& inputSchema) : inputSchema(inputSchema) {}
34 
36  : inputSchema(inputSchema) {
37  // std :: cout << "input schema: " << inputSchema << " and outputs to include: " <<
38  // attsToIncludeInOutput << "\n";
39  matches = match(attsToIncludeInOutput);
40  }
41 
42  // gets a vector that tells us where all of the attributes match
43  std::vector<int> match(TupleSpec& attsToMatch) {
44 
45  // find the positions of all of the matches
46  std::vector<int> matches;
47  for (auto& s : attsToMatch.getAtts()) {
48  int counter = 0;
49  for (auto& t : inputSchema.getAtts()) {
50  if (s == t) {
51  matches.push_back(counter);
52  counter = -1;
53  break;
54  }
55  counter++;
56  }
57  if (counter != -1) {
58  std::cout << "This is bad... could not find a matching attribute\n";
59  std::cout << "Atts to match was: " << attsToMatch << "\n";
60  std::cout << "Input schema was: " << inputSchema << "\n";
61  }
62  }
63  return matches;
64  }
65 
66  // sets up the output tuple by copying over all of the atts that we need to, and setting the
67  // output
68  void setup(TupleSetPtr input, TupleSetPtr output) {
69 
70  // first, do a shallow copy of all of the atts that are being copied over
71  int counter = 0;
72  for (auto& i : matches) {
73 
74  // copy the column over, deleting the old one, if necessary
75  output->copyColumn(input, i, counter++);
76  }
77  }
78 
79  // this is used by a join to replicate a bunch of input columns
80  void replicate(TupleSetPtr input,
81  TupleSetPtr output,
82  std::vector<uint32_t>& counts,
83  int offset) {
84 
85  // first, do a shallow copy of all of the atts that are being copied over
86  int counter = 0;
87  for (auto& i : matches) {
88  output->replicate(input, i, counter + offset, counts);
89  counter++;
90  }
91  }
92 };
93 
94 using TupleSetSetupMachinePtr = std::shared_ptr<TupleSetSetupMachine>;
95 }
96 
97 #endif
TupleSetSetupMachine(TupleSpec &inputSchema, TupleSpec &attsToIncludeInOutput)
std::vector< std::string > & getAtts()
Definition: TupleSpec.h:60
std::shared_ptr< TupleSetSetupMachine > TupleSetSetupMachinePtr
std::vector< int > match(TupleSpec &attsToMatch)
void replicate(TupleSetPtr input, TupleSetPtr output, std::vector< uint32_t > &counts, int offset)
TupleSetSetupMachine(TupleSpec &inputSchema)
void setup(TupleSetPtr input, TupleSetPtr output)
std::vector< int > matches
std::shared_ptr< TupleSet > TupleSetPtr
Definition: TupleSet.h:64