Skip to content

Commit 4ac010e

Browse files
hkaltaiclaude
andcommitted
fix: a column spelling that matches two columns differing only by case leaves their readers uncertain
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3673697 commit 4ac010e

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎packages/opencode/src/altimate/native/dbt/column-reach.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,19 @@ export function columnReach(manifestPath: string, model: string, column: string,
212212
const tracked = new Map<string, Set<string>>([[targetId, new Set([column0])]])
213213
// The same columns with their case kept: consulted only where a parent's names differ by case alone.
214214
// The target's own spelling comes from the manifest: the caller's when documented as typed, else
215-
// every spelling matching ignoring case, else the caller's.
215+
// the one spelling matching ignoring case, else the caller's. Two documented spellings that only
216+
// case tells apart, neither typed as given, leave the column unsettled: no reader of either is certain.
216217
const spellings = Object.entries<any>(target.columns ?? {}).map(([key, col]) => String(col?.name ?? key))
217-
const spelled = spellings.includes(column) ? [column] : spellings.filter((name) => name.toLowerCase() === column0)
218-
const trackedExact = new Map<string, Set<string>>([[targetId, new Set(spelled.length > 0 ? spelled : [column])]])
218+
const matches = spellings.filter((name) => name.toLowerCase() === column0)
219+
const unsettled = !spellings.includes(column) && matches.length > 1
220+
const spelled = spellings.includes(column) ? [column] : unsettled ? [] : matches.length > 0 ? matches : [column]
221+
const trackedExact = new Map<string, Set<string>>([[targetId, new Set(spelled)]])
219222
const carries = (parent: string, source: { column: string; exact: string }) =>
220223
!!tracked.get(parent)?.has(source.column) &&
221224
(!caseCollides(lookup(parent), source.column) || !!trackedExact.get(parent)?.has(source.exact))
222225
// Nodes whose outputs are unknown (untraced, or read through an ambiguous name): their children
223226
// may read the column too. A node that only filters on it was traced and carries nothing on.
224-
const unsure = new Set<string>()
227+
const unsure = new Set<string>(unsettled ? [targetId] : [])
225228
const reached: ColumnReachModel[] = []
226229
const uncertain: ColumnReachUnsure[] = []
227230
const untraced: ColumnReachUnsure[] = []

‎packages/opencode/test/altimate/column-reach.test.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,19 @@ describe("columnReach with columns that differ only by case", () => {
315315
})
316316

317317
describe("columnReach case handling", () => {
318-
test("a caller's spelling of a column the parent documents twice by case still reaches its readers", () => {
318+
test("a spelling matching one documented column ignoring case reaches its readers", () => {
319+
const reach = columnReach(manifestFile(), "fct_orders", "REVENUE")
320+
expect(reach.models.map((m) => m.name)).toContain("fct_daily")
321+
})
322+
323+
test("a spelling matching two columns that differ only by case leaves both columns' readers uncertain, never certain", () => {
319324
const value: any = manifest()
320325
value.nodes["model.shop.fct_orders"].columns = { revenue: column("revenue"), Revenue: column("Revenue") }
326+
value.nodes["model.shop.rpt_case"] = model("rpt_case", ["model.shop.fct_orders"], 'select "Revenue" as other from fct_orders', ["other"])
321327
const reach = columnReach(manifestFile(value), "fct_orders", "REVENUE")
322-
expect(reach.models.map((m) => m.name)).toContain("fct_daily")
328+
expect(reach.models.map((m) => m.name)).not.toContain("fct_daily")
329+
expect(reach.models.map((m) => m.name)).not.toContain("rpt_case")
330+
expect(reach.uncertain.map((m) => m.name)).toEqual(expect.arrayContaining(["fct_daily", "rpt_case"]))
323331
})
324332
})
325333

0 commit comments

Comments
 (0)