mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Merge pull request #61969 from YenchangChan/zero-arguments
Zero-argument variants for table functions numbers, numbers_mt, zeros, and zeros_mt
This commit is contained in:
commit
230ce33954
@ -71,21 +71,30 @@ StoragePtr TableFunctionNumbers<multithreaded>::executeImpl(
|
||||
{
|
||||
auto arguments = function->arguments->children;
|
||||
|
||||
if ((arguments.empty()) || (arguments.size() >= 4))
|
||||
if (arguments.size() >= 4)
|
||||
throw Exception(
|
||||
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Table function '{}' requires 'length' or 'offset, length'.", getName());
|
||||
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Table function '{}' cannot have more than three params", getName());
|
||||
if (!arguments.empty())
|
||||
{
|
||||
UInt64 offset = arguments.size() >= 2 ? evaluateArgument(context, arguments[0]) : 0;
|
||||
UInt64 length = arguments.size() >= 2 ? evaluateArgument(context, arguments[1]) : evaluateArgument(context, arguments[0]);
|
||||
UInt64 step = arguments.size() == 3 ? evaluateArgument(context, arguments[2]) : 1;
|
||||
|
||||
UInt64 offset = arguments.size() >= 2 ? evaluateArgument(context, arguments[0]) : 0;
|
||||
UInt64 length = arguments.size() >= 2 ? evaluateArgument(context, arguments[1]) : evaluateArgument(context, arguments[0]);
|
||||
UInt64 step = arguments.size() == 3 ? evaluateArgument(context, arguments[2]) : 1;
|
||||
if (!step)
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Table function {} requires step to be a positive number", getName());
|
||||
|
||||
if (!step)
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Table function {} requires step to be a positive number", getName());
|
||||
|
||||
auto res = std::make_shared<StorageSystemNumbers>(
|
||||
StorageID(getDatabaseName(), table_name), multithreaded, std::string{"number"}, length, offset, step);
|
||||
res->startup();
|
||||
return res;
|
||||
auto res = std::make_shared<StorageSystemNumbers>(
|
||||
StorageID(getDatabaseName(), table_name), multithreaded, std::string{"number"}, length, offset, step);
|
||||
res->startup();
|
||||
return res;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto res = std::make_shared<StorageSystemNumbers>(
|
||||
StorageID(getDatabaseName(), table_name), multithreaded, std::string{"number"});
|
||||
res->startup();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Table function '{}' requires 'limit' or 'offset, limit'.", getName());
|
||||
}
|
||||
|
@ -55,15 +55,24 @@ StoragePtr TableFunctionZeros<multithreaded>::executeImpl(const ASTPtr & ast_fun
|
||||
{
|
||||
auto arguments = function->arguments->children;
|
||||
|
||||
if (arguments.size() != 1)
|
||||
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Table function '{}' requires 'length'.", getName());
|
||||
if (arguments.size() > 1)
|
||||
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Table function '{}' cannot have more than one params", getName());
|
||||
|
||||
if (!arguments.empty())
|
||||
{
|
||||
UInt64 length = evaluateArgument(context, arguments[0]);
|
||||
|
||||
UInt64 length = evaluateArgument(context, arguments[0]);
|
||||
|
||||
auto res = std::make_shared<StorageSystemZeros>(StorageID(getDatabaseName(), table_name), multithreaded, length);
|
||||
res->startup();
|
||||
return res;
|
||||
auto res = std::make_shared<StorageSystemZeros>(StorageID(getDatabaseName(), table_name), multithreaded, length);
|
||||
res->startup();
|
||||
return res;
|
||||
}
|
||||
else
|
||||
{
|
||||
/// zero-argument, the same as system.zeros
|
||||
auto res = std::make_shared<StorageSystemZeros>(StorageID(getDatabaseName(), table_name), multithreaded);
|
||||
res->startup();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Table function '{}' requires 'limit'.", getName());
|
||||
}
|
||||
|
144
tests/queries/0_stateless/03032_numbers_zeros.reference
Normal file
144
tests/queries/0_stateless/03032_numbers_zeros.reference
Normal file
@ -0,0 +1,144 @@
|
||||
------numbers_0-argument-----
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
------system.numbers---------
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
------numbers_1-argument-----
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
------numbers_2-arguments----
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
------numbers_3-arguments----
|
||||
10
|
||||
12
|
||||
14
|
||||
16
|
||||
18
|
||||
------numbers_mt_0-argument-----
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
------numbers_mt_1-argument-----
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
------numbers_mt_2-arguments----
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
------numbers_mt_3-arguments----
|
||||
10
|
||||
12
|
||||
14
|
||||
16
|
||||
18
|
||||
------zeros_0-argument-------
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
------system.zeros-----------
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
------zeros_1-argument-------
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
------zeros_mt_0-argument-------
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
------zeros_mt_1-argument-------
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
28
tests/queries/0_stateless/03032_numbers_zeros.sql
Normal file
28
tests/queries/0_stateless/03032_numbers_zeros.sql
Normal file
@ -0,0 +1,28 @@
|
||||
SELECT '------numbers_0-argument-----';
|
||||
SELECT number FROM numbers() LIMIT 10;
|
||||
SELECT '------system.numbers---------';
|
||||
SELECT number FROM system.numbers LIMIT 10;
|
||||
SELECT '------numbers_1-argument-----';
|
||||
SELECT number FROM numbers(10);
|
||||
SELECT '------numbers_2-arguments----';
|
||||
SELECT number FROM numbers(10,10);
|
||||
SELECT '------numbers_3-arguments----';
|
||||
SELECT number FROM numbers(10,10,2);
|
||||
SELECT '------numbers_mt_0-argument-----';
|
||||
SELECT number FROM numbers_mt() LIMIT 10;
|
||||
SELECT '------numbers_mt_1-argument-----';
|
||||
SELECT number FROM numbers_mt(10);
|
||||
SELECT '------numbers_mt_2-arguments----';
|
||||
SELECT number FROM numbers_mt(10,10);
|
||||
SELECT '------numbers_mt_3-arguments----';
|
||||
SELECT number FROM numbers_mt(10,10,2);
|
||||
SELECT '------zeros_0-argument-------';
|
||||
SELECT zero FROM zeros() LIMIT 10;
|
||||
SELECT '------system.zeros-----------';
|
||||
SELECT zero FROM system.zeros LIMIT 10;
|
||||
SELECT '------zeros_1-argument-------';
|
||||
SELECT zero FROM zeros(10);
|
||||
SELECT '------zeros_mt_0-argument-------';
|
||||
SELECT zero FROM zeros_mt() LIMIT 10;
|
||||
SELECT '------zeros_mt_1-argument-------';
|
||||
SELECT zero FROM zeros_mt(10);
|
Loading…
Reference in New Issue
Block a user