mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Added ReplicatedMergeTree support and test for constraints, also added VIOLATED_CONSTRAINT error
This commit is contained in:
parent
3b9e1f9bf7
commit
ab1c4139de
@ -217,7 +217,10 @@
|
||||
|
||||
See https://clickhouse.yandex/docs/en/table_engines/replication/
|
||||
-->
|
||||
<zookeeper incl="zookeeper-servers" optional="true" />
|
||||
|
||||
<zookeeper>
|
||||
<implementation>testkeeper</implementation>
|
||||
</zookeeper>
|
||||
|
||||
<!-- Substitutions for parameters of replicated tables.
|
||||
Optional. If you don't use replicated tables, you could omit that.
|
||||
|
@ -443,6 +443,7 @@ namespace ErrorCodes
|
||||
extern const int INSECURE_PATH = 466;
|
||||
extern const int CANNOT_PARSE_BOOL = 467;
|
||||
extern const int CANNOT_PTHREAD_ATTR = 468;
|
||||
extern const int VIOLATED_CONSTRAINT = 469;
|
||||
|
||||
extern const int KEEPER_EXCEPTION = 999;
|
||||
extern const int POCO_EXCEPTION = 1000;
|
||||
|
@ -26,7 +26,7 @@ void CheckConstraintsBlockOutputStream::write(const Block & block)
|
||||
|
||||
throw Exception{"Violated constraint " + constraints.constraints[i]->name +
|
||||
" in table " + table + " at indices " + indices_str + ", constraint expression: " +
|
||||
serializeAST(*(constraints.constraints[i]->expr), true), ErrorCodes::LOGICAL_ERROR};
|
||||
serializeAST(*(constraints.constraints[i]->expr), true), DB::ErrorCodes::VIOLATED_CONSTRAINT};
|
||||
}
|
||||
}
|
||||
output->write(block);
|
||||
|
@ -10,7 +10,7 @@ namespace DB
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int CONSTRAINTS_ARE_NOT_SATISFIED;
|
||||
extern const int VIOLATED_CONSTRAINT;
|
||||
}
|
||||
|
||||
class CheckConstraintsBlockOutputStream : public IBlockOutputStream
|
||||
|
@ -82,6 +82,9 @@ void ReplicatedMergeTreeTableMetadata::write(WriteBuffer & out) const
|
||||
|
||||
if (index_granularity_bytes != 0)
|
||||
out << "granularity bytes: " << index_granularity_bytes << "\n";
|
||||
|
||||
if (!constraints.empty())
|
||||
out << "constraints: " << constraints << "\n";
|
||||
}
|
||||
|
||||
String ReplicatedMergeTreeTableMetadata::toString() const
|
||||
@ -125,6 +128,9 @@ void ReplicatedMergeTreeTableMetadata::read(ReadBuffer & in)
|
||||
}
|
||||
else
|
||||
index_granularity_bytes = 0;
|
||||
|
||||
if (checkString("constraints: ", in))
|
||||
in >> constraints >> "\n";
|
||||
}
|
||||
|
||||
ReplicatedMergeTreeTableMetadata ReplicatedMergeTreeTableMetadata::parse(const String & s)
|
||||
|
@ -3144,6 +3144,10 @@ void StorageReplicatedMergeTree::alter(
|
||||
if (new_indices_str != getIndices().toString())
|
||||
new_metadata.skip_indices = new_indices_str;
|
||||
|
||||
String new_constraints_str = new_constraints.toString();
|
||||
if (new_constraints_str != getConstraints().toString())
|
||||
new_metadata.constraints = new_constraints_str;
|
||||
|
||||
String new_metadata_str = new_metadata.toString();
|
||||
if (new_metadata_str != ReplicatedMergeTreeTableMetadata(*this).toString())
|
||||
changed_nodes.emplace_back(zookeeper_path, "metadata", new_metadata_str);
|
||||
|
@ -0,0 +1,43 @@
|
||||
DROP TABLE IF EXISTS replicated_constraints1;
|
||||
DROP TABLE IF EXISTS replicated_constraints2;
|
||||
|
||||
CREATE TABLE replicated_constraints1
|
||||
(
|
||||
a UInt32,
|
||||
b UInt32,
|
||||
CONSTRAINT a_constraint CHECK a < 10
|
||||
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/alter_constraints', 'r1') ORDER BY (a);
|
||||
|
||||
CREATE TABLE replicated_constraints2
|
||||
(
|
||||
a UInt32,
|
||||
b UInt32,
|
||||
CONSTRAINT a_constraint CHECK a < 10
|
||||
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/alter_constraints', 'r2') ORDER BY (a);
|
||||
|
||||
INSERT INTO replicated_constraints1 VALUES (1, 2);
|
||||
INSERT INTO replicated_constraints2 VALUES (3, 4);
|
||||
|
||||
SYSTEM SYNC REPLICA replicated_constraints1;
|
||||
SYSTEM SYNC REPLICA replicated_constraints2;
|
||||
|
||||
INSERT INTO replicated_constraints1 VALUES (10, 10); -- { serverError 469 }
|
||||
|
||||
ALTER TABLE replicated_constraints1 DROP CONSTRAINT a_constraint;
|
||||
|
||||
SYSTEM SYNC REPLICA replicated_constraints2;
|
||||
|
||||
INSERT INTO replicated_constraints1 VALUES (10, 10);
|
||||
INSERT INTO replicated_constraints2 VALUES (10, 10);
|
||||
|
||||
ALTER TABLE replicated_constraints1 ADD CONSTRAINT b_constraint CHECK b > 10;
|
||||
ALTER TABLE replicated_constraints2 ADD CONSTRAINT a_constraint CHECK a < 10;
|
||||
|
||||
SYSTEM SYNC REPLICA replicated_constraints1;
|
||||
SYSTEM SYNC REPLICA replicated_constraints2;
|
||||
|
||||
INSERT INTO replicated_constraints1 VALUES (10, 11); -- { serverError 469 }
|
||||
INSERT INTO replicated_constraints2 VALUES (9, 10); -- { serverError 469 }
|
||||
|
||||
DROP TABLE replicated_constraints1;
|
||||
DROP TABLE replicated_constraints2;
|
Loading…
Reference in New Issue
Block a user