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-12-21 13:41:53 +00:00
|
|
|
#include <Common/DateLUT.h>
|
2022-06-30 10:58:26 +00:00
|
|
|
#include <Common/ClickHouseRevision.h>
|
2021-09-15 21:17:20 +00:00
|
|
|
|
2022-07-31 07:36:40 +00:00
|
|
|
#include <Poco/Environment.h>
|
2021-10-09 08:49:49 +00:00
|
|
|
|
2021-10-27 23:10:39 +00:00
|
|
|
#include <Common/config_version.h>
|
2021-09-15 21:17:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2022-06-10 08:22:31 +00:00
|
|
|
#if defined(__ELF__) && !defined(OS_FREEBSD)
|
2021-09-15 21:17:20 +00:00
|
|
|
/// 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
|
|
|
};
|
|
|
|
|
2022-06-30 10:58:26 +00:00
|
|
|
/// revision() - returns the current revision.
|
|
|
|
class FunctionRevision : public FunctionConstantBase<FunctionRevision, UInt32, DataTypeUInt32>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "revision";
|
|
|
|
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionRevision>(context); }
|
|
|
|
explicit FunctionRevision(ContextPtr context) : FunctionConstantBase(ClickHouseRevision::getVersionRevision(), 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
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-09-15 21:17:20 +00:00
|
|
|
}
|
|
|
|
|
2022-06-10 08:22:31 +00:00
|
|
|
#if defined(__ELF__) && !defined(OS_FREEBSD)
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(BuildId)
|
|
|
|
{
|
2021-09-15 21:17:20 +00:00
|
|
|
factory.registerFunction<FunctionBuildId>();
|
|
|
|
}
|
2022-07-04 07:01:39 +00:00
|
|
|
#endif
|
2021-09-15 21:17:20 +00:00
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(HostName)
|
2021-09-15 21:17:20 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionHostName>();
|
|
|
|
factory.registerAlias("hostname", "hostName");
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(ServerUUID)
|
2021-09-15 21:17:20 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionServerUUID>();
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(TcpPort)
|
2021-09-15 21:17:20 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionTcpPort>();
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(Timezone)
|
2021-09-15 21:17:20 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionTimezone>();
|
|
|
|
factory.registerAlias("timeZone", "timezone");
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(Uptime)
|
2021-09-15 21:17:20 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionUptime>();
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(Version)
|
2021-09-15 21:17:20 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionVersion>(FunctionFactory::CaseInsensitive);
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(Revision)
|
2022-06-30 10:58:26 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionRevision>(FunctionFactory::CaseInsensitive);
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(ZooKeeperSessionUptime)
|
2021-09-15 21:17:20 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionZooKeeperSessionUptime>();
|
|
|
|
}
|
|
|
|
|
2021-10-09 08:49:49 +00:00
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(GetOSKernelVersion)
|
|
|
|
{
|
2021-10-09 11:53:21 +00:00
|
|
|
factory.registerFunction<FunctionGetOSKernelVersion>();
|
2021-10-09 08:49:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-15 21:17:20 +00:00
|
|
|
}
|
|
|
|
|