MCPcopy Create free account
hub / github.com/rilldata/rill / Search

Method Search

runtime/metricsview/executor/executor.go:562–666  ·  view source on GitHub ↗

Search executes the provided query against the metrics view.

(ctx context.Context, qry *metricsview.SearchQuery, executionTime *time.Time)

Source from the content-addressed store, hash-verified

560
561// Search executes the provided query against the metrics view.
562func (e *Executor) Search(ctx context.Context, qry *metricsview.SearchQuery, executionTime *time.Time) ([]metricsview.SearchResult, error) {
563 if !e.security.CanAccess() {
564 return nil, runtime.ErrForbidden
565 }
566
567 // Generate a metricsview.Query and build a AST
568 // This is a hacky implementation since both metricsview.Query and AST are designed for aggregate queries.
569 // TODO :: Refactor the code and extract common functionality from metricsview.Query and AST and write SearchQuery to underlying SQL/Native druid query directly.
570
571 if e.olap.Dialect().String() == drivers.DialectNameDruid {
572 // native search
573 res, err := e.executeSearchInDruid(ctx, qry, executionTime)
574 if err == nil || !errors.Is(err, errDruidNativeSearchUnimplemented) {
575 return res, err
576 }
577 }
578
579 var (
580 finalSQL strings.Builder
581 finalArgs []any
582 rowsCap int64
583 )
584 for i, d := range qry.Dimensions {
585 if i > 0 {
586 finalSQL.WriteString(" UNION ALL ")
587 }
588 q := &metricsview.Query{
589 MetricsView: qry.MetricsView,
590 Dimensions: []metricsview.Dimension{{Name: d, Compute: nil}},
591 Measures: nil,
592 PivotOn: nil,
593 Spine: nil,
594 Sort: nil,
595 TimeRange: qry.TimeRange,
596 ComparisonTimeRange: nil,
597 Where: nil,
598 Having: qry.Having,
599 Limit: qry.Limit,
600 Offset: nil,
601 TimeZone: "",
602 UseDisplayNames: false,
603 Rows: false,
604 QueryLimits: &metricsview.QueryLimits{
605 RequireTimeRange: false,
606 MaxTimeRangeDays: 0, // not enforced
607 },
608 UnusedFields: nil,
609 } //exhaustruct:enforce
610 q.Where = whereExprForSearch(qry.Where, d, qry.Search)
611
612 err := e.RewriteQueryTimeRanges(ctx, q, executionTime)
613 if err != nil {
614 return nil, err
615 }
616
617 rowsCap, err = e.rewriteQueryEnforceCaps(q)
618 if err != nil {
619 return nil, err

Callers 1

ResolveMethod · 0.45

Calls 15

executeSearchInDruidMethod · 0.95
SQLMethod · 0.95
NewASTFunction · 0.92
EscapeStringValueFunction · 0.92
whereExprForSearchFunction · 0.85
CanAccessMethod · 0.80
SetCapMethod · 0.80
StringMethod · 0.65
DialectMethod · 0.65

Tested by

no test coverage detected