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

expression: Fix warnings for FORMAT() in CTE #56198

Merged
merged 5 commits into from
Sep 26, 2024
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
12 changes: 10 additions & 2 deletions pkg/expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2978,7 +2978,11 @@ func formatDecimal(ctx EvalContext, xBuf *chunk.Column, dInt64s []int64, result
} else if !strings.EqualFold(localeBuf.GetString(i), "en_US") {
// TODO: support other locales.
tc := typeCtx(ctx)
tc.AppendWarning(errUnknownLocale.FastGenByArgs(localeBuf.GetString(i)))

// force copy of the string
// https://github.com/pingcap/tidb/issues/56193
locale := strings.Clone(localeBuf.GetString(i))
tc.AppendWarning(errUnknownLocale.FastGenByArgs(locale))
}

xStr := roundFormatArgs(x.String(), int(d))
Expand Down Expand Up @@ -3020,7 +3024,11 @@ func formatReal(ctx EvalContext, xBuf *chunk.Column, dInt64s []int64, result *ch
} else if !strings.EqualFold(localeBuf.GetString(i), "en_US") {
// TODO: support other locales.
tc := typeCtx(ctx)
tc.AppendWarning(errUnknownLocale.FastGenByArgs(localeBuf.GetString(i)))

// force copy of the string
// https://github.com/pingcap/tidb/issues/56193
locale := strings.Clone(localeBuf.GetString(i))
tc.AppendWarning(errUnknownLocale.FastGenByArgs(locale))
}

xStr := roundFormatArgs(strconv.FormatFloat(x, 'f', -1, 64), int(d))
Expand Down
52 changes: 52 additions & 0 deletions tests/integrationtest/r/expression/format.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
SELECT FORMAT(1.234,0,'en_US');
FORMAT(1.234,0,'en_US')
1
SELECT FORMAT(1.234,1,'en_US');
FORMAT(1.234,1,'en_US')
1.2
SELECT FORMAT(1.234,2,'en_US');
FORMAT(1.234,2,'en_US')
1.23
SELECT FORMAT(1.234,3,'en_US');
FORMAT(1.234,3,'en_US')
1.234
SELECT FORMAT(1.234,4,'en_US');
FORMAT(1.234,4,'en_US')
1.2340
SELECT FORMAT(1.234e-2,4,'en_US');
FORMAT(1.234e-2,4,'en_US')
0.0123
SELECT FORMAT(-1.234,4,'en_US');
FORMAT(-1.234,4,'en_US')
-1.2340
WITH RECURSIVE cte(n) AS (
SELECT 1 n
UNION ALL
SELECT 100+n FROM cte WHERE n<1000
)
SELECT FORMAT(n+0.01,3,'foo_bar') FROM cte;
FORMAT(n+0.01,3,'foo_bar')
1.010
101.010
201.010
301.010
401.010
501.010
601.010
701.010
801.010
901.010
1,001.010
SHOW WARNINGS;
Level Code Message
Warning 1649 Unknown locale: 'foo_bar'
Warning 1649 Unknown locale: 'foo_bar'
Warning 1649 Unknown locale: 'foo_bar'
Warning 1649 Unknown locale: 'foo_bar'
Warning 1649 Unknown locale: 'foo_bar'
Warning 1649 Unknown locale: 'foo_bar'
Warning 1649 Unknown locale: 'foo_bar'
Warning 1649 Unknown locale: 'foo_bar'
Warning 1649 Unknown locale: 'foo_bar'
Warning 1649 Unknown locale: 'foo_bar'
Warning 1649 Unknown locale: 'foo_bar'
15 changes: 15 additions & 0 deletions tests/integrationtest/t/expression/format.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SELECT FORMAT(1.234,0,'en_US');
SELECT FORMAT(1.234,1,'en_US');
SELECT FORMAT(1.234,2,'en_US');
SELECT FORMAT(1.234,3,'en_US');
SELECT FORMAT(1.234,4,'en_US');
SELECT FORMAT(1.234e-2,4,'en_US');
SELECT FORMAT(-1.234,4,'en_US');

WITH RECURSIVE cte(n) AS (
SELECT 1 n
UNION ALL
SELECT 100+n FROM cte WHERE n<1000
)
SELECT FORMAT(n+0.01,3,'foo_bar') FROM cte;
SHOW WARNINGS;