DAZL Documentation | Data Analytics A-to-Z Processing Language


Contents

executeIf

Flow Control

slug: step-executeif

ExecuteIf Step

Purpose

Creates conditional logic in DAZL scripts, enabling dynamic execution paths based on evaluated conditions. Acts as a flow control mechanism for branching data pipelines.

When to Use

  • Implement conditional processing logic in data pipelines
  • Create different processing paths based on data characteristics
  • Skip steps when certain conditions are not met
  • Handle special cases with custom processing
  • Build decision trees for complex data transformations
  • Execute different analysis methods based on dataset properties
  • Implement error handling and fallback processing

How It Works

  1. Takes a logical condition expression and two possible execution branches
  2. Evaluates the condition expression using a safe evaluation method
  3. Executes either the "then" branch (if condition is true) or the "else" branch (if false)
  4. Each branch can contain multiple nested steps that are executed sequentially
  5. Returns the results from the executed branch, maintaining the data contract
  6. Provides debugging information about condition evaluation and branch selection

Parameters

Required

  • condition (string) - Logical expression to evaluate (must resolve to true/false)
  • then (object) - Container for steps to execute when condition is true:
    • steps (array) - List of step definitions to execute

Optional

  • else (object) - Container for steps to execute when condition is false:
    • steps (array) - List of step definitions to execute

Condition Expressions

  • Standard logical operators: ==, !=, >, <, >=, <=, &&, ||, !
  • Functions for complex conditions: isEmpty(), count(), contains()
  • Variables from the DAZL environment
  • Examples:
    • count($data) > 100
    • $extras.filter_applied == true
    • isEmpty($work.customers.data)

Input Requirements

  • Any data that can be passed through the DAZL data contract
  • Valid condition expression that can be safely evaluated
  • Valid step definitions in the "then" and/or "else" branches

Output

  • Returns the data from the executed branch (then/else)
  • If the selected branch is empty or not defined, returns the input data unchanged

Execution Context

  • Nested steps in the branches are executed in the same context as the parent script
  • Variables, work datasets, and context are available to nested steps
  • Changes made by nested steps persist after the executeIf completes

Example Usage

Basic Conditional Processing

executeIf:
  condition: count($data) > 0
  then:
    steps:
      - cube:
          dimensions: [region, product_category]
          measures: [revenue, units_sold]
  else:
    steps:
      - log:
          message: "No data available for cube analysis"

Complex Data Pipeline Branch

executeIf:
  condition: $extras.data_quality.missing_values < 5 && $extras.data_quality.outliers < 10
  then:
    steps:
      - filter:
          where: "status = active"
      - calculate:
          assign:
            score: "$value / $max_value * 100"
  else:
    steps:
      - filter:
          where: "status = active"
      - impute:
          method: mean
          columns: [value]
      - calculate:
          assign:
            score: "min($value / $max_value * 100, 85)"
      - log:
          level: warning
          message: "Applied corrective measures for low quality data"

Error Handling

  • Invalid conditions default to false
  • Condition evaluation errors are logged
  • Missing branches are skipped without error
  • Execution errors in nested steps propagate to the parent

Related Documentation

  • forEach step - loops through a variable's values and runs one or more steps per iteration