06. Đồ thị  /  Bài 2 trong 3

Topological sort

Xếp thứ tự chạy cho một DAG như dbt hay Airflow: bảng nào hết phải chờ thì chạy, đợt nào chạy song song được, và cách phát hiện vòng.

9 phútCơ bản6 bướcCâu đoán 0/5
CẦN BIẾT TRƯỚC
  • Python: dict, set và deque
  • Bài BFS và DFS
Cạnh đã đếm
0/8
Đang xét
—
Bậc vào 0
9
Độ phức tạp
O(V + E)
raw_orders0raw_customers0stg_orders0stg_customers0orders_snapshot0dim_customers0fct_orders0churn_model0revenue_dashboard0raw_orders0raw_customers0stg_orders0stg_customers0orders_snapshot0dim_customers0fct_orders0revenue_dashboard0churn_model0
mũi tên u → v: v đọc dữ liệu từ u, nên phải chờ u
BẬC VÀO = 0
raw_ordersraw_customersstg_ordersstg_customersorders_snapshotdim_customersfct_orderschurn_modelrevenue_dashboard
ĐÃ ĐẾM CẠNH ĐI RA
indegree.py
indegree = {table: 0 for table in tables}for table in graph:    for child in graph[table]:        indegree[child] += 1ready = [t for t in tables if indegree[t] == 0]
1 / 10
chưa chạysẵn sàng, chờ quay luiđang chạy, trên vòngđã chạy
TRONG BÀI NÀYBước 1 / 6
KIỂM TRA CUỐI BÀI

4 câu, không có hình gợi ý

  1. 1Với các phụ thuộc dưới đây, thứ tự chạy nào hợp lệ?

    quiz.py
    raw_orders → stg_ordersstg_orders → fct_ordersdim_customers → fct_orders
  2. 2DAG chia được thành 4 đợt, mỗi model chạy 10 phút, dbt chạy với --threads 50. Cả pipeline nhanh nhất mất bao lâu?

  3. 3Kahn chạy xong, order có 7 bảng trong khi DAG khai báo 9 bảng. Kết luận gì?

  4. 4graphlib.TopologicalSorter(graph) của Python muốn dict graph theo chiều nào?

Đã trả lời 0/4 câu.