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
7 http://www.apache.org/licenses/LICENSE-2.0
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 ------------------------------------------- */
16 #ifndef __PRINT_PLAN_H
17 #define __PRINT_PLAN_H
27 int print_qp_node(FILE* fd, int i, stream_query* query, map<string, int>& lfta_names, map<string, int>& fta_names) {
31 qp_node* node = query->query_plan[i];
33 string ntype = node->node_type();
35 fprintf(fd, "\tNODE %s, type %s\n", node->node_name.c_str(), ntype.c_str());
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());
45 vector<tablevar_t *> input_tables = node->get_input_tbls();
47 for (j = 0; j < input_tables.size(); ++j) {
48 tablevar_t * table = input_tables[j];
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());
64 int print_query(FILE* fd, stream_query* query, map<string, int>& lfta_names) {
66 fprintf(fd, "HFTA %s\n", query->query_name.c_str());
69 vector<tablevar_t *> tmp_tv = query->get_input_tables();
71 map<string, int> fta_names;
73 for(itv=0;itv<tmp_tv.size();++itv) {
74 fta_names[tmp_tv[itv]->get_schema_name()] = 0;
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);
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) {
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);
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());
107 #endif // __PRINT_PLAN_H