Skip to content

Distribute binary expressions with top level functions #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ An engine using the distributed mode can be created through the `NewDistributedE

The interfaces used for remote execution can be found in [api](https://pkg.go.dev/github.com/thanos-io/promql-engine/api) package. Note that the `RemoteEngine` interface has a `NewRangeQuery` method, similar to the one in the Prometheus [v1.QueryEngine](https://pkg.go.dev/github.com/prometheus/[email protected]/web/api/v1#QueryEngine) interface. It is up to the user of the library to implement this method as they see fit. An example implementation could be to forward the query to an HTTP `/api/v1/query_range` endpoint of a Prometheus instance. In Thanos, this method is implemented as a gRPC call to a Thanos Querier.

For more details on the overall design, please refer to the [proposal](https://github.com/thanos-io/thanos/blob/main/docs/proposals-accepted/202301-distributed-query-execution.md) in the Thanos project.
For more details on the overall design, please refer to the [proposal](https://github.com/thanos-io/thanos/blob/main/docs/proposals-done/202301-distributed-query-execution.md) in the Thanos project.

## Continuous benchmark

Expand Down
5 changes: 3 additions & 2 deletions logicalplan/distribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ func isDistributive(expr *parser.Expr, skipBinaryPushdown bool) bool {
if _, ok := distributiveAggregations[e.Op]; !ok {
return false
}
case *parser.Call:
return len(e.Args) > 0
}

return true
Expand Down Expand Up @@ -535,6 +533,9 @@ func isConstantExpr(expr parser.Expr) bool {
case *parser.ParenExpr:
return isConstantExpr(texpr.Expr)
case *parser.Call:
if len(texpr.Args) == 0 {
return true
}
constArgs := true
for _, arg := range texpr.Args {
constArgs = constArgs && isConstantExpr(arg)
Expand Down
15 changes: 15 additions & 0 deletions logicalplan/distribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ dedup(
remote(rate(http_requests_total[2m]))
)`,
},
{
name: "top level function with no args",
expr: `pi()`,
expected: `pi()`,
},
{
name: "binary expression with no arg functions",
expr: `time() - pi()`,
expected: `time() - pi()`,
},
{
name: `histogram quantile`,
expr: `histogram_quantile(0.5, sum by (le) (rate(coredns_dns_request_duration_seconds_bucket[5m])))`,
Expand Down Expand Up @@ -262,6 +272,11 @@ histogram_quantile(0.5, sum by (le) (dedup(
remote(sum by (pod, region) (rate(http_requests_total[2m]) * 60)),
remote(sum by (pod, region) (rate(http_requests_total[2m]) * 60))))`,
},
{
name: "binary expression with no arg function",
expr: `time() - last_update_timestamp`,
expected: `dedup(remote(time() - last_update_timestamp), remote(time() - last_update_timestamp))`,
},
{
name: "subquery",
expr: `sum_over_time(http_requests_total[5m:1m])`,
Expand Down
Loading