mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 02:41:59 +00:00
Added standalone function to get server's own timezone
Fix missing global_context
This commit is contained in:
parent
393830ecdc
commit
c61aff7cac
@ -42,6 +42,16 @@ public:
|
||||
if (!implicit_timezone.empty())
|
||||
return instance(implicit_timezone);
|
||||
}
|
||||
|
||||
const auto global_context = DB::CurrentThread::get().getGlobalContext();
|
||||
if (global_context)
|
||||
{
|
||||
auto implicit_timezone = extractTimezoneFromContext(global_context);
|
||||
|
||||
if (!implicit_timezone.empty())
|
||||
return instance(implicit_timezone);
|
||||
}
|
||||
|
||||
}
|
||||
return *date_lut.default_impl.load(std::memory_order_acquire);
|
||||
}
|
||||
|
@ -60,13 +60,22 @@ namespace
|
||||
};
|
||||
|
||||
|
||||
/// Returns the server time zone.
|
||||
/// Returns default timezone for current session.
|
||||
class FunctionTimezone : public FunctionConstantBase<FunctionTimezone, String, DataTypeString>
|
||||
{
|
||||
public:
|
||||
static constexpr auto name = "timezone";
|
||||
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionTimezone>(context); }
|
||||
explicit FunctionTimezone(ContextPtr context) : FunctionConstantBase(String{DateLUT::instance().getTimeZone()}, context->isDistributed()) {}
|
||||
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<FunctionServerTimezone, String, DataTypeString>
|
||||
{
|
||||
public:
|
||||
static constexpr auto name = "serverTimezone";
|
||||
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionServerTimezone>(context); }
|
||||
explicit FunctionServerTimezone(ContextPtr context) : FunctionConstantBase(String{DateLUT::instance().getTimeZone()}, context->isDistributed()) {}
|
||||
};
|
||||
|
||||
|
||||
@ -155,6 +164,12 @@ REGISTER_FUNCTION(Timezone)
|
||||
factory.registerAlias("timeZone", "timezone");
|
||||
}
|
||||
|
||||
REGISTER_FUNCTION(ServerTimezone)
|
||||
{
|
||||
factory.registerFunction<FunctionServerTimezone>();
|
||||
factory.registerAlias("serverTimeZone", "serverTimezone");
|
||||
}
|
||||
|
||||
REGISTER_FUNCTION(Uptime)
|
||||
{
|
||||
factory.registerFunction<FunctionUptime>();
|
||||
|
Loading…
Reference in New Issue
Block a user