001package gudusoft.gsqlparser.dlineage.statistics; 002 003import java.util.*; 004 005/** 006 * 文件统计信息类 007 */ 008public class FileStatistics { 009 private String file; 010 private long file_size; 011 private int line_count; 012 private int total_statements; 013 private int select_count; 014 private int insert_count; 015 private int update_count; 016 private int delete_count; 017 private int merge_count; 018 private int create_table_count; 019 private int create_temp_table_count; 020 private int ctas_count; 021 private int create_view_count; 022 private int create_temp_view_count; 023 private int drop_count; 024 private int truncate_count; 025 private int join_count; 026 private int parse_error_count; 027 private Map<String, Integer> join_types; 028 private int subquery_depth; 029 private int cte_count; 030 private int case_count; 031 private int union_count; 032 private int window_function_count; 033 private int aggregate_function_count; 034 private Set<String> distinct_table_references; 035 private int where_predicate_count; 036 private List<String> objects_created; 037 private List<String> objects_read; 038 039 public FileStatistics(String file) { 040 this.file = file; 041 this.file_size = 0; 042 this.line_count = 0; 043 this.join_types = new HashMap<>(); 044 this.distinct_table_references = new HashSet<>(); 045 this.objects_created = new ArrayList<>(); 046 this.objects_read = new ArrayList<>(); 047 this.parse_error_count = 0; 048 } 049 050 // Getters and setters 051 public String getFile() { 052 return file; 053 } 054 055 public void setFile(String file) { 056 this.file = file; 057 } 058 059 public int getTotal_statements() { 060 return total_statements; 061 } 062 063 public void setTotal_statements(int total_statements) { 064 this.total_statements = total_statements; 065 } 066 067 public void incrementTotal_statements() { 068 this.total_statements++; 069 } 070 071 public int getSelect_count() { 072 return select_count; 073 } 074 075 public void setSelect_count(int select_count) { 076 this.select_count = select_count; 077 } 078 079 public void incrementSelect_count() { 080 this.select_count++; 081 } 082 083 public int getInsert_count() { 084 return insert_count; 085 } 086 087 public void setInsert_count(int insert_count) { 088 this.insert_count = insert_count; 089 } 090 091 public void incrementInsert_count() { 092 this.insert_count++; 093 } 094 095 public int getUpdate_count() { 096 return update_count; 097 } 098 099 public void setUpdate_count(int update_count) { 100 this.update_count = update_count; 101 } 102 103 public void incrementUpdate_count() { 104 this.update_count++; 105 } 106 107 public int getDelete_count() { 108 return delete_count; 109 } 110 111 public void setDelete_count(int delete_count) { 112 this.delete_count = delete_count; 113 } 114 115 public void incrementDelete_count() { 116 this.delete_count++; 117 } 118 119 public int getMerge_count() { 120 return merge_count; 121 } 122 123 public void setMerge_count(int merge_count) { 124 this.merge_count = merge_count; 125 } 126 127 public void incrementMerge_count() { 128 this.merge_count++; 129 } 130 131 public int getCreate_table_count() { 132 return create_table_count; 133 } 134 135 public void setCreate_table_count(int create_table_count) { 136 this.create_table_count = create_table_count; 137 } 138 139 public void incrementCreate_table_count() { 140 this.create_table_count++; 141 } 142 143 public int getCreate_temp_table_count() { 144 return create_temp_table_count; 145 } 146 147 public void setCreate_temp_table_count(int create_temp_table_count) { 148 this.create_temp_table_count = create_temp_table_count; 149 } 150 151 public void incrementCreate_temp_table_count() { 152 this.create_temp_table_count++; 153 } 154 155 public int getCtas_count() { 156 return ctas_count; 157 } 158 159 public void setCtas_count(int ctas_count) { 160 this.ctas_count = ctas_count; 161 } 162 163 public void incrementCtas_count() { 164 this.ctas_count++; 165 } 166 167 public int getCreate_view_count() { 168 return create_view_count; 169 } 170 171 public void setCreate_view_count(int create_view_count) { 172 this.create_view_count = create_view_count; 173 } 174 175 public void incrementCreate_view_count() { 176 this.create_view_count++; 177 } 178 179 public int getCreate_temp_view_count() { 180 return create_temp_view_count; 181 } 182 183 public void setCreate_temp_view_count(int create_temp_view_count) { 184 this.create_temp_view_count = create_temp_view_count; 185 } 186 187 public void incrementCreate_temp_view_count() { 188 this.create_temp_view_count++; 189 } 190 191 public int getDrop_count() { 192 return drop_count; 193 } 194 195 public void setDrop_count(int drop_count) { 196 this.drop_count = drop_count; 197 } 198 199 public void incrementDrop_count() { 200 this.drop_count++; 201 } 202 203 public int getTruncate_count() { 204 return truncate_count; 205 } 206 207 public void setTruncate_count(int truncate_count) { 208 this.truncate_count = truncate_count; 209 } 210 211 public void incrementTruncate_count() { 212 this.truncate_count++; 213 } 214 215 public int getParse_error_count() { 216 return parse_error_count; 217 } 218 219 public void setParse_error_count(int parse_error_count) { 220 this.parse_error_count = parse_error_count; 221 } 222 223 public void incrementParse_error_count() { 224 this.parse_error_count++; 225 } 226 227 public int getJoin_count() { 228 return join_count; 229 } 230 231 public void setJoin_count(int join_count) { 232 this.join_count = join_count; 233 } 234 235 public void incrementJoin_count() { 236 this.join_count++; 237 } 238 239 240 public Map<String, Integer> getJoin_types() { 241 return join_types; 242 } 243 244 public void setJoin_types(Map<String, Integer> join_types) { 245 this.join_types = join_types; 246 } 247 248 public void addJoin_type(String join_type) { 249 this.join_types.put(join_type, this.join_types.getOrDefault(join_type, 0) + 1); 250 } 251 252 public int getSubquery_depth() { 253 return subquery_depth; 254 } 255 256 public void setSubquery_depth(int subquery_depth) { 257 this.subquery_depth = subquery_depth; 258 } 259 260 public int getCte_count() { 261 return cte_count; 262 } 263 264 public void setCte_count(int cte_count) { 265 this.cte_count = cte_count; 266 } 267 268 public void incrementCte_count() { 269 this.cte_count++; 270 } 271 272 public void addCte_count(int count) { 273 this.cte_count += count; 274 } 275 276 public int getCase_count() { 277 return case_count; 278 } 279 280 public void setCase_count(int case_count) { 281 this.case_count = case_count; 282 } 283 284 public void incrementCase_count() { 285 this.case_count++; 286 } 287 288 public void addCase_count(int count) { 289 this.case_count += count; 290 } 291 292 public int getUnion_count() { 293 return union_count; 294 } 295 296 public void setUnion_count(int union_count) { 297 this.union_count = union_count; 298 } 299 300 public void incrementUnion_count() { 301 this.union_count++; 302 } 303 304 public int getWindow_function_count() { 305 return window_function_count; 306 } 307 308 public void setWindow_function_count(int window_function_count) { 309 this.window_function_count = window_function_count; 310 } 311 312 public void incrementWindow_function_count() { 313 this.window_function_count++; 314 } 315 316 public void addWindow_function_count(int count) { 317 this.window_function_count += count; 318 } 319 320 public int getAggregate_function_count() { 321 return aggregate_function_count; 322 } 323 324 public void setAggregate_function_count(int aggregate_function_count) { 325 this.aggregate_function_count = aggregate_function_count; 326 } 327 328 public void incrementAggregate_function_count() { 329 this.aggregate_function_count++; 330 } 331 332 public void addAggregate_function_count(int count) { 333 this.aggregate_function_count += count; 334 } 335 336 public Set<String> getDistinct_table_references() { 337 return distinct_table_references; 338 } 339 340 public void setDistinct_table_references(Set<String> distinct_table_references) { 341 this.distinct_table_references = distinct_table_references; 342 } 343 344 public void addTableReference(String tableReference) { 345 this.distinct_table_references.add(tableReference); 346 } 347 348 public void addTableReferences(Set<String> tableReferences) { 349 this.distinct_table_references.addAll(tableReferences); 350 } 351 352 public int getWhere_predicate_count() { 353 return where_predicate_count; 354 } 355 356 public void setWhere_predicate_count(int where_predicate_count) { 357 this.where_predicate_count = where_predicate_count; 358 } 359 360 public void incrementWhere_predicate_count() { 361 this.where_predicate_count++; 362 } 363 364 public void addWhere_predicate_count(int count) { 365 this.where_predicate_count += count; 366 } 367 368 public List<String> getObjects_created() { 369 return objects_created; 370 } 371 372 public void setObjects_created(List<String> objects_created) { 373 this.objects_created = objects_created; 374 } 375 376 public void addObject_created(String object) { 377 this.objects_created.add(object); 378 } 379 380 public List<String> getObjects_read() { 381 return objects_read; 382 } 383 384 public void setObjects_read(List<String> objects_read) { 385 this.objects_read = objects_read; 386 } 387 388 public long getFile_size() { 389 return file_size; 390 } 391 392 public void setFile_size(long file_size) { 393 this.file_size = file_size; 394 } 395 396 public int getLine_count() { 397 return line_count; 398 } 399 400 public void setLine_count(int line_count) { 401 this.line_count = line_count; 402 } 403 404 public void addObject_read(String object) { 405 if (!this.objects_read.contains(object)) { 406 this.objects_read.add(object); 407 } 408 } 409 410 public Map toJSON() { 411 Map json = new LinkedHashMap(); 412 json.put("file", file); 413 json.put("file_size", file_size); 414 json.put("line_count", line_count); 415 json.put("total_statements", total_statements); 416 json.put("parse_error_count", parse_error_count); 417 json.put("select_count", select_count); 418 json.put("insert_count", insert_count); 419 json.put("update_count", update_count); 420 json.put("delete_count", delete_count); 421 json.put("merge_count", merge_count); 422 json.put("create_table_count", create_table_count); 423 json.put("create_temp_table_count", create_temp_table_count); 424 json.put("ctas_count", ctas_count); 425 json.put("create_view_count", create_view_count); 426 json.put("create_temp_view_count", create_temp_view_count); 427 json.put("drop_count", drop_count); 428 json.put("truncate_count", truncate_count); 429 json.put("join_count", join_count); 430 json.put("join_types", join_types); 431 json.put("subquery_depth", subquery_depth); 432 json.put("cte_count", cte_count); 433 json.put("case_count", case_count); 434 json.put("union_count", union_count); 435 json.put("window_function_count", window_function_count); 436 json.put("aggregate_function_count", aggregate_function_count); 437 json.put("distinct_table_references", distinct_table_references.size()); 438 json.put("where_predicate_count", where_predicate_count); 439 json.put("objects_created", objects_created); 440 json.put("objects_read", objects_read); 441 return json; 442 } 443}