diff --git a/dbms/src/Common/FieldVisitors.cpp b/dbms/src/Common/FieldVisitors.cpp index 9a437d5ffe6..c5ce10c0db4 100644 --- a/dbms/src/Common/FieldVisitors.cpp +++ b/dbms/src/Common/FieldVisitors.cpp @@ -130,7 +130,7 @@ String FieldVisitorToString::operator() (const DecimalField & x) con String FieldVisitorToString::operator() (const UInt128 & x) const { return formatQuoted(UUID(x)); } String FieldVisitorToString::operator() (const AggregateFunctionStateData & x) const { - return "(" + formatQuoted(x.name) + ")" + formatQuoted(x.data); + return formatQuoted(x.data); } String FieldVisitorToString::operator() (const Array & x) const diff --git a/dbms/src/DataTypes/DataTypeAggregateFunction.cpp b/dbms/src/DataTypes/DataTypeAggregateFunction.cpp index 1855522c713..2c5516e100a 100644 --- a/dbms/src/DataTypes/DataTypeAggregateFunction.cpp +++ b/dbms/src/DataTypes/DataTypeAggregateFunction.cpp @@ -218,9 +218,11 @@ void DataTypeAggregateFunction::deserializeTextQuoted(IColumn & column, ReadBuff } -void DataTypeAggregateFunction::deserializeWholeText(IColumn &, ReadBuffer &, const FormatSettings &) const +void DataTypeAggregateFunction::deserializeWholeText(IColumn & column, ReadBuffer & istr, const FormatSettings &) const { - throw Exception("AggregateFunction data type cannot be read from text", ErrorCodes::NOT_IMPLEMENTED); + String s; + readStringUntilEOF(s, istr); + deserializeFromString(function, column, s); } diff --git a/dbms/src/Functions/FunctionsConversion.h b/dbms/src/Functions/FunctionsConversion.h index 3baca412497..3bb4a795b73 100644 --- a/dbms/src/Functions/FunctionsConversion.h +++ b/dbms/src/Functions/FunctionsConversion.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -636,7 +637,7 @@ struct ConvertImplGenericFromString { ReadBufferFromMemory read_buffer(&chars[current_offset], offsets[i] - current_offset - 1); - data_type_to.deserializeAsTextEscaped(column_to, read_buffer, format_settings); + data_type_to.deserializeAsWholeText(column_to, read_buffer, format_settings); if (!read_buffer.eof()) throwExceptionForIncompletelyParsedValue(read_buffer, block, result); @@ -1668,6 +1669,21 @@ private: } }; } + + WrapperType createAggregateFunctionWrapper(const DataTypePtr & from_type_untyped, const DataTypeAggregateFunction * to_type) const + { + /// Conversion from String through parsing. + if (checkAndGetDataType(from_type_untyped.get())) + { + return [] (Block & block, const ColumnNumbers & arguments, const size_t result, size_t /*input_rows_count*/) + { + ConvertImplGenericFromString::execute(block, arguments, result); + }; + } + else + throw Exception{"Conversion from " + from_type_untyped->getName() + " to " + to_type->getName() + + " is not supported", ErrorCodes::CANNOT_CONVERT_TYPE}; + } WrapperType createArrayWrapper(const DataTypePtr & from_type_untyped, const DataTypeArray * to_type) const { @@ -2145,13 +2161,12 @@ private: case TypeIndex::Tuple: return createTupleWrapper(from_type, checkAndGetDataType(to_type.get())); + case TypeIndex::AggregateFunction: + return createAggregateFunctionWrapper(from_type, checkAndGetDataType(to_type.get())); default: break; } - /// It's possible to use ConvertImplGenericFromString to convert from String to AggregateFunction, - /// but it is disabled because deserializing aggregate functions state might be unsafe. - throw Exception{"Conversion from " + from_type->getName() + " to " + to_type->getName() + " is not supported", ErrorCodes::CANNOT_CONVERT_TYPE}; } diff --git a/dbms/src/IO/ReadHelpers.h b/dbms/src/IO/ReadHelpers.h index 9105f593ed7..1c1d594bb83 100644 --- a/dbms/src/IO/ReadHelpers.h +++ b/dbms/src/IO/ReadHelpers.h @@ -39,7 +39,7 @@ #endif -#define DEFAULT_MAX_STRING_SIZE 0x00FFFFFFULL +#define DEFAULT_MAX_STRING_SIZE 0x3FFFFFFFULL namespace DB