ClickHouse/src/Storages/StorageSet.h

92 lines
2.5 KiB
C++
Raw Normal View History

2015-01-27 00:52:03 +00:00
#pragma once
2017-06-06 17:18:32 +00:00
#include <ext/shared_ptr_helper.h>
#include <Storages/IStorage.h>
2015-01-27 00:52:03 +00:00
namespace DB
{
Squashed commit of the following: commit e712f469a55ff34ad34b482b15cc4153b7ad7233 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:59:13 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 2a002823084e3a79bffcc17d479620a68eb0644b Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:58:30 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 9e06f407c8ee781ed8ddf98bdfcc31846bf2a0fe Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:55:14 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 9581620f1e839f456fa7894aa1f996d5162ac6cd Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:54:22 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 2a8564c68cb6cc3649fafaf401256d43c9a2e777 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:47:34 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit cf60632d78ec656be3304ef4565e859bb6ce80ba Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:40:09 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit ee3d1dc6e0c4ca60e3ac1e0c30d4b3ed1e66eca0 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:22:49 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 65592ef7116a90104fcd524b53ef8b7cf22640f2 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:18:17 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 37972c257320d3b7e7b294e0fdeffff218647bfd Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:17:06 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit dd909d149974ce5bed2456de1261aa5a368fd3ff Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:16:28 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 3cf43266ca7e30adf01212b1a739ba5fe43639fd Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:15:42 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 6731a3df96d1609286e2536b6432916af7743f0f Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:13:35 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 1b5727e0d56415b7add4cb76110105358663602c Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:11:18 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit bbcf726a55685b8e72f5b40ba0bf1904bd1c0407 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:09:04 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit c03b477d5e2e65014e8906ecfa2efb67ee295af1 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:06:30 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 2986e2fb0466bc18d73693dcdded28fccc0dc66b Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:05:44 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit 5d6cdef13d2e02bd5c4954983334e9162ab2635b Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:04:53 2017 +0300 Less dependencies [#CLICKHOUSE-2] commit f2b819b25ce8b2ccdcb201eefb03e1e6f5aab590 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Sat Jan 14 11:01:47 2017 +0300 Less dependencies [#CLICKHOUSE-2]
2017-01-14 09:00:19 +00:00
class Set;
using SetPtr = std::shared_ptr<Set>;
2017-04-16 15:00:33 +00:00
/** Common part of StorageSet and StorageJoin.
*/
class StorageSetOrJoinBase : public IStorage
{
friend class SetOrJoinBlockOutputStream;
public:
2020-04-07 14:05:51 +00:00
void rename(const String & new_path_to_table_data, const StorageID & new_table_id) override;
BlockOutputStreamPtr write(const ASTPtr & query, const StorageMetadataPtr & /*metadata_snapshot*/, const Context & context) override;
2019-04-04 13:13:59 +00:00
Strings getDataPaths() const override { return {path}; }
protected:
StorageSetOrJoinBase(
2019-10-25 19:07:47 +00:00
const String & relative_path_,
2019-12-04 16:06:55 +00:00
const StorageID & table_id_,
2019-08-24 21:20:20 +00:00
const ColumnsDescription & columns_,
2019-10-25 19:07:47 +00:00
const ConstraintsDescription & constraints_,
2020-09-13 15:11:18 +00:00
bool disable_set_and_join_persistency_,
2019-10-25 19:07:47 +00:00
const Context & context_);
String base_path;
String path;
2020-09-13 15:11:18 +00:00
bool disable_set_and_join_persistency;
std::atomic<UInt64> increment = 0; /// For the backup file names.
2017-04-16 15:00:33 +00:00
/// Restore from backup.
void restore();
private:
void restoreFromFile(const String & file_path);
2017-04-16 15:00:33 +00:00
/// Insert the block into the state.
virtual void insertBlock(const Block & block) = 0;
2019-11-01 10:58:29 +00:00
/// Call after all blocks were inserted.
virtual void finishInsert() = 0;
virtual size_t getSize() const = 0;
};
2017-04-16 15:00:33 +00:00
/** Lets you save the set for later use on the right side of the IN statement.
* When inserted into a table, the data will be inserted into the set,
* and also written to a file-backup, for recovery after a restart.
* Reading from the table is not possible directly - it is possible to specify only the right part of the IN statement.
2015-01-27 00:52:03 +00:00
*/
class StorageSet final : public ext::shared_ptr_helper<StorageSet>, public StorageSetOrJoinBase
2015-01-27 00:52:03 +00:00
{
friend struct ext::shared_ptr_helper<StorageSet>;
2015-01-27 00:52:03 +00:00
public:
String getName() const override { return "Set"; }
2017-04-16 15:00:33 +00:00
/// Access the insides.
SetPtr & getSet() { return set; }
2015-01-27 00:52:03 +00:00
2020-06-18 16:10:47 +00:00
void truncate(const ASTPtr &, const StorageMetadataPtr & metadata_snapshot, const Context &, TableExclusiveLockHolder &) override;
2018-04-21 00:35:20 +00:00
2015-01-27 00:52:03 +00:00
private:
SetPtr set;
void insertBlock(const Block & block) override;
2019-11-01 10:58:29 +00:00
void finishInsert() override;
size_t getSize() const override;
protected:
StorageSet(
2019-10-25 19:07:47 +00:00
const String & relative_path_,
2019-12-04 16:06:55 +00:00
const StorageID & table_id_,
2019-08-24 21:20:20 +00:00
const ColumnsDescription & columns_,
2019-10-25 19:07:47 +00:00
const ConstraintsDescription & constraints_,
2020-09-13 15:11:18 +00:00
bool disable_set_and_join_persistency_,
2019-10-25 19:07:47 +00:00
const Context & context_);
2015-01-27 00:52:03 +00:00
};
}