ClickHouse/src/Analyzer/TableNode.h

113 lines
2.9 KiB
C++
Raw Normal View History

2022-07-14 11:20:16 +00:00
#pragma once
#include <Storages/IStorage_fwd.h>
#include <Storages/TableLockHolder.h>
#include <Storages/StorageSnapshot.h>
#include <Interpreters/Context_fwd.h>
#include <Interpreters/StorageID.h>
#include <Analyzer/IQueryTreeNode.h>
#include <Analyzer/TableExpressionModifiers.h>
2022-07-14 11:20:16 +00:00
namespace DB
{
/** Table node represents table in query tree.
* Example: SELECT a FROM test_table.
* test_table - is identifier, that during query analysis pass must be resolved into table node.
*
* During construction table node:
* 1. Lock storage for share. Later lock can be moved out of node using `moveTableLock` method.
* 2. Take storage snapshot.
*/
class TableNode;
using TableNodePtr = std::shared_ptr<TableNode>;
class TableNode : public IQueryTreeNode
{
public:
2022-08-15 16:34:10 +00:00
/// Construct table node with storage, storage lock, storage snapshot
explicit TableNode(StoragePtr storage_, TableLockHolder storage_lock_, StorageSnapshotPtr storage_snapshot_);
2022-07-14 11:20:16 +00:00
/// Get storage
const StoragePtr & getStorage() const
{
return storage;
}
/// Get storage id
const StorageID & getStorageID() const
{
return storage_id;
}
/// Get storage snapshot
const StorageSnapshotPtr & getStorageSnapshot() const
{
return storage_snapshot;
}
2022-08-15 16:34:10 +00:00
/// Get storage lock
const TableLockHolder & getStorageLock() const
2022-07-14 11:20:16 +00:00
{
2022-08-15 16:34:10 +00:00
return storage_lock;
2022-07-14 11:20:16 +00:00
}
/** Move table lock out of table node.
* After using this method table node state becomes invalid.
*/
2022-08-15 16:34:10 +00:00
TableLockHolder && moveStorageLock()
2022-07-14 11:20:16 +00:00
{
2022-08-15 16:34:10 +00:00
return std::move(storage_lock);
2022-07-14 11:20:16 +00:00
}
/// Return true if table node has table expression modifiers, false otherwise
bool hasTableExpressionModifiers() const
{
return table_expression_modifiers.has_value();
}
/// Get table expression modifiers
std::optional<TableExpressionModifiers> getTableExpressionModifiers() const
{
return table_expression_modifiers;
}
/// Set table expression modifiers
void setTableExpressionModifiers(TableExpressionModifiers table_expression_modifiers_value)
{
table_expression_modifiers = std::move(table_expression_modifiers_value);
}
2022-07-14 11:20:16 +00:00
QueryTreeNodeType getNodeType() const override
{
return QueryTreeNodeType::TABLE;
}
String getName() const override;
void dumpTreeImpl(WriteBuffer & buffer, FormatState & format_state, size_t indent) const override;
2022-07-15 13:32:53 +00:00
bool isEqualImpl(const IQueryTreeNode & rhs) const override;
2022-07-14 11:20:16 +00:00
void updateTreeHashImpl(HashState & state) const override;
protected:
2022-07-14 11:20:16 +00:00
ASTPtr toASTImpl() const override;
QueryTreeNodePtr cloneImpl() const override;
private:
2022-07-20 15:25:24 +00:00
TableNode();
2022-07-14 11:20:16 +00:00
StoragePtr storage;
StorageID storage_id;
2022-08-15 16:34:10 +00:00
TableLockHolder storage_lock;
2022-07-14 11:20:16 +00:00
StorageSnapshotPtr storage_snapshot;
std::optional<TableExpressionModifiers> table_expression_modifiers;
2022-07-14 11:20:16 +00:00
};
}