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

Backport #59739 to 23.3: Fix leftPad / rightPad function with FixedString input #59756

Merged
merged 1 commit into from
Feb 8, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Functions/padString.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Columns/ColumnFixedString.h>
#include <Columns/ColumnString.h>
#include <DataTypes/DataTypeString.h>
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionHelpers.h>
#include <Functions/GatherUtils/Algorithms.h>
Expand Down Expand Up @@ -188,7 +189,7 @@ namespace
arguments[2]->getName(),
getName());

return arguments[0];
return std::make_shared<DataTypeString>();
}

ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
Expand Down
124 changes: 124 additions & 0 deletions tests/queries/0_stateless/02986_leftpad_fixedstring.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@

a String

a String
1 1 1
61 1 1 1
6162 1 1 1
616263 1 1 1
61626333 1 1 1
6162633334 1 1 1
616263333433 1 1 1
61626333343332 1 1 1
6162633334333234 1 1 1
206162633334333234 1 1 1
20206162633334333234 1 1 1
2020206162633334333234 1 1 1
202020206162633334333234 1 1 1
20202020206162633334333234 1 1 1
2020202020206162633334333234 1 1 1
202020202020206162633334333234 1 1 1
20202020202020206162633334333234 1 1 1
2020202020202020206162633334333234 1 1 1
202020202020202020206162633334333234 1 1 1
20202020202020202020206162633334333234 1 1 1
1 1 1
61 1 1 1
6162 1 1 1
616263 1 1 1
61626333 1 1 1
6162633334 1 1 1
616263333433 1 1 1
61626333343332 1 1 1
6162633334333234 1 1 1
616263333433323420 1 1 1
61626333343332342020 1 1 1
6162633334333234202020 1 1 1
616263333433323420202020 1 1 1
61626333343332342020202020 1 1 1
6162633334333234202020202020 1 1 1
616263333433323420202020202020 1 1 1
61626333343332342020202020202020 1 1 1
6162633334333234202020202020202020 1 1 1
616263333433323420202020202020202020 1 1 1
61626333343332342020202020202020202020 1 1 1
1
61 1
6162 1
616263 1
61626333 1
6162633334 1
616263333433 1
61626333343332 1
6162633334333234 1
F09F87AA6162633334333234 1
F09F87AAF09F87B86162633334333234 1
F09F87AAF09F87B8F09F87AA6162633334333234 1
F09F87AAF09F87B8F09F87AAF09F87B86162633334333234 1
F09F87AAF09F87B8F09F87AAF09F87B8F09F87AA6162633334333234 1
F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B86162633334333234 1
F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AA6162633334333234 1
F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B86162633334333234 1
F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AA6162633334333234 1
F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B86162633334333234 1
F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AA6162633334333234 1
1
61 1
6162 1
616263 1
61626333 1
6162633334 1
616263333433 1
61626333343332 1
6162633334333234 1
6162633334333234F09F87AA 1
6162633334333234F09F87AAF09F87B8 1
6162633334333234F09F87AAF09F87B8F09F87AA 1
6162633334333234F09F87AAF09F87B8F09F87AAF09F87B8 1
6162633334333234F09F87AAF09F87B8F09F87AAF09F87B8F09F87AA 1
6162633334333234F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8 1
6162633334333234F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AA 1
6162633334333234F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8 1
6162633334333234F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AA 1
6162633334333234F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8 1
6162633334333234F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AAF09F87B8F09F87AA 1
1
F09F87AA 1
F09F87AAF09F87B8 1
C391F09F87AAF09F87B8 1
C391C391F09F87AAF09F87B8 1
C391C391C391F09F87AAF09F87B8 1
C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391C391C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391C391C391C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391C391C391C391C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391C391C391C391C391C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391C391C391C391C391C391C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391C391C391C391C391C391C391C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391C391C391C391C391C391C391C391C391C391C391C391F09F87AAF09F87B8 1
C391C391C391C391C391C391C391C391C391C391C391C391C391C391C391C391C391F09F87AAF09F87B8 1
1
F09F87AA 1
F09F87AAF09F87B8 1
F09F87AAF09F87B8C391 1
F09F87AAF09F87B8C391C391 1
F09F87AAF09F87B8C391C391C391 1
F09F87AAF09F87B8C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391C391C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391C391C391C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391C391C391C391C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391C391C391C391C391C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391C391C391C391C391C391C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391C391C391C391C391C391C391C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391C391C391C391C391C391C391C391C391C391C391C391 1
F09F87AAF09F87B8C391C391C391C391C391C391C391C391C391C391C391C391C391C391C391C391C391 1
41 changes: 41 additions & 0 deletions tests/queries/0_stateless/02986_leftpad_fixedstring.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- https://github.com/ClickHouse/ClickHouse/issues/59604
SELECT leftPad(toFixedString('abc', 3), 0), leftPad('abc', CAST('0', 'Int32'));
SELECT leftPad(toFixedString('abc343243424324', 15), 1) as a, toTypeName(a);

SELECT rightPad(toFixedString('abc', 3), 0), rightPad('abc', CAST('0', 'Int32'));
SELECT rightPad(toFixedString('abc343243424324', 15), 1) as a, toTypeName(a);

SELECT
hex(leftPad(toFixedString('abc34324' as s, 8), number)) as result,
hex(leftPad(s, number)) = result,
hex(leftPadUTF8(toFixedString(s, 8), number)) = result,
hex(leftPadUTF8(s, number)) = result
FROM numbers(20);

SELECT
hex(rightPad(toFixedString('abc34324' as s, 8), number)) as result,
hex(rightPad(s, number)) = result,
hex(rightPadUTF8(toFixedString(s, 8), number)) = result,
hex(rightPadUTF8(s, number)) = result
FROM numbers(20);

-- I'm not confident the behaviour should be like this. I'm only testing memory problems
SELECT
hex(leftPadUTF8(toFixedString('abc34324' as s, 8), number, '🇪🇸')) as result,
hex(leftPadUTF8(s, number, '🇪🇸')) = result
FROM numbers(20);

SELECT
hex(rightPadUTF8(toFixedString('abc34324' as s, 8), number, '🇪🇸')) as result,
hex(rightPadUTF8(s, number, '🇪🇸')) = result
FROM numbers(20);

SELECT
hex(leftPadUTF8(toFixedString('🇪🇸' as s, 8), number, 'Ñ')) as result,
hex(leftPadUTF8(s, number, 'Ñ')) = result
FROM numbers(20);

SELECT
hex(rightPadUTF8(toFixedString('🇪🇸' as s, 8), number, 'Ñ')) as result,
hex(rightPadUTF8(s, number, 'Ñ')) = result
FROM numbers(20);