2021-04-10 23:33:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Common/Exception.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Block;
|
|
|
|
|
|
|
|
/// Scalar results of subqueries
|
|
|
|
using Scalars = std::map<String, Block>;
|
|
|
|
|
|
|
|
class Context;
|
|
|
|
|
|
|
|
/// Most used types have shorter names
|
2021-05-31 14:49:02 +00:00
|
|
|
using ContextPtr = std::shared_ptr<const Context>;
|
|
|
|
using ContextMutablePtr = std::shared_ptr<Context>;
|
|
|
|
using ContextWeakPtr = std::weak_ptr<const Context>;
|
|
|
|
using ContextWeakMutablePtr = std::weak_ptr<Context>;
|
2021-04-10 23:33:54 +00:00
|
|
|
|
|
|
|
template <class Shared = ContextPtr>
|
|
|
|
struct WithContextImpl
|
|
|
|
{
|
|
|
|
using Weak = typename Shared::weak_type;
|
|
|
|
using ConstShared = std::shared_ptr<const typename Shared::element_type>;
|
|
|
|
using ConstWeak = typename ConstShared::weak_type;
|
|
|
|
|
|
|
|
WithContextImpl() = default;
|
|
|
|
explicit WithContextImpl(Weak context_) : context(context_) {}
|
|
|
|
|
|
|
|
inline Shared getContext() const
|
|
|
|
{
|
|
|
|
auto ptr = context.lock();
|
2023-01-23 21:13:58 +00:00
|
|
|
if (!ptr) throw Exception(ErrorCodes::LOGICAL_ERROR, "Context has expired");
|
2021-04-10 23:33:54 +00:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Weak context;
|
|
|
|
};
|
|
|
|
|
|
|
|
using WithContext = WithContextImpl<>;
|
2021-06-01 13:38:47 +00:00
|
|
|
using WithConstContext = WithContext; /// For compatibility. Use WithContext.
|
2021-05-31 14:49:02 +00:00
|
|
|
using WithMutableContext = WithContextImpl<ContextMutablePtr>;
|
2021-04-10 23:33:54 +00:00
|
|
|
|
|
|
|
}
|