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])`,