Skip to content

Commit

Permalink
Merge pull request ClickHouse#69455 from yariks5s/group_concat_return…
Browse files Browse the repository at this point in the history
…_string

`groupConcat` consistency with `arrayStringConcat`
  • Loading branch information
yariks5s authored Sep 11, 2024
2 parents 7a3d69b + f588e3c commit ccfb7ad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/AggregateFunctions/AggregateFunctionGroupConcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,17 @@ class GroupConcatImpl final
SerializationPtr serialization;
UInt64 limit;
const String delimiter;
const DataTypePtr type;

public:
GroupConcatImpl(const DataTypePtr & data_type_, const Array & parameters_, UInt64 limit_, const String & delimiter_)
: IAggregateFunctionDataHelper<GroupConcatData<has_limit>, GroupConcatImpl<has_limit>>(
{data_type_}, parameters_, std::make_shared<DataTypeString>())
, serialization(this->argument_types[0]->getDefaultSerialization())
, limit(limit_)
, delimiter(delimiter_)
, type(data_type_)
{
serialization = isFixedString(type) ? std::make_shared<DataTypeString>()->getDefaultSerialization() : this->argument_types[0]->getDefaultSerialization();
}

String getName() const override { return name; }
Expand All @@ -140,7 +142,14 @@ class GroupConcatImpl final
if (cur_data.data_size != 0)
cur_data.insertChar(delimiter.c_str(), delimiter.size(), arena);

cur_data.insert(columns[0], serialization, row_num, arena);
if (isFixedString(type))
{
ColumnWithTypeAndName col = {columns[0]->getPtr(), type, "column"};
const auto & col_str = castColumn(col, std::make_shared<DataTypeString>());
cur_data.insert(col_str.get(), serialization, row_num, arena);
}
else
cur_data.insert(columns[0], serialization, row_num, arena);
}

void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena * arena) const override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
10 changes: 10 additions & 0 deletions tests/queries/0_stateless/03235_groupArray_string_consistency.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE t (st FixedString(54)) ENGINE=MergeTree ORDER BY ();

INSERT INTO t VALUES
('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRTUVWXYZ'),
('\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'),
('IIIIIIIIII\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0');

WITH (SELECT groupConcat(',')(st) FROM t) AS a,
(SELECT groupConcat(',')(st :: String) FROM t) AS b
SELECT equals(a, b);

0 comments on commit ccfb7ad

Please sign in to comment.