3 - Avoid recreating snapshot_by_name in evaluator

Đang mở Phù hợp với người mới
#6,019 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
68/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
data-engineering

Hướng nghiên cứu

Đọc sqlmesh/core/snapshot/evaluator.py, tập trung vào promote và _promote_snapshot tại các dòng được trích dẫn. Theo dõi cách mỗi hàm sử dụng snapshots và ánh xạ theo tên, bao gồm cả các lệnh gọi tiếp theo, trước khi quyết định liệu có thể loại bỏ đầu vào ban đầu hay không. Hoàn tất khi ánh xạ được tạo một lần và được truyền qua khi cần, đồng thời các bài kiểm thử liên quan đều đạt.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

File: sqlmesh/core/snapshot/evaluator.py
Function: promote , _promote_snapshot
Lines: 267 - 330 , 1253 - 1285

Issue with _promote_snapshot

In _promote_snapshot we are passed the snapshots, which is keyed by snapshot_id. The function needs to key by snapshot_name though, so we keep recreating:

snapshot_by_name = {s.name: s for s in (snapshots or {}).values()}
render_kwargs["snapshots"] = snapshot_by_name

We should just create this once in promote before we pass it in.

        # Fetch the view data objects for the promoted snapshots to get them cached
        self._get_virtual_data_objects(target_snapshots, environment_naming_info)

       snapshot_by_name = {s.name: s for s in (snapshots or {}).values()}    <------NEW

        deployability_index = deployability_index or DeployabilityIndex.all_deployable()
        with self.concurrent_context():
            concurrent_apply_to_snapshots(
                target_snapshots,
                lambda s: self._promote_snapshot(
                    s,
                    start=start,
                    end=end,
                    execution_time=execution_time,
                    snapshots=snapshots,
                    snapshots_by_name=snapshots_by_name,    <-------- NEW
                    table_mapping=table_mapping,
                    environment_naming_info=environment_naming_info,
                    deployability_index=deployability_index,  # type: ignore
                    on_complete=on_complete,
                ),
                self.ddl_concurrent_tasks,
            )

Roughly. I would also evaluate if we can remove the snapshots input to self._promote_snapshot. Maybe snapshots_by_name fulfills all the functions downstream.

Ngôn ngữ chính
Python
Star
3.3k
Fork
471
Merge trung bình
6 ngày 7 giờ
Pull request đã merge (30 ngày)
35

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của SQLMesh/sqlmesh

Tất cả issue của SQLMesh/sqlmesh

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.