Skip to content

Commit

Permalink
Don't optimize comparison query for druid mvd (#5536)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjain1 authored Aug 27, 2024
1 parent 194bdd7 commit 554ac6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
11 changes: 7 additions & 4 deletions runtime/metricsview/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ type SelectNode struct {
// The Name must always match a the name of a dimension/measure in the metrics view or a computed field specified in the request.
// This means that if two columns in different places in the AST have the same Name, they're guaranteed to resolve to the same value.
type FieldNode struct {
Name string
Label string
Expr string
Name string
Label string
Expr string
AutoUnnest bool
}

// ExprNode represents an expression for a WHERE clause.
Expand Down Expand Up @@ -154,7 +155,9 @@ func NewAST(mv *runtimev1.MetricsViewSpec, sec *runtime.ResolvedSecurity, qry *Q
return nil, fmt.Errorf("failed to unnest field %q: %w", f.Name, err)
}

if !auto {
if auto {
f.AutoUnnest = true
} else {
ast.unnests = append(ast.unnests, tblWithAlias)
f.Expr = ast.sqlForMember(unnestAlias, f.Name)
}
Expand Down
12 changes: 8 additions & 4 deletions runtime/metricsview/executor_rewrite_approx_comparisons.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ func (e *Executor) rewriteApproxComparisonNode(a *AST, n *SelectNode) bool {
}
sortField := a.Root.OrderBy[0]

// if there are unnests in the query, we can't rewrite the query for Druid
// it fails with join on cte having multi value dimension, issue - https://github.com/apache/druid/issues/16896
if e.olap.Dialect() == drivers.DialectDruid && len(a.unnests) > 0 {
return false
if e.olap.Dialect() == drivers.DialectDruid {
// if there are unnests in the query, we can't rewrite the query for Druid
// it fails with join on cte having multi value dimension, issue - https://github.com/apache/druid/issues/16896
for _, dim := range n.FromSelect.DimFields {
if dim.AutoUnnest {
return false
}
}
}

// Find out what we're sorting by
Expand Down

0 comments on commit 554ac6c

Please sign in to comment.