Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
38ce912
fix: dbt_cte_profile lists the earlier CTEs each CTE reads
hkaltai Nov 20, 2026
cb559bf
fix: CTE reads skip Jinja, match brackets and any letter case, scan o…
hkaltai Nov 20, 2026
a860746
fix: CTE reads step over Jinja strings holding }}, backslash-escaped …
hkaltai Nov 20, 2026
49b2fd0
fix: a Jinja expression's braces are balanced before its closing }}
hkaltai Nov 20, 2026
99a6dbf
fix: Jinja inside a SQL string stays inside it; the backslash limit i…
hkaltai Nov 20, 2026
cec32c8
fix: quoted names and strings step over Jinja comments and Jinja hold…
hkaltai Nov 20, 2026
8d85639
fix: CTE reads blank Jinja before reading the SQL, and a body's own W…
hkaltai Nov 20, 2026
11305b6
fix: CTE reads: shadowing starts after the inner CTE's definition, qu…
hkaltai Nov 20, 2026
79304cf
fix: a subquery's WITH shadows an outer CTE of the same name inside t…
hkaltai Nov 20, 2026
f7e8c8d
fix: an inner WITH RECURSIVE CTE shadows from its clause's start; inn…
hkaltai Nov 20, 2026
26df3ff
fix: WITH RECURSIVE is recognised across comments and any whitespace
hkaltai Nov 20, 2026
92b0802
fix: cte reads follow rendered Jinja and DuckDB lists; package schema…
hkaltai Nov 23, 2026
a785363
Merge origin/main into fix/cte-profile-reads
hkaltai Nov 23, 2026
97c3fd5
fix: cte reads keep Jinja branches apart, shadow lookup stays linear,…
hkaltai Nov 23, 2026
fefb5fa
fix: a bracketed CTE name holding a comma or parenthesis is read as t…
hkaltai Nov 23, 2026
684c245
fix: a Jinja comment run is read once with its trimming; an unprefixe…
hkaltai Nov 23, 2026
0809eaa
fix: nested WITH scopes are found in one pass; a left-trimming Jinja …
hkaltai Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions packages/opencode/src/altimate/native/dbt/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
// cannot read a large manifest themselves (the Claude Code plugin reads files up to 4 MiB) get it
// from the CLI (`altimate tool run dbt_lineage --json` with include_graph); MCP carries no graph.

import { createHash } from "crypto"

export interface GraphNode {
id: string
name: string
/** An exposure's label; null for other nodes. */
label: string | null
type: string
path: string | null
/**
* The project-relative schema.yml that describes the node (dbt's patch_path without its `package://`), when there
* is one in the project itself: a node of an installed package has none, its file being relative to that package.
*/
yml?: string
materialized: string | null
/** database.schema.table, lower-cased. */
relation: string | null
Expand Down Expand Up @@ -49,14 +56,35 @@ function relationOf(node: any): string | null {
return parts.length === 3 ? parts.join(".").toLowerCase() : null
}

function nodeOf(id: string, node: any): GraphNode {
/** Whether a package is the manifest's root project: by `project_name`, or by `project_id`, the MD5 of that name. */
function isRootPackage(name: string, metadata: any): boolean {
if (typeof metadata?.project_name === "string" && metadata.project_name) return name === metadata.project_name
if (typeof metadata?.project_id === "string" && metadata.project_id)
return createHash("md5").update(name).digest("hex") === metadata.project_id
return false
}

/** The project-relative schema.yml path of a node's patch_path. A path of an installed package, or of a package
* the manifest cannot tell is the root project, is relative to somewhere else and is left out. */
function ymlOf(node: any, metadata: any): string | undefined {
if (typeof node?.patch_path !== "string") return undefined
const scheme = /^([^:/]+):\/\//.exec(node.patch_path)
// A path without the package prefix (older manifests) belongs to the node's own package.
const owner = scheme ? scheme[1] : node?.package_name
if (typeof owner !== "string" || !isRootPackage(owner, metadata)) return undefined
return node.patch_path.slice(scheme?.[0].length ?? 0)
}

function nodeOf(id: string, node: any, metadata?: any): GraphNode {
const yml = ymlOf(node, metadata)
const type: string = node?.resource_type ?? id.split(".")[0] ?? "unknown"
return {
id,
name: node?.name ?? id.split(".").pop() ?? id,
label: type === "exposure" ? node?.label || node?.name || id : null,
type,
path: node?.original_file_path ?? null,
...(yml !== undefined ? { yml } : {}),
materialized: node?.config?.materialized ?? null,
relation: relationOf(node),
columns: Object.entries<any>(node?.columns ?? {}).map(([key, col]) => String(col?.name ?? key)),
Expand Down Expand Up @@ -103,13 +131,13 @@ export function lineageGraph(manifest: any, id: string): LineageGraph {
const truncated = walk(children, MAX_DOWNSTREAM, counted)
const graph: LineageGraph = { nodes: {}, parents: {}, children: {}, truncated, upTruncated }
for (const one of keep) {
graph.nodes[one] = nodeOf(one, lookup(manifest, one))
graph.nodes[one] = nodeOf(one, lookup(manifest, one), manifest.metadata)
graph.parents[one] = (parents[one] ?? []).filter((other) => keep.has(other))
graph.children[one] = (children[one] ?? []).filter((other) => {
if (keep.has(other)) return true
if (!isTest(other) || !counted.has(one)) return false
if (!graph.nodes[other]) {
graph.nodes[other] = { ...nodeOf(other, lookup(manifest, other)), type: "test" }
graph.nodes[other] = { ...nodeOf(other, lookup(manifest, other), manifest.metadata), type: "test" }
graph.parents[other] = (parents[other] ?? []).filter((p) => keep.has(p))
graph.children[other] = []
}
Expand Down
Loading
Loading