Skip to content

Commit 570ea09

Browse files
mhallidaclaude
andcommitted
fix: altimate_core_semantics detects implicit cross joins (comma-joins)
Added TypeScript-level detection for comma-separated tables in the FROM clause (e.g., FROM orders o, customers c). The Rust checkSemantics doesn't flag this pattern. Now reports it as an implicit_cross_join warning with a suggestion to use explicit JOIN syntax. Fixes TICKET-012 in #422. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 248bd68 commit 570ea09

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

‎packages/opencode/src/altimate/native/altimate-core.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,35 @@ register("altimate_core.policy", async (params) => {
386386
}
387387
})
388388

389-
// 9. altimate_core.semantics
389+
// 9. altimate_core.semantics — with implicit cross join detection
390390
register("altimate_core.semantics", async (params) => {
391391
try {
392392
const schema = schemaOrEmpty(params.schema_path, params.schema_context)
393393
const raw = await core.checkSemantics(params.sql, schema)
394394
const data = toData(raw)
395+
396+
// Augment with TypeScript-level detection for comma-joins (implicit cross joins)
397+
const findings = (data.findings as any[]) ?? []
398+
const commaJoinPattern = /\bFROM\b\s+(\w+)\s+\w*\s*,\s*(\w+)/gi
399+
const match = commaJoinPattern.exec(params.sql)
400+
if (match) {
401+
const hasCommaJoinFinding = findings.some(
402+
(f) => f.rule === "implicit_cross_join" || f.rule === "comma_join",
403+
)
404+
if (!hasCommaJoinFinding) {
405+
findings.push({
406+
rule: "implicit_cross_join",
407+
severity: "warning",
408+
message: `Implicit cross join detected: comma-separated tables in FROM clause (${match[1]}, ${match[2]}). Use explicit JOIN syntax for clarity.`,
409+
explanation: "Comma-separated tables in the FROM clause create an implicit cross join. While a WHERE clause may filter the result, explicit JOIN...ON syntax is preferred for readability and to avoid accidental cartesian products.",
410+
suggestion: "Rewrite using explicit JOIN syntax: FROM table1 JOIN table2 ON ...",
411+
confidence: 0.8,
412+
})
413+
data.findings = findings
414+
if (findings.length > 0) data.valid = false
415+
}
416+
}
417+
395418
return ok(data.valid !== false, data)
396419
} catch (e) {
397420
return fail(e)

0 commit comments

Comments
 (0)