MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / analyzeQuery

Method analyzeQuery

frontend/src/lib/duckdb/utils/queryRouter.ts:52–93  ·  view source on GitHub ↗

* Analyze a SQL query and determine the best execution target

(sql: string)

Source from the content-addressed store, hash-verified

50 * Analyze a SQL query and determine the best execution target
51 */
52 analyzeQuery(sql: string): QueryRouterResult {
53 const tableReferences = this.extractTableReferences(sql);
54
55 // Categorize table references
56 const postgresqlTables: TableReference[] = [];
57 const motherduckTables: TableReference[] = [];
58 const localTables: TableReference[] = [];
59
60 let postgresConnectionId: string | undefined;
61
62 for (const ref of tableReferences) {
63 const classification = this.classifyTable(ref);
64
65 if (classification.type === 'postgresql') {
66 postgresqlTables.push(ref);
67 if (!postgresConnectionId) {
68 postgresConnectionId = classification.connectionId;
69 }
70 } else if (classification.type === 'motherduck') {
71 motherduckTables.push(ref);
72 } else {
73 localTables.push(ref);
74 }
75 }
76
77 // Determine routing target and confidence
78 const result = this.determineTarget(
79 postgresqlTables,
80 motherduckTables,
81 localTables,
82 postgresConnectionId
83 );
84
85 return {
86 ...result,
87 tableReferences,
88 postgresqlTables,
89 motherduckTables,
90 localTables,
91 connectionId: postgresConnectionId,
92 };
93 }
94
95 /**
96 * Extract all table references from a SQL query

Callers 2

analyzeQueryFunction · 0.95

Calls 3

classifyTableMethod · 0.95
determineTargetMethod · 0.95

Tested by

no test coverage detected