| 1 | #pragma once |
| 2 | |
| 3 | #include <ext/shared_ptr_helper.h> |
| 4 | |
| 5 | #include <Storages/StorageSet.h> |
| 6 | #include <Parsers/ASTTablesInSelectQuery.h> |
| 7 | |
| 8 | |
| 9 | namespace DB |
| 10 | { |
| 11 | |
| 12 | class AnalyzedJoin; |
| 13 | class Join; |
| 14 | using HashJoinPtr = std::shared_ptr<Join>; |
| 15 | |
| 16 | |
| 17 | /** Allows you save the state for later use on the right side of the JOIN. |
| 18 | * When inserted into a table, the data will be inserted into the state, |
| 19 | * and also written to the backup file, to restore after the restart. |
| 20 | * Reading from the table is not possible directly - only specifying on the right side of JOIN is possible. |
| 21 | * |
| 22 | * When using, JOIN must be of the appropriate type (ANY|ALL LEFT|INNER ...). |
| 23 | */ |
| 24 | class StorageJoin : public ext::shared_ptr_helper<StorageJoin>, public StorageSetOrJoinBase |
| 25 | { |
| 26 | friend struct ext::shared_ptr_helper<StorageJoin>; |
| 27 | public: |
| 28 | String getName() const override { return "Join" ; } |
| 29 | |
| 30 | void truncate(const ASTPtr &, const Context &, TableStructureWriteLockHolder &) override; |
| 31 | |
| 32 | /// Access the innards. |
| 33 | HashJoinPtr & getJoin() { return join; } |
| 34 | HashJoinPtr getJoin(std::shared_ptr<AnalyzedJoin> analyzed_join) const; |
| 35 | |
| 36 | /// Verify that the data structure is suitable for implementing this type of JOIN. |
| 37 | void assertCompatible(ASTTableJoin::Kind kind_, ASTTableJoin::Strictness strictness_) const; |
| 38 | |
| 39 | BlockInputStreams read( |
| 40 | const Names & column_names, |
| 41 | const SelectQueryInfo & query_info, |
| 42 | const Context & context, |
| 43 | QueryProcessingStage::Enum processed_stage, |
| 44 | size_t max_block_size, |
| 45 | unsigned num_streams) override; |
| 46 | |
| 47 | private: |
| 48 | Block sample_block; |
| 49 | const Names key_names; |
| 50 | bool use_nulls; |
| 51 | SizeLimits limits; |
| 52 | ASTTableJoin::Kind kind; /// LEFT | INNER ... |
| 53 | ASTTableJoin::Strictness strictness; /// ANY | ALL |
| 54 | |
| 55 | std::shared_ptr<AnalyzedJoin> table_join; |
| 56 | HashJoinPtr join; |
| 57 | |
| 58 | void insertBlock(const Block & block) override; |
| 59 | void finishInsert() override {} |
| 60 | size_t getSize() const override; |
| 61 | |
| 62 | protected: |
| 63 | StorageJoin( |
| 64 | const String & relative_path_, |
| 65 | const String & database_name_, |
| 66 | const String & table_name_, |
| 67 | const Names & key_names_, |
| 68 | bool use_nulls_, |
| 69 | SizeLimits limits_, |
| 70 | ASTTableJoin::Kind kind_, ASTTableJoin::Strictness strictness_, |
| 71 | const ColumnsDescription & columns_, |
| 72 | const ConstraintsDescription & constraints_, |
| 73 | bool overwrite, |
| 74 | const Context & context_); |
| 75 | }; |
| 76 | |
| 77 | } |
| 78 | |