Skip to content

Commit 845a612

Browse files
Merge pull request #6773 from infinivision/fix_issue_6575
fix DataTypeAggregateFunction deserialization
2 parents 0a998fd + fd09478 commit 845a612

6 files changed

Lines changed: 34 additions & 8 deletions

File tree

dbms/src/Common/FieldVisitors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ String FieldVisitorToString::operator() (const DecimalField<Decimal128> & x) con
130130
String FieldVisitorToString::operator() (const UInt128 & x) const { return formatQuoted(UUID(x)); }
131131
String FieldVisitorToString::operator() (const AggregateFunctionStateData & x) const
132132
{
133-
return "(" + formatQuoted(x.name) + ")" + formatQuoted(x.data);
133+
return formatQuoted(x.data);
134134
}
135135

136136
String FieldVisitorToString::operator() (const Array & x) const

dbms/src/DataTypes/DataTypeAggregateFunction.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,11 @@ void DataTypeAggregateFunction::deserializeTextQuoted(IColumn & column, ReadBuff
218218
}
219219

220220

221-
void DataTypeAggregateFunction::deserializeWholeText(IColumn &, ReadBuffer &, const FormatSettings &) const
221+
void DataTypeAggregateFunction::deserializeWholeText(IColumn & column, ReadBuffer & istr, const FormatSettings &) const
222222
{
223-
throw Exception("AggregateFunction data type cannot be read from text", ErrorCodes::NOT_IMPLEMENTED);
223+
String s;
224+
readStringUntilEOF(s, istr);
225+
deserializeFromString(function, column, s);
224226
}
225227

226228

dbms/src/Functions/FunctionsConversion.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <DataTypes/DataTypeNothing.h>
2424
#include <DataTypes/DataTypeUUID.h>
2525
#include <DataTypes/DataTypeInterval.h>
26+
#include <DataTypes/DataTypeAggregateFunction.h>
2627
#include <Formats/FormatSettings.h>
2728
#include <Columns/ColumnString.h>
2829
#include <Columns/ColumnFixedString.h>
@@ -636,7 +637,7 @@ struct ConvertImplGenericFromString
636637
{
637638
ReadBufferFromMemory read_buffer(&chars[current_offset], offsets[i] - current_offset - 1);
638639

639-
data_type_to.deserializeAsTextEscaped(column_to, read_buffer, format_settings);
640+
data_type_to.deserializeAsWholeText(column_to, read_buffer, format_settings);
640641

641642
if (!read_buffer.eof())
642643
throwExceptionForIncompletelyParsedValue(read_buffer, block, result);
@@ -1669,6 +1670,21 @@ class FunctionCast final : public IFunctionBase
16691670
};
16701671
}
16711672

1673+
WrapperType createAggregateFunctionWrapper(const DataTypePtr & from_type_untyped, const DataTypeAggregateFunction * to_type) const
1674+
{
1675+
/// Conversion from String through parsing.
1676+
if (checkAndGetDataType<DataTypeString>(from_type_untyped.get()))
1677+
{
1678+
return [] (Block & block, const ColumnNumbers & arguments, const size_t result, size_t /*input_rows_count*/)
1679+
{
1680+
ConvertImplGenericFromString::execute(block, arguments, result);
1681+
};
1682+
}
1683+
else
1684+
throw Exception{"Conversion from " + from_type_untyped->getName() + " to " + to_type->getName() +
1685+
" is not supported", ErrorCodes::CANNOT_CONVERT_TYPE};
1686+
}
1687+
16721688
WrapperType createArrayWrapper(const DataTypePtr & from_type_untyped, const DataTypeArray * to_type) const
16731689
{
16741690
/// Conversion from String through parsing.
@@ -2145,13 +2161,12 @@ class FunctionCast final : public IFunctionBase
21452161
case TypeIndex::Tuple:
21462162
return createTupleWrapper(from_type, checkAndGetDataType<DataTypeTuple>(to_type.get()));
21472163

2164+
case TypeIndex::AggregateFunction:
2165+
return createAggregateFunctionWrapper(from_type, checkAndGetDataType<DataTypeAggregateFunction>(to_type.get()));
21482166
default:
21492167
break;
21502168
}
21512169

2152-
/// It's possible to use ConvertImplGenericFromString to convert from String to AggregateFunction,
2153-
/// but it is disabled because deserializing aggregate functions state might be unsafe.
2154-
21552170
throw Exception{"Conversion from " + from_type->getName() + " to " + to_type->getName() + " is not supported",
21562171
ErrorCodes::CANNOT_CONVERT_TYPE};
21572172
}

dbms/src/IO/ReadHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#endif
4040

4141

42-
#define DEFAULT_MAX_STRING_SIZE 0x00FFFFFFULL
42+
#define DEFAULT_MAX_STRING_SIZE 0x3FFFFFFFULL
4343

4444

4545
namespace DB
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1000000
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DROP TABLE IF EXISTS numbers500k;
2+
CREATE VIEW numbers500k AS SELECT number FROM system.numbers LIMIT 500000;
3+
4+
SET max_query_size = 1073741824;
5+
6+
SELECT count(*) FROM remote('127.0.0.{2,3}', currentDatabase(), numbers500k) WHERE bitmapContains((SELECT groupBitmapState(number) FROM numbers500k), toUInt32(number));
7+
8+
DROP TABLE numbers500k;

0 commit comments

Comments
 (0)