Runner

LineageRunner is the entry point for SQLLineage core processing logic. After parsing command-line options, a string representation of SQL statements will be fed to LineageRunner for processing. From a bird’s-eye view, it contains three steps:

  1. Calling sqllineage.utils.helpers.split function to split string-base SQL statements into a list of str statements.

  2. Calling sqllineage.core.analyzer.LineageAnalyzer to analyze each one statement sql string. Get a list of sqllineage.core.holders.StatementLineageHolder .

  3. Calling sqllineage.core.holders.SQLLineageHolder.of function to assemble the list of sqllineage.core.holders.StatementLineageHolder into one sqllineage.core.holders.SQLLineageHolder.

sqllineage.core.holders.SQLLineageHolder then will serve for lineage summary, in text or in visualization form.

sqllineage.runner.LineageRunner

class sqllineage.runner.LineageRunner(sql: str, dialect: str = 'ansi', metadata_provider: MetaDataProvider = <sqllineage.core.metadata.dummy.DummyMetaDataProvider object>, verbose: bool = False, silent_mode: bool = False, draw_options: dict[str, ~typing.Any] | None=None, file_path: str = '.')[source]

The entry point of SQLLineage after command line options are parsed.

Parameters:
  • sql – a string representation of SQL statements.

  • dialect – sql dialect

  • metadata_provider – metadata service object providing table schema

  • verbose – verbose flag indicating whether statement-wise lineage result will be shown

  • silent_mode – boolean flag indicating whether to skip lineage analysis for unknown statement types

  • file_path – path of the SQL file.

__str__()[source]

print out the Lineage Summary.

to_cytoscape(level='table') → list[dict[str, dict[str, str]]][source]

to turn the DAG into cytoscape format.

draw() → None[source]

to draw the lineage directed graph

statements() → list[str][source]

a list of SQL statements.

property source_tables: list[Table | Path]

a list of source sqllineage.models.Table

property target_tables: list[Table | Path]

a list of target sqllineage.models.Table

property intermediate_tables: list[Table | Path]

a list of intermediate sqllineage.models.Table

find_nodes(predicate: Callable[[Column | Table | Path], bool]) → list[Column | Table | Path][source]

a list of sqllineage.models.Column/sqllineage.models.Table/ sqllineage.models.Path for which predicate is true. To discover a node to pass into get_column_lineage(), filter the result to sqllineage.models.Column instances first.

get_column_lineage(exclude_path_ending_in_subquery=True, exclude_subquery_columns=False, node: Column | None = None) → list[tuple[Column, ...]][source]

a list of column tuple sqllineage.models.Column

Parameters:
  • exclude_path_ending_in_subquery – exclude_subquery rename to exclude_path_ending_in_subquery exclude column from SubQuery in the ending path

  • exclude_subquery_columns – exclude column from SubQuery in the path.

  • node – restrict the result to paths that touch this column. Use find_nodes() to discover a candidate, filtering its result to sqllineage.models.Column instances first, since find_nodes can also return sqllineage.models.Table and sqllineage.models.Path vertices that this method rejects.

print_column_lineage(node: Column | None = None) → None[source]

print column level lineage to stdout

Parameters:

node – see get_column_lineage()

print_table_lineage() → None[source]

print table level lineage to stdout

static supported_dialects() → dict[str, list[str]][source]

an ordered dict (so we can make sure the default parser implementation comes first) with key, value as parser_name, dialect list respectively

sqllineage.cli.main

sqllineage.cli.main(args=None) → None[source]

The command line interface entry point.

Parameters:

args – the command line arguments for sqllineage command