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