ClickHouse/src/Storages/StorageNull.h

73 lines
2.0 KiB
C++
Raw Normal View History

#pragma once
2021-06-15 19:55:21 +00:00
#include <common/shared_ptr_helper.h>
#include <Core/NamesAndTypes.h>
#include <Storages/IStorage.h>
#include <DataStreams/NullBlockOutputStream.h>
#include <Processors/Sources/NullSource.h>
#include <Processors/Pipe.h>
namespace DB
{
2017-04-16 15:00:33 +00:00
/** When writing, does nothing.
* When reading, returns nothing.
*/
2021-06-15 19:55:21 +00:00
class StorageNull final : public shared_ptr_helper<StorageNull>, public IStorage
{
2021-06-15 19:55:21 +00:00
friend struct shared_ptr_helper<StorageNull>;
public:
std::string getName() const override { return "Null"; }
2020-08-03 13:54:14 +00:00
Pipe read(
const Names & column_names,
const StorageMetadataPtr & metadata_snapshot,
SelectQueryInfo &,
ContextPtr /*context*/,
QueryProcessingStage::Enum /*processing_stage*/,
2017-12-01 21:13:25 +00:00
size_t,
unsigned) override
{
2020-08-03 13:54:14 +00:00
return Pipe(
std::make_shared<NullSource>(getSampleBlockForColumns(metadata_snapshot, column_names)));
}
bool supportsParallelInsert() const override { return true; }
BlockOutputStreamPtr write(const ASTPtr &, const StorageMetadataPtr & metadata_snapshot, ContextPtr) override
{
return std::make_shared<NullBlockOutputStream>(metadata_snapshot->getSampleBlock());
}
void checkAlterIsPossible(const AlterCommands & commands, ContextPtr context) const override;
2019-12-26 18:17:05 +00:00
void alter(const AlterCommands & params, ContextPtr context, TableLockHolder & table_lock_holder) override;
2018-01-11 19:13:19 +00:00
2020-11-25 13:47:32 +00:00
std::optional<UInt64> totalRows(const Settings &) const override
2020-03-29 12:22:17 +00:00
{
return {0};
}
2020-11-25 13:47:32 +00:00
std::optional<UInt64> totalBytes(const Settings &) const override
2020-03-29 14:44:32 +00:00
{
return {0};
}
2020-03-29 12:22:17 +00:00
private:
protected:
2021-04-23 12:18:23 +00:00
StorageNull(
const StorageID & table_id_, ColumnsDescription columns_description_, ConstraintsDescription constraints_, const String & comment)
2019-12-04 16:06:55 +00:00
: IStorage(table_id_)
{
StorageInMemoryMetadata metadata_;
metadata_.setColumns(columns_description_);
metadata_.setConstraints(constraints_);
2021-04-23 12:18:23 +00:00
metadata_.setComment(comment);
setInMemoryMetadata(metadata_);
}
};
}