From ba2290b948053494889ad3a9bfba64da588a5a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Thu, 30 Jan 2025 12:09:58 +0200 Subject: [PATCH] logicalplan: fix edgecase with scalar() in distribution (#511) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scalar() is not really distributive from our experience. This is because it returns NaN even if the given vector selector doesn't match anything so as a consequence it is impossible to know whether the NaN is expected or not from the PoV of the root querier. Signed-off-by: Giedrius Statkevičius --- logicalplan/distribute.go | 6 ++++++ logicalplan/distribute_test.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/logicalplan/distribute.go b/logicalplan/distribute.go index 7eb63d4f..2c81ef81 100644 --- a/logicalplan/distribute.go +++ b/logicalplan/distribute.go @@ -552,6 +552,12 @@ func isDistributive(expr *Node, skipBinaryPushdown bool, engineLabels map[string return false } } + // scalar() returns NaN if the vector selector returns nothing + // so it's not possible to know which result is correct. Hence, + // it is not distributive. + if e.Func.Name == "scalar" { + return false + } } return true diff --git a/logicalplan/distribute_test.go b/logicalplan/distribute_test.go index 7354c075..2ba14bb8 100644 --- a/logicalplan/distribute_test.go +++ b/logicalplan/distribute_test.go @@ -42,6 +42,11 @@ func TestDistributedExecution(t *testing.T) { expr: `(http_requests_total)`, expected: `dedup(remote((http_requests_total)), remote((http_requests_total)))`, }, + { + name: "scalar", + expr: `scalar(redis::shard_price_per_month)`, + expected: `scalar(dedup(remote(redis::shard_price_per_month), remote(redis::shard_price_per_month)))`, + }, { name: "rate", expr: `rate(http_requests_total[5m])`,