@@ -233,12 +233,18 @@ func extractQueries(sessions []internal.Session) <-chan string {
233
233
}
234
234
235
235
queryIndex := 0
236
+ needRemoveLine := false
236
237
for _ , session := range sessions {
237
238
for _ , transaction := range session .Transactions {
238
239
for _ , pgQuery := range transaction .Queries {
239
240
queryIndex ++
240
241
if queryIndex % checkPgQueriesConfig .printProgressEveryQueries == 0 {
241
242
percent := float64 (queryIndex ) / float64 (totalQueries ) * 100
243
+ if needRemoveLine {
244
+ fmt .Printf ("\033 [1A\033 [K" )
245
+ } else {
246
+ needRemoveLine = true
247
+ }
242
248
log .Printf ("Checking query %8d/%v (%0.2f)" , queryIndex , totalQueries , percent )
243
249
}
244
250
queries <- pgQuery .Text
@@ -314,7 +320,7 @@ func checkQuery(stat *QueryStats, rules Rules, db *ydb.Driver, queryText string)
314
320
}
315
321
316
322
reason = fmt .Sprintf ("%v (%v): %#v" , ydbErr .Name (), ydbErr .Code (), unknownIssues )
317
- stat .CountAsUnknown (unknownIssues , queryText )
323
+ stat .CountAsUnknown (reason , queryText )
318
324
return reason , checkResultErrUnknown
319
325
}
320
326
@@ -342,16 +348,16 @@ func fixCreateTable(queryText string) string {
342
348
}
343
349
344
350
func cutGreenplumSpecific (q string ) string {
345
- q = createAndDistributedByWithBrackets .ReplaceAllString (q , "$1; " )
351
+ q = createAndDistributedByWithBrackets .ReplaceAllString (q , "$1" )
346
352
q = createTableAsSelect .ReplaceAllLiteralString (q , "" )
347
- q = distributedBy .ReplaceAllLiteralString (q , "; " )
353
+ q = distributedBy .ReplaceAllLiteralString (q , "" )
348
354
return q
349
355
}
350
356
351
357
var (
352
- createAndDistributedByWithBrackets = regexp .MustCompile (`(?is)CREATE\s+.*\sTABLE\s+.*\s+AS\s+\(\s*(.*)\s*\)\s+DISTRIBUTED\s+BY\s\(.*\); ` )
358
+ createAndDistributedByWithBrackets = regexp .MustCompile (`(?is)CREATE\s+.*\sTABLE\s+.*\s+AS\s+\(\s*(.*)\s*\)\s+DISTRIBUTED\s+BY\s\(.*\)` )
353
359
createTableAsSelect = regexp .MustCompile (`(?i)create\s+(temporary\s+)?table .* as` )
354
- distributedBy = regexp .MustCompile (`(?i)DISTRIBUTED BY ([^\)]+); ` )
360
+ distributedBy = regexp .MustCompile (`(?i)DISTRIBUTED BY \(.*\) ` )
355
361
)
356
362
357
363
type QueryStats struct {
@@ -360,7 +366,7 @@ type QueryStats struct {
360
366
TotalCount int
361
367
362
368
MatchToRules map [string ]* CounterWithExample [string ] // [rule name] query example
363
- UnknownProblems map [internal. YdbIssue ]* CounterWithExample [internal. YdbIssue ]
369
+ UnknownProblems map [string ]* CounterWithExample [string ]
364
370
}
365
371
366
372
func (s * QueryStats ) GetOkPercent () float64 {
@@ -403,29 +409,27 @@ func (s *QueryStats) CountAsKnown(ruleName string, query string) {
403
409
}
404
410
}
405
411
406
- func (s * QueryStats ) CountAsUnknown (issues []internal. YdbIssue , query string ) {
412
+ func (s * QueryStats ) CountAsUnknown (reason string , query string ) {
407
413
s .m .Lock ()
408
414
defer s .m .Unlock ()
409
415
410
416
s .TotalCount ++
411
417
if s .UnknownProblems == nil {
412
- s .UnknownProblems = make (map [internal. YdbIssue ]* CounterWithExample [internal. YdbIssue ])
418
+ s .UnknownProblems = make (map [string ]* CounterWithExample [string ])
413
419
}
414
420
415
- for _ , issue := range issues {
416
- var stat * CounterWithExample [internal.YdbIssue ]
417
- var ok bool
418
- if stat , ok = s .UnknownProblems [issue ]; ! ok {
419
- stat = & CounterWithExample [internal.YdbIssue ]{
420
- ID : issue ,
421
- Example : query ,
422
- }
423
- s .UnknownProblems [issue ] = stat
424
- }
425
- stat .Count ++
426
- if len (query ) < len (stat .Example ) {
427
- stat .Example = query
421
+ var stat * CounterWithExample [string ]
422
+ var ok bool
423
+ if stat , ok = s .UnknownProblems [reason ]; ! ok {
424
+ stat = & CounterWithExample [string ]{
425
+ ID : reason ,
426
+ Example : query ,
428
427
}
428
+ s .UnknownProblems [reason ] = stat
429
+ }
430
+ stat .Count ++
431
+ if len (query ) < len (stat .Example ) {
432
+ stat .Example = query
429
433
}
430
434
}
431
435
@@ -436,7 +440,7 @@ func (s *QueryStats) GetTopKnown(count int) []CounterWithExample[string] {
436
440
return getTopCounter (s .MatchToRules , count )
437
441
}
438
442
439
- func (s * QueryStats ) GetTopUnknown (count int ) []CounterWithExample [internal. YdbIssue ] {
443
+ func (s * QueryStats ) GetTopUnknown (count int ) []CounterWithExample [string ] {
440
444
s .m .Lock ()
441
445
defer s .m .Unlock ()
442
446
@@ -494,11 +498,11 @@ func getTopCounter[K comparable](m map[K]*CounterWithExample[K], count int) []Co
494
498
495
499
func (s * QueryStats ) SaveToFile (path string ) error {
496
500
var statFile struct {
497
- TotalCount int `yaml:"total_count"`
498
- OkCount int `yaml:"ok_count"`
499
- OkPercent float64 `yaml:"ok_percent"`
500
- UnknownIssues []CounterWithExample [internal. YdbIssue ] `yaml:"unknown_issues"`
501
- KnownIssues []CounterWithExample [string ] `yaml:"known_issues"`
501
+ TotalCount int `yaml:"total_count"`
502
+ OkCount int `yaml:"ok_count"`
503
+ OkPercent float64 `yaml:"ok_percent"`
504
+ UnknownIssues []CounterWithExample [string ] `yaml:"unknown_issues"`
505
+ KnownIssues []CounterWithExample [string ] `yaml:"known_issues"`
502
506
}
503
507
504
508
statFile .TotalCount = s .TotalCount
0 commit comments