<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shi Heng Zhang on Medium]]></title>
        <description><![CDATA[Stories by Shi Heng Zhang on Medium]]></description>
        <link>https://medium.com/@shz1?source=rss-b78880fbf782------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Shi Heng Zhang on Medium</title>
            <link>https://medium.com/@shz1?source=rss-b78880fbf782------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:32:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shz1/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[LineageX: The Python library for your lineage needs]]></title>
            <link>https://medium.com/@shz1/lineagex-the-python-library-for-your-lineage-needs-d262b03b06e3?source=rss-b78880fbf782------2</link>
            <guid isPermaLink="false">https://medium.com/p/d262b03b06e3</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[lineage]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Shi Heng Zhang]]></dc:creator>
            <pubDate>Thu, 08 Jun 2023 23:25:05 GMT</pubDate>
            <atom:updated>2023-06-08T23:28:38.464Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2AXM73NrdWsPJWgT0lyKTw.jpeg" /><figcaption>HBO’s Game of Thrones Family Tree by Magdalena Maslowska</figcaption></figure><p>LineageX aims to generate the column-level lineage information by providing a lightweight, accessible, and flexible tool for developers and analysts. In this article, we will give you a brief overview of LineageX by answering the following questions:</p><ul><li><a href="#48dd">What is LineageX?</a></li><li><a href="#2a67">How to use LineageX?</a></li><li><a href="#e9bb">Who would use LineageX?</a></li><li><a href="#5551">Why is LineageX a better choice?</a></li><li><a href="#29ea">What’s happening next?</a></li></ul><p><strong>What is LineageX?</strong></p><p>LineageX is an open-source Python library that generates an interactive webpage for exploration as well as a JSON file for further processing or analytics. It only requires minimum amount of coding background and it is very lightweight for installation. Here is the link to the <a href="https://sfu-db.github.io/lineagex/intro.html">documentation</a>.</p><p>Next, let’s see how to use LineageX with a single line of code.</p><p><strong>How to use LineageX?</strong></p><p>Step 1: Install LineageX:</p><pre>pip install lineagex</pre><p>Step 2: Call the lineagex function, and its input format is anything but flexible, it can be a path to a SQL file, a path to a folder containing SQL files, a list of SQLs or a list of view names and/or schemas. Optionally, you can provide less information with only the SQLs, but providing the schema information and database connection is highly recommended for the best result.</p><pre>from lineagex.lineagex import lineagex</pre><pre>lineagex(sql=path/to/sql, target_schema=&quot;schema1&quot;, search_path_schema=&quot;schema1, public&quot;)</pre><pre># Other alternative ways of calling, like a list of SQL<br>lineagex(sql=[list_of_sql], target_schema=&quot;schema1&quot;, search_path_schema=&quot;schema1, public&quot;) </pre><pre># Schema and view name, this would output lineage information for all views in schema1 and schema2.view2<br>lineagex(sql=&quot;schema1, schema2.view2&quot;, conn_string=&quot;postgresql://username:password@server:port/database&quot;)</pre><p>There are built-in examples included with the package: dependency_example, github_example, <a href="https://github.com/MIT-LCP/mimic-code/tree/main/mimic-iii/concepts_postgres">mimic-iii</a>, <a href="https://github.com/MIT-LCP/mimic-code/tree/main/mimic-iv/concepts_postgres">mimic-iv</a></p><pre>from lineagex.example import example</pre><pre>example(&quot;dependency_example&quot;)<br>example(&quot;github_example&quot;) ## this would produce the gif below<br>example(&quot;mimic-iii&quot;)<br>example(&quot;mimic-iv&quot;)</pre><p>Check out more detailed usage and examples <a href="https://sfu-db.github.io/lineagex/api.html">here</a>.</p><p>This would provide you with an <strong>index.html</strong> and an <strong>output.json</strong>. The <strong>index.html</strong> is the interactive webpage for navigation and exploration while the <strong>output.json</strong> is for processed later by other means.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7N6kGxmdjZ5855WE2dB30Q.gif" /><figcaption>Sample index.html of LineageX</figcaption></figure><p>For navigation around the site:</p><ul><li>Start by clicking the star on the right(select) and input a SQL name that you want to start with.</li><li>It should show a table on the canvas with table names and its columns, by clicking the “explore” button on the top right, it will show all the downstream and upstream tables that are related to the columns.</li><li>Hovering over a column will highlight its downstream and upstream columns as well.</li></ul><p>Here is a live <a href="https://zshandy.github.io/lineagex-demo/">demo</a> with the <a href="https://github.com/MIT-LCP/mimic-code/tree/main/mimic-iv/concepts_postgres">mimic-iv concepts_postgres</a> files and that is created with the above one line of code.</p><p>As for the <strong>output.json </strong>file, it follows this format:</p><pre>{schema.table_name: {<br>    tables: [table1, table2], <br>    columns: {<br>      column1: [table1.column1], column2: [table1.column1, table2.column2]<br>    }, <br>    table_name: schema.table_name<br>  }<br>}</pre><p>Check out more detailed navigation instructions <a href="https://sfu-db.github.io/lineagex/output.html#how-to-navigate-the-webpage">here</a>.</p><p><strong>Who would use LineageX?</strong></p><p>Lineage tools are often used for data governance, data quality, data exploration, as well as in assisting finding errors in the data pipeline, etc.</p><p><strong><em>Sample scenario —data exploration and finding errors in the data pipeline</em></strong></p><p>Rick the data scientist is set out to find the error in the recent_customer_info view as it has stopped updating since the start of 2023. He is given the following scripts:</p><pre>-- recent_customer_info<br>CREATE VIEW recent_customer_info AS<br>SELECT c.customer_id, o.order_id, c.name, c.age, o.total_amount, w.last_login<br>FROM customers c<br>JOIN orders o ON c.customer_id = o.customer_id<br>JOIN recent_website_interactions w ON c.customer_id = w.customer_id;<br>-- recent_website_interactions<br>CREATE VIEW recent_website_interactions AS <br>SELECT c.customer_id, w.interaction_date, w.page_visited, w.last_login<br>FROM customers c<br>JOIN website_interactions w ON c.customer_id = w.customer_id<br>WHERE EXTRACT(YEAR from w.last_login) = 2022;<br>-- other SQLs...</pre><p>With the LineageX tool, Rick simply needs one line of code to visualize the lineage relationship:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*YKbzOICl6a-UwahvLC8Adw.png" /></figure><p>With the visualization, Rick would easily know that recent_customer_info is dependent on customers, orders, and recent_website_interactions, and that recent_website_interactions is dependent on customers and website_interactions. He then digs a little further and realizes that recent_website_interactions has also stopped updating since the start of the year. Finally, after inspecting the SQL for recent_website_interactions, he finds out that this issue is caused by the WHERE clause such that it is set to be in year 2022. LineageX is the one-liner Python library that could solve such issues and create an interactive webpage in no time.</p><p><strong>Why is LineageX a better choice?</strong></p><p>Other Python libraries like <a href="https://github.com/reata/sqllineage"><em>sqllineage</em></a><em> </em>also produces lineage information, so what makes LineageX stand out? To answer this, here are some of the features that only LineageX offers with just one line of code.</p><ol><li><strong>Automatic dependency creation</strong></li></ol><p>When there are dependencies among the SQL files, and those tables are not yet in the database, LineageX will automatically tries to find the dependency table and creates it. When the files are first inputted, LineageX will scan all the files and sorts out which SQL corresponds to which table name if it is after a “CREATE VIEW” or “CREATE TABLE” or assume the file name as the table name. When trying to produce the lineage information and encounters a not yet created table, it would scan over the table names and creates it for the most accurate lineage information. Example:</p><pre>table1.sql - SELECT column1, column2 FROM schema1.other_table WHERE column3 IS NOT NULL;<br>table2.sql - SELECT column1 AS new_column1, column2 AS new_column2 from schema1.table1;</pre><p>LineageX is able to detect that table1 is an input table, and would acquire the information for that table first before producing the lineage information for table2(this is the example(&quot;github_example&quot;) ).</p><p><strong>2. Clean and simple but very interactive user interface</strong></p><p>The user interface is very simple to use with minimal clutters on the page. Other Python libraries usually shows relationships for a single file and even if you input a list of files, the visualization would be broken down into file-level. Therefore, if the user were to investigate the relationship between the files as well as the base table, he or she would need to click on each individual file to view the relationship. However, LineageX provides the overview on all the selected files, and hovering over a column also highlights all related column in an eye-catching manner. The webpage also provides the functionality that if you have a JSON file with the above format, it can parse the JSON for you to visualize the lineage graph.</p><p><strong>3. Variety of SQL statements</strong></p><p>LineageX supports a variety of SQL statements, aside from the typical “SELECT” statement, it also supports “CREATE TABLE/VIEW [IF NOT EXISTS]” statement as well as the “INSERT” and “DELETE” statement. The “INSERT” and “DELETE” statement would have the tag “insertion” or “deletion” in its name, and it is very interesting to visualize. If the statement does not include “SELECT”, it is just a single node connecting to the table that it is doing the operation on. Otherwise, it would show columns that are used and connects to tables that has a dependency relationship as well as the table the statement is doing an operation on.</p><p>4. <a href="https://docs.getdbt.com/">dbt </a>support</p><p>LineageX is also implemented in the <a href="https://github.com/sfu-db/dbt-lineagex">dbt-LineageX</a>, it is added into a dbt project and by using the dbt library <a href="https://github.com/fal-ai/fal">fal</a>, it is able to reuse the Python core and create the similar output from the dbt project. For more detailed usage and examples, please visit the <a href="https://github.com/sfu-db/dbt-lineagex">Github</a> repo.</p><p><strong>What’s happening next?</strong></p><p>Until now, LineageX is able to produce the lineage information for most of the SQL statements in PostgreSQL, the biggest next step would be able to provide support for other major SQL dialects, like MySQL, SQLite, and others. Aside from supporting other dialects, it would also be more powerful if the user is able to input dialect plugins, so that he or she is able to produce the lineage information cater the needs. You can follow us on <a href="https://github.com/sfu-db/lineagex">Github</a> for our most up-to-date implementation status and next plan!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d262b03b06e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>