2021-03-02 10:53:06 +00:00
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <Functions/FunctionFactory.h>
|
2021-05-17 07:30:42 +00:00
|
|
|
#include <Functions/IFunction.h>
|
2021-03-02 10:53:06 +00:00
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-03-09 12:09:35 +00:00
|
|
|
/// Get the connection Id. It's used for MySQL handler only.
|
2021-06-01 12:20:52 +00:00
|
|
|
class FunctionConnectionId : public IFunction, WithContext
|
2021-03-02 15:17:02 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-03-09 12:09:35 +00:00
|
|
|
static constexpr auto name = "connectionId";
|
2021-03-02 10:53:06 +00:00
|
|
|
|
2021-06-01 12:20:52 +00:00
|
|
|
explicit FunctionConnectionId(ContextPtr context_) : WithContext(context_) {}
|
2021-03-02 10:53:06 +00:00
|
|
|
|
2021-06-01 12:20:52 +00:00
|
|
|
static FunctionPtr create(ContextPtr context_) { return std::make_shared<FunctionConnectionId>(context_); }
|
2021-03-02 10:53:06 +00:00
|
|
|
|
2021-03-02 15:17:02 +00:00
|
|
|
String getName() const override { return name; }
|
2021-03-02 10:53:06 +00:00
|
|
|
|
2021-03-02 15:17:02 +00:00
|
|
|
size_t getNumberOfArguments() const override { return 0; }
|
2021-03-02 10:53:06 +00:00
|
|
|
|
2021-06-22 16:21:23 +00:00
|
|
|
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
|
2021-04-29 14:48:26 +00:00
|
|
|
|
2021-03-02 15:17:02 +00:00
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override { return std::make_shared<DataTypeUInt64>(); }
|
2021-03-02 10:53:06 +00:00
|
|
|
|
2021-03-02 15:17:02 +00:00
|
|
|
ColumnPtr executeImpl(const ColumnsWithTypeAndName &, const DataTypePtr & result_type, size_t input_rows_count) const override
|
|
|
|
{
|
2021-04-10 23:33:54 +00:00
|
|
|
return result_type->createColumnConst(input_rows_count, getContext()->getClientInfo().connection_id);
|
2021-03-02 15:17:02 +00:00
|
|
|
}
|
|
|
|
};
|
2021-03-02 10:53:06 +00:00
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(ConnectionId)
|
2021-03-02 10:53:06 +00:00
|
|
|
{
|
2022-08-27 20:06:03 +00:00
|
|
|
factory.registerFunction<FunctionConnectionId>({}, FunctionFactory::CaseInsensitive);
|
2021-03-25 23:38:49 +00:00
|
|
|
factory.registerAlias("connection_id", "connectionID", FunctionFactory::CaseInsensitive);
|
2021-03-02 10:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|