Added quantiling UDAFs
[com/gs-lite.git] / src / ftacmp / type_objects.h
1 /* ------------------------------------------------\r
2 Copyright 2014 AT&T Intellectual Property\r
3    Licensed under the Apache License, Version 2.0 (the "License");\r
4    you may not use this file except in compliance with the License.\r
5    You may obtain a copy of the License at\r
6 \r
7      http://www.apache.org/licenses/LICENSE-2.0\r
8 \r
9    Unless required by applicable law or agreed to in writing, software\r
10    distributed under the License is distributed on an "AS IS" BASIS,\r
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12    See the License for the specific language governing permissions and\r
13    limitations under the License.\r
14  ------------------------------------------- */\r
15 #ifndef __TYPE_OBJECTS_H_DEFINED__\r
16 #define __TYPE_OBJECTS_H_DEFINED__\r
17 \r
18 #include <string>\r
19 #include<vector>\r
20 \r
21 #include"literal_types.h"\r
22 #include"parse_schema.h"\r
23 #include"type_indicators.h"\r
24 #include"gstypes.h"\r
25 #include"vstring.h"\r
26 \r
27 enum dtype {u_int_t, int_t, u_llong_t, llong_t, u_short_t, floating_t,\r
28                         bool_t, v_str_t, timeval_t, ip_t, ipv6_t, fstring_t, undefined_t};\r
29 \r
30 enum temporal_type {increasing_t, decreasing_t, constant_t, varying_t};\r
31                 // varying_t means I don't know.\r
32         // constant_t MUST MEAN THAT ALL VALUES IN THE SE TREE ARE LITERALS!\r
33 \r
34 \r
35 class data_type{\r
36 private:\r
37   std::string schema_type;              // String representation of the data type.\r
38   dtype type;                                   // Internal representation of the data type.\r
39   std::string subtype;                          // specialization of the type.\r
40                                                                 // use to restrict access and provide annotation\r
41   temporal_type temporal;               // How does the value change over time.\r
42   int size;                                             // # bytes, it it can't be readily determined\r
43 \r
44   void assign_schema_type();\r
45   void assign_type_from_string(std::string st);\r
46 \r
47 public:\r
48   data_type(){type = undefined_t; assign_schema_type(); size=0; temporal=varying_t;};\r
49   data_type(std::string st);\r
50   data_type(std::string st, param_list *modifiers);\r
51   data_type(int it);\r
52   data_type(data_type *lhs, std::string &op);\r
53   data_type(data_type *lhs, data_type *rhs, const std::string &op);\r
54 \r
55   static temporal_type compute_temporal_type(temporal_type l_tempo,  std::string &op);\r
56   static temporal_type compute_temporal_type(temporal_type l_tempo, temporal_type r_tempo,  dtype l_type, dtype r_type, const std::string &op);\r
57 \r
58   data_type *duplicate();\r
59   field_entry *make_field_entry(std::string n);\r
60 \r
61   void set_aggr_data_type(const std::string &op, data_type *dt);\r
62 \r
63   int type_indicator();\r
64 \r
65   dtype get_type(){return type;                                         };\r
66   std::string get_type_str(){return schema_type;        };\r
67   std::string to_string();\r
68 \r
69   temporal_type get_temporal(){return temporal;         };\r
70   void set_temporal(temporal_type t){temporal = t;              };\r
71   void reset_temporal(){ if(this->is_temporal()) temporal = varying_t;};\r
72   bool is_temporal(){return( temporal == increasing_t || temporal == decreasing_t);};\r
73   bool is_increasing(){return( temporal == increasing_t );};\r
74   bool is_decreasing(){return( temporal == decreasing_t );};\r
75 \r
76   std::string get_temporal_string();\r
77   std::vector<std::string> get_param_keys();\r
78   std::string get_param_val(std::string k);\r
79 \r
80   bool is_defined(){return(type != undefined_t);        };\r
81 \r
82   bool is_comparable(data_type *rhs, std::string op);\r
83 \r
84   std::string get_CC_accessor_type();\r
85   std::string get_cvar_type();\r
86   std::string get_tuple_cvar_type();\r
87   std::string make_cvar(std::string v);\r
88   std::string make_tuple_cvar(std::string v);\r
89   std::string get_host_cvar_type();\r
90   std::string make_host_cvar(std::string v);\r
91   std::string make_host_tuple_cvar(std::string v);\r
92   std::string get_hfta_unpack_fcn();\r
93   std::string get_hfta_unpack_fcn_noxf();\r
94 \r
95   bool complex_comparison(data_type *dt);\r
96   std::string get_comparison_fcn(data_type *dt);\r
97   std::string get_hfta_comparison_fcn(data_type *dt);\r
98 \r
99   bool complex_operator(data_type *dt, std::string &op);\r
100   std::string get_complex_operator(data_type *dt, std::string &op);\r
101 \r
102   bool complex_operator(std::string &op);\r
103   std::string get_complex_operator(std::string &op);\r
104 \r
105     bool use_hashfunc();\r
106         std::string get_hfta_hashfunc();\r
107 \r
108   bool needs_hn_translation();\r
109   std::string hton_translation();\r
110   std::string ntoh_translation();\r
111 \r
112   bool is_buffer_type();\r
113 //              LFTA functions\r
114   std::string get_buffer_assign_copy();\r
115   std::string get_buffer_tuple_copy();\r
116   std::string get_buffer_replace();\r
117   std::string get_buffer_size();\r
118   std::string get_buffer_destroy();\r
119 //              HFTA functions\r
120   std::string get_hfta_buffer_assign_copy();\r
121   std::string get_hfta_buffer_tuple_copy();\r
122   std::string get_hfta_buffer_replace();\r
123   std::string get_hfta_buffer_size();\r
124   std::string get_hfta_buffer_destroy();\r
125 \r
126   bool is_structured_type();\r
127 //  std::string get_interface_type();\r
128 \r
129 //              These functions are obsolete\r
130   std::string handle_registration_name();\r
131   std::string hfta_handle_registration_name();\r
132   std::string get_handle_destructor();\r
133 \r
134   bool fta_legal_type();\r
135   static bool fta_legal_operation(data_type *lhs, data_type *rhs, std::string &op);\r
136   static bool fta_legal_operation(data_type *lhs, std::string &op);\r
137 \r
138 //              for schemaparser\r
139   int type_size();\r
140 \r
141 /*\r
142 //              for external functions and predicates\r
143 bool call_compatible(data_type *o);\r
144 \r
145 //              test for equality : used by bind_to_schema and by testing for\r
146 //              mergability.\r
147 bool equal(data_type *o);\r
148 */\r
149 \r
150   bool subsumes_type(data_type *o);\r
151   bool equals(data_type *o);\r
152   bool equal_subtypes(data_type *o);\r
153 \r
154 // literals corresponding to minimum and maximum values\r
155   std::string get_min_literal();\r
156   std::string get_max_literal();\r
157 \r
158 \r
159 };\r
160 \r
161 \r
162 #endif\r