Added quantiling UDAFs
[com/gs-lite.git] / src / ftacmp / print_plan.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 \r
16 #ifndef __PRINT_PLAN_H\r
17 #define __PRINT_PLAN_H\r
18 \r
19 \r
20 #include <stdio.h>\r
21 #include <vector>\r
22 #include <set>\r
23 #include <stdlib.h>\r
24 using namespace std;\r
25 \r
26 \r
27 int print_qp_node(FILE* fd, int i, stream_query* query, map<string, int>& lfta_names, map<string, int>& fta_names) {\r
28 \r
29         int j;\r
30 \r
31         qp_node* node = query->query_plan[i];\r
32 \r
33         string ntype = node->node_type();\r
34 \r
35         fprintf(fd, "\tNODE %s, type %s\n", node->node_name.c_str(), ntype.c_str());\r
36 \r
37         if (!node->predecessors.empty()) {\r
38                 for (j = 0; j < node->predecessors.size(); ++j)\r
39                         fprintf(fd, "\t\tCHILD_NODE %s\n", query->query_plan[query->query_plan[i]->predecessors[j]]->node_name.c_str());\r
40         }\r
41 \r
42 \r
43 \r
44         // print input tables\r
45         vector<tablevar_t *> input_tables = node->get_input_tbls();\r
46 \r
47         for (j = 0; j <  input_tables.size(); ++j) {\r
48                 tablevar_t * table = input_tables[j];\r
49 \r
50                 if (lfta_names.count(table->schema_name))\r
51                         fprintf(fd, "\t\tSOURCE_LFTA %s\n", table->schema_name.c_str());\r
52                 else if (fta_names.count(table->schema_name))\r
53                         fprintf(fd, "\t\tSOURCE_HFTA %s\n", table->schema_name.c_str());\r
54         }\r
55 \r
56         fprintf(fd, "\n");\r
57 \r
58 \r
59 \r
60         return 0;\r
61 \r
62 }\r
63 \r
64 int print_query(FILE* fd, stream_query* query, map<string, int>& lfta_names) {\r
65 \r
66         fprintf(fd, "HFTA %s\n", query->query_name.c_str());\r
67 \r
68 \r
69         vector<tablevar_t *> tmp_tv = query->get_input_tables();\r
70         int itv;\r
71         map<string, int> fta_names;\r
72 \r
73         for(itv=0;itv<tmp_tv.size();++itv) {\r
74                 fta_names[tmp_tv[itv]->get_schema_name()] = 0;\r
75         }\r
76 \r
77         for (int i = 0; i < query->query_plan.size(); ++i) {\r
78                 if (query->query_plan[i])\r
79                         print_qp_node(fd, i, query, lfta_names, fta_names);\r
80         }\r
81 \r
82         return 0;\r
83 \r
84 }\r
85 \r
86 int print_hftas(const char* fname, vector<stream_query *>& hfta_list, map<string, int>& lfta_names, vector<string>& query_names, vector<string>& interface_names) {\r
87 \r
88         FILE* f = fopen(fname, "w");\r
89         for (int i = 0; i < hfta_list.size(); ++i) {\r
90                 print_query(f, hfta_list[i], lfta_names);\r
91         }\r
92 \r
93 \r
94         for (int mi = 0; mi < query_names.size(); ++mi) {\r
95                 fprintf(f,"LFTA %s\n",query_names[mi].c_str());\r
96                 fprintf(f,"\tINTERFACE %s\n",interface_names[mi].c_str());\r
97 \r
98         }\r
99 \r
100         fclose(f);\r
101 \r
102 \r
103         return 0;\r
104 \r
105 }\r
106 \r
107 #endif          // __PRINT_PLAN_H\r