Skip to content

Commit

Permalink
lightning: fix data error summary table format (#58099)
Browse files Browse the repository at this point in the history
close #58085
  • Loading branch information
lance6716 authored Dec 17, 2024
1 parent 0f32738 commit d97f0ee
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
9 changes: 4 additions & 5 deletions br/pkg/lightning/errormanager/errormanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,11 @@ func (em *ErrorManager) Output() string {
t := table.NewWriter()
t.AppendHeader(table.Row{"#", "Error Type", "Error Count", "Error Data Table"})
t.SetColumnConfigs([]table.ColumnConfig{
{Name: "#", WidthMax: 6},
{Name: "Error Type", WidthMax: 20},
{Name: "Error Count", WidthMax: 12},
{Name: "Error Data Table", WidthMax: 42},
{Name: "#"},
{Name: "Error Type"},
{Name: "Error Count"},
{Name: "Error Data Table"},
})
t.SetAllowedRowLength(80)
t.SetRowPainter(func(row table.Row) text.Colors {
return text.Colors{text.FgRed}
})
Expand Down
52 changes: 42 additions & 10 deletions br/pkg/lightning/errormanager/errormanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"io"
"math/rand"
"strconv"
"strings"
"testing"

"github.com/DATA-DOG/go-sqlmock"
Expand Down Expand Up @@ -240,17 +239,28 @@ func TestErrorMgrErrorOutput(t *testing.T) {

em.remainingError.Syntax.Sub(1)
output = em.Output()
checkStr := strings.ReplaceAll(output, "\n", "")
expected := "Import Data Error Summary: +---+-------------+-------------+--------------------------------+| # | ERROR TYPE | ERROR COUNT | ERROR DATA TABLE |+---+-------------+-------------+--------------------------------+|\x1b[31m 1 \x1b[0m|\x1b[31m Data Syntax \x1b[0m|\x1b[31m 1 \x1b[0m|\x1b[31m `error_info`.`syntax_error_v1` \x1b[0m|+---+-------------+-------------+--------------------------------+"
require.Equal(t, expected, checkStr)
expected := "\n" +
"Import Data Error Summary: \n" +
"+---+-------------+-------------+--------------------------------+\n" +
"| # | ERROR TYPE | ERROR COUNT | ERROR DATA TABLE |\n" +
"+---+-------------+-------------+--------------------------------+\n" +
"|\x1b[31m 1 \x1b[0m|\x1b[31m Data Syntax \x1b[0m|\x1b[31m 1 \x1b[0m|\x1b[31m `error_info`.`syntax_error_v1` \x1b[0m|\n" +
"+---+-------------+-------------+--------------------------------+\n"
require.Equal(t, expected, output)

em.remainingError = cfg.App.MaxError
em.remainingError.Syntax.Sub(10)
em.remainingError.Type.Store(10)
output = em.Output()
checkStr = strings.ReplaceAll(output, "\n", "")
expected = "Import Data Error Summary: +---+-------------+-------------+--------------------------------+| # | ERROR TYPE | ERROR COUNT | ERROR DATA TABLE |+---+-------------+-------------+--------------------------------+|\x1b[31m 1 \x1b[0m|\x1b[31m Data Type \x1b[0m|\x1b[31m 90 \x1b[0m|\x1b[31m `error_info`.`type_error_v1` \x1b[0m||\x1b[31m 2 \x1b[0m|\x1b[31m Data Syntax \x1b[0m|\x1b[31m 10 \x1b[0m|\x1b[31m `error_info`.`syntax_error_v1` \x1b[0m|+---+-------------+-------------+--------------------------------+"
require.Equal(t, expected, checkStr)
expected = "\n" +
"Import Data Error Summary: \n" +
"+---+-------------+-------------+--------------------------------+\n" +
"| # | ERROR TYPE | ERROR COUNT | ERROR DATA TABLE |\n" +
"+---+-------------+-------------+--------------------------------+\n" +
"|\x1b[31m 1 \x1b[0m|\x1b[31m Data Type \x1b[0m|\x1b[31m 90 \x1b[0m|\x1b[31m `error_info`.`type_error_v1` \x1b[0m|\n" +
"|\x1b[31m 2 \x1b[0m|\x1b[31m Data Syntax \x1b[0m|\x1b[31m 10 \x1b[0m|\x1b[31m `error_info`.`syntax_error_v1` \x1b[0m|\n" +
"+---+-------------+-------------+--------------------------------+\n"
require.Equal(t, expected, output)

// change multiple keys
em.remainingError = cfg.App.MaxError
Expand All @@ -259,7 +269,29 @@ func TestErrorMgrErrorOutput(t *testing.T) {
em.remainingError.Type.Store(0)
em.remainingError.Conflict.Store(0)
output = em.Output()
checkStr = strings.ReplaceAll(output, "\n", "")
expected = "Import Data Error Summary: +---+---------------------+-------------+----------------------------------+| # | ERROR TYPE | ERROR COUNT | ERROR DATA TABLE |+---+---------------------+-------------+----------------------------------+|\x1b[31m 1 \x1b[0m|\x1b[31m Data Type \x1b[0m|\x1b[31m 100 \x1b[0m|\x1b[31m `error_info`.`type_error_v1` \x1b[0m||\x1b[31m 2 \x1b[0m|\x1b[31m Data Syntax \x1b[0m|\x1b[31m 100 \x1b[0m|\x1b[31m `error_info`.`syntax_error_v1` \x1b[0m||\x1b[31m 3 \x1b[0m|\x1b[31m Charset Error \x1b[0m|\x1b[31m 100 \x1b[0m|\x1b[31m \x1b[0m||\x1b[31m 4 \x1b[0m|\x1b[31m Unique Key Conflict \x1b[0m|\x1b[31m 100 \x1b[0m|\x1b[31m `error_info`.`conflict_error_v1` \x1b[0m|+---+---------------------+-------------+----------------------------------+"
require.Equal(t, expected, checkStr)
expected = "\n" +
"Import Data Error Summary: \n" +
"+---+---------------------+-------------+----------------------------------+\n" +
"| # | ERROR TYPE | ERROR COUNT | ERROR DATA TABLE |\n" +
"+---+---------------------+-------------+----------------------------------+\n" +
"|\x1b[31m 1 \x1b[0m|\x1b[31m Data Type \x1b[0m|\x1b[31m 100 \x1b[0m|\x1b[31m `error_info`.`type_error_v1` \x1b[0m|\n" +
"|\x1b[31m 2 \x1b[0m|\x1b[31m Data Syntax \x1b[0m|\x1b[31m 100 \x1b[0m|\x1b[31m `error_info`.`syntax_error_v1` \x1b[0m|\n" +
"|\x1b[31m 3 \x1b[0m|\x1b[31m Charset Error \x1b[0m|\x1b[31m 100 \x1b[0m|\x1b[31m \x1b[0m|\n" +
"|\x1b[31m 4 \x1b[0m|\x1b[31m Unique Key Conflict \x1b[0m|\x1b[31m 100 \x1b[0m|\x1b[31m `error_info`.`conflict_error_v1` \x1b[0m|\n" +
"+---+---------------------+-------------+----------------------------------+\n"
require.Equal(t, expected, output)

em.schemaEscaped = "`lightning_task_info`"
output = em.Output()
expected = "\n" +
"Import Data Error Summary: \n" +
"+---+---------------------+-------------+-------------------------------------------+\n" +
"| # | ERROR TYPE | ERROR COUNT | ERROR DATA TABLE |\n" +
"+---+---------------------+-------------+-------------------------------------------+\n" +
"|\x1b[31m 1 \x1b[0m|\x1b[31m Data Type \x1b[0m|\x1b[31m 100 \x1b[0m|\x1b[31m `lightning_task_info`.`type_error_v1` \x1b[0m|\n" +
"|\x1b[31m 2 \x1b[0m|\x1b[31m Data Syntax \x1b[0m|\x1b[31m 100 \x1b[0m|\x1b[31m `lightning_task_info`.`syntax_error_v1` \x1b[0m|\n" +
"|\x1b[31m 3 \x1b[0m|\x1b[31m Charset Error \x1b[0m|\x1b[31m 100 \x1b[0m|\x1b[31m \x1b[0m|\n" +
"|\x1b[31m 4 \x1b[0m|\x1b[31m Unique Key Conflict \x1b[0m|\x1b[31m 100 \x1b[0m|\x1b[31m `lightning_task_info`.`conflict_error_v1` \x1b[0m|\n" +
"+---+---------------------+-------------+-------------------------------------------+\n"
require.Equal(t, expected, output)
}

0 comments on commit d97f0ee

Please sign in to comment.