Skip to main content

Comparisons

You can compare two values for equality, and order via the typical operators, like ==, !=, <, <=, > and >=. For example, interface.mtu == 1000 and 1000 < interface.mtu are valid expressions.

The order of items that have the same type (used by < and other relational operators) is as follows:

  • Numbers: numerical order. For example, 1 is less than 2
  • Strings: alphabetical order. For example, "ac" is less than "bb".
  • Booleans: false is less than true.
  • IP addresses: numerically. For example, ipAddress("1.2.3.4") is less than ipAddress("1.2.4.5").
  • IP subnets: ordered by prefix length first. For subnets with equal prefix lengths, the subnets are ordered numerically by host part. For example, ipSubnet("1.2.3.4/24") is less than ipSubnet("1.2.3.4/25"), but greater than ipSubnet("1.2.3.3/24).
  • MAC addresses: ordered numerically. For example, macAddress("11:22:33:44:88:99") is less than macAddress("11:22:33:44:66:77").
  • Date: chronological order. For example, 2000-01-01 is before 2000-01-02
  • Timestamp: chronological order. For example, 2000-01-01T00:00:00Z is before 2000-01-01T00:00:01Z
  • Duration: numerically. For example, 1 second is less than 2 seconds.
  • Lists: ordered lexicographically; for example [1, 4] is less than [2, 3].
  • Records: two records are ordered lexicographically based on their field values, with fields compared in order of alphabetically increasing field name. For example {x: 1, z: "b"} is less than {x: 2, z: "a"}, but is greater than {x: 1, z: "a"}.
  • OneOfs: two OneOf values are compared based on alphabetical order of their alternative names. For example, AdminStatus.DOWN is less than AdminStatus.UP. If the two values have the same alternative, then they are ordered based on the ordering of any values they contain.
  • A null value is less than all other values (except itself, to which it is equal).