Skip to content

Commit f5d0620

Browse files
committed
update stat
1 parent 69e3333 commit f5d0620

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

tools/greenplum-to-pg-tests/cmd/extraxtSessions.go

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ var extractSessionsCmd = &cobra.Command{
109109
sessions := readSessions()
110110

111111
log.Println("Start check queries")
112-
var stats SessionStats
112+
var stats QueryStats
113113
checkQueries(rules, &stats, schema, db, sessions)
114114

115115
if extractSessionsConfig.writeRulesWithStat != "" {
@@ -215,9 +215,9 @@ readLoop:
215215
return res
216216
}
217217

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) {
219219
reasonFilter := regexp.MustCompile(extractSessionsConfig.filterReason)
220-
checked := map[string]bool{}
220+
//checked := map[string]bool{}
221221

222222
errorLimit := extractSessionsConfig.errorLimit
223223
if errorLimit == 0 {
@@ -240,10 +240,10 @@ func checkQueries(rules Rules, stats *SessionStats, pgSchema *internal.PgSchema,
240240
if queryIndex%extractSessionsConfig.printProgressEveryQueries == 0 {
241241
log.Printf("Checking query %8d/%v", queryIndex, totalQueries)
242242
}
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
247247

248248
reason, checkResult := checkQuery(stats, rules, db, pgQuery.Text)
249249
if !reasonFilter.MatchString(reason) {
@@ -290,7 +290,7 @@ const (
290290
checkResultErrUnknown
291291
)
292292

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) {
294294
queryText = strings.TrimSpace(queryText)
295295
queryText = fixSchemaNames(queryText)
296296
queryText = fixCreateTable(queryText)
@@ -350,23 +350,24 @@ func fixCreateTable(queryText string) string {
350350
return queryText
351351
}
352352

353-
type SessionStats struct {
353+
type QueryStats struct {
354354
OkCount int
355355
TotalCount int
356356

357357
MatchToRules map[string]*CounterWithExample[string] // [rule name] query example
358358
UnknownProblems map[internal.YdbIssue]*CounterWithExample[internal.YdbIssue]
359359
}
360360

361-
func (s *SessionStats) GetOkPercent() float64 {
361+
func (s *QueryStats) GetOkPercent() float64 {
362362
return float64(s.OkCount) / float64(s.TotalCount) * 100
363363
}
364364

365-
func (s *SessionStats) CountASOK(query string) {
365+
func (s *QueryStats) CountASOK(query string) {
366+
s.TotalCount++
366367
s.OkCount++
367368
}
368369

369-
func (s *SessionStats) CountAsKnown(ruleName string, query string) {
370+
func (s *QueryStats) CountAsKnown(ruleName string, query string) {
370371
s.TotalCount++
371372
if s.MatchToRules == nil {
372373
s.MatchToRules = make(map[string]*CounterWithExample[string])
@@ -383,9 +384,12 @@ func (s *SessionStats) CountAsKnown(ruleName string, query string) {
383384
}
384385

385386
stat.Count++
387+
if len(query) < len(stat.Example) {
388+
stat.Example = query
389+
}
386390
}
387391

388-
func (s *SessionStats) CountAsUnknown(issues []internal.YdbIssue, query string) {
392+
func (s *QueryStats) CountAsUnknown(issues []internal.YdbIssue, query string) {
389393
s.TotalCount++
390394
if s.UnknownProblems == nil {
391395
s.UnknownProblems = make(map[internal.YdbIssue]*CounterWithExample[internal.YdbIssue])
@@ -402,18 +406,21 @@ func (s *SessionStats) CountAsUnknown(issues []internal.YdbIssue, query string)
402406
s.UnknownProblems[issue] = stat
403407
}
404408
stat.Count++
409+
if len(query) < len(stat.Example) {
410+
stat.Example = query
411+
}
405412
}
406413
}
407414

408-
func (s *SessionStats) GetTopKnown(count int) []CounterWithExample[string] {
415+
func (s *QueryStats) GetTopKnown(count int) []CounterWithExample[string] {
409416
return getTopCounter(s.MatchToRules, count)
410417
}
411418

412-
func (s *SessionStats) GetTopUnknown(count int) []CounterWithExample[internal.YdbIssue] {
419+
func (s *QueryStats) GetTopUnknown(count int) []CounterWithExample[internal.YdbIssue] {
413420
return getTopCounter(s.UnknownProblems, count)
414421
}
415422

416-
func (s *SessionStats) PrintStats() {
423+
func (s *QueryStats) PrintStats() {
417424
fmt.Println("Queries stat.")
418425
fmt.Println("Ok Count:", s.OkCount)
419426
fmt.Println()
@@ -459,7 +466,7 @@ func getTopCounter[K comparable](m map[K]*CounterWithExample[K], count int) []Co
459466
return res[:count]
460467
}
461468

462-
func (s *SessionStats) SaveToFile(path string) error {
469+
func (s *QueryStats) SaveToFile(path string) error {
463470
var statFile struct {
464471
TotalCount int `yaml:"total_count"`
465472
OkCount int `yaml:"ok_count"`

tools/greenplum-to-pg-tests/cmd/issue_rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (r *Rules) FindKnownIssue(queryText string, ydbIssues []internal.YdbIssue)
8686
return ""
8787
}
8888

89-
func (r *Rules) UpdateFromStats(stats SessionStats, sortByCount bool) {
89+
func (r *Rules) UpdateFromStats(stats QueryStats, sortByCount bool) {
9090
r.TotalStat.TotalCount = stats.TotalCount
9191
r.TotalStat.TotalOk = stats.OkCount
9292
r.TotalStat.OkPercent = math.Round(stats.GetOkPercent()*100) / 100

0 commit comments

Comments
 (0)