Missing Values and Null Expressions
Data are sometimes missing in the data model (marked as nullable in the Data Model tab). For example, the mtu of
an interface may be missing. To determine if an expression produces a value or is missing, the isPresent(value)
operator can be used.
A missing value can also be introduced by the query using the syntax null : T for any type T. For example,
null: Integer denotes a null numeric value, while null: List<Device> denotes a null value whose type is a list of
Device records.
This expression can be useful when performing a case analysis, if you prefer to ignore some possible cases. For example,
a SubInterface record has a vlan field whose type is SubInterfaceVlan, which is a OneOf type, with two subtypes:
VLAN_ID(vlan) where vlan is a Integer and QINQ_ID(outerInner) where outerInner is a String. To get just the
vlan number for a subinterface record held in a variable called subiface, you could use the following expression:
when subiface.vlan is VLAN_ID(vlan) -> vlan; otherwise -> null : Integer
The expression can be used in a larger context, for example within a where clause of a query to filter the results to
just subinterfaces that have a vlan number, as in the following fragment:
...
let vlan = when subiface.vlan is VLAN_ID(vlan) -> vlan; otherwise -> null : Integer
where isPresent(vlan)
...
See OneOfs and Enumerations for information on OneOf types and when expressions.