spiralcraft.data Query reference

Overview

Data query operations are specified using a modular set of declarative Query objects, connected together to represent a processing tree. The Query is presented to zero or more Stores, where applicable, where it is transformed and bound into an optimal data pipeline for the specific type of Store.

All the queries below are found in the spiralcraft.data.query package.

Scan

Retrieves instances of a given type from a Store.

Most Queries in general, and all Queries that retrieve Tuple data, include a Scan as their original data source. In the unoptimized case, a Scan will "scan" all instances of a given Type.

Properties

  • type
    The type to retrieve

EquiJoin

An EquiJoin selects a subset of Tuples from its source where a set of field values in the source Tuple, aka. the "variant values", exactly matches a set of input values, aka. the "invariant values".

An EquiJoin is usually implemented using an index lookup, where applicable, and is an optimized case of a Selection. It is the optimized form of a Selection with a set of conjunctive equality constraints- ie. .f1==p1 [ && .f2==p2 ... ]

Properties

  • source
    The source Query
  • LHSExpressions
    A set of expressions, each in the form .fieldName, which represent the set of fields of the variant Tuple to search (ie. the key fields).
  • RHSExpressions
    A set of expressions, each in the form valueExpression, which provide the values to search for. The variant Tuple will not be visible to the RHS expressions.

Selection

A Selection retrieves the set of Tuples from the source Query that match the specified constraint expression. The constraint expression is evaluated in a TeleFocus where the subject, represented by "." prefixed expressions, is the variant source Tuple, and the context is invariant.

For example, the constraint expression .name=myName would compare the "name" field in the variant Tuple to the value of myName in the context (which may be some application Focus or a Tuple from an outer Query).

Stores may optimize Selections based on an analysis of the constraint expression and source pipeline.

For instance, a Selection with a constraint that contains a conjunctive equality sub-expression (ie. .f1==p1 && .f2==p2 ...)may be factored to use an EquiJoin for this purpose and would filter the result using the remainder of the constraint expression.

Properties

  • source
    The source of data for this Selection
  • constraints
    The constraint expression

Union

Combines the results of multiple sources, eliminating duplicates.

Concatenation

Combines the results of multiple sources, without checking for duplicates. Used when memory efficient streaming behavior is required and duplicates don't matter or are known not to be present.

Distinct

Returns the set of distinct values of a projection of a source query (ie. the set of unique value combinations over a subset of the source fields).

SetFilter

Filters the source data by determining whether a function of the source Tuple is contained in an invariant set.

Properties

  • filterSetX
    An Expression that resolves against the invariant context to the set of items to search. This set will be pre-indexed, per execution, in the default implementation of this query.
  • searchX
    An Expression that defines the function of the variant Tuple to search for. The result of this Expression will be looked up in the filter set, and must be of a type compatible with the filter set element type.

Examples

 <query:SetFilter
   xmlns:query="class:/spiralcraft/data/query/"
   xmlns:example="class:/spiralcraft/data/test/example/"
   >
 
   <filterSetX>myListOfNames
   </filterSetX>
 
   <searchX>.name
   </searchX>
 
   <source>
     <query:Scan>
       <type><example:Customer.type/>
       </type>
     </query:Scan>
   </source>
 
 </query:SetFilter>

Sort

Sorts the data from the source according to a multi-element Order.

Shuffle

Randomly sorts the source data

ReferenceQuery

Allows an arbitrary source of Aggregate data to source another Query pipeline. The data source is specified using an Expression, which must resolve to an Aggregate.