-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest-analyzer.mjs
More file actions
92 lines (78 loc) · 2.59 KB
/
test-analyzer.mjs
File metadata and controls
92 lines (78 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Test script to inspect analyzer output
import { analyzeSql } from './packages/core/dist/index.js';
import fs from 'fs';
const testSql = `
-- Simple test with column derivation
WITH source_data AS (
SELECT
user_id,
email,
created_at
FROM users
),
derived AS (
SELECT
user_id,
UPPER(email) as email_upper,
DATE(created_at) as signup_date
FROM source_data
)
SELECT
user_id,
email_upper,
signup_date,
CONCAT(email_upper, '@', signup_date) as user_key
FROM derived;
`;
async function test() {
console.log('Testing analyzer with SQL:');
console.log(testSql);
console.log('\n' + '='.repeat(80) + '\n');
try {
const result = await analyzeSql({
sql: testSql,
dialect: 'generic'
});
console.log('ANALYSIS RESULT:');
console.log('Statements:', result.statements.length);
console.log('\n');
result.statements.forEach((stmt, idx) => {
console.log(`Statement ${idx}: ${stmt.statementType}`);
console.log(` Nodes (${stmt.nodes.length}):`);
const tables = stmt.nodes.filter(n => n.type === 'table' || n.type === 'cte');
const columns = stmt.nodes.filter(n => n.type === 'column');
console.log(` Tables/CTEs: ${tables.length}`);
tables.forEach(t => console.log(` - ${t.type}: ${t.label} (${t.id})`));
console.log(` Columns: ${columns.length}`);
columns.forEach(c => {
const expr = c.expression ? ` = ${c.expression.substring(0, 50)}...` : '';
console.log(` - ${c.label} (${c.id})${expr}`);
});
console.log(`\n Edges (${stmt.edges.length}):`);
const edgesByType = {};
stmt.edges.forEach(e => {
if (!edgesByType[e.type]) edgesByType[e.type] = [];
edgesByType[e.type].push(e);
});
Object.keys(edgesByType).forEach(type => {
console.log(` ${type}: ${edgesByType[type].length} edges`);
edgesByType[type].forEach(e => {
const fromNode = stmt.nodes.find(n => n.id === e.from);
const toNode = stmt.nodes.find(n => n.id === e.to);
const expr = e.expression ? ` [expr: ${e.expression.substring(0, 30)}...]` : '';
console.log(` ${fromNode?.label || e.from} -> ${toNode?.label || e.to}${expr}`);
});
});
console.log('\n' + '-'.repeat(80) + '\n');
});
// Write full output to file for inspection
fs.writeFileSync(
'/home/sasha/Developer/tries/2025-11-20-flow/test-output.json',
JSON.stringify(result, null, 2)
);
console.log('Full output written to test-output.json');
} catch (err) {
console.error('Error:', err);
}
}
test();