3 - Avoid recreating snapshot_by_name in evaluator

未關閉 適合新手
#6,019 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 4 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
68/100
Issue 類型
重構
描述清晰度
描述清楚
活躍度
冷清
技術堆疊
python

研究方向

閱讀 sqlmesh/core/snapshot/evaluator.py,著重查看引用行中的 promote 和 _promote_snapshot。在決定是否可以移除原始輸入之前,追蹤每個函式如何使用 snapshots 和以名稱為鍵的對應,包括下游呼叫。完成標準是對應只建立一次,並在需要時傳遞,且相關測試通過。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
Python
星號
3.3k
分支
471
平均合併
6 天 7 小時
30 天內合併 PR
35

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

SQLMesh/sqlmesh 的其他 Issue

查看 SQLMesh/sqlmesh 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。