summaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Functions/timezoneOf.cpp
diff options
context:
space:
mode:
authorvitalyisaev <[email protected]>2023-11-14 09:58:56 +0300
committervitalyisaev <[email protected]>2023-11-14 10:20:20 +0300
commitc2b2dfd9827a400a8495e172a56343462e3ceb82 (patch)
treecd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/Functions/timezoneOf.cpp
parentd4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff)
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Functions/timezoneOf.cpp')
-rw-r--r--contrib/clickhouse/src/Functions/timezoneOf.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Functions/timezoneOf.cpp b/contrib/clickhouse/src/Functions/timezoneOf.cpp
new file mode 100644
index 00000000000..7a5957a5dbc
--- /dev/null
+++ b/contrib/clickhouse/src/Functions/timezoneOf.cpp
@@ -0,0 +1,75 @@
+#include <Functions/IFunction.h>
+#include <Functions/FunctionFactory.h>
+#include <DataTypes/DataTypeString.h>
+#include <DataTypes/DataTypeNullable.h>
+#include <DataTypes/DataTypeDateTime.h>
+#include <Common/DateLUTImpl.h>
+#include <Core/Field.h>
+
+namespace DB
+{
+
+namespace ErrorCodes
+{
+ extern const int BAD_ARGUMENTS;
+}
+
+
+namespace
+{
+
+
+/** timezoneOf(x) - get the name of the timezone of DateTime data type.
+ * Example: Pacific/Pitcairn.
+ */
+class FunctionTimezoneOf : public IFunction
+{
+public:
+ static constexpr auto name = "timezoneOf";
+ String getName() const override { return name; }
+ static FunctionPtr create(ContextPtr) { return std::make_unique<FunctionTimezoneOf>(); }
+
+ size_t getNumberOfArguments() const override { return 1; }
+
+ bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
+
+ DataTypePtr getReturnTypeImpl(const DataTypes & types) const override
+ {
+ DataTypePtr type_no_nullable = removeNullable(types[0]);
+
+ if (isDateTime(type_no_nullable) || isDateTime64(type_no_nullable))
+ return std::make_shared<DataTypeString>();
+ else
+ throw Exception(ErrorCodes::BAD_ARGUMENTS, "Bad argument for function {}, should be DateTime or DateTime64", name);
+ }
+
+ bool useDefaultImplementationForNulls() const override { return false; }
+ bool useDefaultImplementationForLowCardinalityColumns() const override { return false; }
+ ColumnNumbers getArgumentsThatDontImplyNullableReturnType(size_t /*number_of_arguments*/) const override { return {0}; }
+
+ ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
+ {
+ DataTypePtr type_no_nullable = removeNullable(arguments[0].type);
+
+ return DataTypeString().createColumnConst(input_rows_count,
+ dynamic_cast<const TimezoneMixin &>(*type_no_nullable).getTimeZone().getTimeZone());
+ }
+
+ ColumnPtr getConstantResultForNonConstArguments(const ColumnsWithTypeAndName & arguments, const DataTypePtr &) const override
+ {
+ DataTypePtr type_no_nullable = removeNullable(arguments[0].type);
+
+ return DataTypeString().createColumnConst(1,
+ dynamic_cast<const TimezoneMixin &>(*type_no_nullable).getTimeZone().getTimeZone());
+ }
+};
+
+}
+
+REGISTER_FUNCTION(TimezoneOf)
+{
+ factory.registerFunction<FunctionTimezoneOf>();
+ factory.registerAlias("timeZoneOf", "timezoneOf");
+}
+
+}