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 <Columns/ColumnsNumber.h>
|
2018-09-08 22:57:56 +00:00
|
|
|
#include <atomic>
|
2018-09-08 22:04:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-09-07 18:00:37 +00:00
|
|
|
namespace
|
|
|
|
{
|
2018-09-08 22:04:39 +00:00
|
|
|
|
2020-10-14 14:04:50 +00:00
|
|
|
/** Incremental columns number among calls of this function. */
|
2018-09-08 22:04:39 +00:00
|
|
|
class FunctionBlockNumber : public IFunction
|
|
|
|
{
|
|
|
|
private:
|
2020-10-14 14:04:50 +00:00
|
|
|
mutable std::atomic<size_t> columns_number{0};
|
2018-09-08 22:04:39 +00:00
|
|
|
|
|
|
|
public:
|
2020-10-14 14:04:50 +00:00
|
|
|
static constexpr auto name = "columnsNumber";
|
2018-09-08 22:04:39 +00:00
|
|
|
static FunctionPtr create(const Context &)
|
|
|
|
{
|
|
|
|
return std::make_shared<FunctionBlockNumber>();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the function name.
|
|
|
|
String getName() const override
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2019-01-30 02:47:26 +00:00
|
|
|
bool isStateful() const override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-08 22:04:39 +00:00
|
|
|
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>();
|
|
|
|
}
|
|
|
|
|
2020-10-14 14:04:50 +00:00
|
|
|
void executeImpl(ColumnsWithTypeAndName & columns, const ColumnNumbers &, size_t result, size_t input_rows_count) const override
|
2018-09-08 22:04:39 +00:00
|
|
|
{
|
2020-10-14 14:04:50 +00:00
|
|
|
size_t current_columns_number = columns_number++;
|
|
|
|
columns[result].column = ColumnUInt64::create(input_rows_count, current_columns_number);
|
2018-09-08 22:04:39 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
}
|
2018-09-08 22:04:39 +00:00
|
|
|
|
|
|
|
void registerFunctionBlockNumber(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionBlockNumber>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|