SkySpark by SkyFoundry

16. Filter

Overview

Filter strings are a special sub-set of Axon used to query projects for various APIs such as:

In addition Axon allows filters to specified as a lazily evaluated boolean condition with the exact same syntax for use in the core Axon read and readAll functions.

Usage

The simple usage is just a tag name which matches any record that has the tag (regardless of its value):

site  // query any record with the "site" tag

To match a tag value you can use any of the equality or comparison operators:

geoPostalCode == "23220"   // equal to
geoPostalCode != "23220"   // not equal to
temp < 75                  // less than
temp <= 75                 // less than or equal to
temp > 75                  // greater than
temp >= 75                 // greater than or equal to

Compare operators can use all the standard literal values with the same format as Axon for bool, int, float, str, date, etc.

You can combine filters using and, or, or not:

site or equip             // has site or equip tag
equip and hvac            // has equip and hvac tag
equip and not hvacRtu     // has equip tag, but not the hvacRtu tag

If you need to query a tag which is an Axon keyword you can specify the tag name as a string literal:

"return" and temp        // has return and temp tags

Pathing

You use the -> to dereference a tag which has a Ref value. For example if your equip rec has a siteRef tag that references the site, you can query for equip in a given city such as:

equip and siteRef->geoCity == "Chicago"

The way to read the above expression is match a record if:

Grammar

<filter>     :=  <predicate>
<predicate>  :=  <condOr>
<condOr>     :=  <condAnd> ("or" <condAnd>)*
<condAnd>    :=  <term> ("and" <term>)*
<term>       :=  <parens> | <has> | <missing> | <cmp>
<parens>     :=  "(" <predicate> ")"
<has>        :=  <path>
<missing>    :=  "not" <path>
<cmp>        :=  <path> <cmpOp> <val>
<cmpOp>      :=  "=" | "!=" | "<" | "<=" | ">" | ">="
<val>        :=  <bool> | <int> | <float> | <str> | <dur> | <recId> |
                 <uri> | <time> | <date> 
<path>       :=  <idPath> | <strLiteral>
<idPath>     :=  <name> ("->" <name>)*
<strLiteral> :=  Axon double quote string literal

The val literals have the same lexical representation as Axon.