1 | #include <Functions/IFunctionImpl.h> |
---|---|
2 | #include <Functions/FunctionFactory.h> |
3 | #include <DataTypes/DataTypesNumber.h> |
4 | #include <Columns/ColumnsNumber.h> |
5 | |
6 | |
7 | namespace DB |
8 | { |
9 | |
10 | /** blockSize() - get the block size in number of rows. |
11 | */ |
12 | class FunctionBlockSize : public IFunction |
13 | { |
14 | public: |
15 | static constexpr auto name = "blockSize"; |
16 | static FunctionPtr create(const Context &) |
17 | { |
18 | return std::make_shared<FunctionBlockSize>(); |
19 | } |
20 | |
21 | /// Get the function name. |
22 | String getName() const override |
23 | { |
24 | return name; |
25 | } |
26 | |
27 | bool isDeterministic() const override { return false; } |
28 | |
29 | bool isDeterministicInScopeOfQuery() const override |
30 | { |
31 | return false; |
32 | } |
33 | |
34 | size_t getNumberOfArguments() const override |
35 | { |
36 | return 0; |
37 | } |
38 | |
39 | DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override |
40 | { |
41 | return std::make_shared<DataTypeUInt64>(); |
42 | } |
43 | |
44 | void executeImpl(Block & block, const ColumnNumbers &, size_t result, size_t input_rows_count) override |
45 | { |
46 | block.getByPosition(result).column = ColumnUInt64::create(input_rows_count, input_rows_count); |
47 | } |
48 | }; |
49 | |
50 | |
51 | void registerFunctionBlockSize(FunctionFactory & factory) |
52 | { |
53 | factory.registerFunction<FunctionBlockSize>(); |
54 | } |
55 | |
56 | } |
57 |