Skip to content

Commit 0c66a13

Browse files
VJ-yadavVijay Yadav
andcommitted
fix: pass warehouse dialect to altimate-core tools instead of hardcoding snowflake
Add optional `dialect` parameter (default: "snowflake") to all 8 altimate-core tools that were missing it: - altimate-core-validate, fix, correct, semantics, equivalence, policy, check, and impact-analysis Each tool now: 1. Accepts `dialect` via its zod parameter schema 2. Passes it through to the Dispatcher call 3. Includes it in telemetry metadata Follows the pattern established in sql-analyze.ts, sql-optimize.ts, and schema-diff.ts. Type interfaces updated in types.ts. Tests updated to pass dialect explicitly. Fixes #455 Co-Authored-By: Vijay Yadav <vijay@studentsucceed.com>
1 parent 0d34855 commit 0c66a13

File tree

11 files changed

+93
-34
lines changed

11 files changed

+93
-34
lines changed

packages/opencode/src/altimate/native/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ export interface SchemaDiffResult {
680680

681681
export interface AltimateCoreValidateParams {
682682
sql: string
683+
dialect?: string
683684
schema_path?: string
684685
schema_context?: Record<string, any>
685686
}
@@ -708,6 +709,7 @@ export interface AltimateCoreExplainParams {
708709

709710
export interface AltimateCoreCheckParams {
710711
sql: string
712+
dialect?: string
711713
schema_path?: string
712714
schema_context?: Record<string, any>
713715
}
@@ -722,20 +724,23 @@ export interface AltimateCoreResult {
722724

723725
export interface AltimateCoreFixParams {
724726
sql: string
727+
dialect?: string
725728
schema_path?: string
726729
schema_context?: Record<string, any>
727730
max_iterations?: number
728731
}
729732

730733
export interface AltimateCorePolicyParams {
731734
sql: string
735+
dialect?: string
732736
policy_json: string
733737
schema_path?: string
734738
schema_context?: Record<string, any>
735739
}
736740

737741
export interface AltimateCoreSemanticsParams {
738742
sql: string
743+
dialect?: string
739744
schema_path?: string
740745
schema_context?: Record<string, any>
741746
}
@@ -751,6 +756,7 @@ export interface AltimateCoreTestgenParams {
751756
export interface AltimateCoreEquivalenceParams {
752757
sql1: string
753758
sql2: string
759+
dialect?: string
754760
schema_path?: string
755761
schema_context?: Record<string, any>
756762
}
@@ -776,6 +782,7 @@ export interface AltimateCoreRewriteParams {
776782

777783
export interface AltimateCoreCorrectParams {
778784
sql: string
785+
dialect?: string
779786
schema_path?: string
780787
schema_context?: Record<string, any>
781788
}

packages/opencode/src/altimate/tools/altimate-core-check.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export const AltimateCoreCheckTool = Tool.define("altimate_core_check", {
88
"Run full analysis pipeline: validate + lint + safety scan + PII check. Single call for comprehensive SQL analysis. Provide schema_context or schema_path for accurate table/column resolution.",
99
parameters: z.object({
1010
sql: z.string().describe("SQL query to analyze"),
11+
dialect: z
12+
.string()
13+
.optional()
14+
.default("snowflake")
15+
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
1116
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
1217
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
1318
}),
@@ -16,6 +21,7 @@ export const AltimateCoreCheckTool = Tool.define("altimate_core_check", {
1621
try {
1722
const result = await Dispatcher.call("altimate_core.check", {
1823
sql: args.sql,
24+
dialect: args.dialect,
1925
schema_path: args.schema_path ?? "",
2026
schema_context: args.schema_context,
2127
})
@@ -40,6 +46,7 @@ export const AltimateCoreCheckTool = Tool.define("altimate_core_check", {
4046
title: `Check: ${formatCheckTitle(data)}`,
4147
metadata: {
4248
success: result.success,
49+
dialect: args.dialect,
4350
has_schema: hasSchema,
4451
...(error && { error }),
4552
...(findings.length > 0 && { findings }),
@@ -50,7 +57,7 @@ export const AltimateCoreCheckTool = Tool.define("altimate_core_check", {
5057
const msg = e instanceof Error ? e.message : String(e)
5158
return {
5259
title: "Check: ERROR",
53-
metadata: { success: false, has_schema: hasSchema, error: msg },
60+
metadata: { success: false, dialect: args.dialect, has_schema: hasSchema, error: msg },
5461
output: `Failed: ${msg}`,
5562
}
5663
}

packages/opencode/src/altimate/tools/altimate-core-correct.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export const AltimateCoreCorrectTool = Tool.define("altimate_core_correct", {
88
"Iteratively correct SQL using a propose-verify-refine loop. More thorough than fix — applies multiple correction rounds to produce valid SQL. Provide schema_context or schema_path for accurate table/column resolution.",
99
parameters: z.object({
1010
sql: z.string().describe("SQL query to correct"),
11+
dialect: z
12+
.string()
13+
.optional()
14+
.default("snowflake")
15+
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
1116
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
1217
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
1318
}),
@@ -16,6 +21,7 @@ export const AltimateCoreCorrectTool = Tool.define("altimate_core_correct", {
1621
try {
1722
const result = await Dispatcher.call("altimate_core.correct", {
1823
sql: args.sql,
24+
dialect: args.dialect,
1925
schema_path: args.schema_path ?? "",
2026
schema_context: args.schema_context,
2127
})
@@ -32,6 +38,7 @@ export const AltimateCoreCorrectTool = Tool.define("altimate_core_correct", {
3238
metadata: {
3339
success: result.success,
3440
iterations: data.iterations,
41+
dialect: args.dialect,
3542
has_schema: hasSchema,
3643
...(error && { error }),
3744
...(findings.length > 0 && { findings }),
@@ -42,7 +49,7 @@ export const AltimateCoreCorrectTool = Tool.define("altimate_core_correct", {
4249
const msg = e instanceof Error ? e.message : String(e)
4350
return {
4451
title: "Correct: ERROR",
45-
metadata: { success: false, iterations: 0, has_schema: hasSchema, error: msg },
52+
metadata: { success: false, iterations: 0, dialect: args.dialect, has_schema: hasSchema, error: msg },
4653
output: `Failed: ${msg}`,
4754
}
4855
}

packages/opencode/src/altimate/tools/altimate-core-equivalence.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export const AltimateCoreEquivalenceTool = Tool.define("altimate_core_equivalenc
99
parameters: z.object({
1010
sql1: z.string().describe("First SQL query"),
1111
sql2: z.string().describe("Second SQL query"),
12+
dialect: z
13+
.string()
14+
.optional()
15+
.default("snowflake")
16+
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
1217
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
1318
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
1419
}),
@@ -27,6 +32,7 @@ export const AltimateCoreEquivalenceTool = Tool.define("altimate_core_equivalenc
2732
const result = await Dispatcher.call("altimate_core.equivalence", {
2833
sql1: args.sql1,
2934
sql2: args.sql2,
35+
dialect: args.dialect,
3036
schema_path: args.schema_path ?? "",
3137
schema_context: args.schema_context,
3238
})
@@ -48,6 +54,7 @@ export const AltimateCoreEquivalenceTool = Tool.define("altimate_core_equivalenc
4854
metadata: {
4955
success: !isRealFailure,
5056
equivalent: data.equivalent,
57+
dialect: args.dialect,
5158
has_schema: hasSchema,
5259
...(error && { error }),
5360
...(findings.length > 0 && { findings }),
@@ -58,7 +65,7 @@ export const AltimateCoreEquivalenceTool = Tool.define("altimate_core_equivalenc
5865
const msg = e instanceof Error ? e.message : String(e)
5966
return {
6067
title: "Equivalence: ERROR",
61-
metadata: { success: false, equivalent: false, has_schema: hasSchema, error: msg },
68+
metadata: { success: false, equivalent: false, dialect: args.dialect, has_schema: hasSchema, error: msg },
6269
output: `Failed: ${msg}`,
6370
}
6471
}

packages/opencode/src/altimate/tools/altimate-core-fix.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export const AltimateCoreFixTool = Tool.define("altimate_core_fix", {
88
"Auto-fix SQL errors using fuzzy matching and iterative re-validation. Corrects syntax errors, typos, and schema reference issues. IMPORTANT: Provide schema_context or schema_path — without schema, table/column references cannot be resolved or fixed.",
99
parameters: z.object({
1010
sql: z.string().describe("SQL query to fix"),
11+
dialect: z
12+
.string()
13+
.optional()
14+
.default("snowflake")
15+
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
1116
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
1217
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
1318
max_iterations: z.number().optional().describe("Maximum fix iterations (default: 5)"),
@@ -17,6 +22,7 @@ export const AltimateCoreFixTool = Tool.define("altimate_core_fix", {
1722
try {
1823
const result = await Dispatcher.call("altimate_core.fix", {
1924
sql: args.sql,
25+
dialect: args.dialect,
2026
schema_path: args.schema_path ?? "",
2127
schema_context: args.schema_context,
2228
max_iterations: args.max_iterations ?? 5,
@@ -40,6 +46,7 @@ export const AltimateCoreFixTool = Tool.define("altimate_core_fix", {
4046
metadata: {
4147
success,
4248
fixed: !!data.fixed_sql,
49+
dialect: args.dialect,
4350
has_schema: hasSchema,
4451
...(error && { error }),
4552
...(findings.length > 0 && { findings }),
@@ -50,7 +57,7 @@ export const AltimateCoreFixTool = Tool.define("altimate_core_fix", {
5057
const msg = e instanceof Error ? e.message : String(e)
5158
return {
5259
title: "Fix: ERROR",
53-
metadata: { success: false, fixed: false, has_schema: hasSchema, error: msg },
60+
metadata: { success: false, fixed: false, dialect: args.dialect, has_schema: hasSchema, error: msg },
5461
output: `Failed: ${msg}`,
5562
}
5663
}

packages/opencode/src/altimate/tools/altimate-core-policy.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export const AltimateCorePolicyTool = Tool.define("altimate_core_policy", {
88
"Check SQL against YAML-based governance policy guardrails. Validates compliance with custom rules like allowed tables, forbidden operations, and data access restrictions. Provide schema_context or schema_path for accurate table/column resolution.",
99
parameters: z.object({
1010
sql: z.string().describe("SQL query to check against policy"),
11+
dialect: z
12+
.string()
13+
.optional()
14+
.default("snowflake")
15+
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
1116
policy_json: z.string().describe("JSON string defining the policy rules"),
1217
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
1318
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
@@ -17,6 +22,7 @@ export const AltimateCorePolicyTool = Tool.define("altimate_core_policy", {
1722
try {
1823
const result = await Dispatcher.call("altimate_core.policy", {
1924
sql: args.sql,
25+
dialect: args.dialect,
2026
policy_json: args.policy_json,
2127
schema_path: args.schema_path ?? "",
2228
schema_context: args.schema_context,
@@ -34,6 +40,7 @@ export const AltimateCorePolicyTool = Tool.define("altimate_core_policy", {
3440
metadata: {
3541
success: true, // engine ran — violations are findings, not failures
3642
pass: data.pass,
43+
dialect: args.dialect,
3744
has_schema: hasSchema,
3845
...(error && { error }),
3946
...(findings.length > 0 && { findings }),
@@ -44,7 +51,7 @@ export const AltimateCorePolicyTool = Tool.define("altimate_core_policy", {
4451
const msg = e instanceof Error ? e.message : String(e)
4552
return {
4653
title: "Policy: ERROR",
47-
metadata: { success: false, pass: false, has_schema: hasSchema, error: msg },
54+
metadata: { success: false, pass: false, dialect: args.dialect, has_schema: hasSchema, error: msg },
4855
output: `Failed: ${msg}`,
4956
}
5057
}

packages/opencode/src/altimate/tools/altimate-core-semantics.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export const AltimateCoreSemanticsTool = Tool.define("altimate_core_semantics",
88
"Run semantic validation rules against SQL. Detects logical issues like cartesian products, wrong JOIN conditions, NULL misuse, and type mismatches that syntax checking alone misses. Provide schema_context or schema_path for accurate table/column resolution.",
99
parameters: z.object({
1010
sql: z.string().describe("SQL query to validate semantically"),
11+
dialect: z
12+
.string()
13+
.optional()
14+
.default("snowflake")
15+
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
1116
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
1217
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
1318
}),
@@ -25,6 +30,7 @@ export const AltimateCoreSemanticsTool = Tool.define("altimate_core_semantics",
2530
try {
2631
const result = await Dispatcher.call("altimate_core.semantics", {
2732
sql: args.sql,
33+
dialect: args.dialect,
2834
schema_path: args.schema_path ?? "",
2935
schema_context: args.schema_context,
3036
})
@@ -44,6 +50,7 @@ export const AltimateCoreSemanticsTool = Tool.define("altimate_core_semantics",
4450
success: true, // engine ran — semantic issues are findings, not failures
4551
valid: data.valid,
4652
issue_count: issueCount,
53+
dialect: args.dialect,
4754
has_schema: hasSchema,
4855
...(error && { error }),
4956
...(findings.length > 0 && { findings }),
@@ -54,7 +61,7 @@ export const AltimateCoreSemanticsTool = Tool.define("altimate_core_semantics",
5461
const msg = e instanceof Error ? e.message : String(e)
5562
return {
5663
title: "Semantics: ERROR",
57-
metadata: { success: false, valid: false, issue_count: 0, has_schema: hasSchema, error: msg },
64+
metadata: { success: false, valid: false, issue_count: 0, dialect: args.dialect, has_schema: hasSchema, error: msg },
5865
output: `Failed: ${msg}`,
5966
}
6067
}

packages/opencode/src/altimate/tools/altimate-core-validate.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export const AltimateCoreValidateTool = Tool.define("altimate_core_validate", {
88
"Validate SQL syntax and schema references. Checks if tables/columns exist in the schema and if SQL is valid for the target dialect. IMPORTANT: Provide schema_context or schema_path — without schema, all table/column references will report as 'not found'.",
99
parameters: z.object({
1010
sql: z.string().describe("SQL query to validate"),
11+
dialect: z
12+
.string()
13+
.optional()
14+
.default("snowflake")
15+
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
1116
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
1217
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
1318
}),
@@ -26,6 +31,7 @@ export const AltimateCoreValidateTool = Tool.define("altimate_core_validate", {
2631
try {
2732
const result = await Dispatcher.call("altimate_core.validate", {
2833
sql: args.sql,
34+
dialect: args.dialect,
2935
schema_path: args.schema_path ?? "",
3036
schema_context: args.schema_context,
3137
})
@@ -42,6 +48,7 @@ export const AltimateCoreValidateTool = Tool.define("altimate_core_validate", {
4248
metadata: {
4349
success: true, // engine ran — validation errors are findings, not failures
4450
valid: data.valid,
51+
dialect: args.dialect,
4552
has_schema: hasSchema,
4653
...(error && { error }),
4754
...(findings.length > 0 && { findings }),
@@ -52,7 +59,7 @@ export const AltimateCoreValidateTool = Tool.define("altimate_core_validate", {
5259
const msg = e instanceof Error ? e.message : String(e)
5360
return {
5461
title: "Validate: ERROR",
55-
metadata: { success: false, valid: false, has_schema: hasSchema, error: msg },
62+
metadata: { success: false, valid: false, dialect: args.dialect, has_schema: hasSchema, error: msg },
5663
output: `Failed: ${msg}`,
5764
}
5865
}

packages/opencode/src/altimate/tools/impact-analysis.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export const ImpactAnalysisTool = Tool.define("impact_analysis", {
139139
transitive_count: transitive.length,
140140
test_count: affectedTestCount,
141141
column_impact: columnImpact.length,
142+
dialect: args.dialect,
142143
has_schema: false,
143144
...(findings.length > 0 && { findings }),
144145
},
@@ -148,7 +149,7 @@ export const ImpactAnalysisTool = Tool.define("impact_analysis", {
148149
const msg = e instanceof Error ? e.message : String(e)
149150
return {
150151
title: "Impact: ERROR",
151-
metadata: { success: false, has_schema: false, error: msg },
152+
metadata: { success: false, dialect: args.dialect, has_schema: false, error: msg },
152153
output: `Failed to analyze impact: ${msg}\n\nEnsure the dbt manifest exists (run \`dbt compile\`) and the dispatcher is running.`,
153154
}
154155
}

0 commit comments

Comments
 (0)