ClickHouse/dbms/DataStreams/CheckConstraintsBlockOutputStream.h

42 lines
1.0 KiB
C++
Raw Normal View History

2019-05-19 05:27:00 +00:00
#pragma once
#include <DataStreams/IBlockOutputStream.h>
#include <Storages/ConstraintsDescription.h>
2020-03-13 10:30:55 +00:00
#include <Interpreters/StorageID.h>
2019-05-19 05:27:00 +00:00
namespace DB
{
/** Check for constraints violation. If anything is found - throw an exception with detailed error message.
* Otherwise just pass block to output unchanged.
*/
2019-05-19 05:27:00 +00:00
class CheckConstraintsBlockOutputStream : public IBlockOutputStream
{
public:
CheckConstraintsBlockOutputStream(
2020-03-02 20:23:58 +00:00
const StorageID & table_,
2019-05-19 05:27:00 +00:00
const BlockOutputStreamPtr & output_,
const Block & header_,
const ConstraintsDescription & constraints_,
const Context & context_);
2019-05-19 05:27:00 +00:00
Block getHeader() const override { return header; }
void write(const Block & block) override;
void flush() override;
void writePrefix() override;
void writeSuffix() override;
private:
2020-03-02 20:23:58 +00:00
StorageID table_id;
2019-05-19 05:27:00 +00:00
BlockOutputStreamPtr output;
Block header;
const ConstraintsDescription constraints;
const ConstraintsExpressions expressions;
size_t rows_written = 0;
2019-05-19 05:27:00 +00:00
};
}