rhombic
Version:
SQL parsing, lineage extraction and manipulation
71 lines • 3.36 kB
TypeScript
import { Lineage } from "../Lineage";
import { StatementContext } from "./SqlBaseParser";
import { TablePrimary, TablePrimaryIncomplete } from "..";
import { Cursor } from "./Cursor";
/**
* Options available for SQL parser.
*/
export interface LineageParserOptions {
/**
* Whether double quoted identifiers are allowed. If `true` - then both double quotes and backticks can be used
* to quote identifiers. String literals are quoted with single quotes only.
* If `false` (default) - double quotes are used for string literals (as an alternative
* to single quotes). Identifiers are quoted with backquotes.
*/
doubleQuotedIdentifier?: boolean;
}
/**
* SQL parse tree with available operations.
*/
export declare class SqlLineageParseTree {
readonly tree: StatementContext;
readonly cursor?: Cursor | undefined;
/**
* Creates SQL parse tree from antlr StatementContext
* @param tree StatementContext object which is the product of parsing SQL
* @param cursor A representation of the cursor to look for in the query
*/
constructor(tree: StatementContext, cursor?: Cursor | undefined);
/**
* Extracts and returns all potentially used tables. Note that this method does not perform context
* analysis and thus can return not only external tables used but also references to CTEs or subqueries
* defined inside the query itself. But it is guaranteed that all external (to the query)
* tables will be returned.
* This method commonly used to analyse query and pre-fetch metadata for tables used.
* @returns Tables used in query
*/
getUsedTables(): {
references: TablePrimary[];
incomplete: TablePrimaryIncomplete[];
};
/**
* Extracts column level lineage from SQL parse tree.
* There are 2 principal modes that control lineage representation: "merged leaves" and "tree" (default).
* - In "tree" mode (default) all source tables are displayed with all their columns and mentioned as many
* times as they occur in the query.
* - In "mergedLeaves" mode source tables are mentioned only once even if they are used multiple times in
* the query. Source table columns that are not used in the query omitted from lineage.
* @param getTable Function to get table metadata. It takes table identifier and returns some table data
* plus the list of columns for this table. Columns are expected to be in particular order as defined
* in this table's DDL.
* @param mergedLeaves Selects mode for the lineage generation ("tree" (default) when `false`,
* "mergedLeaves" when `true`).
* @param options Lineage generation options:
* - `positionalRefsEnabled` (`false` by default) options controls whether to interpret numerical references
* inside ORDER BY as references to SELECT list expressions
* @returns Calculated lineage.
*/
getLineage<TableData, ColumnData>(getTable?: (id: TablePrimary) => {
table: {
id: string;
data: TableData;
};
columns: {
id: string;
data: ColumnData;
}[];
} | undefined, mergedLeaves?: boolean, options?: {
positionalRefsEnabled?: boolean;
}): Lineage<TableData, ColumnData>;
}
//# sourceMappingURL=SqlLineageParseTree.d.ts.map