Addition to prev. revision

This commit is contained in:
Alexey Milovidov 2019-08-25 01:04:36 +03:00
parent 2fc177830c
commit 17a1938f0f
4 changed files with 8 additions and 10 deletions

View File

@ -34,12 +34,9 @@ void CheckConstraintsBlockOutputStream::write(const Block & block)
{
if (block.rows() > 0)
{
std::cerr << "Checking " << expressions.size() << " constraints\n";
Block block_to_calculate = block;
for (size_t i = 0; i < expressions.size(); ++i)
{
std::cerr << serializeAST(*(constraints.constraints[i]->expr), true) << "\n";
Block block_to_calculate = block;
auto constraint_expr = expressions[i];
constraint_expr->execute(block_to_calculate);
@ -54,8 +51,11 @@ void CheckConstraintsBlockOutputStream::write(const Block & block)
{
size_t row_idx = 0;
for (; row_idx < size; ++row_idx)
{
std::cerr << row_idx << ": " << int(data[row_idx]) << "\n";
if (data[row_idx] != 1)
break;
}
Names related_columns = constraint_expr->getRequiredColumns();

View File

@ -121,8 +121,6 @@ BlockIO InterpreterInsertQuery::execute()
out = std::make_shared<AddingDefaultBlockOutputStream>(
out, query_sample_block, out->getHeader(), table->getColumns().getDefaults(), context);
std::cerr << table->getConstraints().toString() << "\n";
if (const auto & constraints = table->getConstraints(); !constraints.empty())
out = std::make_shared<CheckConstraintsBlockOutputStream>(query.table,
out, query_sample_block, table->getConstraints(), context);

View File

@ -3,6 +3,7 @@
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $CURDIR/../shell_config.sh
EXCEPTION_TEXT=violated
EXCEPTION_SUCCESS_TEXT=ok
$CLICKHOUSE_CLIENT --query="CREATE DATABASE IF NOT EXISTS test;"
$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS test_constraints;"
@ -20,7 +21,7 @@ $CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (1, 2);"
$CLICKHOUSE_CLIENT --query="SELECT * FROM test_constraints;"
# This one must throw and exception
EXCEPTION_TEXT="Violated constraint b_constraint in table test_constraints at indices {1, 3}"
$CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (3, 4), (1, 0), (3, 4), (6, 0);" 2>&1 \
| grep -q "$EXCEPTION_TEXT" && echo "$EXCEPTION_SUCCESS_TEXT" || echo "Did not thrown an exception"
$CLICKHOUSE_CLIENT --query="SELECT * FROM test_constraints;"
@ -38,13 +39,11 @@ $CLICKHOUSE_CLIENT --query="CREATE TABLE test_constraints
ENGINE = MergeTree ORDER BY (a);"
# This one must throw an exception
EXCEPTION_TEXT="Violated constraint b_constraint in table test_constraints at indices {0}"
$CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (1, 2);" 2>&1 \
| grep -q "$EXCEPTION_TEXT" && echo "$EXCEPTION_SUCCESS_TEXT" || echo "Did not thrown an exception"
$CLICKHOUSE_CLIENT --query="SELECT * FROM test_constraints;"
# This one must throw an exception
EXCEPTION_TEXT="Violated constraint a_constraint in table test_constraints at indices {1}"
$CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (5, 16), (10, 11), (9, 11), (8, 12);" 2>&1 \
| grep -q "$EXCEPTION_TEXT" && echo "$EXCEPTION_SUCCESS_TEXT" || echo "Did not thrown an exception"
$CLICKHOUSE_CLIENT --query="SELECT * FROM test_constraints;"

View File

@ -3,6 +3,7 @@
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $CURDIR/../shell_config.sh
EXCEPTION_TEXT=violated
EXCEPTION_SUCCESS_TEXT=ok
$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS test_constraints;"
@ -20,7 +21,7 @@ $CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (1, 2);"
$CLICKHOUSE_CLIENT --query="SELECT * FROM test_constraints;"
# This one must throw and exception
EXCEPTION_TEXT="Violated constraint b_constraint in table test_constraints at indices"
$CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (1, 0);" 2>&1 \
| grep -q "$EXCEPTION_TEXT" && echo "$EXCEPTION_SUCCESS_TEXT" || echo "Did not thrown an exception"
$CLICKHOUSE_CLIENT --query="SELECT * FROM test_constraints;"