2019-12-09 13:12:54 +00:00
|
|
|
#include <Functions/IFunctionImpl.h>
|
2018-09-08 22:04:39 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Returns server uptime in seconds.
|
|
|
|
*/
|
|
|
|
class FunctionUptime : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "uptime";
|
|
|
|
static FunctionPtr create(const Context & context)
|
|
|
|
{
|
|
|
|
return std::make_shared<FunctionUptime>(context.getUptimeSeconds());
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit FunctionUptime(time_t uptime_) : uptime(uptime_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
String getName() const override
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t getNumberOfArguments() const override
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override
|
|
|
|
{
|
|
|
|
return std::make_shared<DataTypeUInt32>();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isDeterministic() const override { return false; }
|
|
|
|
|
2020-11-17 13:24:45 +00:00
|
|
|
ColumnPtr executeImpl(const ColumnsWithTypeAndName &, const DataTypePtr &, size_t input_rows_count) const override
|
2018-09-08 22:04:39 +00:00
|
|
|
{
|
2020-10-19 15:27:41 +00:00
|
|
|
return DataTypeUInt32().createColumnConst(input_rows_count, static_cast<UInt64>(uptime));
|
2018-09-08 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
time_t uptime;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void registerFunctionUptime(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionUptime>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|