Interface QueryExpression<T extends DataObject>

Type Parameters:
T - Result object type
All Superinterfaces:
Immutable
All Known Implementing Classes:
DefaultQuery

@Beta public interface QueryExpression<T extends DataObject> extends Immutable
An opaque query expression. A query execution results in a QueryResult, which is composed of zero or more objects of the same type. Implementations of this interface are expected to be effectively-immutable and therefore thread-safe and reusable.

While this interface does not expose any useful methods, it represents a well-defined concept, which is composed of three distinct parts:

  • root path, which defines the subtree on which the expression is executed
  • select path, which is a strict subset of the root path and defines which objects should be selected
  • a set of predicates, which are to be evaluated on selected objects
When the expression is evaluated, its QueryResult will contain only those selected objects which also match all predicates in the expression.

For the purposes of illustration of how these three parts work together, let's imagine the following simple model:

   module foo {
     list foo {
       key name;

       leaf name {
         type string;
       }

       leaf alias {
         type string;
       }

       container bar {
         list baz {
           key id;

           leaf id {
             type uint64;
           }

           leaf value {
             type string;
           }
         }
       }
     }
   }
 

We have two nested lists, each having two leaves -- one addressable as a key, one a plain property. There is a number of different queries we could perform on such a model:

  1. select all bazes which have value="foo"
  2. select all bazes under foo[name="xyzzy"], which have value="foo"
  3. select all foos which have alias="xyzzy"
  4. select all foos which have alias="xyzzy" and contain a baz[value="foo"]

Note how the first and second options differ in what is being searched:

  • search for all baz entries needs to traverse all foo entries
  • search for all baz entries for foo[name="xyzzy"] needs to traverse only a single directly-addressable entry.
The distinction here is made by selecting different root paths: the first will specify the entire foo list, while the second will select a specific foo entry.