Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Analyzer/Resolve/resolveFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2775,8 +2775,12 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi
/// `randConstant(), randConstant()` shares. What separates two calls is their arguments, which
/// the hash still covers: `randConstant(1)` and `randConstant(2)` keep their own values, and that
/// is the documented way to ask for two different constants in one query.
///
/// Server constants (`hostName`, `serverUUID`, ...) capture `Context::isDistributed` when built.
/// A local `UNION` branch and a later cluster branch must not share that instance.
if (function && !function->isDeterministic() && !function->isStateful()
&& function->isDeterministicInScopeOfQuery())
&& function->isDeterministicInScopeOfQuery()
&& !function->isServerConstant())
{
auto hash = function_node_ptr->getTreeHash({ .compare_aliases = false });
function_base_cache = &functions_cache[hash];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 1 1
2 2 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- A local GROUP BY hostName() must not be reused for a later cluster branch.
-- hostName() is folded on the local branch and must stay a per-shard column on the cluster branch.

SELECT tag, c, h = hostName()
FROM
(
SELECT hostName() AS h, count() AS c, 1 AS tag
FROM numbers(1)
GROUP BY h
UNION ALL
SELECT hostName() AS h, count() AS c, 2 AS tag
FROM cluster('test_cluster_two_shards', system.one)
GROUP BY h
)
ORDER BY tag;
Loading