ClickHouse/src/DataStreams/AddingDefaultBlockOutputStream.h

49 lines
1.4 KiB
C++
Raw Normal View History

2013-10-25 14:56:47 +00:00
#pragma once
#include <DataStreams/IBlockOutputStream.h>
#include <Columns/ColumnConst.h>
2020-10-02 12:38:50 +00:00
#include <Storages/ColumnsDescription.h>
2013-10-25 14:56:47 +00:00
namespace DB
{
2021-02-05 11:41:44 +00:00
class ExpressionActions;
using ExpressionActionsPtr = std::shared_ptr<ExpressionActions>;
class Context;
2013-10-25 14:56:47 +00:00
2018-09-20 15:35:52 +00:00
/** This stream adds three types of columns into block
* 1. Columns, that are missed inside request, but present in table without defaults (missed columns)
* 2. Columns, that are missed inside request, but present in table with defaults (columns with default values)
* 3. Columns that materialized from other columns (materialized columns)
2021-04-23 12:36:40 +00:00
* Also the stream can substitute NULL into DEFAULT value in case of INSERT SELECT query (null_as_default) if according setting is 1.
2018-09-20 15:35:52 +00:00
* All three types of columns are materialized (not constants).
2013-10-25 14:56:47 +00:00
*/
class AddingDefaultBlockOutputStream : public IBlockOutputStream
{
public:
AddingDefaultBlockOutputStream(
const BlockOutputStreamPtr & output_,
const Block & header_,
2020-10-02 12:38:50 +00:00
const ColumnsDescription & columns_,
ContextPtr context_,
bool null_as_default_ = false);
2013-10-25 14:56:47 +00:00
Block getHeader() const override { return header; }
void write(const Block & block) override;
2013-10-25 14:56:47 +00:00
void flush() override;
void writePrefix() override;
void writeSuffix() override;
2013-10-25 14:56:47 +00:00
private:
BlockOutputStreamPtr output;
2018-09-20 15:35:52 +00:00
const Block header;
2021-02-10 12:45:39 +00:00
ExpressionActionsPtr adding_defaults_actions;
2013-10-25 14:56:47 +00:00
};
2013-10-25 14:56:47 +00:00
}