From 4a55e5f94b0a73b3cfc51b3fa1bcaa5209681c6a Mon Sep 17 00:00:00 2001 From: Vitaliy Lyudvichenko Date: Mon, 30 Oct 2017 15:14:36 +0300 Subject: [PATCH 1/2] Hotfix of CREATE MATERIALIZED VIEW a TO b. [#CLICKHOUSE-2] --- dbms/src/Databases/DatabasesCommon.cpp | 2 +- dbms/src/Parsers/ParserCreateQuery.cpp | 2 ++ dbms/src/Storages/StorageMaterializedView.cpp | 2 +- dbms/tests/queries/0_stateless/00508_materialized_view_to.sql | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dbms/src/Databases/DatabasesCommon.cpp b/dbms/src/Databases/DatabasesCommon.cpp index d2164b5f5e9..73717acf507 100644 --- a/dbms/src/Databases/DatabasesCommon.cpp +++ b/dbms/src/Databases/DatabasesCommon.cpp @@ -35,7 +35,7 @@ String getTableDefinitionFromCreateQuery(const ASTPtr & query) create.select = nullptr; /// For "MATERIALIZED VIEW x TO y" it's necessary to save destination table - if (!(create.is_materialized_view && !create.storage)) + if (!create.is_materialized_view || create.storage) { create.as_database.clear(); create.as_table.clear(); diff --git a/dbms/src/Parsers/ParserCreateQuery.cpp b/dbms/src/Parsers/ParserCreateQuery.cpp index ce97297258a..35b9781b2a6 100644 --- a/dbms/src/Parsers/ParserCreateQuery.cpp +++ b/dbms/src/Parsers/ParserCreateQuery.cpp @@ -364,6 +364,8 @@ bool ParserCreateQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { to_table = true; + /// FIXME: as_table is ambiguous, it is set in AS clause also + if (!name_p.parse(pos, as_table, expected)) return false; diff --git a/dbms/src/Storages/StorageMaterializedView.cpp b/dbms/src/Storages/StorageMaterializedView.cpp index 403d80c641d..778dffdf42c 100644 --- a/dbms/src/Storages/StorageMaterializedView.cpp +++ b/dbms/src/Storages/StorageMaterializedView.cpp @@ -81,7 +81,7 @@ StorageMaterializedView::StorageMaterializedView( DatabaseAndTableName(database_name, table_name)); // If the destination table is not set, use inner table - if (!query.storage) + if (!query.as_table.empty()) { target_database_name = query.as_database; target_table_name = query.as_table; diff --git a/dbms/tests/queries/0_stateless/00508_materialized_view_to.sql b/dbms/tests/queries/0_stateless/00508_materialized_view_to.sql index d2a819ec623..e327f131b23 100644 --- a/dbms/tests/queries/0_stateless/00508_materialized_view_to.sql +++ b/dbms/tests/queries/0_stateless/00508_materialized_view_to.sql @@ -3,7 +3,7 @@ DROP TABLE IF EXISTS test.dst; DROP TABLE IF EXISTS test.mv; CREATE TABLE test.src (x UInt8) ENGINE = Null; -CREATE TABLE test.dst (x UInt8) ENGINE = Memory(); +CREATE TABLE test.dst (x UInt8) ENGINE = Memory; CREATE MATERIALIZED VIEW test.mv TO test.dst AS SELECT * FROM test.src; INSERT INTO test.src VALUES (1), (2); From 4b9163c3cc2803cc70b835dadb827d42aed32489 Mon Sep 17 00:00:00 2001 From: Vitaliy Lyudvichenko Date: Mon, 30 Oct 2017 16:10:22 +0300 Subject: [PATCH 2/2] Fix bash warning in the test. [#CLICKHOUSE-3385] Also use 'clickhouse compressor' util instead of clickhouse-compressor binary. --- .../0_stateless/00429_http_bufferization.sh | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/dbms/tests/queries/0_stateless/00429_http_bufferization.sh b/dbms/tests/queries/0_stateless/00429_http_bufferization.sh index 8946d798c7b..b47cbc5b00d 100755 --- a/dbms/tests/queries/0_stateless/00429_http_bufferization.sh +++ b/dbms/tests/queries/0_stateless/00429_http_bufferization.sh @@ -5,7 +5,8 @@ max_block_size=100 URL='http://localhost:8123/' function query { - echo "SELECT toUInt8(intHash64(number)) FROM system.numbers LIMIT $1 FORMAT RowBinary" + # bash isn't able to store \0 bytes, so use [1; 255] random range + echo "SELECT greatest(toUInt8(1), toUInt8(intHash64(number))) FROM system.numbers LIMIT $1 FORMAT RowBinary" } function ch_url() { @@ -81,13 +82,12 @@ check_cli_and_http # Check HTTP internal compression in normal case -# Skip if clickhouse-compressor not installed function cmp_http_compression() { clickhouse-client -q "`query $1`" > res0 - ch_url 'compress=1' $1 | clickhouse-compressor --decompress > res1 - ch_url "compress=1&buffer_size=$2&wait_end_of_query=0" $1 | clickhouse-compressor --decompress > res2 - ch_url "compress=1&buffer_size=$2&wait_end_of_query=1" $1 | clickhouse-compressor --decompress > res3 + ch_url 'compress=1' $1 | clickhouse compressor --decompress > res1 + ch_url "compress=1&buffer_size=$2&wait_end_of_query=0" $1 | clickhouse compressor --decompress > res2 + ch_url "compress=1&buffer_size=$2&wait_end_of_query=1" $1 | clickhouse compressor --decompress > res3 cmp res0 res1 cmp res1 res2 cmp res1 res3 @@ -103,8 +103,4 @@ function check_http_compression() { done } -has_compressor=$(command -v clickhouse-compressor &>/dev/null && echo 1 || echo 0) - -if [[ $has_compressor -eq 1 ]]; then - check_http_compression -fi +check_http_compression