Added quantiling UDAFs
[com/gs-lite.git] / src / ftacmp / test_interfacelib.cc
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 #include <string>\r
17 \r
18 #include <stdlib.h>\r
19 #include <stdio.h>\r
20 \r
21 #include "schemaparser.h"\r
22 #include "schemaparser_impl.h"\r
23 \r
24 //      Interface to FTA definition lexer and parser ...\r
25 \r
26 \r
27 //double htonf(double f){return f;}\r
28 //long long int htonll(long long int l){return l;}\r
29 \r
30 \r
31 using namespace std;\r
32 extern int errno;\r
33 \r
34 // ./test_interfacelib test_param1.q_0.sch  test_param4.q_1.sch\r
35 \r
36 \r
37 \r
38 int main(int argc, char **argv){\r
39         int i;\r
40         char tmpstr[1000];\r
41         void * pblock;\r
42         int block_size;\r
43         \r
44         if(argc < 2){\r
45                 fprintf(stderr,"Usage: %s schema_file [schema_file ... ]\n",argv[0]);\r
46                 exit(1);\r
47         }\r
48         \r
49         int nfiles = argc-1;\r
50         int f;\r
51         for(f=0;f<nfiles;++f){\r
52 \r
53                 FILE *infl = fopen(argv[f+1],"r");\r
54                 if(infl == NULL){\r
55                         fprintf(stderr,"ERROR can't open schema file %s\n",argv[1]);\r
56                         exit(1);\r
57                 }\r
58 \r
59                 int sch_handle;\r
60                 if(f%2==0){\r
61                         sch_handle = ftaschema_parse_file(infl);\r
62                 }else{\r
63                         string fstr;\r
64                         while(fgets(tmpstr, 1000, infl)){\r
65                                 fstr += tmpstr;\r
66                                 fstr += "\n";\r
67                         }\r
68                         sch_handle = ftaschema_parse_string( (char *)(fstr.c_str()) );\r
69                 }\r
70 \r
71                 if(sch_handle < 0){\r
72                         fprintf(stderr,"ERROR parsing schema file.\n");\r
73                         exit(1);\r
74                 }\r
75 \r
76                 ftaschema_debugdump(sch_handle);\r
77                 \r
78                 fclose(infl);\r
79         }\r
80         \r
81         printf("Testing access library.\n");\r
82         \r
83 //                      test_param1.q_0.sch\r
84 \r
85         printf("Query %s has %d fields and %d parameters.\n",\r
86                 ftaschema_name(0), ftaschema_tuple_len(0), ftaschema_parameter_len(0));\r
87         printf("The parameters are named:\n");\r
88         for(i=0;i<ftaschema_parameter_len(0);++i){\r
89                 printf("%s  ",ftaschema_parameter_name(0,i));\r
90         }\r
91         printf("\n");\r
92         printf("Setting parameters by name.\n");\r
93         sprintf(tmpstr,"%d",1111); printf("min_hdr_length : %s\n",tmpstr);\r
94         ftaschema_setparam_by_name(0,"min_hdr_length",tmpstr,strlen(tmpstr));\r
95         sprintf(tmpstr,"%d",2222); printf("unused_param : %s\n",tmpstr);\r
96         ftaschema_setparam_by_name(0,"unused_param",tmpstr,strlen(tmpstr));\r
97         printf("Creating param block.\n");\r
98         ftaschema_create_param_block(0,&pblock, &block_size);\r
99         printf("Block created, size is %d. Accessing by name.\n",block_size);\r
100         printf("\t%s=%d (type is %d) %s=%lu (type is %d)\n",\r
101                 "time",\r
102                 (ftaschema_get_field_by_name(0,"time",pblock, block_size)).r.i,\r
103                 (ftaschema_get_field_by_name(0,"time",pblock, block_size)).field_data_type,\r
104                 "hdr_length",\r
105                 (ftaschema_get_field_by_name(0,"hdr_length",pblock, block_size)).r.ul,\r
106                 (ftaschema_get_field_by_name(0,"hdr_length",pblock, block_size)).field_data_type\r
107         );\r
108         \r
109         printf("Query %s has %d fields and %d parameters.\n",\r
110                 ftaschema_name(1), ftaschema_tuple_len(1), ftaschema_parameter_len(1));\r
111         printf("The parameters are named:\n");\r
112         for(i=0;i<ftaschema_parameter_len(1);++i){\r
113                 printf("%s  ",ftaschema_parameter_name(1,i));\r
114         }\r
115 \r
116         printf("\n");\r
117         printf("Setting parameters by index.\n");\r
118         sprintf(tmpstr,"%d",3333); printf("an_ullong_parameter : %s\n",tmpstr);\r
119         ftaschema_setparam_by_index(1,0,tmpstr,strlen(tmpstr));\r
120         sprintf(tmpstr,"%d",2222); printf("ullong_parameter2 : %s\n",tmpstr);\r
121         ftaschema_setparam_by_index(1,1,tmpstr,strlen(tmpstr));\r
122         sprintf(tmpstr,"%f",4444.0); printf("min_prec : %s\n",tmpstr);\r
123         ftaschema_setparam_by_index(1,2,tmpstr,strlen(tmpstr)); \r
124         sprintf(tmpstr,"%s","Foo"); printf("min_str : %s\n",tmpstr);\r
125         ftaschema_setparam_by_index(1,3,tmpstr,strlen(tmpstr)+1);       \r
126         sprintf(tmpstr,"%s","Bar"); printf("min_str : %s\n",tmpstr);\r
127         ftaschema_setparam_by_index(1,3,tmpstr,strlen(tmpstr)+1);       \r
128         ftaschema_create_param_block(1,&pblock, &block_size);\r
129         printf("Block created, size is %d. Accessing by index.\n",block_size);\r
130         printf("\t%s=%ld, type is %d\n",\r
131                 ftaschema_tuple_name(1,0),\r
132                 (ftaschema_get_field_by_index(1,0,pblock, block_size)).r.ul,\r
133                 (ftaschema_get_field_by_index(1,0,pblock, block_size)).field_data_type\r
134         );      \r
135         printf("\t%s=%ld, type is %d\n",\r
136                 ftaschema_tuple_name(1,1),\r
137                 (ftaschema_get_field_by_index(1,1,pblock, block_size)).r.ul,\r
138                 (ftaschema_get_field_by_index(1,1,pblock, block_size)).field_data_type\r
139         );      \r
140         printf("\t%s=%lf, type is %d\n",\r
141                 ftaschema_tuple_name(1,2),\r
142                 (ftaschema_get_field_by_index(1,2,pblock, block_size)).r.f,\r
143                 (ftaschema_get_field_by_index(1,2,pblock, block_size)).field_data_type\r
144         );      \r
145         printf("\t%s=%s (length=%d), type is %d\n",\r
146                 ftaschema_tuple_name(1,3),\r
147                 (ftaschema_get_field_by_index(1,3,pblock, block_size)).r.vs.offset,\r
148                 (ftaschema_get_field_by_index(1,3,pblock, block_size)).r.vs.length,\r
149                 (ftaschema_get_field_by_index(1,3,pblock, block_size)).field_data_type\r
150         );      \r
151         \r
152         \r
153         \r
154 }\r