Skip to content

Python: extract statement granularity info #136

Answered by reata
user5651 asked this question in Q&A
Discussion options

You must be logged in to vote

Since this is more of a "how-to" question, I converted this from issue to discussion.

For your question, two options here:

  1. To split the sql into multiple string-represented statements first and then feed each statement string to LineageRunner one by one. This is the preferred way to do it.
import sqlparse
from sqllineage.runner import LineageRunner
for statement in sqlparse.split(sql):
    result = LineageRunner(statement)
    print(result.source_tables, result.target_tables)
    # or if you want the text result, just print(result)
  1. To use sqllineage's internal API to read the same result as you have with verbose option passed in LineageRunner. I'd advice against it since this internal …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by user5651
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #135 on April 21, 2021 11:53.