Skip to content

Commit

Permalink
Merge pull request #59756 from ClickHouse/backport/23.3/59739
Browse files Browse the repository at this point in the history
Backport #59739 to 23.3: Fix leftPad / rightPad function with FixedString input
  • Loading branch information
Algunenano authored Feb 8, 2024
2 parents b557756 + 9b950e1 commit a8f0c97
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 1 deletion.
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);

0 comments on commit a8f0c97

Please sign in to comment.