Variables Syntax¶
The system supports Jinja variable references with {{ }} syntax in all recipe files—JSON files, and others that might be executed in a node, such as a SQL file.
Overview¶
- Variable references for string values are typically enclosed in quotes and/or curly braces, such as
{"key":"xyz{{variable_name}}12345". - Variable references for dictionaries in keys, steps, and mappings can be written as
{"key":{{dictionary_variable_name}} }. - Specific variable references, such as test variables (shown below) and credentials defined as JSON dictionaries like
"config-ref": "mssqlConfig", require syntax without the Jinja braces.
See Basic Jinja Variable References for more information.
Example¶
action_node/actions/create-order-dimensions.json
{
"name": "create-order-dimensions",
"type": "DKDataSource_MSSQL",
"config": {
"username": "{{mssqlConfig.username}}", // Use Jinja syntax to reference these tool connection credentials stored in kitchen overrides
"password": "{{mssqlConfig.password}}",
"hostname": "{{mssqlConfig.hostname}}",
"port": "",
"database": "{{mssqlConfig.database}}"
// Alternatively, reference a JSON dictionary variable pre-defined with all of the credentials: "config-ref": "mssqlConfig"
},
"keys": {
"Create_Order_Line_Dimension_Table": {
"sql": "{{load_text(sqlFileName)}}", // Built-in function load_text loads a SQL file from the recipe's /resources directory
// The filename is parameterized as the variable sqlFileName
// Note, this SQL file includes Jinja expressions to call the {{schema_name}} variable
"query-type": "execute_scalar",
"set-runtime-vars": {
"result": "dimension_table_order_line_count" // This step in the action node record results as variable values, which are then used in tests
}
},
"Query_Stage_Table_Order_Line_Count": {
"sql": "SELECT COUNT(*) FROM {{schema_name}}.{{table_name}}", // Where schema_name are variables used in SQL statements
"query-type": "execute_scalar",
"set-runtime-vars": {
"result": "stage_table_order_line_count" // This step in the action node record results as variable values, which are then used in tests
}
}
},
"tests": {
"Ensure_Order_Line_Counts_Equal": {
"action": "warning",
"test-variable": "dimension_table_order_line_count", // Reference test variables in quotes without curly-braces
"type": "test-contents-as-integer",
"test-logic": {
"test-compare": "equal-to",
"test-metric": "stage_table_order_line_count" // Reference test variables in quotes without curly-braces
},
"keep-history": true
},
"Ensure_Order_Line_Counts_Always_Increasing": {
"action": "stop-on-error",
"test-variable": "dimension_table_order_line_count", // Compares a test variable to the previous value of the same variable
"type": "test-contents-as-integer",
"test-logic": {
"test-compare": "greater-than-equal-to",
"test-metric": {
"historic-calculation": "previous-value",
"historic-metric": "dimension_table_order_line_count" // Compares a test variable to the previous value of the same variable
}
},
"keep-history": true
}
}
}