diff options
author | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-14 09:58:56 +0300 |
---|---|---|
committer | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-14 10:20:20 +0300 |
commit | c2b2dfd9827a400a8495e172a56343462e3ceb82 (patch) | |
tree | cd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/Functions/blockNumber.cpp | |
parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
download | ydb-c2b2dfd9827a400a8495e172a56343462e3ceb82.tar.gz |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Functions/blockNumber.cpp')
-rw-r--r-- | contrib/clickhouse/src/Functions/blockNumber.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Functions/blockNumber.cpp b/contrib/clickhouse/src/Functions/blockNumber.cpp new file mode 100644 index 0000000000..52263061c4 --- /dev/null +++ b/contrib/clickhouse/src/Functions/blockNumber.cpp @@ -0,0 +1,76 @@ +#include <Functions/IFunction.h> +#include <Functions/FunctionFactory.h> +#include <DataTypes/DataTypesNumber.h> +#include <Columns/ColumnsNumber.h> +#include <atomic> + + +namespace DB +{ +namespace +{ + +/** Incremental columns number among calls of this function. */ +class FunctionBlockNumber : public IFunction +{ +private: + mutable std::atomic<size_t> columns_number{0}; + +public: + static constexpr auto name = "blockNumber"; + static FunctionPtr create(ContextPtr) + { + return std::make_shared<FunctionBlockNumber>(); + } + + /// Get the function name. + String getName() const override + { + return name; + } + + bool isStateful() const override + { + return true; + } + + bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override + { + return false; + } + + size_t getNumberOfArguments() const override + { + return 0; + } + + bool isDeterministic() const override + { + return false; + } + + bool isDeterministicInScopeOfQuery() const override + { + return false; + } + + DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override + { + return std::make_shared<DataTypeUInt64>(); + } + + ColumnPtr executeImpl(const ColumnsWithTypeAndName &, const DataTypePtr &, size_t input_rows_count) const override + { + size_t current_columns_number = columns_number.fetch_add(1, std::memory_order_relaxed); + return ColumnUInt64::create(input_rows_count, current_columns_number); + } +}; + +} + +REGISTER_FUNCTION(BlockNumber) +{ + factory.registerFunction<FunctionBlockNumber>(); +} + +} |