Dagexamples

Introduction #

This chapter provides complete DAG configuration examples demonstrating task orchestration, dependencies, and scheduled execution in practice.

Dependency Operators #

Symbol Meaning Example
>> Downstream dependency t1 >> t2 (t2 depends on t1)
<< Upstream dependency t2 << t1 (t2 depends on t1)
[] Parallel execution [t1, t2] >> t3

Complete Sample #

"""Variable definitions (Python syntax, optional)"""
P_DAYS = 12
MSG = 'xxxx'
report_time = datetime.datetime.now() - datetime.timedelta(days=int(P_DAYS))
P_START_ZYM = report_time.strftime('%Y%m')

-- JOB definitions
#link  lastdag 30 3600        -- Poll every 30s, 1hr timeout
#impala_sql  sqlfile1         -- Execute Impala
#hive_sql    sqlfile2         -- Execute Hive
#dataset     checkinfo  321   -- Data query/validation
#sp  sp1   report_time,MSG    -- Execute SP with params
#ktr myktr   P_START_ZYM      -- Execute Kettle ktr
#kjb mykjb   P_START_ZYM
-- #kjb abc                    -- Comment out to skip

-- Grouped (collapsible with //):
    #datax   jobabc   --comment
    #datax   jobabc   --comment

//////////////
-- Task chain
lastdag >> sqlfile1 >>  \
validate >> sp1 >> [myktr, mykjb]
lastdag >> sqlfile2

Dependency Setup Explanation #

# Chain A
t1 >> t2 >> t3
# Chain B
t4 >> t5 >> t6
# Chain C
t7 >> t8 >> t9
# Execute C only after A and B complete
[t3, t6] >> t7

Methods: #

  • t1.set_downstream(t2): t2 depends on t1
  • t2.set_upstream(t1): same as above
  • t1 >> t2: shorthand for set_downstream
  • t1 >> t2 >> t3: chain of dependencies
  • t1 >> [t2, t3]: multiple downstream tasks execute in parallel