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
AtomicComputation.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 ATOMIC_COMPUTATION_H
20 #define ATOMIC_COMPUTATION_H
21 
22 #include <iostream>
23 #include <memory>
24 #include <stdlib.h>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 #include <map>
29 #include <unordered_map>
30 
31 #include "TupleSpec.h"
32 
34 
35 // all computations in TCAP (aggregates, scans, filters, etc.) descend from this class
37 typedef std::shared_ptr<struct AtomicComputation> AtomicComputationPtr;
38 
39 // the TypeIDs for each AtomicComputations
52 };
53 
55 
56 protected:
60  std::string computationName;
62  std::shared_ptr<std::map <std::string, std::string>> keyValuePairs;
63 
64 public:
65  // returns the type of this computation
66  virtual std::string getAtomicComputationType() = 0;
67 
68  // returns the type id of this computation
70 
71  // sometimes, we'll need to figure out the type of a particular attribute in a tuple set. What
72  // this does is to
73  // compute, for a particular attribute in the output of the AtomicComputation, what
74  // (computationName, lambdaName)
75  // pair is that is responsible for creating this attribute... then, we can ask that pair what
76  // the type of the
77  // atribute is.
78  virtual std::pair<std::string, std::string> findSource(std::string attName,
79  AtomicComputationList& allComps) = 0;
80 
81  // virtual destructor
82  virtual ~AtomicComputation() {}
83 
84  // get a shared pointer to this computation..
86  return me;
87  }
88 
89  // forget the shared poitner for this computation
90  void destroyPtr() {
91  me = nullptr;
92  }
93 
94  // simple constructor... gives the tuple specs that this guy (a) accepts as input, (b) produces
95  // as output, and (c)
96  // projects from the input to perform the computation. It also accepts the name of the
97  // Computation object that
98  // is actually responsible for this computation
100  TupleSpec outputIn,
101  TupleSpec projectionIn,
102  std::string computationName) : input(inputIn),
103  output(outputIn),
104  projection(projectionIn),
105  computationName(computationName) {
106 
107  // initialize the key value pairs
108  keyValuePairs = std::make_shared<std::map <std::string, std::string>>();
109  }
110 
111  std::shared_ptr<std::map <std::string, std::string>> &getKeyValuePairs () {
112  return keyValuePairs;
113  }
114 
115 
116 
117 
118  // remember the shared pointer for this computation
120  me = meIn;
121  }
122 
123  // gets the tuple set specifier for the output of this computation
125  return output;
126  }
127 
128  // gets the name of the tuple set produced by this computation
129  std::string& getOutputName() {
130  return output.getSetName();
131  }
132 
133  // gets the specifier for the input tuple set used by this computation
135  return input;
136  }
137 
138  // gets the name of the tuple set operated on by this computation
139  std::string& getInputName() {
140  return input.getSetName();
141  }
142 
143  // gets the specifier for the set of output attributes that will be produced by this computation
145  return projection;
146  }
147 
148  // this gets a string that allows us to look up the actual Computation object associated with this node
149  std::string& getComputationName() {
150  return computationName;
151  }
152 
153  // for printing
154  friend std::ostream& operator<<(std::ostream& os, const AtomicComputationList& printMe);
155 
156  // this finds the position of the specified attribute in all of the output attributes
157  int findPosInOutputAtts(std::string& findMe) {
158  // find where the attribute appears in the outputs
159  int counter = 0;
160  for (auto& a : getOutput().getAtts()) {
161  if (a == findMe) {
162  break;
163  }
164  counter++;
165  }
166 
167  if (getOutput().getAtts().size() == counter) {
168  std::cout << "This is bad... could not find the attribute that you were asking for!!\n";
169  exit(1);
170  }
171 
172  return counter;
173  }
174 };
175 
176 #endif
AtomicComputationTypeID
AtomicComputationPtr getShared()
std::string & getOutputName()
std::shared_ptr< std::map< std::string, std::string > > keyValuePairs
AtomicComputation(TupleSpec inputIn, TupleSpec outputIn, TupleSpec projectionIn, std::string computationName)
std::string & getComputationName()
virtual ~AtomicComputation()
virtual AtomicComputationTypeID getAtomicComputationTypeID()=0
TupleSpec & getInput()
TupleSpec & getOutput()
std::string & getSetName()
Definition: TupleSpec.h:56
virtual std::pair< std::string, std::string > findSource(std::string attName, AtomicComputationList &allComps)=0
std::shared_ptr< std::map< std::string, std::string > > & getKeyValuePairs()
void setShared(AtomicComputationPtr meIn)
virtual std::string getAtomicComputationType()=0
int findPosInOutputAtts(std::string &findMe)
std::shared_ptr< struct AtomicComputation > AtomicComputationPtr
TupleSpec & getProjection()
std::string & getInputName()
AtomicComputationPtr me
friend std::ostream & operator<<(std::ostream &os, const AtomicComputationList &printMe)
std::string computationName