|
1 | 1 | import { afterEach, describe, expect, spyOn, test } from "bun:test" |
2 | 2 | import * as core from "@altimateai/altimate-core" |
3 | | -import { mkdtempSync, rmSync, writeFileSync } from "node:fs" |
| 3 | +import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs" |
4 | 4 | import { tmpdir } from "node:os" |
5 | 5 | import { join } from "node:path" |
6 | 6 | import { columnReach, exposuresOn, parentsNamed, joinsNaturally, selectsStar } from "../../src/altimate/native/dbt/column-reach" |
@@ -74,9 +74,14 @@ describe("columnReach", () => { |
74 | 74 |
|
75 | 75 | test("an output alias or a comment naming the column is not a read", () => { |
76 | 76 | const value = manifest() |
77 | | - value.nodes["model.shop.rpt_counts"].compiled_code = "select count(order_id) as revenue /* revenue */ from fct_orders -- revenue" |
78 | | - const reach = columnReach(manifestFile(value), "fct_orders", "revenue") |
79 | | - expect(reach.uncertain.map((m) => m.name)).toEqual(["rpt_big_orders"]) |
| 77 | + for (const sql of [ |
| 78 | + "select count(order_id) as revenue /* revenue */ from fct_orders -- revenue", |
| 79 | + "select count(order_id) as `revenue` from fct_orders", |
| 80 | + ]) { |
| 81 | + value.nodes["model.shop.rpt_counts"].compiled_code = sql |
| 82 | + const reach = columnReach(manifestFile(value), "fct_orders", "revenue") |
| 83 | + expect(reach.uncertain.map((m) => m.name)).toEqual(["rpt_big_orders"]) |
| 84 | + } |
80 | 85 | }) |
81 | 86 |
|
82 | 87 | test("a downstream model without compiled SQL is reported untraced, and what reads it only may read the column", () => { |
@@ -262,6 +267,8 @@ describe("selectsStar", () => { |
262 | 267 | for (const sql of [ |
263 | 268 | "select revenue * 100 as cents from a", |
264 | 269 | "select count(*) as n from a", |
| 270 | + "select count_big(*) as n from a", |
| 271 | + "select count_if(*) as n from a", |
265 | 272 | "select a, b*c as d from t", |
266 | 273 | "select '*' as s from a", |
267 | 274 | "select (a + b) * c as d from t", |
@@ -583,6 +590,10 @@ describe("dbtLineage", () => { |
583 | 590 | // `./` and Windows separators spell the same path. |
584 | 591 | expect(dbtLineage({ manifest_path: file, model: "./models/mart_ltv.sql" }).model_unique_id).toBe("model.shop.mart_ltv") |
585 | 592 | expect(dbtLineage({ manifest_path: file, model: "models\\mart_ltv.sql" }).model_unique_id).toBe("model.shop.mart_ltv") |
| 593 | + // An empty path is no model's, not the first one's without a file path. |
| 594 | + const pathless = JSON.parse(readFileSync(file, "utf8")) |
| 595 | + delete pathless.nodes["model.shop.fct_orders"].original_file_path |
| 596 | + expect(dbtLineage({ manifest_path: manifestFile(pathless), model: "./" }).confidence_factors).toContain("Model './' not found in manifest") |
586 | 597 | const withSnapshot: any = manifest() |
587 | 598 | withSnapshot.nodes["snapshot.shop.snap"] = { ...model("snap", ["model.shop.fct_orders"], "select order_id from fct_orders", ["order_id"]), resource_type: "snapshot", unique_id: "snapshot.shop.snap" } |
588 | 599 | expect(dbtLineage({ manifest_path: manifestFile(withSnapshot), model: "snap" }).model_unique_id).toBe("snapshot.shop.snap") |
@@ -635,6 +646,7 @@ describe("columnReach with a NATURAL JOIN", () => { |
635 | 646 | "select a.id from a natural # mysql\njoin b", |
636 | 647 | "select a.id from a natural // snowflake\njoin b", |
637 | 648 | "select a.id from a natural -- old mac\rjoin b", |
| 649 | + "select a.id from a natural /* " + "x".repeat(5000) + " */ join b", |
638 | 650 | // Many `natural` words in a string before the real join: each is checked in a bounded window. |
639 | 651 | "select $$" + "natural /* ".repeat(4000) + "$$ as s from a natural join b", |
640 | 652 | "select '/*' as s from a natural /* c */ join b", |
|
0 commit comments