@@ -109,7 +109,7 @@ var extractSessionsCmd = &cobra.Command{
109
109
sessions := readSessions ()
110
110
111
111
log .Println ("Start check queries" )
112
- var stats SessionStats
112
+ var stats QueryStats
113
113
checkQueries (rules , & stats , schema , db , sessions )
114
114
115
115
if extractSessionsConfig .writeRulesWithStat != "" {
@@ -215,9 +215,9 @@ readLoop:
215
215
return res
216
216
}
217
217
218
- func checkQueries (rules Rules , stats * SessionStats , pgSchema * internal.PgSchema , db * ydb.Driver , sessions []internal.Session ) {
218
+ func checkQueries (rules Rules , stats * QueryStats , pgSchema * internal.PgSchema , db * ydb.Driver , sessions []internal.Session ) {
219
219
reasonFilter := regexp .MustCompile (extractSessionsConfig .filterReason )
220
- checked := map [string ]bool {}
220
+ // checked := map[string]bool{}
221
221
222
222
errorLimit := extractSessionsConfig .errorLimit
223
223
if errorLimit == 0 {
@@ -240,10 +240,10 @@ func checkQueries(rules Rules, stats *SessionStats, pgSchema *internal.PgSchema,
240
240
if queryIndex % extractSessionsConfig .printProgressEveryQueries == 0 {
241
241
log .Printf ("Checking query %8d/%v" , queryIndex , totalQueries )
242
242
}
243
- if checked [pgQuery .Text ] {
244
- continue
245
- }
246
- checked [pgQuery .Text ] = true
243
+ // if checked[pgQuery.Text] {
244
+ // continue
245
+ // }
246
+ // checked[pgQuery.Text] = true
247
247
248
248
reason , checkResult := checkQuery (stats , rules , db , pgQuery .Text )
249
249
if ! reasonFilter .MatchString (reason ) {
@@ -290,7 +290,7 @@ const (
290
290
checkResultErrUnknown
291
291
)
292
292
293
- func checkQuery (stat * SessionStats , rules Rules , db * ydb.Driver , queryText string ) (reason string , checkResult checkResultType ) {
293
+ func checkQuery (stat * QueryStats , rules Rules , db * ydb.Driver , queryText string ) (reason string , checkResult checkResultType ) {
294
294
queryText = strings .TrimSpace (queryText )
295
295
queryText = fixSchemaNames (queryText )
296
296
queryText = fixCreateTable (queryText )
@@ -350,23 +350,24 @@ func fixCreateTable(queryText string) string {
350
350
return queryText
351
351
}
352
352
353
- type SessionStats struct {
353
+ type QueryStats struct {
354
354
OkCount int
355
355
TotalCount int
356
356
357
357
MatchToRules map [string ]* CounterWithExample [string ] // [rule name] query example
358
358
UnknownProblems map [internal.YdbIssue ]* CounterWithExample [internal.YdbIssue ]
359
359
}
360
360
361
- func (s * SessionStats ) GetOkPercent () float64 {
361
+ func (s * QueryStats ) GetOkPercent () float64 {
362
362
return float64 (s .OkCount ) / float64 (s .TotalCount ) * 100
363
363
}
364
364
365
- func (s * SessionStats ) CountASOK (query string ) {
365
+ func (s * QueryStats ) CountASOK (query string ) {
366
+ s .TotalCount ++
366
367
s .OkCount ++
367
368
}
368
369
369
- func (s * SessionStats ) CountAsKnown (ruleName string , query string ) {
370
+ func (s * QueryStats ) CountAsKnown (ruleName string , query string ) {
370
371
s .TotalCount ++
371
372
if s .MatchToRules == nil {
372
373
s .MatchToRules = make (map [string ]* CounterWithExample [string ])
@@ -383,9 +384,12 @@ func (s *SessionStats) CountAsKnown(ruleName string, query string) {
383
384
}
384
385
385
386
stat .Count ++
387
+ if len (query ) < len (stat .Example ) {
388
+ stat .Example = query
389
+ }
386
390
}
387
391
388
- func (s * SessionStats ) CountAsUnknown (issues []internal.YdbIssue , query string ) {
392
+ func (s * QueryStats ) CountAsUnknown (issues []internal.YdbIssue , query string ) {
389
393
s .TotalCount ++
390
394
if s .UnknownProblems == nil {
391
395
s .UnknownProblems = make (map [internal.YdbIssue ]* CounterWithExample [internal.YdbIssue ])
@@ -402,18 +406,21 @@ func (s *SessionStats) CountAsUnknown(issues []internal.YdbIssue, query string)
402
406
s .UnknownProblems [issue ] = stat
403
407
}
404
408
stat .Count ++
409
+ if len (query ) < len (stat .Example ) {
410
+ stat .Example = query
411
+ }
405
412
}
406
413
}
407
414
408
- func (s * SessionStats ) GetTopKnown (count int ) []CounterWithExample [string ] {
415
+ func (s * QueryStats ) GetTopKnown (count int ) []CounterWithExample [string ] {
409
416
return getTopCounter (s .MatchToRules , count )
410
417
}
411
418
412
- func (s * SessionStats ) GetTopUnknown (count int ) []CounterWithExample [internal.YdbIssue ] {
419
+ func (s * QueryStats ) GetTopUnknown (count int ) []CounterWithExample [internal.YdbIssue ] {
413
420
return getTopCounter (s .UnknownProblems , count )
414
421
}
415
422
416
- func (s * SessionStats ) PrintStats () {
423
+ func (s * QueryStats ) PrintStats () {
417
424
fmt .Println ("Queries stat." )
418
425
fmt .Println ("Ok Count:" , s .OkCount )
419
426
fmt .Println ()
@@ -459,7 +466,7 @@ func getTopCounter[K comparable](m map[K]*CounterWithExample[K], count int) []Co
459
466
return res [:count ]
460
467
}
461
468
462
- func (s * SessionStats ) SaveToFile (path string ) error {
469
+ func (s * QueryStats ) SaveToFile (path string ) error {
463
470
var statFile struct {
464
471
TotalCount int `yaml:"total_count"`
465
472
OkCount int `yaml:"ok_count"`
0 commit comments