ClickHouse/src/Functions/connectionId.cpp

42 lines
1.3 KiB
C++
Raw Normal View History

2021-03-02 10:53:06 +00:00
#include <DataTypes/DataTypesNumber.h>
#include <Functions/FunctionFactory.h>
#include <Functions/IFunctionImpl.h>
#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.
class FunctionConnectionId : public IFunction
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-03-09 12:09:35 +00:00
explicit FunctionConnectionId(const Context & context_) : context(context_) {}
2021-03-02 10:53:06 +00:00
2021-03-09 12:09:35 +00:00
static FunctionPtr create(const Context & 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-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
{
return result_type->createColumnConst(input_rows_count, context.getClientInfo().connection_id);
}
2021-03-02 10:53:06 +00:00
2021-03-02 15:17:02 +00:00
private:
const Context & context;
};
2021-03-02 10:53:06 +00:00
2021-03-09 12:09:35 +00:00
void registerFunctionConnectionId(FunctionFactory & factory)
2021-03-02 10:53:06 +00:00
{
2021-03-29 21:43:00 +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
}
}