Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Refactor code quality issues #23445

Merged
merged 7 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/importer/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func genColumnData(table *table, column *column) (string, error) {
}

func execSQL(db *sql.DB, sql string) error {
if len(sql) == 0 {
if sql == "" {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/importer/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func parseIndex(table *table, stmt *ast.CreateIndexStmt) error {
}

func parseIndexSQL(table *table, sql string) error {
if len(sql) == 0 {
if sql == "" {
return nil
}

Expand Down
12 changes: 6 additions & 6 deletions cmd/importer/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func randDate(col *column) string {
}

min, max := col.min, col.max
if len(min) == 0 {
if min == "" {
year := time.Now().Year()
month := randInt(1, 12)
day := randInt(1, 28)
Expand All @@ -83,7 +83,7 @@ func randDate(col *column) string {
if err != nil {
log.Warn("parse min date failed", zap.Error(err))
}
if len(max) == 0 {
if max == "" {
t := minTime.Add(time.Duration(randInt(0, 365)) * 24 * time.Hour)
return fmt.Sprintf("%04d-%02d-%02d", t.Year(), t.Month(), t.Day())
}
Expand All @@ -102,7 +102,7 @@ func randTime(col *column) string {
return col.hist.randDate("SECOND", "%H:%i:%s", timeFormat)
}
min, max := col.min, col.max
if len(min) == 0 || len(max) == 0 {
if min == "" || max == "" {
hour := randInt(0, 23)
min := randInt(0, 59)
sec := randInt(0, 59)
Expand All @@ -127,7 +127,7 @@ func randTimestamp(col *column) string {
return col.hist.randDate("SECOND", "%Y-%m-%d %H:%i:%s", dateTimeFormat)
}
min, max := col.min, col.max
if len(min) == 0 {
if min == "" {
year := time.Now().Year()
month := randInt(1, 12)
day := randInt(1, 28)
Expand All @@ -141,7 +141,7 @@ func randTimestamp(col *column) string {
if err != nil {
log.Warn("parse min timestamp failed", zap.Error(err))
}
if len(max) == 0 {
if max == "" {
t := minTime.Add(time.Duration(randInt(0, 365)) * 24 * time.Hour)
return fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
}
Expand All @@ -160,7 +160,7 @@ func randYear(col *column) string {
return col.hist.randDate("YEAR", "%Y", yearFormat)
}
min, max := col.min, col.max
if len(min) == 0 || len(max) == 0 {
if min == "" || max == "" {
return fmt.Sprintf("%04d", time.Now().Year()-randInt(0, 10))
}

Expand Down
4 changes: 1 addition & 3 deletions executor/hash_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ func (h hashCollision) Size() int { panic("not implement
func (h hashCollision) BlockSize() int { panic("not implemented") }

func (s *pkgTestSerialSuite) TestHashRowContainer(c *C) {
hashFunc := func() hash.Hash64 {
return fnv.New64()
}
hashFunc := fnv.New64
rowContainer := s.testHashRowContainer(c, hashFunc, false)
c.Assert(rowContainer.stat.probeCollision, Equals, 0)
// On windows time.Now() is imprecise, the elapse time may equal 0
Expand Down
2 changes: 1 addition & 1 deletion executor/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func drainRecordSet(ctx context.Context, sctx sessionctx.Context, rs sqlexec.Rec

func dfsTree(t *appdash.Trace, prefix string, isLast bool, chk *chunk.Chunk) {
var newPrefix, suffix string
if len(prefix) == 0 {
if prefix == "" {
newPrefix = prefix + " "
} else {
if !isLast {
Expand Down
2 changes: 1 addition & 1 deletion expression/builtin_miscellaneous.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func (b *builtinInet6AtonSig) evalString(row chunk.Row) (string, bool, error) {
copy(result, ip.To4())
}

return string(result[:]), false, nil
return string(result), false, nil
}

type inet6NtoaFunctionClass struct {
Expand Down
2 changes: 1 addition & 1 deletion expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ func (s *testEvaluatorSuite) TestNowAndUTCTimestamp(c *C) {
fc functionClass
now func() time.Time
}{
{funcs[ast.Now], func() time.Time { return time.Now() }},
{funcs[ast.Now], time.Now},
{funcs[ast.UTCTimestamp], func() time.Time { return time.Now().UTC() }},
} {
f, err := x.fc.getFunction(s.ctx, s.datumsToConstants(nil))
Expand Down
2 changes: 1 addition & 1 deletion owner/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var ManagerSessionTTL = 60
// setManagerSessionTTL sets the ManagerSessionTTL value, it's used for testing.
func setManagerSessionTTL() error {
ttlStr := os.Getenv("tidb_manager_ttl")
if len(ttlStr) == 0 {
if ttlStr == "" {
return nil
}
ttl, err := strconv.Atoi(ttlStr)
Expand Down
2 changes: 1 addition & 1 deletion types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,7 @@ func parseSingleTimeValue(unit string, format string, strictCheck bool) (int64,
return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, format)
}
} else {
if dv, err = strconv.ParseInt(dvPre[:]+"000000"[:6-dvPreLen], 10, 64); err != nil {
if dv, err = strconv.ParseInt(dvPre+"000000"[:6-dvPreLen], 10, 64); err != nil {
return 0, 0, 0, 0, ErrWrongValue.GenWithStackByArgs(DateTimeStr, format)
}
}
Expand Down