This page covers best practices for defining variables in Treasure workflows, focusing on avoiding common pitfalls that can cause unexpected operator behavior.
Prerequisites: Understand basic variable concepts in Workflow Definition.
Avoid defining variables at the top-level _export - they become options for ALL operators.
# BAD: Affects all operators unexpectedly
_export:
database: my_db # Goes to ALL operators
engine: presto # Goes to ALL operators
timeout: 30m # Goes to ALL operators
+td_task:
td>: query.sql # Uses global database 'my_db'
+pg_task:
pg>: other.sql # ALSO uses global database! (unexpected)The workflow definition is equivalent to:
+td_task:
td>: query.sql
database: my_db
engine: presto
timeout: 30m
+pg_task:
pg>: other.sql
database: my_db
engine: presto
timeout: 30mAvoid adding your own variables to operator namespaces like td, aws, bq - they merge with operator options. These options might be interpreted as actual operator options in future versions. Please refer to Appendix for a list of reserved namespaces.
# BAD: Custom variables in operator namespace
_export:
td: # td namespace
database: my_db # OK - this is a real TD option
engine: presto # OK - this is a real TD option
timeout: 10m # BAD - not a real TD option, might conflict with future operator options
user_name: treasure # BAD - not a real TD option, might conflict with future operator options
+td_task:
td>: query.sql
+td_task2:
td_wait>: query.sqlThe workflow definition is equivalent to:
+td_task:
td>: query.sql
database: my_db
engine: presto
timeout: 10m
user_name: treasure
+td_task2:
td_wait>: query.sql
database: my_db
engine: presto
timeout: 10m
user_name: treasure Create your own namespaces for custom variables and use operator namespaces only for real operator options.
# GOOD: Clear separation
_export:
# Your custom variables/namespaces
config:
timeout: 10
user_name: "treasure"
# Only real TD operator options
td:
database: analytics_db
engine: presto
+my_task:
td>: query.sql
# You can access custom variables with ${config.user_name}_export:
td:
database: default_db
+special_task:
td>: special_query.sql
database: special_db # Override for this task only- No top-level variables - use namespaces
- No custom variables in
td/aws/bqnamespaces - only real operator options - Create your own namespaces for custom variables/configs
- Override at task level when needed
Some operators have reserved namespaces. Variables defined in these namespaces are automatically merged with operator options.
td>,td_run>,td_ddl>,td_load>,td_for_each>,td_wait>,td_wait_table>,td_table_export>,td_result_export>→td
mail>→mailhttp>→http
pg>→pg
s3_wait>,s3_delete>,s3_copy>,s3_move>→aws.s3,awsredshift>→redshiftredshift_load>→redshift_load,redshiftredshift_unload>→redshift_unload,redshift
bq>,bq_ddl>,bq_extract>,bq_load>→bqgcs_wait>→gcs
py>→py