Skip to content

Commit e6d2009

Browse files
committed
print progress better
1 parent c7265a3 commit e6d2009

File tree

3 files changed

+42
-36
lines changed

3 files changed

+42
-36
lines changed

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

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,18 @@ func extractQueries(sessions []internal.Session) <-chan string {
233233
}
234234

235235
queryIndex := 0
236+
needRemoveLine := false
236237
for _, session := range sessions {
237238
for _, transaction := range session.Transactions {
238239
for _, pgQuery := range transaction.Queries {
239240
queryIndex++
240241
if queryIndex%checkPgQueriesConfig.printProgressEveryQueries == 0 {
241242
percent := float64(queryIndex) / float64(totalQueries) * 100
243+
if needRemoveLine {
244+
fmt.Printf("\033[1A\033[K")
245+
} else {
246+
needRemoveLine = true
247+
}
242248
log.Printf("Checking query %8d/%v (%0.2f)", queryIndex, totalQueries, percent)
243249
}
244250
queries <- pgQuery.Text
@@ -314,7 +320,7 @@ func checkQuery(stat *QueryStats, rules Rules, db *ydb.Driver, queryText string)
314320
}
315321

316322
reason = fmt.Sprintf("%v (%v): %#v", ydbErr.Name(), ydbErr.Code(), unknownIssues)
317-
stat.CountAsUnknown(unknownIssues, queryText)
323+
stat.CountAsUnknown(reason, queryText)
318324
return reason, checkResultErrUnknown
319325
}
320326

@@ -342,16 +348,16 @@ func fixCreateTable(queryText string) string {
342348
}
343349

344350
func cutGreenplumSpecific(q string) string {
345-
q = createAndDistributedByWithBrackets.ReplaceAllString(q, "$1;")
351+
q = createAndDistributedByWithBrackets.ReplaceAllString(q, "$1")
346352
q = createTableAsSelect.ReplaceAllLiteralString(q, "")
347-
q = distributedBy.ReplaceAllLiteralString(q, ";")
353+
q = distributedBy.ReplaceAllLiteralString(q, "")
348354
return q
349355
}
350356

351357
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\(.*\)`)
353359
createTableAsSelect = regexp.MustCompile(`(?i)create\s+(temporary\s+)?table .* as`)
354-
distributedBy = regexp.MustCompile(`(?i)DISTRIBUTED BY ([^\)]+);`)
360+
distributedBy = regexp.MustCompile(`(?i)DISTRIBUTED BY \(.*\)`)
355361
)
356362

357363
type QueryStats struct {
@@ -360,7 +366,7 @@ type QueryStats struct {
360366
TotalCount int
361367

362368
MatchToRules map[string]*CounterWithExample[string] // [rule name] query example
363-
UnknownProblems map[internal.YdbIssue]*CounterWithExample[internal.YdbIssue]
369+
UnknownProblems map[string]*CounterWithExample[string]
364370
}
365371

366372
func (s *QueryStats) GetOkPercent() float64 {
@@ -403,29 +409,27 @@ func (s *QueryStats) CountAsKnown(ruleName string, query string) {
403409
}
404410
}
405411

406-
func (s *QueryStats) CountAsUnknown(issues []internal.YdbIssue, query string) {
412+
func (s *QueryStats) CountAsUnknown(reason string, query string) {
407413
s.m.Lock()
408414
defer s.m.Unlock()
409415

410416
s.TotalCount++
411417
if s.UnknownProblems == nil {
412-
s.UnknownProblems = make(map[internal.YdbIssue]*CounterWithExample[internal.YdbIssue])
418+
s.UnknownProblems = make(map[string]*CounterWithExample[string])
413419
}
414420

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,
428427
}
428+
s.UnknownProblems[reason] = stat
429+
}
430+
stat.Count++
431+
if len(query) < len(stat.Example) {
432+
stat.Example = query
429433
}
430434
}
431435

@@ -436,7 +440,7 @@ func (s *QueryStats) GetTopKnown(count int) []CounterWithExample[string] {
436440
return getTopCounter(s.MatchToRules, count)
437441
}
438442

439-
func (s *QueryStats) GetTopUnknown(count int) []CounterWithExample[internal.YdbIssue] {
443+
func (s *QueryStats) GetTopUnknown(count int) []CounterWithExample[string] {
440444
s.m.Lock()
441445
defer s.m.Unlock()
442446

@@ -494,11 +498,11 @@ func getTopCounter[K comparable](m map[K]*CounterWithExample[K], count int) []Co
494498

495499
func (s *QueryStats) SaveToFile(path string) error {
496500
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"`
502506
}
503507

504508
statFile.TotalCount = s.TotalCount

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ type PgIssueRules struct {
122122
QueryRegexp OneOrSliceString `yaml:"query_regexp,omitempty"`
123123
Example string `yaml:"example,omitempty"`
124124
Comment string `yaml:"comment,omitempty"`
125-
Skip bool `yaml:"skip"` // skip the issue on check query step
125+
Skip bool `yaml:"skip,omitempty"` // skip the issue on check query step
126126

127127
issuesRegexpCompiled []*regexp.Regexp
128128
queryRegexpCompiled []*regexp.Regexp

tools/greenplum-to-pg-tests/issues.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ issues:
77
issue_regexp:
88
- "Error while parsing query."
99
skip: true
10+
- name: Select from pg_tables
11+
query_regexp:
12+
- (?is)SELECT.*FROM\s+pg_
13+
- name: Transaction control (OK)
14+
count: 1
15+
query_regexp:
16+
- "(?i)^\\s*COMMIT\\s*;?\\s*$"
17+
- "(?i)^\\s*ROLLBACK\\s*;?\\s*$"
18+
- name: Set variables
19+
issue_regexp: "VariableSetStmt, not supported name"
1020
- name: drop external table
1121
count: 2
1222
tag:
@@ -35,14 +45,6 @@ issues:
3545
count: 2
3646
issue_regexp:
3747
- 'No such proc: '
38-
- name: Rollback in query service (OK)
39-
count: 1
40-
skip: true
41-
query_regexp: ROLLBACK
42-
- name: Commit in query service (OK)
43-
count: 1
44-
skip: true
45-
query_regexp: COMMIT
4648
- name: Not supported set greenplum var
4749
count: 1
4850
issue_regexp:

0 commit comments

Comments
 (0)