From fe83c8dab1152c27c6d0d28ef32a9398843c4f82 Mon Sep 17 00:00:00 2001 From: Alexey Zatelepin Date: Thu, 5 Jul 2018 17:19:33 +0300 Subject: [PATCH] stricter validation of mutation commands #2588 --- dbms/src/Storages/MutationCommands.cpp | 5 +++++ .../00652_replicated_mutations_zookeeper.reference | 2 ++ .../00652_replicated_mutations_zookeeper.sh | 12 ++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/dbms/src/Storages/MutationCommands.cpp b/dbms/src/Storages/MutationCommands.cpp index ff36f6ed27e..0ce99d9b73c 100644 --- a/dbms/src/Storages/MutationCommands.cpp +++ b/dbms/src/Storages/MutationCommands.cpp @@ -45,6 +45,11 @@ void MutationCommands::validate(const IStorage & table, const Context & context) case MutationCommand::DELETE: { auto actions = ExpressionAnalyzer(command.predicate, context, {}, all_columns).getActions(true); + + /// Try executing the resulting actions on the table sample block to detect malformed queries. + auto table_sample_block = table.getSampleBlock(); + actions->execute(table_sample_block); + const ColumnWithTypeAndName & predicate_column = actions->getSampleBlock().getByName( command.predicate->getColumnName()); checkColumnCanBeUsedAsFilter(predicate_column); diff --git a/dbms/tests/queries/0_stateless/00652_replicated_mutations_zookeeper.reference b/dbms/tests/queries/0_stateless/00652_replicated_mutations_zookeeper.reference index 85687101109..a82c2571055 100644 --- a/dbms/tests/queries/0_stateless/00652_replicated_mutations_zookeeper.reference +++ b/dbms/tests/queries/0_stateless/00652_replicated_mutations_zookeeper.reference @@ -1,3 +1,5 @@ +Query should fail 1 +Query should fail 2 2000-01-01 2 b 2000-01-01 5 e 2000-02-01 2 b diff --git a/dbms/tests/queries/0_stateless/00652_replicated_mutations_zookeeper.sh b/dbms/tests/queries/0_stateless/00652_replicated_mutations_zookeeper.sh index 446b61ccb89..c652596cd1a 100755 --- a/dbms/tests/queries/0_stateless/00652_replicated_mutations_zookeeper.sh +++ b/dbms/tests/queries/0_stateless/00652_replicated_mutations_zookeeper.sh @@ -13,17 +13,22 @@ ${CLICKHOUSE_CLIENT} --query="CREATE TABLE test.mutations_r2(d Date, x UInt32, s ${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.mutations_r1 DELETE WHERE x = 1" # Insert some data -${CLICKHOUSE_CLIENT} --query="INSERT INTO test.mutations_r1 VALUES ('2000-01-01', 1, 'a')" -${CLICKHOUSE_CLIENT} --query="INSERT INTO test.mutations_r1 VALUES \ +${CLICKHOUSE_CLIENT} --query="INSERT INTO test.mutations_r1(d, x, s) VALUES \ + ('2000-01-01', 1, 'a')" +${CLICKHOUSE_CLIENT} --query="INSERT INTO test.mutations_r1(d, x, s) VALUES \ ('2000-01-01', 2, 'b'), ('2000-01-01', 3, 'c'), ('2000-01-01', 4, 'd') \ ('2000-02-01', 2, 'b'), ('2000-02-01', 3, 'c'), ('2000-02-01', 4, 'd')" +# Try some malformed queries that should fail validation. +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.mutations_r1 DELETE WHERE nonexistent = 0" 2>/dev/null || echo "Query should fail 1" +${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.mutations_r1 DELETE WHERE d = '11'" 2>/dev/null || echo "Query should fail 2" + # Delete some values ${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.mutations_r1 DELETE WHERE x % 2 = 1" ${CLICKHOUSE_CLIENT} --query="ALTER TABLE test.mutations_r1 DELETE WHERE s = 'd'" # Insert more data -${CLICKHOUSE_CLIENT} --query="INSERT INTO test.mutations_r1 VALUES \ +${CLICKHOUSE_CLIENT} --query="INSERT INTO test.mutations_r1(d, x, s) VALUES \ ('2000-01-01', 5, 'e'), ('2000-02-01', 5, 'e')" # Wait until all mutations are done. @@ -36,7 +41,6 @@ do if [[ $i -eq 100 ]]; then echo "Timed out while waiting for mutations to execute!" - exit 1 fi done