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(); node_to_replace = &sort_node->getExpression();
auto * constant_node = (*node_to_replace)->as<ConstantNode>(); 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; continue;
UInt64 positional_argument_number = constant_node->getValue().get<UInt64>(); UInt64 pos;
if (positional_argument_number == 0 || positional_argument_number > projection_nodes.size()) if (constant_node->getValue().getType() == Field::Types::UInt64)
throw Exception(ErrorCodes::BAD_ARGUMENTS, {
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 {} is out of bounds. Expected in range [1, {}]. In scope {}",
positional_argument_number, pos,
projection_nodes.size(), projection_nodes.size(),
scope.scope_node->formatASTForErrorMessage()); scope.scope_node->formatASTForErrorMessage());
--positional_argument_number; *node_to_replace = projection_nodes[--pos];
*node_to_replace = projection_nodes[positional_argument_number];
} }
} }

View File

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

View File

@ -3,7 +3,7 @@ DROP TABLE IF EXISTS t;
CREATE TABLE t CREATE TABLE t
( (
`n` int, `n` int,
`__unused_group_by_column` int `__unused_group_by_column` int
) )
ENGINE = MergeTree ENGINE = MergeTree
ORDER BY n AS ORDER BY n AS
@ -14,7 +14,9 @@ SELECT
sum(n), sum(n),
__unused_group_by_column __unused_group_by_column
FROM t 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 SELECT
'processed' AS type, 'processed' AS type,