@polyglot-sql/sdk 0.5.1 → 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 +61 -11
- package/dist/cdn/polyglot.esm.js +1214 -1214
- package/dist/index.cjs +13 -10
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +13 -10
- package/dist/index.node.js +13 -10
- package/dist/manual.js +13 -10
- package/dist/polyglot_sql.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -604,26 +604,76 @@ are marked as `virtual`.
|
|
|
604
604
|
## Compact Query Analysis
|
|
605
605
|
|
|
606
606
|
Use `analyzeQuery` when you need summary facts instead of the full AST or full
|
|
607
|
-
lineage graph
|
|
607
|
+
lineage graph. `relations` contains sources visible in the analyzed scope;
|
|
608
|
+
`baseTables` contains deduplicated physical dependencies across nested CTEs,
|
|
609
|
+
derived tables, subqueries, and set-operation branches. With a schema,
|
|
610
|
+
parseable detailed type strings such as `DECIMAL(10,2)` are preserved in
|
|
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'`.
|
|
608
615
|
|
|
609
616
|
```typescript
|
|
610
617
|
import { analyzeQuery, Dialect } from '@polyglot-sql/sdk';
|
|
611
618
|
|
|
612
|
-
const result = analyzeQuery(
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
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
|
+
},
|
|
618
634
|
},
|
|
619
|
-
|
|
635
|
+
);
|
|
620
636
|
|
|
621
637
|
if (result.success) {
|
|
622
|
-
console.log(result.analysis.
|
|
623
|
-
console.log(result.analysis.
|
|
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'
|
|
624
642
|
}
|
|
643
|
+
|
|
644
|
+
const duckdbSummary = analyzeQuery('SELECT 1', Dialect.DuckDB);
|
|
625
645
|
```
|
|
626
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
|
+
|
|
627
677
|
## OpenLineage Output
|
|
628
678
|
|
|
629
679
|
Generate OpenLineage-compatible JSON payloads from SQL analysis. The SDK only
|
|
@@ -743,7 +793,7 @@ const formattedSafe = pg.formatWithOptions('SELECT a,b FROM t', Dialect.Generic,
|
|
|
743
793
|
| `lineage(column, sql, dialect?, trimSelects?)` | Trace column lineage through a query |
|
|
744
794
|
| `lineageWithSchema(column, sql, schema, dialect?, trimSelects?)` | Trace lineage with schema-based qualification |
|
|
745
795
|
| `getSourceTables(column, sql, dialect?)` | Get source tables for a column |
|
|
746
|
-
| `analyzeQuery(sql,
|
|
796
|
+
| `analyzeQuery(sql, optionsOrDialect?)` | Return compact projection, visible relation, transitive base-table, CTE, set-operation, and upstream-reference facts |
|
|
747
797
|
| `openLineageColumnLineage(sql, options)` | Build an OpenLineage columnLineage facet and datasets |
|
|
748
798
|
| `openLineageJobEvent(sql, options)` | Build an OpenLineage JobEvent payload |
|
|
749
799
|
| `openLineageRunEvent(sql, options)` | Build an OpenLineage RunEvent payload |
|