mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Merge pull request #4523 from yandex/fix_column_description_parse
Fix column description parse. Now creation of replicated MT table wit…
This commit is contained in:
commit
40d8abbc34
@ -210,12 +210,41 @@ void readStringUntilEOFInto(Vector & s, ReadBuffer & buf)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void readStringUntilEOF(String & s, ReadBuffer & buf)
|
||||
{
|
||||
s.clear();
|
||||
readStringUntilEOFInto(s, buf);
|
||||
}
|
||||
|
||||
template <typename Vector>
|
||||
void readEscapedStringUntilEOLInto(Vector & s, ReadBuffer & buf)
|
||||
{
|
||||
while (!buf.eof())
|
||||
{
|
||||
char * next_pos = find_first_symbols<'\n', '\\'>(buf.position(), buf.buffer().end());
|
||||
|
||||
appendToStringOrVector(s, buf, next_pos);
|
||||
buf.position() = next_pos;
|
||||
|
||||
if (!buf.hasPendingData())
|
||||
continue;
|
||||
|
||||
if (*buf.position() == '\n')
|
||||
return;
|
||||
|
||||
if (*buf.position() == '\\')
|
||||
parseComplexEscapeSequence(s, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void readEscapedStringUntilEOL(String & s, ReadBuffer & buf)
|
||||
{
|
||||
s.clear();
|
||||
readEscapedStringUntilEOLInto(s, buf);
|
||||
}
|
||||
|
||||
template void readStringUntilEOFInto<PaddedPODArray<UInt8>>(PaddedPODArray<UInt8> & s, ReadBuffer & buf);
|
||||
|
||||
|
||||
|
@ -403,6 +403,7 @@ void readBackQuotedString(String & s, ReadBuffer & buf);
|
||||
void readBackQuotedStringWithSQLStyle(String & s, ReadBuffer & buf);
|
||||
|
||||
void readStringUntilEOF(String & s, ReadBuffer & buf);
|
||||
void readEscapedStringUntilEOL(String & s, ReadBuffer & buf);
|
||||
|
||||
|
||||
/** Read string in CSV format.
|
||||
|
@ -2,12 +2,14 @@
|
||||
#include <Parsers/ASTLiteral.h>
|
||||
#include <Parsers/ExpressionElementParsers.h>
|
||||
#include <Parsers/ExpressionListParsers.h>
|
||||
#include <Parsers/ParserCreateQuery.h>
|
||||
#include <Parsers/parseQuery.h>
|
||||
#include <Parsers/queryToString.h>
|
||||
#include <IO/WriteBuffer.h>
|
||||
#include <IO/WriteHelpers.h>
|
||||
#include <IO/ReadBuffer.h>
|
||||
#include <IO/ReadHelpers.h>
|
||||
|
||||
#include <IO/WriteBufferFromString.h>
|
||||
#include <IO/ReadBufferFromString.h>
|
||||
#include <DataTypes/DataTypeFactory.h>
|
||||
@ -71,6 +73,30 @@ bool ColumnsDescription::hasPhysical(const String & column_name) const
|
||||
}
|
||||
|
||||
|
||||
bool ColumnsDescription::operator==(const ColumnsDescription & other) const
|
||||
{
|
||||
if (ordinary != other.ordinary
|
||||
|| materialized != other.materialized
|
||||
|| aliases != other.aliases
|
||||
|| defaults != other.defaults
|
||||
|| comments != other.comments)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (codecs.size() != other.codecs.size())
|
||||
return false;
|
||||
|
||||
for (const auto & [col_name, codec_ptr] : codecs)
|
||||
{
|
||||
if (other.codecs.count(col_name) == 0)
|
||||
return false;
|
||||
if (other.codecs.at(col_name)->getCodecDesc() != codec_ptr->getCodecDesc())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
String ColumnsDescription::toString() const
|
||||
{
|
||||
WriteBufferFromOwnString buf;
|
||||
@ -100,14 +126,11 @@ String ColumnsDescription::toString() const
|
||||
writeChar('\t', buf);
|
||||
writeText(queryToString(defaults_it->second.expression), buf);
|
||||
}
|
||||
else if (exist_comment)
|
||||
{
|
||||
writeChar('\t', buf);
|
||||
}
|
||||
|
||||
if (exist_comment)
|
||||
{
|
||||
writeChar('\t', buf);
|
||||
writeText("COMMENT ", buf);
|
||||
writeText(queryToString(ASTLiteral(Field(comments_it->second))), buf);
|
||||
}
|
||||
|
||||
@ -129,78 +152,22 @@ String ColumnsDescription::toString() const
|
||||
return buf.str();
|
||||
}
|
||||
|
||||
std::optional<ColumnDefault> parseDefaultInfo(ReadBufferFromString & buf)
|
||||
{
|
||||
if (*buf.position() == '\n')
|
||||
return {};
|
||||
|
||||
assertChar('\t', buf);
|
||||
if (*buf.position() == '\t')
|
||||
return {};
|
||||
|
||||
String default_kind_str;
|
||||
readText(default_kind_str, buf);
|
||||
const auto default_kind = columnDefaultKindFromString(default_kind_str);
|
||||
assertChar('\t', buf);
|
||||
|
||||
ParserExpression expr_parser;
|
||||
String default_expr_str;
|
||||
readText(default_expr_str, buf);
|
||||
ASTPtr default_expr = parseQuery(expr_parser, default_expr_str, "default_expression", 0);
|
||||
return ColumnDefault{default_kind, std::move(default_expr)};
|
||||
}
|
||||
|
||||
String parseComment(ReadBufferFromString& buf)
|
||||
{
|
||||
if (*buf.position() == '\n')
|
||||
return {};
|
||||
|
||||
assertChar('\t', buf);
|
||||
ParserStringLiteral string_literal_parser;
|
||||
String comment_expr_str;
|
||||
readText(comment_expr_str, buf);
|
||||
ASTPtr comment_expr = parseQuery(string_literal_parser, comment_expr_str, "comment expression", 0);
|
||||
return typeid_cast<ASTLiteral &>(*comment_expr).value.get<String>();
|
||||
}
|
||||
|
||||
CompressionCodecPtr parseCodec(ReadBufferFromString& buf)
|
||||
{
|
||||
if (*buf.position() == '\n')
|
||||
return {};
|
||||
|
||||
assertChar('\t', buf);
|
||||
ParserCodec codec_parser;
|
||||
String codec_expr_str;
|
||||
readText(codec_expr_str, buf);
|
||||
ASTPtr codec_expr = parseQuery(codec_parser, codec_expr_str, "codec expression", 0);
|
||||
if (codec_expr)
|
||||
return CompressionCodecFactory::instance().get(codec_expr);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void parseColumn(ReadBufferFromString & buf, ColumnsDescription & result, const DataTypeFactory & data_type_factory)
|
||||
{
|
||||
String column_name;
|
||||
readBackQuotedStringWithSQLStyle(column_name, buf);
|
||||
assertChar(' ', buf);
|
||||
|
||||
String type_name;
|
||||
readText(type_name, buf);
|
||||
auto type = data_type_factory.get(type_name);
|
||||
if (*buf.position() == '\n')
|
||||
ParserColumnDeclaration column_parser(true);
|
||||
String column_line;
|
||||
readEscapedStringUntilEOL(column_line, buf);
|
||||
ASTPtr ast = parseQuery(column_parser, column_line, "column parser", 0);
|
||||
if (const ASTColumnDeclaration * col_ast = typeid_cast<const ASTColumnDeclaration *>(ast.get()))
|
||||
{
|
||||
assertChar('\n', buf);
|
||||
result.ordinary.emplace_back(column_name, std::move(type));
|
||||
return;
|
||||
}
|
||||
String column_name = col_ast->name;
|
||||
auto type = data_type_factory.get(col_ast->type);
|
||||
|
||||
auto column_default = parseDefaultInfo(buf);
|
||||
if (column_default)
|
||||
{
|
||||
switch (column_default->kind)
|
||||
if (col_ast->default_expression)
|
||||
{
|
||||
auto kind = columnDefaultKindFromString(col_ast->default_specifier);
|
||||
switch (kind)
|
||||
{
|
||||
case ColumnDefaultKind::Default:
|
||||
result.ordinary.emplace_back(column_name, std::move(type));
|
||||
break;
|
||||
@ -209,25 +176,26 @@ void parseColumn(ReadBufferFromString & buf, ColumnsDescription & result, const
|
||||
break;
|
||||
case ColumnDefaultKind::Alias:
|
||||
result.aliases.emplace_back(column_name, std::move(type));
|
||||
break;
|
||||
}
|
||||
|
||||
result.defaults.emplace(column_name, ColumnDefault{kind, std::move(col_ast->default_expression)});
|
||||
}
|
||||
else
|
||||
result.ordinary.emplace_back(column_name, std::move(type));
|
||||
|
||||
result.defaults.emplace(column_name, std::move(*column_default));
|
||||
if (col_ast->comment)
|
||||
if (auto comment_str = typeid_cast<ASTLiteral &>(*col_ast->comment).value.get<String>(); !comment_str.empty())
|
||||
result.comments.emplace(column_name, std::move(comment_str));
|
||||
|
||||
if (col_ast->codec)
|
||||
{
|
||||
auto codec = CompressionCodecFactory::instance().get(col_ast->codec, type);
|
||||
result.codecs.emplace(column_name, std::move(codec));
|
||||
}
|
||||
}
|
||||
|
||||
auto comment = parseComment(buf);
|
||||
if (!comment.empty())
|
||||
{
|
||||
result.comments.emplace(column_name, std::move(comment));
|
||||
}
|
||||
|
||||
auto codec = parseCodec(buf);
|
||||
if (codec)
|
||||
{
|
||||
result.codecs.emplace(column_name, std::move(codec));
|
||||
}
|
||||
|
||||
|
||||
assertChar('\n', buf);
|
||||
else
|
||||
throw Exception("Cannot parse column description", ErrorCodes::CANNOT_PARSE_TEXT);
|
||||
}
|
||||
|
||||
CompressionCodecPtr ColumnsDescription::getCodecOrDefault(const String & column_name, CompressionCodecPtr default_codec) const
|
||||
@ -255,13 +223,13 @@ ColumnsDescription ColumnsDescription::parse(const String & str)
|
||||
readText(count, buf);
|
||||
assertString(" columns:\n", buf);
|
||||
|
||||
ParserExpression expr_parser;
|
||||
const DataTypeFactory & data_type_factory = DataTypeFactory::instance();
|
||||
|
||||
ColumnsDescription result;
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
parseColumn(buf, result, data_type_factory);
|
||||
buf.ignore(1); /// ignore new line
|
||||
}
|
||||
|
||||
assertEOF(buf);
|
||||
|
@ -41,15 +41,7 @@ struct ColumnsDescription
|
||||
|
||||
explicit ColumnsDescription(NamesAndTypesList ordinary_) : ordinary(std::move(ordinary_)) {}
|
||||
|
||||
bool operator==(const ColumnsDescription & other) const
|
||||
{
|
||||
return ordinary == other.ordinary
|
||||
&& materialized == other.materialized
|
||||
&& aliases == other.aliases
|
||||
&& defaults == other.defaults
|
||||
&& comments == other.comments
|
||||
&& codecs == other.codecs;
|
||||
}
|
||||
bool operator==(const ColumnsDescription & other) const;
|
||||
|
||||
bool operator!=(const ColumnsDescription & other) const { return !(*this == other); }
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
CREATE TABLE test.check_comments ( column_name1 UInt8 DEFAULT 1 COMMENT \'comment\') ENGINE = ReplicatedMergeTree(\'clickhouse/tables/test_comments\', \'r1\') ORDER BY column_name1 SETTINGS index_granularity = 8192
|
||||
CREATE TABLE test.check_comments ( column_name1 UInt8 DEFAULT 1 COMMENT \'comment\', column_name2 UInt8 COMMENT \'non default comment\') ENGINE = ReplicatedMergeTree(\'clickhouse/tables/test_comments\', \'r1\') ORDER BY column_name1 SETTINGS index_granularity = 8192
|
||||
column_name1 UInt8 DEFAULT 1 comment
|
||||
CREATE TABLE test.check_comments ( column_name1 UInt8 DEFAULT 1 COMMENT \'another comment\') ENGINE = ReplicatedMergeTree(\'clickhouse/tables/test_comments\', \'r1\') ORDER BY column_name1 SETTINGS index_granularity = 8192
|
||||
column_name2 UInt8 non default comment
|
||||
CREATE TABLE test.check_comments ( column_name1 UInt8 DEFAULT 1 COMMENT \'another comment\', column_name2 UInt8 COMMENT \'non default comment\') ENGINE = ReplicatedMergeTree(\'clickhouse/tables/test_comments\', \'r1\') ORDER BY column_name1 SETTINGS index_granularity = 8192
|
||||
column_name1 UInt8 DEFAULT 1 another comment
|
||||
column_name2 UInt8 non default comment
|
||||
|
@ -2,7 +2,8 @@ DROP TABLE IF EXISTS test.check_comments;
|
||||
|
||||
CREATE TABLE test.check_comments
|
||||
(
|
||||
column_name1 UInt8 DEFAULT 1 COMMENT 'comment'
|
||||
column_name1 UInt8 DEFAULT 1 COMMENT 'comment',
|
||||
column_name2 UInt8 COMMENT 'non default comment'
|
||||
) ENGINE = ReplicatedMergeTree('clickhouse/tables/test_comments', 'r1')
|
||||
ORDER BY column_name1;
|
||||
|
||||
|
@ -0,0 +1,27 @@
|
||||
1 hello 2018-12-14 1.1 aaa 5
|
||||
2 world 2018-12-15 2.2 bbb 6
|
||||
3 ! 2018-12-16 3.3 ccc 7
|
||||
1 hello 2018-12-14 1.1 aaa 5
|
||||
2 world 2018-12-15 2.2 bbb 6
|
||||
3 ! 2018-12-16 3.3 ccc 7
|
||||
2
|
||||
2
|
||||
1 world 2018-10-05 1.1
|
||||
2 hello 2018-10-01 2.2
|
||||
3 buy 2018-10-11 3.3
|
||||
1 world 2018-10-05 1.1
|
||||
2 hello 2018-10-01 2.2
|
||||
3 buy 2018-10-11 3.3
|
||||
10003
|
||||
10003
|
||||
10003
|
||||
10003
|
||||
274972506.6
|
||||
274972506.6
|
||||
9175437371954010821
|
||||
9175437371954010821
|
||||
CREATE TABLE test.compression_codec_multiple_more_types_replicated ( id Decimal(38, 13) CODEC(ZSTD(1), LZ4, ZSTD(1), ZSTD(1), Delta(2), Delta(4), Delta(1), LZ4HC(0)), data FixedString(12) CODEC(ZSTD(1), ZSTD(1), Delta(1), Delta(1), Delta(1), NONE, NONE, NONE, LZ4HC(0)), `ddd.age` Array(UInt8) CODEC(LZ4, LZ4HC(0), NONE, NONE, NONE, ZSTD(1), Delta(8)), `ddd.Name` Array(String) CODEC(LZ4, LZ4HC(0), NONE, NONE, NONE, ZSTD(1), Delta(8))) ENGINE = ReplicatedMergeTree(\'/clickhouse/tables/test/compression_codec_multiple_more_types_replicated\', \'1\') ORDER BY tuple() SETTINGS index_granularity = 8192
|
||||
1.5555555555555 hello world! [77] ['John']
|
||||
7.1000000000000 xxxxxxxxxxxx [127] ['Henry']
|
||||
!
|
||||
222
|
@ -0,0 +1,136 @@
|
||||
SET send_logs_level = 'none';
|
||||
|
||||
DROP TABLE IF EXISTS test.compression_codec_replicated;
|
||||
|
||||
CREATE TABLE test.compression_codec_replicated1(
|
||||
id UInt64 CODEC(LZ4),
|
||||
data String CODEC(ZSTD),
|
||||
ddd Date CODEC(NONE),
|
||||
somenum Float64 CODEC(ZSTD(2)),
|
||||
somestr FixedString(3) CODEC(LZ4HC(7)),
|
||||
othernum Int64 CODEC(Delta)
|
||||
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/compression_codec_replicated', '1') ORDER BY tuple();
|
||||
|
||||
CREATE TABLE test.compression_codec_replicated2(
|
||||
id UInt64 CODEC(LZ4),
|
||||
data String CODEC(ZSTD),
|
||||
ddd Date CODEC(NONE),
|
||||
somenum Float64 CODEC(ZSTD(2)),
|
||||
somestr FixedString(3) CODEC(LZ4HC(7)),
|
||||
othernum Int64 CODEC(Delta)
|
||||
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/compression_codec_replicated', '2') ORDER BY tuple();
|
||||
|
||||
|
||||
INSERT INTO test.compression_codec_replicated1 VALUES(1, 'hello', toDate('2018-12-14'), 1.1, 'aaa', 5);
|
||||
INSERT INTO test.compression_codec_replicated1 VALUES(2, 'world', toDate('2018-12-15'), 2.2, 'bbb', 6);
|
||||
INSERT INTO test.compression_codec_replicated1 VALUES(3, '!', toDate('2018-12-16'), 3.3, 'ccc', 7);
|
||||
|
||||
SYSTEM SYNC REPLICA test.compression_codec_replicated2;
|
||||
|
||||
SELECT * FROM test.compression_codec_replicated1 ORDER BY id;
|
||||
SELECT * FROM test.compression_codec_replicated2 ORDER BY id;
|
||||
|
||||
OPTIMIZE TABLE test.compression_codec_replicated1 FINAL;
|
||||
|
||||
INSERT INTO test.compression_codec_replicated1 VALUES(2, '', toDate('2018-12-13'), 4.4, 'ddd', 8);
|
||||
|
||||
SYSTEM SYNC REPLICA test.compression_codec_replicated2;
|
||||
|
||||
DETACH TABLE test.compression_codec_replicated1;
|
||||
ATTACH TABLE test.compression_codec_replicated1;
|
||||
|
||||
SELECT count(*) FROM test.compression_codec_replicated1 WHERE id = 2 GROUP BY id;
|
||||
SELECT count(*) FROM test.compression_codec_replicated2 WHERE id = 2 GROUP BY id;
|
||||
|
||||
DROP TABLE IF EXISTS test.compression_codec_replicated1;
|
||||
DROP TABLE IF EXISTS test.compression_codec_replicated2;
|
||||
|
||||
DROP TABLE IF EXISTS test.compression_codec_multiple_replicated1;
|
||||
DROP TABLE IF EXISTS test.compression_codec_multiple_replicated2;
|
||||
|
||||
SET network_compression_method = 'lz4hc';
|
||||
|
||||
CREATE TABLE test.compression_codec_multiple_replicated1 (
|
||||
id UInt64 CODEC(LZ4, ZSTD, NONE, LZ4HC, Delta(4)),
|
||||
data String CODEC(ZSTD(2), NONE, Delta(2), LZ4HC, LZ4, LZ4, Delta(8)),
|
||||
ddd Date CODEC(NONE, NONE, NONE, Delta(1), LZ4, ZSTD, LZ4HC, LZ4HC),
|
||||
somenum Float64 CODEC(Delta(4), LZ4, LZ4, ZSTD(2), LZ4HC(5), ZSTD(3), ZSTD)
|
||||
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/compression_codec_multiple', '1') ORDER BY tuple();
|
||||
|
||||
CREATE TABLE test.compression_codec_multiple_replicated2 (
|
||||
id UInt64 CODEC(LZ4, ZSTD, NONE, LZ4HC, Delta(4)),
|
||||
data String CODEC(ZSTD(2), NONE, Delta(2), LZ4HC, LZ4, LZ4, Delta(8)),
|
||||
ddd Date CODEC(NONE, NONE, NONE, Delta(1), LZ4, ZSTD, LZ4HC, LZ4HC),
|
||||
somenum Float64 CODEC(Delta(4), LZ4, LZ4, ZSTD(2), LZ4HC(5), ZSTD(3), ZSTD)
|
||||
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/compression_codec_multiple', '2') ORDER BY tuple();
|
||||
|
||||
|
||||
INSERT INTO test.compression_codec_multiple_replicated2 VALUES (1, 'world', toDate('2018-10-05'), 1.1), (2, 'hello', toDate('2018-10-01'), 2.2), (3, 'buy', toDate('2018-10-11'), 3.3);
|
||||
|
||||
SYSTEM SYNC REPLICA test.compression_codec_multiple_replicated1;
|
||||
|
||||
SELECT * FROM test.compression_codec_multiple_replicated2 ORDER BY id;
|
||||
SELECT * FROM test.compression_codec_multiple_replicated1 ORDER BY id;
|
||||
|
||||
INSERT INTO test.compression_codec_multiple_replicated1 select modulo(number, 100), toString(number), toDate('2018-12-01'), 5.5 * number FROM system.numbers limit 10000;
|
||||
|
||||
SYSTEM SYNC REPLICA test.compression_codec_multiple_replicated2;
|
||||
|
||||
SELECT count(*) FROM test.compression_codec_multiple_replicated1;
|
||||
SELECT count(*) FROM test.compression_codec_multiple_replicated2;
|
||||
|
||||
SELECT count(distinct data) FROM test.compression_codec_multiple_replicated1;
|
||||
SELECT count(distinct data) FROM test.compression_codec_multiple_replicated2;
|
||||
|
||||
SELECT floor(sum(somenum), 1) FROM test.compression_codec_multiple_replicated1;
|
||||
SELECT floor(sum(somenum), 1) FROM test.compression_codec_multiple_replicated2;
|
||||
|
||||
TRUNCATE TABLE test.compression_codec_multiple_replicated1;
|
||||
SYSTEM SYNC REPLICA test.compression_codec_multiple_replicated2;
|
||||
|
||||
INSERT INTO test.compression_codec_multiple_replicated1 select modulo(number, 100), toString(number), toDate('2018-12-01'), 5.5 * number FROM system.numbers limit 10000;
|
||||
|
||||
SYSTEM SYNC REPLICA test.compression_codec_multiple_replicated2;
|
||||
|
||||
SELECT sum(cityHash64(*)) FROM test.compression_codec_multiple_replicated2;
|
||||
SELECT sum(cityHash64(*)) FROM test.compression_codec_multiple_replicated1;
|
||||
|
||||
DROP TABLE IF EXISTS test.compression_codec_multiple_replicated1;
|
||||
DROP TABLE IF EXISTS test.compression_codec_multiple_replicated2;
|
||||
|
||||
DROP TABLE IF EXISTS test.compression_codec_multiple_more_types_replicated;
|
||||
|
||||
CREATE TABLE test.compression_codec_multiple_more_types_replicated (
|
||||
id Decimal128(13) CODEC(ZSTD, LZ4, ZSTD, ZSTD, Delta(2), Delta(4), Delta(1), LZ4HC),
|
||||
data FixedString(12) CODEC(ZSTD, ZSTD, Delta, Delta, Delta, NONE, NONE, NONE, LZ4HC),
|
||||
ddd Nested (age UInt8, Name String) CODEC(LZ4, LZ4HC, NONE, NONE, NONE, ZSTD, Delta(8))
|
||||
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/compression_codec_multiple_more_types_replicated', '1') ORDER BY tuple();
|
||||
|
||||
SHOW CREATE TABLE test.compression_codec_multiple_more_types_replicated;
|
||||
|
||||
INSERT INTO test.compression_codec_multiple_more_types_replicated VALUES(1.5555555555555, 'hello world!', [77], ['John']);
|
||||
INSERT INTO test.compression_codec_multiple_more_types_replicated VALUES(7.1, 'xxxxxxxxxxxx', [127], ['Henry']);
|
||||
|
||||
SELECT * FROM test.compression_codec_multiple_more_types_replicated order by id;
|
||||
|
||||
DROP TABLE IF EXISTS test.compression_codec_multiple_with_key_replicated;
|
||||
|
||||
SET network_compression_method = 'zstd';
|
||||
SET network_zstd_compression_level = 5;
|
||||
|
||||
CREATE TABLE test.compression_codec_multiple_with_key_replicated (
|
||||
somedate Date CODEC(ZSTD, ZSTD, ZSTD(12), LZ4HC(12), Delta, Delta),
|
||||
id UInt64 CODEC(LZ4, ZSTD, Delta, NONE, LZ4HC, Delta),
|
||||
data String CODEC(ZSTD(2), Delta, LZ4HC, NONE, LZ4, LZ4)
|
||||
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/compression_codec_multiple_with_key_replicated', '1') PARTITION BY somedate ORDER BY id SETTINGS index_granularity = 2;
|
||||
|
||||
|
||||
INSERT INTO test.compression_codec_multiple_with_key_replicated VALUES(toDate('2018-10-12'), 100000, 'hello'), (toDate('2018-10-12'), 100002, 'world'), (toDate('2018-10-12'), 1111, '!');
|
||||
|
||||
SELECT data FROM test.compression_codec_multiple_with_key_replicated WHERE id BETWEEN 3 AND 1112;
|
||||
|
||||
INSERT INTO test.compression_codec_multiple_with_key_replicated SELECT toDate('2018-10-12'), number, toString(number) FROM system.numbers LIMIT 1000;
|
||||
|
||||
SELECT COUNT(DISTINCT data) FROM test.compression_codec_multiple_with_key_replicated WHERE id < 222;
|
||||
|
||||
DROP TABLE IF EXISTS test.compression_codec_multiple_with_key_replicated;
|
@ -0,0 +1,48 @@
|
||||
2018-01-01 1
|
||||
2018-01-01 2
|
||||
2018-01-01 1
|
||||
2018-01-01 2
|
||||
CODEC(ZSTD(1))
|
||||
CODEC(ZSTD(1))
|
||||
2018-01-01 1 default_value
|
||||
2018-01-01 2 default_value
|
||||
2018-01-01 3 3
|
||||
2018-01-01 4 4
|
||||
2018-01-01 1 default_value
|
||||
2018-01-01 2 default_value
|
||||
2018-01-01 3 3
|
||||
2018-01-01 4 4
|
||||
CODEC(NONE)
|
||||
CODEC(NONE)
|
||||
2018-01-01 1 default_value
|
||||
2018-01-01 2 default_value
|
||||
2018-01-01 3 3
|
||||
2018-01-01 4 4
|
||||
2018-01-01 5 5
|
||||
2018-01-01 6 6
|
||||
2018-01-01 1 default_value
|
||||
2018-01-01 2 default_value
|
||||
2018-01-01 3 3
|
||||
2018-01-01 4 4
|
||||
2018-01-01 5 5
|
||||
2018-01-01 6 6
|
||||
CODEC(ZSTD(1), LZ4HC(0), LZ4, LZ4, NONE)
|
||||
CODEC(ZSTD(1), LZ4HC(0), LZ4, LZ4, NONE)
|
||||
2018-01-01 1 default_value
|
||||
2018-01-01 2 default_value
|
||||
2018-01-01 3 3
|
||||
2018-01-01 4 4
|
||||
2018-01-01 5 5
|
||||
2018-01-01 6 6
|
||||
2018-01-01 7 7
|
||||
2018-01-01 8 8
|
||||
2018-01-01 1 default_value
|
||||
2018-01-01 2 default_value
|
||||
2018-01-01 3 3
|
||||
2018-01-01 4 4
|
||||
2018-01-01 5 5
|
||||
2018-01-01 6 6
|
||||
2018-01-01 7 7
|
||||
2018-01-01 8 8
|
||||
CODEC(ZSTD(1), LZ4HC(0), LZ4, LZ4, NONE)
|
||||
CODEC(ZSTD(1), LZ4HC(0), LZ4, LZ4, NONE)
|
@ -0,0 +1,65 @@
|
||||
SET send_logs_level = 'none';
|
||||
|
||||
DROP TABLE IF EXISTS test.alter_compression_codec1;
|
||||
DROP TABLE IF EXISTS test.alter_compression_codec2;
|
||||
|
||||
CREATE TABLE test.alter_compression_codec1 (
|
||||
somedate Date CODEC(LZ4),
|
||||
id UInt64 CODEC(NONE)
|
||||
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/alter_compression_codecs', '1') PARTITION BY somedate ORDER BY id;
|
||||
|
||||
CREATE TABLE test.alter_compression_codec2 (
|
||||
somedate Date CODEC(LZ4),
|
||||
id UInt64 CODEC(NONE)
|
||||
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/alter_compression_codecs', '2') PARTITION BY somedate ORDER BY id;
|
||||
|
||||
INSERT INTO test.alter_compression_codec1 VALUES('2018-01-01', 1);
|
||||
INSERT INTO test.alter_compression_codec1 VALUES('2018-01-01', 2);
|
||||
SYSTEM SYNC REPLICA test.alter_compression_codec2;
|
||||
|
||||
SELECT * FROM test.alter_compression_codec1 ORDER BY id;
|
||||
SELECT * FROM test.alter_compression_codec2 ORDER BY id;
|
||||
|
||||
ALTER TABLE test.alter_compression_codec1 ADD COLUMN alter_column String DEFAULT 'default_value' CODEC(ZSTD);
|
||||
SYSTEM SYNC REPLICA test.alter_compression_codec2;
|
||||
|
||||
SELECT compression_codec FROM system.columns WHERE database = 'test' AND table = 'alter_compression_codec1' AND name = 'alter_column';
|
||||
SELECT compression_codec FROM system.columns WHERE database = 'test' AND table = 'alter_compression_codec2' AND name = 'alter_column';
|
||||
|
||||
INSERT INTO test.alter_compression_codec1 VALUES('2018-01-01', 3, '3');
|
||||
INSERT INTO test.alter_compression_codec1 VALUES('2018-01-01', 4, '4');
|
||||
SYSTEM SYNC REPLICA test.alter_compression_codec2;
|
||||
|
||||
SELECT * FROM test.alter_compression_codec1 ORDER BY id;
|
||||
SELECT * FROM test.alter_compression_codec2 ORDER BY id;
|
||||
|
||||
ALTER TABLE test.alter_compression_codec1 MODIFY COLUMN alter_column CODEC(NONE);
|
||||
SELECT compression_codec FROM system.columns WHERE database = 'test' AND table = 'alter_compression_codec1' AND name = 'alter_column';
|
||||
SELECT compression_codec FROM system.columns WHERE database = 'test' AND table = 'alter_compression_codec2' AND name = 'alter_column';
|
||||
|
||||
INSERT INTO test.alter_compression_codec2 VALUES('2018-01-01', 5, '5');
|
||||
INSERT INTO test.alter_compression_codec2 VALUES('2018-01-01', 6, '6');
|
||||
SYSTEM SYNC REPLICA test.alter_compression_codec1;
|
||||
SELECT * FROM test.alter_compression_codec1 ORDER BY id;
|
||||
SELECT * FROM test.alter_compression_codec2 ORDER BY id;
|
||||
|
||||
ALTER TABLE test.alter_compression_codec1 MODIFY COLUMN alter_column CODEC(ZSTD, LZ4HC, LZ4, LZ4, NONE);
|
||||
SYSTEM SYNC REPLICA test.alter_compression_codec1;
|
||||
SYSTEM SYNC REPLICA test.alter_compression_codec2;
|
||||
SELECT compression_codec FROM system.columns WHERE database = 'test' AND table = 'alter_compression_codec1' AND name = 'alter_column';
|
||||
SELECT compression_codec FROM system.columns WHERE database = 'test' AND table = 'alter_compression_codec2' AND name = 'alter_column';
|
||||
|
||||
INSERT INTO test.alter_compression_codec1 VALUES('2018-01-01', 7, '7');
|
||||
INSERT INTO test.alter_compression_codec2 VALUES('2018-01-01', 8, '8');
|
||||
SYSTEM SYNC REPLICA test.alter_compression_codec2;
|
||||
SYSTEM SYNC REPLICA test.alter_compression_codec1;
|
||||
SELECT * FROM test.alter_compression_codec1 ORDER BY id;
|
||||
SELECT * FROM test.alter_compression_codec2 ORDER BY id;
|
||||
|
||||
ALTER TABLE test.alter_compression_codec1 MODIFY COLUMN alter_column FixedString(100);
|
||||
SYSTEM SYNC REPLICA test.alter_compression_codec2;
|
||||
SELECT compression_codec FROM system.columns WHERE database = 'test' AND table = 'alter_compression_codec1' AND name = 'alter_column';
|
||||
SELECT compression_codec FROM system.columns WHERE database = 'test' AND table = 'alter_compression_codec2' AND name = 'alter_column';
|
||||
|
||||
DROP TABLE IF EXISTS test.alter_compression_codec1;
|
||||
DROP TABLE IF EXISTS test.alter_compression_codec2;
|
Loading…
Reference in New Issue
Block a user