#include #include #include #include #include #include #include #include #if defined(OS_LINUX) # include #endif #if !defined(ARCADIA_BUILD) # include #endif namespace DB { namespace { #if defined(__ELF__) && !defined(__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(context, SymbolIndex::instance()->getBuildIDHex()) {} }; #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(context, DNSResolver::instance().getHostName()) {} }; 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(context, ServerUUID::get()) {} }; 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, context->getTCPPort()) {} }; /// 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(context, String{DateLUT::instance().getTimeZone()}) {} }; /// 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, context->getUptimeSeconds()) {} }; /// 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(context, VERSION_STRING) {} }; class FunctionZooKeeperSessionUptime : public FunctionConstantBase { public: static constexpr auto name = "zookeeperSessionUptime"; explicit FunctionZooKeeperSessionUptime(ContextPtr context) : FunctionConstantBase(context, context->getZooKeeperSessionUptime()) {} static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } }; #if defined(OS_LINUX) class FunctionOSKernelVersion : public FunctionConstantBase { public: static constexpr auto name = "OSKernelVersion"; explicit FunctionOSKernelVersion(ContextPtr context) : FunctionConstantBase(context, Poco::Environment::osName() + " " + Poco::Environment::osVersion()) {} static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } }; #endif } void registerFunctionBuildId([[maybe_unused]] FunctionFactory & factory) { #if defined(__ELF__) && !defined(__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 registerFunctionZooKeeperSessionUptime(FunctionFactory & factory) { factory.registerFunction(); } void registerFunctionOSKernelVersion(FunctionFactory & factory) { #if defined(OS_LINUX) factory.registerFunction(); #endif } }