aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Functions/nowInBlock.cpp
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@ydb.tech>2023-11-14 09:58:56 +0300
committervitalyisaev <vitalyisaev@ydb.tech>2023-11-14 10:20:20 +0300
commitc2b2dfd9827a400a8495e172a56343462e3ceb82 (patch)
treecd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/Functions/nowInBlock.cpp
parentd4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff)
downloadydb-c2b2dfd9827a400a8495e172a56343462e3ceb82.tar.gz
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Functions/nowInBlock.cpp')
-rw-r--r--contrib/clickhouse/src/Functions/nowInBlock.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Functions/nowInBlock.cpp b/contrib/clickhouse/src/Functions/nowInBlock.cpp
new file mode 100644
index 0000000000..0d5f9c4578
--- /dev/null
+++ b/contrib/clickhouse/src/Functions/nowInBlock.cpp
@@ -0,0 +1,95 @@
+#include <Functions/IFunction.h>
+#include <Functions/FunctionFactory.h>
+#include <Functions/extractTimeZoneFromFunctionArguments.h>
+#include <DataTypes/DataTypeDateTime.h>
+#include <Columns/ColumnsDateTime.h>
+#include <Columns/ColumnVector.h>
+#include <Interpreters/Context.h>
+
+
+namespace DB
+{
+
+namespace ErrorCodes
+{
+ extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
+ extern const int ILLEGAL_TYPE_OF_ARGUMENT;
+}
+
+namespace
+{
+
+/** Returns current time at calculation of every block.
+ * In contrast to 'now' function, it's not a constant expression and is not a subject of constant folding.
+ */
+class FunctionNowInBlock : public IFunction
+{
+public:
+ static constexpr auto name = "nowInBlock";
+ static FunctionPtr create(ContextPtr context)
+ {
+ return std::make_shared<FunctionNowInBlock>(context);
+ }
+ explicit FunctionNowInBlock(ContextPtr context)
+ : allow_nonconst_timezone_arguments(context->getSettings().allow_nonconst_timezone_arguments)
+ {}
+
+ String getName() const override
+ {
+ return name;
+ }
+
+ bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override
+ {
+ return false;
+ }
+
+ /// Optional timezone argument.
+ bool isVariadic() const override { return true; }
+
+ size_t getNumberOfArguments() const override { return 0; }
+
+ bool isDeterministic() const override
+ {
+ return false;
+ }
+
+ bool isDeterministicInScopeOfQuery() const override
+ {
+ return false;
+ }
+
+ DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
+ {
+ if (arguments.size() > 1)
+ {
+ throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Arguments size of function {} should be 0 or 1", getName());
+ }
+ if (arguments.size() == 1 && !isStringOrFixedString(arguments[0].type))
+ {
+ throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Arguments of function {} should be String or FixedString",
+ getName());
+ }
+ if (arguments.size() == 1)
+ {
+ return std::make_shared<DataTypeDateTime>(extractTimeZoneNameFromFunctionArguments(arguments, 0, 0, allow_nonconst_timezone_arguments));
+ }
+ return std::make_shared<DataTypeDateTime>();
+ }
+
+ ColumnPtr executeImpl(const ColumnsWithTypeAndName &, const DataTypePtr &, size_t input_rows_count) const override
+ {
+ return ColumnDateTime::create(input_rows_count, static_cast<UInt32>(time(nullptr)));
+ }
+private:
+ const bool allow_nonconst_timezone_arguments;
+};
+
+}
+
+REGISTER_FUNCTION(NowInBlock)
+{
+ factory.registerFunction<FunctionNowInBlock>();
+}
+
+}