Fixed error; added test [#CLICKHOUSE-3764]

This commit is contained in:
Alexey Milovidov 2018-06-07 23:49:59 +03:00
parent f71eb36719
commit 8901414ad2
3 changed files with 50 additions and 7 deletions

View File

@ -67,9 +67,9 @@ String ColumnsDescription::toString() const
{
WriteBufferFromOwnString buf;
writeString("columns format version: 1\n", buf);
writeCString("columns format version: 1\n", buf);
writeText(ordinary.size() + materialized.size() + aliases.size(), buf);
writeString(" columns:\n", buf);
writeCString(" columns:\n", buf);
const auto write_columns = [this, &buf] (const NamesAndTypesList & columns)
{
@ -79,7 +79,7 @@ String ColumnsDescription::toString() const
writeBackQuotedString(column.name, buf);
writeChar(' ', buf);
writeString(column.type->getName(), buf);
writeText(column.type->getName(), buf);
if (it == std::end(defaults))
{
writeChar('\n', buf);
@ -88,9 +88,9 @@ String ColumnsDescription::toString() const
else
writeChar('\t', buf);
writeString(DB::toString(it->second.kind), buf);
writeText(DB::toString(it->second.kind), buf);
writeChar('\t', buf);
writeString(queryToString(it->second.expression), buf);
writeText(queryToString(it->second.expression), buf);
writeChar('\n', buf);
}
};
@ -123,7 +123,7 @@ ColumnsDescription ColumnsDescription::parse(const String & str)
assertChar(' ', buf);
String type_name;
readString(type_name, buf);
readText(type_name, buf);
auto type = data_type_factory.get(type_name);
if (*buf.position() == '\n')
{
@ -135,7 +135,7 @@ ColumnsDescription ColumnsDescription::parse(const String & str)
assertChar('\t', buf);
String default_kind_str;
readString(default_kind_str, buf);
readText(default_kind_str, buf);
const auto default_kind = columnDefaultKindFromString(default_kind_str);
assertChar('\t', buf);

View File

@ -0,0 +1,5 @@
CREATE TABLE test.cast1 ( x UInt8, e Enum8('hello' = 1, 'world' = 2) DEFAULT CAST(x, 'Enum8(\'hello\' = 1, \'world\' = 2)')) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_cast', 'r1') ORDER BY e SETTINGS index_granularity = 8192
x UInt8
e Enum8(\'hello\' = 1, \'world\' = 2) DEFAULT CAST(x, \'Enum8(\\\'hello\\\' = 1, \\\'world\\\' = 2)\')
1 hello
1 hello

View File

@ -0,0 +1,38 @@
DROP TABLE IF EXISTS test.cast1;
DROP TABLE IF EXISTS test.cast2;
CREATE TABLE test.cast1
(
x UInt8,
e Enum8
(
'hello' = 1,
'world' = 2
)
DEFAULT
CAST
(
x
AS
Enum8
(
'hello' = 1,
'world' = 2
)
)
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_cast', 'r1') ORDER BY e;
SHOW CREATE TABLE test.cast1 FORMAT TSVRaw;
DESC TABLE test.cast1;
INSERT INTO test.cast1 (x) VALUES (1);
SELECT * FROM test.cast1;
CREATE TABLE test.cast2 AS test.cast1 ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_cast', 'r2') ORDER BY e;
SYSTEM SYNC REPLICA test.cast2;
SELECT * FROM test.cast2;
DROP TABLE test.cast1;
DROP TABLE test.cast2;