#include #include #include #include #include #include #include #include #include #if defined(OS_LINUX) # include #endif #include namespace DB { namespace { #if defined(__ELF__) && !defined(OS_FREEBSD) /// buildId() - returns the compiler build id of the running binary. class FunctionBuildId : public FunctionConstantBase { public: static constexpr auto name = "buildId"; static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } explicit FunctionBuildId(ContextPtr context) : FunctionConstantBase(SymbolIndex::instance()->getBuildIDHex(), context->isDistributed()) {} }; #endif /// Get the host name. Is is constant on single server, but is not constant in distributed queries. class FunctionHostName : public FunctionConstantBase { public: static constexpr auto name = "hostName"; static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } explicit FunctionHostName(ContextPtr context) : FunctionConstantBase(DNSResolver::instance().getHostName(), context->isDistributed()) {} }; class FunctionServerUUID : public FunctionConstantBase { public: static constexpr auto name = "serverUUID"; static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } explicit FunctionServerUUID(ContextPtr context) : FunctionConstantBase(ServerUUID::get(), context->isDistributed()) {} }; class FunctionTcpPort : public FunctionConstantBase { public: static constexpr auto name = "tcpPort"; static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } explicit FunctionTcpPort(ContextPtr context) : FunctionConstantBase(context->getTCPPort(), context->isDistributed()) {} }; /// Returns the server time zone. class FunctionTimezone : public FunctionConstantBase { public: static constexpr auto name = "timezone"; static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } explicit FunctionTimezone(ContextPtr context) : FunctionConstantBase(String{DateLUT::instance().getTimeZone()}, context->isDistributed()) {} }; /// Returns server uptime in seconds. class FunctionUptime : public FunctionConstantBase { public: static constexpr auto name = "uptime"; static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } explicit FunctionUptime(ContextPtr context) : FunctionConstantBase(context->getUptimeSeconds(), context->isDistributed()) {} }; /// version() - returns the current version as a string. class FunctionVersion : public FunctionConstantBase { public: static constexpr auto name = "version"; static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } explicit FunctionVersion(ContextPtr context) : FunctionConstantBase(VERSION_STRING, context->isDistributed()) {} }; /// revision() - returns the current revision. class FunctionRevision : public FunctionConstantBase { public: static constexpr auto name = "revision"; static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } explicit FunctionRevision(ContextPtr context) : FunctionConstantBase(ClickHouseRevision::getVersionRevision(), context->isDistributed()) {} }; class FunctionZooKeeperSessionUptime : public FunctionConstantBase { public: static constexpr auto name = "zookeeperSessionUptime"; explicit FunctionZooKeeperSessionUptime(ContextPtr context) : FunctionConstantBase(context->getZooKeeperSessionUptime(), context->isDistributed()) { } static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } }; #if defined(OS_LINUX) class FunctionGetOSKernelVersion : public FunctionConstantBase { public: static constexpr auto name = "getOSKernelVersion"; explicit FunctionGetOSKernelVersion(ContextPtr context) : FunctionConstantBase(Poco::Environment::osName() + " " + Poco::Environment::osVersion(), context->isDistributed()) {} static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } }; #endif } void registerFunctionBuildId([[maybe_unused]] FunctionFactory & factory) { #if defined(__ELF__) && !defined(OS_FREEBSD) factory.registerFunction(); #endif } void registerFunctionHostName(FunctionFactory & factory) { factory.registerFunction(); factory.registerAlias("hostname", "hostName"); } void registerFunctionServerUUID(FunctionFactory & factory) { factory.registerFunction(); } void registerFunctionTcpPort(FunctionFactory & factory) { factory.registerFunction(); } void registerFunctionTimezone(FunctionFactory & factory) { factory.registerFunction(); factory.registerAlias("timeZone", "timezone"); } void registerFunctionUptime(FunctionFactory & factory) { factory.registerFunction(); } void registerFunctionVersion(FunctionFactory & factory) { factory.registerFunction(FunctionFactory::CaseInsensitive); } void registerFunctionRevision(FunctionFactory & factory) { factory.registerFunction(FunctionFactory::CaseInsensitive); } void registerFunctionZooKeeperSessionUptime(FunctionFactory & factory) { factory.registerFunction(); } void registerFunctionGetOSKernelVersion([[maybe_unused]] FunctionFactory & factory) { #if defined(OS_LINUX) factory.registerFunction(); #endif } }