@polyglot-sql/sdk 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -12
- package/dist/cdn/polyglot.esm.js +815 -815
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/polyglot_sql.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -608,30 +608,72 @@ lineage graph. `relations` contains sources visible in the analyzed scope;
|
|
|
608
608
|
`baseTables` contains deduplicated physical dependencies across nested CTEs,
|
|
609
609
|
derived tables, subqueries, and set-operation branches. With a schema,
|
|
610
610
|
parseable detailed type strings such as `DECIMAL(10,2)` are preserved in
|
|
611
|
-
projection `typeHint` values.
|
|
611
|
+
projection `typeHint` values. `cteFacts` reports top-level CTE definitions,
|
|
612
|
+
`starProjections` records original star projections and schema-expanded
|
|
613
|
+
columns, and each projection includes conservative `nullability`: `'non_null'`,
|
|
614
|
+
`'nullable'`, or `'unknown'`.
|
|
612
615
|
|
|
613
616
|
```typescript
|
|
614
617
|
import { analyzeQuery, Dialect } from '@polyglot-sql/sdk';
|
|
615
618
|
|
|
616
|
-
const result = analyzeQuery(
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
619
|
+
const result = analyzeQuery(
|
|
620
|
+
'WITH base AS (SELECT id, amount FROM orders) SELECT * FROM base',
|
|
621
|
+
{
|
|
622
|
+
dialect: Dialect.Generic,
|
|
623
|
+
schema: {
|
|
624
|
+
tables: [
|
|
625
|
+
{
|
|
626
|
+
name: 'orders',
|
|
627
|
+
columns: [
|
|
628
|
+
{ name: 'id', type: 'INT', nullable: false },
|
|
629
|
+
{ name: 'amount', type: 'DECIMAL(10,2)', nullable: true },
|
|
630
|
+
],
|
|
631
|
+
},
|
|
632
|
+
],
|
|
633
|
+
},
|
|
622
634
|
},
|
|
623
|
-
|
|
635
|
+
);
|
|
624
636
|
|
|
625
637
|
if (result.success) {
|
|
626
|
-
console.log(result.analysis.
|
|
627
|
-
console.log(result.analysis.
|
|
628
|
-
console.log(result.analysis.
|
|
629
|
-
console.log(result.analysis.baseTables[0].
|
|
638
|
+
console.log(result.analysis.cteFacts[0].bodySql); // 'SELECT id, amount FROM orders'
|
|
639
|
+
console.log(result.analysis.starProjections[0].expandedColumns); // ['id', 'amount']
|
|
640
|
+
console.log(result.analysis.projections[0].nullability); // 'non_null'
|
|
641
|
+
console.log(result.analysis.baseTables[0].name); // 'orders'
|
|
630
642
|
}
|
|
631
643
|
|
|
632
644
|
const duckdbSummary = analyzeQuery('SELECT 1', Dialect.DuckDB);
|
|
633
645
|
```
|
|
634
646
|
|
|
647
|
+
`ValidationSchema` objects use this shape:
|
|
648
|
+
|
|
649
|
+
```typescript
|
|
650
|
+
const schema = {
|
|
651
|
+
strict: true,
|
|
652
|
+
tables: [
|
|
653
|
+
{
|
|
654
|
+
name: 'orders',
|
|
655
|
+
schema: 'analytics',
|
|
656
|
+
aliases: ['o'],
|
|
657
|
+
primaryKey: ['id'],
|
|
658
|
+
uniqueKeys: [['external_id']],
|
|
659
|
+
foreignKeys: [
|
|
660
|
+
{
|
|
661
|
+
columns: ['customer_id'],
|
|
662
|
+
references: { table: 'customers', columns: ['id'] },
|
|
663
|
+
},
|
|
664
|
+
],
|
|
665
|
+
columns: [
|
|
666
|
+
{ name: 'id', type: 'INT', nullable: false, primaryKey: true },
|
|
667
|
+
{ name: 'amount', type: 'DECIMAL(10,2)', nullable: true },
|
|
668
|
+
],
|
|
669
|
+
},
|
|
670
|
+
],
|
|
671
|
+
};
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
Use the `type` key for column types. `dataType` / `data_type` are not accepted
|
|
675
|
+
aliases in this payload.
|
|
676
|
+
|
|
635
677
|
## OpenLineage Output
|
|
636
678
|
|
|
637
679
|
Generate OpenLineage-compatible JSON payloads from SQL analysis. The SDK only
|