2021-09-15 21:17:20 +00:00
|
|
|
#include <Functions/FunctionConstantBase.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypeUUID.h>
|
|
|
|
#include <Core/ServerUUID.h>
|
|
|
|
#include <Common/SymbolIndex.h>
|
|
|
|
#include <Common/DNSResolver.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/DateLUT.h>
|
2021-09-15 21:17:20 +00:00
|
|
|
|
2021-10-09 08:49:49 +00:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
# include <Poco/Environment.h>
|
|
|
|
#endif
|
|
|
|
|
2021-10-27 23:10:39 +00:00
|
|
|
#include <Common/config_version.h>
|
2021-09-15 21:17:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
#if defined(__ELF__) && !defined(__FreeBSD__)
|
|
|
|
/// buildId() - returns the compiler build id of the running binary.
|
|
|
|
class FunctionBuildId : public FunctionConstantBase<FunctionBuildId, String, DataTypeString>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "buildId";
|
|
|
|
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionBuildId>(context); }
|
2021-10-09 03:47:08 +00:00
|
|
|
explicit FunctionBuildId(ContextPtr context) : FunctionConstantBase(SymbolIndex::instance()->getBuildIDHex(), context->isDistributed()) {}
|
2021-09-15 21:17:20 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/// Get the host name. Is is constant on single server, but is not constant in distributed queries.
|
|
|
|
class FunctionHostName : public FunctionConstantBase<FunctionHostName, String, DataTypeString>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "hostName";
|
|
|
|
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionHostName>(context); }
|
2021-10-09 03:47:08 +00:00
|
|
|
explicit FunctionHostName(ContextPtr context) : FunctionConstantBase(DNSResolver::instance().getHostName(), context->isDistributed()) {}
|
2021-09-15 21:17:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FunctionServerUUID : public FunctionConstantBase<FunctionServerUUID, UUID, DataTypeUUID>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "serverUUID";
|
|
|
|
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionServerUUID>(context); }
|
2021-10-09 03:47:08 +00:00
|
|
|
explicit FunctionServerUUID(ContextPtr context) : FunctionConstantBase(ServerUUID::get(), context->isDistributed()) {}
|
2021-09-15 21:17:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FunctionTcpPort : public FunctionConstantBase<FunctionTcpPort, UInt16, DataTypeUInt16>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "tcpPort";
|
|
|
|
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionTcpPort>(context); }
|
2021-10-09 03:47:08 +00:00
|
|
|
explicit FunctionTcpPort(ContextPtr context) : FunctionConstantBase(context->getTCPPort(), context->isDistributed()) {}
|
2021-09-15 21:17:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the server time zone.
|
|
|
|
class FunctionTimezone : public FunctionConstantBase<FunctionTimezone, String, DataTypeString>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "timezone";
|
|
|
|
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionTimezone>(context); }
|
2021-10-09 03:47:08 +00:00
|
|
|
explicit FunctionTimezone(ContextPtr context) : FunctionConstantBase(String{DateLUT::instance().getTimeZone()}, context->isDistributed()) {}
|
2021-09-15 21:17:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns server uptime in seconds.
|
|
|
|
class FunctionUptime : public FunctionConstantBase<FunctionUptime, UInt32, DataTypeUInt32>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "uptime";
|
|
|
|
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionUptime>(context); }
|
2021-10-09 03:47:08 +00:00
|
|
|
explicit FunctionUptime(ContextPtr context) : FunctionConstantBase(context->getUptimeSeconds(), context->isDistributed()) {}
|
2021-09-15 21:17:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// version() - returns the current version as a string.
|
|
|
|
class FunctionVersion : public FunctionConstantBase<FunctionVersion, String, DataTypeString>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "version";
|
|
|
|
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionVersion>(context); }
|
2021-10-09 03:47:08 +00:00
|
|
|
explicit FunctionVersion(ContextPtr context) : FunctionConstantBase(VERSION_STRING, context->isDistributed()) {}
|
2021-09-15 21:17:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FunctionZooKeeperSessionUptime : public FunctionConstantBase<FunctionZooKeeperSessionUptime, UInt32, DataTypeUInt32>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "zookeeperSessionUptime";
|
2021-10-09 03:47:08 +00:00
|
|
|
explicit FunctionZooKeeperSessionUptime(ContextPtr context)
|
|
|
|
: FunctionConstantBase(context->getZooKeeperSessionUptime(), context->isDistributed())
|
|
|
|
{
|
|
|
|
}
|
2021-09-15 21:17:20 +00:00
|
|
|
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionZooKeeperSessionUptime>(context); }
|
|
|
|
};
|
2021-10-09 08:49:49 +00:00
|
|
|
|
|
|
|
#if defined(OS_LINUX)
|
2021-10-09 11:53:21 +00:00
|
|
|
class FunctionGetOSKernelVersion : public FunctionConstantBase<FunctionGetOSKernelVersion, String, DataTypeString>
|
2021-10-09 08:49:49 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-10-09 11:53:21 +00:00
|
|
|
static constexpr auto name = "getOSKernelVersion";
|
2021-10-10 00:40:51 +00:00
|
|
|
explicit FunctionGetOSKernelVersion(ContextPtr context) : FunctionConstantBase(Poco::Environment::osName() + " " + Poco::Environment::osVersion(), context->isDistributed()) {}
|
2021-10-09 11:53:21 +00:00
|
|
|
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionGetOSKernelVersion>(context); }
|
2021-10-09 08:49:49 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2021-09-15 21:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-16 09:15:22 +00:00
|
|
|
void registerFunctionBuildId([[maybe_unused]] FunctionFactory & factory)
|
2021-09-15 21:17:20 +00:00
|
|
|
{
|
|
|
|
#if defined(__ELF__) && !defined(__FreeBSD__)
|
|
|
|
factory.registerFunction<FunctionBuildId>();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerFunctionHostName(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionHostName>();
|
|
|
|
factory.registerAlias("hostname", "hostName");
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerFunctionServerUUID(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionServerUUID>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerFunctionTcpPort(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionTcpPort>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerFunctionTimezone(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionTimezone>();
|
|
|
|
factory.registerAlias("timeZone", "timezone");
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerFunctionUptime(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionUptime>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerFunctionVersion(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionVersion>(FunctionFactory::CaseInsensitive);
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerFunctionZooKeeperSessionUptime(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionZooKeeperSessionUptime>();
|
|
|
|
}
|
|
|
|
|
2021-10-09 08:49:49 +00:00
|
|
|
|
2021-10-09 11:53:21 +00:00
|
|
|
void registerFunctionGetOSKernelVersion([[maybe_unused]] FunctionFactory & factory)
|
2021-10-09 08:49:49 +00:00
|
|
|
{
|
|
|
|
#if defined(OS_LINUX)
|
2021-10-09 11:53:21 +00:00
|
|
|
factory.registerFunction<FunctionGetOSKernelVersion>();
|
2021-10-09 08:49:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-15 21:17:20 +00:00
|
|
|
}
|
|
|
|
|