github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/api/query/concrete_query.go (about)

     1  // Copyright 2018 The WPT Dashboard Project. All rights reserved.
     2  // Use of this source code is governed by a BSD-style license that can be
     3  // found in the LICENSE file.
     4  
     5  package query
     6  
     7  import (
     8  	"github.com/web-platform-tests/wpt.fyi/shared"
     9  )
    10  
    11  // Average as of Aug 20, 2019.
    12  const averageNumberOfSubtests = int(1655263 / 34236)
    13  
    14  // AggregationOpts are options for the aggregation format used when collecting
    15  // the results.
    16  type AggregationOpts struct {
    17  	IncludeSubtests         bool
    18  	InteropFormat           bool
    19  	IncludeDiff             bool
    20  	IgnoreTestHarnessResult bool // Don't +1 the "OK" status for testharness tests.
    21  	DiffFilter              shared.DiffFilterParam
    22  }
    23  
    24  // Binder is a mechanism for binding a query over a slice of test runs to
    25  // a particular query service mechanism.
    26  type Binder interface {
    27  	// Bind produces an query execution Plan and/or error after binding its inputs
    28  	// to a query service mechanism. E.g., an in-memory cache may verify that the
    29  	// given runs are in the cache and extract results data subsets that pertain
    30  	// to the runs before producing a Plan implementation that can operate over
    31  	// the subsets directly.
    32  	Bind([]shared.TestRun, ConcreteQuery) (Plan, error)
    33  }
    34  
    35  // Plan a query execution plan that returns results.
    36  type Plan interface {
    37  	// Execute runs the query execution plan. The result set type depends on the
    38  	// underlying query service mechanism that the Plan was bound with.
    39  	Execute([]shared.TestRun, AggregationOpts) interface{}
    40  }
    41  
    42  // ConcreteQuery is an AbstractQuery that has been bound to specific test runs.
    43  type ConcreteQuery interface {
    44  	Size() int
    45  }
    46  
    47  // Count constrains search results to include only test results where the number
    48  // of runs that match the given criteria is exactly the expected count.
    49  type Count struct {
    50  	Count int
    51  	Args  []ConcreteQuery
    52  }
    53  
    54  // MoreThan constrains search results to include only test results where the number
    55  // of runs that match the given criteria is more than the given count.
    56  type MoreThan struct {
    57  	Count
    58  }
    59  
    60  // LessThan constrains search results to include only test results where the number
    61  // of runs that match the given criteria is less than the given count.
    62  type LessThan struct {
    63  	Count
    64  }
    65  
    66  // Link is a ConcreteQuery of AbstractLink.
    67  type Link struct {
    68  	Pattern  string
    69  	Metadata map[string][]string
    70  }
    71  
    72  // Triaged is a ConcreteQuery of AbstractTriaged.
    73  type Triaged struct {
    74  	Run      int64
    75  	Metadata map[string][]string
    76  }
    77  
    78  // TestLabel is a ConcreteQuery of AbstractTestLabel.
    79  type TestLabel struct {
    80  	Label    string
    81  	Metadata map[string][]string
    82  }
    83  
    84  // TestWebFeature is a ConcreteQuery of AbstractTestWebFeature.
    85  type TestWebFeature struct {
    86  	WebFeature      string
    87  	WebFeaturesData shared.WebFeaturesData
    88  }
    89  
    90  // RunTestStatusEq constrains search results to include only test results from a
    91  // particular run that have a particular test status value. Run IDs are those
    92  // values automatically assigned to shared.TestRun instances by Datastore.
    93  // Status IDs are those codified in shared.TestStatus* symbols.
    94  type RunTestStatusEq struct {
    95  	Run    int64
    96  	Status shared.TestStatus
    97  }
    98  
    99  // RunTestStatusNeq constrains search results to include only test results from a
   100  // particular run that do not have a particular test status value. Run IDs are
   101  // those values automatically assigned to shared.TestRun instances by Datastore.
   102  // Status IDs are those codified in shared.TestStatus* symbols.
   103  type RunTestStatusNeq struct {
   104  	Run    int64
   105  	Status shared.TestStatus
   106  }
   107  
   108  // Or is a logical disjunction of ConcreteQuery instances.
   109  type Or struct {
   110  	Args []ConcreteQuery
   111  }
   112  
   113  // And is a logical conjunction of ConcreteQuery instances.
   114  type And struct {
   115  	Args []ConcreteQuery
   116  }
   117  
   118  // Not is a logical negation of ConcreteQuery instances.
   119  type Not struct {
   120  	Arg ConcreteQuery
   121  }
   122  
   123  // Size of TestNamePattern has a size of 1: servicing such a query requires a
   124  // substring match per test.
   125  func (TestNamePattern) Size() int { return 1 }
   126  
   127  // Size of SubtestNamePattern has a size of 1: servicing such a query requires a
   128  // substring match per subtest.
   129  func (SubtestNamePattern) Size() int { return averageNumberOfSubtests }
   130  
   131  // Size of TestPath has a size of 1: servicing such a query requires a
   132  // substring match per test.
   133  func (TestPath) Size() int { return 1 }
   134  
   135  // Size of RunTestStatusEq is 1: servicing such a query requires a single lookup
   136  // in a test run result mapping per test.
   137  func (RunTestStatusEq) Size() int { return 1 }
   138  
   139  // Size of RunTestStatusNeq is 1: servicing such a query requires a single
   140  // lookup in a test run result mapping per test.
   141  func (RunTestStatusNeq) Size() int { return 1 }
   142  
   143  // Size of Link has a size of 1: servicing such a query requires a
   144  // substring match per Metadata Link Node.
   145  func (Link) Size() int { return 1 }
   146  
   147  // Size of Triaged is 1: servicing such a query requires a single
   148  // lookup in a test run result mapping per test.
   149  func (Triaged) Size() int { return 1 }
   150  
   151  // Size of TestLabel has a size of 1: servicing such a query requires a
   152  // label match per Metadata Link Node.
   153  func (TestLabel) Size() int { return 1 }
   154  
   155  // Size of TestWebFeature has a size of 1: servicing such a query requires a
   156  // web feature match per Web Features Node.
   157  func (TestWebFeature) Size() int { return 1 }
   158  
   159  // Size of Count is the sum of the sizes of its constituent ConcretQuery instances.
   160  func (c Count) Size() int { return size(c.Args) }
   161  
   162  // Size of Is depends on the quality.
   163  func (q MetadataQuality) Size() int {
   164  	// Currently only 'Different' supported, which is one set comparison per row.
   165  	return 1
   166  }
   167  
   168  // Size of Or is the sum of the sizes of its constituent ConcretQuery instances.
   169  func (o Or) Size() int { return size(o.Args) }
   170  
   171  // Size of And is the sum of the sizes of its constituent ConcretQuery
   172  // instances.
   173  func (a And) Size() int { return size(a.Args) }
   174  
   175  // Size of Not is one unit greater than the size of its ConcreteQuery argument.
   176  func (n Not) Size() int { return 1 + n.Arg.Size() }
   177  
   178  // Size of True is 0: It should be optimized out of queries in practice.
   179  func (True) Size() int { return 0 }
   180  
   181  // Size of False is 0: It should be optimized out of queries in practice.
   182  func (False) Size() int { return 0 }
   183  
   184  func size(qs []ConcreteQuery) int {
   185  	s := 0
   186  	for _, q := range qs {
   187  		s += q.Size()
   188  	}
   189  
   190  	return s
   191  }