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

Method classifyTable

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

* Classify a table reference as PostgreSQL, MotherDuck, or Local

(ref: TableReference)

Source from the content-addressed store, hash-verified

197 * Classify a table reference as PostgreSQL, MotherDuck, or Local
198 */
199 private classifyTable(ref: TableReference): { type: 'postgresql' | 'motherduck' | 'local'; connectionId?: string } {
200 console.log(`[QueryRouter] Classifying table:`, ref);
201
202 // Check if this matches a PostgreSQL virtual table
203 for (const [tableKey, table] of this.postgresVirtualTables) {
204 const schemaMatch = ref.schema === table.schemaName || (!ref.schema && table.schemaName === 'public');
205 const tableMatch = ref.table === table.tableName;
206
207 console.log(`[QueryRouter] Checking against PostgreSQL table:`, {
208 virtualTable: table,
209 schemaMatch,
210 tableMatch,
211 refSchema: ref.schema,
212 refTable: ref.table
213 });
214
215 if (schemaMatch && tableMatch) {
216 console.log(`[QueryRouter] Found PostgreSQL match:`, table.connectionId);
217 return { type: 'postgresql', connectionId: table.connectionId };
218 }
219 }
220
221 // Check if this is a MotherDuck database reference
222 if (ref.database && this.motherduckDatabases.has(ref.database)) {
223 console.log(`[QueryRouter] Found MotherDuck match:`, ref.database);
224 return { type: 'motherduck' };
225 }
226
227 // Special MotherDuck database patterns
228 if (ref.database && (
229 ref.database.includes('my_db') ||
230 ref.database.includes('sample_data') ||
231 ref.database.startsWith('md:')
232 )) {
233 console.log(`[QueryRouter] Found MotherDuck pattern match:`, ref.database);
234 return { type: 'motherduck' };
235 }
236
237 // Default to local
238 console.log(`[QueryRouter] Defaulting to local for:`, ref);
239 return { type: 'local' };
240 }
241
242 /**
243 * Determine the final routing target based on classified tables

Callers 1

analyzeQueryMethod · 0.95

Calls 1

hasMethod · 0.80

Tested by

no test coverage detected