mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Extended constraint exception with constraint name and expression
This commit is contained in:
parent
108b4c6a51
commit
b63623d014
@ -1,14 +1,18 @@
|
||||
#include <DataStreams/CheckConstraintsBlockOutputStream.h>
|
||||
|
||||
#include <Parsers/formatAST.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
void CheckConstraintsBlockOutputStream::write(const Block & block)
|
||||
{
|
||||
for (auto & constraint_expr: expressions)
|
||||
for (size_t i = 0; i < expressions.size(); ++i)
|
||||
{
|
||||
auto constraint_expr = expressions[i];
|
||||
if (!checkConstraintOnBlock(block, constraint_expr))
|
||||
throw Exception{"Some constraints are not satisfied", ErrorCodes::QUERY_WAS_CANCELLED};
|
||||
throw Exception{"Constraint " + constraints.constraints[i]->name + " is not satisfied at, constraint expression: " +
|
||||
serializeAST(*(constraints.constraints[i]->expr), true), ErrorCodes::LOGICAL_ERROR};
|
||||
}
|
||||
output->write(block);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
. $CURDIR/../shell_config.sh
|
||||
|
||||
EXCEPTION_SUCCESS_TEXT=ok
|
||||
|
||||
$CLICKHOUSE_CLIENT --query="CREATE DATABASE IF NOT EXISTS test;"
|
||||
$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS test_constraints;"
|
||||
|
||||
$CLICKHOUSE_CLIENT --query="CREATE TABLE test_constraints
|
||||
@ -20,7 +20,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="Some constraints are not satisfied"
|
||||
EXCEPTION_TEXT="Constraint b_constraint is not satisfied"
|
||||
$CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (3, 4), (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;"
|
||||
@ -38,13 +38,13 @@ $CLICKHOUSE_CLIENT --query="CREATE TABLE test_constraints
|
||||
ENGINE = MergeTree ORDER BY (a);"
|
||||
|
||||
# This one must throw an exception
|
||||
EXCEPTION_TEXT="Some constraints are not satisfied"
|
||||
EXCEPTION_TEXT="Constraint b_constraint is not satisfied"
|
||||
$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="Some constraints are not satisfied"
|
||||
EXCEPTION_TEXT="Constraint a_constraint is not satisfied"
|
||||
$CLICKHOUSE_CLIENT --query="INSERT INTO test_constraints VALUES (5, 16), (10, 11);" 2>&1 \
|
||||
| grep -q "$EXCEPTION_TEXT" && echo "$EXCEPTION_SUCCESS_TEXT" || echo "Did not thrown an exception"
|
||||
$CLICKHOUSE_CLIENT --query="SELECT * FROM test_constraints;"
|
||||
|
Loading…
Reference in New Issue
Block a user