Skip to main content

Logic

Logical conditions

The logical conditions generally follow a structured format:

[Left-Hand Side Element] [Condition Operator] [Right-Hand Side Element]

Valid Left-Hand Side (LHS) Elements:

  • Function Result: The result of a function that processes object data, metadata, or relations.
  • Identifier: A reference to an object property

Valid Right-Hand Side (RHS) Elements:

  • Boolean: A true/false value used for logical comparisons.
  • Identifier: Another reference to an object property
  • String: A sequence of characters enclosed in quotes, used for matching text values
  • Number: A numerical value, which can be an integer or floating-point number, used for quantitative comparisons.

When the LHS element is of boolean type, a shorthand condition is allowed where the condition operator and RHS are omitted. In this case, the condition is implicitly treated as equal to true. For example:

  • Standard Form: is_root() == true
  • Short Form: is_root()
note

ContexQL enforces strong typing, meaning that the types of the LHS and RHS must match. A type mismatch between LHS and RHS will result in a runtime error.

Conditions

The following conditions (both lexical and numerical) are defined:

  • equal: == or =
  • not equal: != or <>
  • lesser: <
  • lesser or equal: <=
  • greater: >
  • greater or equal: >=

Examples:

  • object_id = "something"
  • size > 1024
  • is_entry == true
  • is_entry

Logical Expressions

Multiple logic conditions can be combined into complex logic expressions using boolean operators. These expressions allow for precise and flexible querying of object characteristics and relationships within data graphs.

Available Boolean Operators:

  • Logical AND:
    • Symbols: && or and
    • Combines conditions that must all be true.
  • Logical OR:
    • Symbols: || or or
    • Combines conditions where at least one must be true.
  • Logical NOT:
    • Symbols: ! or not
    • Negates a condition, making true conditions false and vice versa.

Operator Precedence:

The default precedence of boolean operators is:

  1. NOT (! or not)
  2. AND (&& or and)
  3. OR (|| or or)

This precedence can be altered using parentheses, allowing for customized evaluation order within expressions.

Using Parentheses:

Parentheses ( ) can wrap conditions and sub-expressions, overriding the default precedence to ensure desired logical grouping and execution order. Balanced parentheses are not only valid but encouraged to enhance readability and maintain clear logical flow.

Examples:

  • (object_type = "Text" && size > 4096) || (object_type = "HTML" && size > 8192)
  • object_type = "ZIP" and is_root()