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 摘要。