#include #include #include #include #include #include #include #include #include #include #include #include #include "config_version.h" 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 default timezone for current session. 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 the server time zone (timezone in which server runs). class FunctionServerTimezone : public FunctionConstantBase { public: static constexpr auto name = "serverTimezone"; static FunctionPtr create(ContextPtr context) { return std::make_shared(context); } explicit FunctionServerTimezone(ContextPtr context) : FunctionConstantBase(String{DateLUT::serverTimezoneInstance().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); } }; 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); } }; class FunctionDisplayName : public FunctionConstantBase { public: static constexpr auto name = "displayName"; explicit FunctionDisplayName(ContextPtr context) : FunctionConstantBase(context->getConfigRef().getString("display_name", getFQDNOrHostName()), context->isDistributed()) {} static FunctionPtr create(ContextPtr context) {return std::make_shared(context); } }; } #if defined(__ELF__) && !defined(OS_FREEBSD) REGISTER_FUNCTION(BuildId) { factory.registerFunction(); } #endif REGISTER_FUNCTION(HostName) { factory.registerFunction(); factory.registerAlias("hostname", "hostName"); } REGISTER_FUNCTION(ServerUUID) { factory.registerFunction(); } REGISTER_FUNCTION(TcpPort) { factory.registerFunction(); } REGISTER_FUNCTION(Timezone) { factory.registerFunction( FunctionDocumentation{ .description=R"( Returns the default timezone for current session. Used as default timezone for parsing DateTime|DateTime64 without explicitly specified timezone. Can be changed with SET timezone = 'New/Tz' [example:timezone] )", .examples{{"timezone", "SELECT timezone();", ""}}, .categories{"Constant", "Miscellaneous"} }); factory.registerAlias("timeZone", "timezone"); } REGISTER_FUNCTION(ServerTimezone) { factory.registerFunction( FunctionDocumentation{ .description=R"( Returns the timezone name in which server operates. [example:serverTimezone] )", .examples{{"serverTimezone", "SELECT serverTimezone();", ""}}, .categories{"Constant", "Miscellaneous"} }); factory.registerAlias("serverTimeZone", "serverTimezone"); factory.registerAlias("servertimezone", "serverTimezone"); } REGISTER_FUNCTION(Uptime) { factory.registerFunction(); } REGISTER_FUNCTION(Version) { factory.registerFunction({}, FunctionFactory::CaseInsensitive); } REGISTER_FUNCTION(Revision) { factory.registerFunction({}, FunctionFactory::CaseInsensitive); } REGISTER_FUNCTION(ZooKeeperSessionUptime) { factory.registerFunction(); } REGISTER_FUNCTION(GetOSKernelVersion) { factory.registerFunction(); } REGISTER_FUNCTION(DisplayName) { factory.registerFunction(FunctionDocumentation { .description=R"( Returns the value of `display_name` from config or server FQDN if not set. [example:displayName] )", .examples{{"displayName", "SELECT displayName();", ""}}, .categories{"Constant", "Miscellaneous"} }, FunctionFactory::CaseSensitive); } }