Add new udafs and RMR support to gsprintconsole_ves
[com/gs-lite.git] / include / hfta / selection_operator.h
1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3    Licensed under the Apache License, Version 2.0 (the "License");
4    you may not use this file except in compliance with the License.
5    You may obtain a copy of the License at
6
7      http://www.apache.org/licenses/LICENSE-2.0
8
9    Unless required by applicable law or agreed to in writing, software
10    distributed under the License is distributed on an "AS IS" BASIS,
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12    See the License for the specific language governing permissions and
13    limitations under the License.
14  ------------------------------------------- */
15
16 #ifndef SELECTION_OPERATOR_H
17 #define SELECTION_OPERATOR_H
18
19 #include "host_tuple.h"
20 #include "base_operator.h"
21 #include <list>
22 using namespace std;
23
24 template <class select_project_functor> class select_project_operator :
25                 public base_operator
26 {
27 private :
28         select_project_functor func;
29 public:
30
31         select_project_operator(int schema_handle, const char* name) : base_operator(name), func(schema_handle) { }
32
33         virtual int accept_tuple(host_tuple& tup, list<host_tuple>& result) {
34                 host_tuple res;
35
36                 if (func.predicate(tup)) {
37                         res = func.create_output_tuple();
38                         res.channel = output_channel;
39                         result.push_back(res);
40                 } else {
41                         if (func.temp_status_received()) {
42                                 if (!func.create_temp_status_tuple(res)) {
43                                         res.channel = output_channel;
44                                         result.push_back(res);
45                                 }
46                         }
47                 }
48                 tup.free_tuple();
49                 return 0;
50         }
51
52         virtual int flush(list<host_tuple>& result) {
53                 return 0;
54         }
55
56         virtual int set_param_block(int sz, void * value) {
57                 func.set_param_block(sz, value);
58                 return 0;
59         }
60
61         virtual int get_temp_status(host_tuple& result) {
62                 result.channel = output_channel;
63                 return func.create_temp_status_tuple(result);
64         }
65
66         virtual int get_blocked_status () {
67                 return -1;              // selection operators are not blocked on any input
68         }
69 };
70
71 #endif  // SELECTION_OPERATOR_H