Skip to content

Commit

Permalink
types: fix types's pkg warning and note generation (get rid of stack …
Browse files Browse the repository at this point in the history
…info) (#49880)

close #49291
  • Loading branch information
AilinKid authored Dec 29, 2023
1 parent 4a47236 commit c766530
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,10 +1157,10 @@ func ProduceStrWithSpecifiedTp(s string, tp *FieldType, ctx Context, padZero boo
trimed := strings.TrimRight(overflowed, " \t\n\r")
if len(trimed) == 0 && !IsBinaryStr(tp) && IsTypeChar(tp.GetType()) {
if tp.GetType() == mysql.TypeVarchar {
ctx.AppendWarning(ErrTruncated.GenWithStack("Data truncated, field len %d, data len %d", flen, characterLen))
ctx.AppendWarning(ErrTruncated.FastGen("Data truncated, field len %d, data len %d", flen, characterLen))
}
} else {
err = ErrDataTooLong.GenWithStack("Data Too Long, field len %d, data len %d", flen, characterLen)
err = ErrDataTooLong.FastGen("Data Too Long, field len %d, data len %d", flen, characterLen)
}
}

Expand Down Expand Up @@ -1515,7 +1515,7 @@ func ProduceDecWithSpecifiedTp(ctx Context, dec *MyDecimal, tp *FieldType) (_ *M
// select cast(111 as decimal(1)) causes a warning in MySQL.
err = ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%d, %d)", flen, decimal))
} else if old != nil && dec.Compare(old) != 0 {
ctx.AppendWarning(ErrTruncatedWrongVal.GenWithStackByArgs("DECIMAL", old))
ctx.AppendWarning(ErrTruncatedWrongVal.FastGenByArgs("DECIMAL", old))
}
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ func parseDatetime(ctx Context, str string, fsp int, isFloat bool) (Time, error)

seps, fracStr, hasTZ, tzSign, tzHour, tzSep, tzMinute, truncatedOrIncorrect := splitDateTime(str)
if truncatedOrIncorrect {
ctx.AppendWarning(ErrTruncatedWrongVal.GenWithStackByArgs("datetime", str))
ctx.AppendWarning(ErrTruncatedWrongVal.FastGenByArgs("datetime", str))
}
/*
if we have timezone parsed, there are the following cases to be considered, however some of them are wrongly parsed, and we should consider absorb them back to seps.
Expand Down Expand Up @@ -1116,11 +1116,11 @@ func parseDatetime(ctx Context, str string, fsp int, isFloat bool) (Time, error)
truncatedOrIncorrect = err != nil
}
if truncatedOrIncorrect {
ctx.AppendWarning(ErrTruncatedWrongVal.GenWithStackByArgs("datetime", str))
ctx.AppendWarning(ErrTruncatedWrongVal.FastGenByArgs("datetime", str))
err = nil
}
case 2:
return ZeroDatetime, errors.Trace(ErrWrongValue.GenWithStackByArgs(DateTimeStr, str))
return ZeroDatetime, errors.Trace(ErrWrongValue.FastGenByArgs(DateTimeStr, str))
case 3:
// YYYY-MM-DD
err = scanTimeArgs(seps, &year, &month, &day)
Expand All @@ -1139,7 +1139,7 @@ func parseDatetime(ctx Context, str string, fsp int, isFloat bool) (Time, error)
// For case like `2020-05-28 23:59:59 00:00:00`, the seps should be > 6, the reluctant parts should be truncated.
seps = seps[:6]
// YYYY-MM-DD HH-MM-SS
ctx.AppendWarning(ErrTruncatedWrongVal.GenWithStackByArgs("datetime", str))
ctx.AppendWarning(ErrTruncatedWrongVal.FastGenByArgs("datetime", str))
err = scanTimeArgs(seps, &year, &month, &day, &hour, &minute, &second)
hhmmss = true
}
Expand Down Expand Up @@ -2917,7 +2917,7 @@ func (t *Time) StrToDate(typeCtx Context, date, format string) bool {
if warning {
// Only append this warning when success but still need warning.
// Currently this only happens when `date` has extra characters at the end.
typeCtx.AppendWarning(ErrTruncatedWrongVal.GenWithStackByArgs(DateTimeStr, date))
typeCtx.AppendWarning(ErrTruncatedWrongVal.FastGenByArgs(DateTimeStr, date))
}
return true
}
Expand Down

0 comments on commit c766530

Please sign in to comment.