#include #include #include #include #include #include #include namespace DB { namespace { class FunctionTransactionID : public FunctionConstantBase { public: static constexpr auto name = "transactionID"; static Tuple getValue(const MergeTreeTransactionPtr & txn) { Tuple res; if (txn) res = {txn->tid.start_csn, txn->tid.local_tid, txn->tid.host_id}; else res = {static_cast(0), static_cast(0), UUIDHelpers::Nil}; return res; } DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override { return getTransactionIDDataType(); } static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } explicit FunctionTransactionID(ContextPtr context) : FunctionConstantBase(getValue(context->getCurrentTransaction()), context->isDistributed()) {} }; class FunctionTransactionLatestSnapshot : public FunctionConstantBase { static UInt64 getLatestSnapshot(ContextPtr context) { context->checkTransactionsAreAllowed(/* explicit_tcl_query */ true); return TransactionLog::instance().getLatestSnapshot(); } public: static constexpr auto name = "transactionLatestSnapshot"; static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } explicit FunctionTransactionLatestSnapshot(ContextPtr context) : FunctionConstantBase(getLatestSnapshot(context), context->isDistributed()) {} }; class FunctionTransactionOldestSnapshot : public FunctionConstantBase { static UInt64 getOldestSnapshot(ContextPtr context) { context->checkTransactionsAreAllowed(/* explicit_tcl_query */ true); return TransactionLog::instance().getOldestSnapshot(); } public: static constexpr auto name = "transactionOldestSnapshot"; static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } explicit FunctionTransactionOldestSnapshot(ContextPtr context) : FunctionConstantBase(getOldestSnapshot(context), context->isDistributed()) {} }; } REGISTER_FUNCTION(TransactionCounters) { factory.registerFunction(); factory.registerFunction(); factory.registerFunction(); } }