Fix flaky test

This commit is contained in:
flynn 2023-12-28 14:08:14 +00:00
parent e2f4219c12
commit 2e9cdd17ef
3 changed files with 29 additions and 14 deletions

View File

@ -2156,19 +2156,31 @@ void QueryAnalyzer::replaceNodesWithPositionalArguments(QueryTreeNodePtr & node_
node_to_replace = &sort_node->getExpression();
auto * constant_node = (*node_to_replace)->as<ConstantNode>();
if (!constant_node || constant_node->getValue().getType() != Field::Types::UInt64)
if (!constant_node
|| (constant_node->getValue().getType() != Field::Types::UInt64 && constant_node->getValue().getType() != Field::Types::Int64))
continue;
UInt64 positional_argument_number = constant_node->getValue().get<UInt64>();
if (positional_argument_number == 0 || positional_argument_number > projection_nodes.size())
throw Exception(ErrorCodes::BAD_ARGUMENTS,
UInt64 pos;
if (constant_node->getValue().getType() == Field::Types::UInt64)
{
pos = constant_node->getValue().get<UInt64>();
}
else // Int64
{
auto value = constant_node->getValue().get<Int64>();
pos = value > 0 ? value : projection_nodes.size() + value + 1;
}
if (!pos || pos > projection_nodes.size())
throw Exception(
ErrorCodes::BAD_ARGUMENTS,
"Positional argument number {} is out of bounds. Expected in range [1, {}]. In scope {}",
positional_argument_number,
pos,
projection_nodes.size(),
scope.scope_node->formatASTForErrorMessage());
--positional_argument_number;
*node_to_replace = projection_nodes[positional_argument_number];
*node_to_replace = projection_nodes[--pos];
}
}

View File

@ -1,11 +1,12 @@
0 0
4 4
3 3
2 2
5 5
1 1
2 2
3 3
4 4
5 5
6 6
7 7
9 9
8 8
9 9
45 1
processed 99 0

View File

@ -3,7 +3,7 @@ DROP TABLE IF EXISTS t;
CREATE TABLE t
(
`n` int,
`__unused_group_by_column` int
`__unused_group_by_column` int
)
ENGINE = MergeTree
ORDER BY n AS
@ -14,7 +14,9 @@ SELECT
sum(n),
__unused_group_by_column
FROM t
GROUP BY __unused_group_by_column;
GROUP BY __unused_group_by_column ORDER BY __unused_group_by_column;
SELECT sum(n), 1 as x from t group by x;
SELECT
'processed' AS type,