summaryrefslogtreecommitdiffstats
path: root/docs/sqlglot/lineage.html
diff options
context:
space:
mode:
Diffstat (limited to 'docs/sqlglot/lineage.html')
-rw-r--r--docs/sqlglot/lineage.html1407
1 files changed, 747 insertions, 660 deletions
diff --git a/docs/sqlglot/lineage.html b/docs/sqlglot/lineage.html
index 77dbfc0..d6f2d77 100644
--- a/docs/sqlglot/lineage.html
+++ b/docs/sqlglot/lineage.html
@@ -31,6 +31,9 @@
<h2>API Documentation</h2>
<ul class="memberlist">
<li>
+ <a class="variable" href="#logger">logger</a>
+ </li>
+ <li>
<a class="class" href="#Node">Node</a>
<ul class="memberlist">
<li>
@@ -49,7 +52,10 @@
<a class="variable" href="#Node.downstream">downstream</a>
</li>
<li>
- <a class="variable" href="#Node.alias">alias</a>
+ <a class="variable" href="#Node.source_name">source_name</a>
+ </li>
+ <li>
+ <a class="variable" href="#Node.reference_node_name">reference_node_name</a>
</li>
<li>
<a class="function" href="#Node.walk">walk</a>
@@ -64,6 +70,9 @@
<a class="function" href="#lineage">lineage</a>
</li>
<li>
+ <a class="function" href="#to_node">to_node</a>
+ </li>
+ <li>
<a class="class" href="#GraphHTML">GraphHTML</a>
<ul class="memberlist">
<li>
@@ -110,312 +119,345 @@
<div class="pdoc-code codehilite"><pre><span></span><span id="L-1"><a href="#L-1"><span class="linenos"> 1</span></a><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">annotations</span>
</span><span id="L-2"><a href="#L-2"><span class="linenos"> 2</span></a>
</span><span id="L-3"><a href="#L-3"><span class="linenos"> 3</span></a><span class="kn">import</span> <span class="nn">json</span>
-</span><span id="L-4"><a href="#L-4"><span class="linenos"> 4</span></a><span class="kn">import</span> <span class="nn">typing</span> <span class="k">as</span> <span class="nn">t</span>
-</span><span id="L-5"><a href="#L-5"><span class="linenos"> 5</span></a><span class="kn">from</span> <span class="nn">dataclasses</span> <span class="kn">import</span> <span class="n">dataclass</span><span class="p">,</span> <span class="n">field</span>
-</span><span id="L-6"><a href="#L-6"><span class="linenos"> 6</span></a>
-</span><span id="L-7"><a href="#L-7"><span class="linenos"> 7</span></a><span class="kn">from</span> <span class="nn">sqlglot</span> <span class="kn">import</span> <span class="n">Schema</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">maybe_parse</span>
-</span><span id="L-8"><a href="#L-8"><span class="linenos"> 8</span></a><span class="kn">from</span> <span class="nn">sqlglot.errors</span> <span class="kn">import</span> <span class="n">SqlglotError</span>
-</span><span id="L-9"><a href="#L-9"><span class="linenos"> 9</span></a><span class="kn">from</span> <span class="nn">sqlglot.optimizer</span> <span class="kn">import</span> <span class="n">Scope</span><span class="p">,</span> <span class="n">build_scope</span><span class="p">,</span> <span class="n">find_all_in_scope</span><span class="p">,</span> <span class="n">qualify</span>
-</span><span id="L-10"><a href="#L-10"><span class="linenos"> 10</span></a>
-</span><span id="L-11"><a href="#L-11"><span class="linenos"> 11</span></a><span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">TYPE_CHECKING</span><span class="p">:</span>
-</span><span id="L-12"><a href="#L-12"><span class="linenos"> 12</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dialects.dialect</span> <span class="kn">import</span> <span class="n">DialectType</span>
-</span><span id="L-13"><a href="#L-13"><span class="linenos"> 13</span></a>
+</span><span id="L-4"><a href="#L-4"><span class="linenos"> 4</span></a><span class="kn">import</span> <span class="nn">logging</span>
+</span><span id="L-5"><a href="#L-5"><span class="linenos"> 5</span></a><span class="kn">import</span> <span class="nn">typing</span> <span class="k">as</span> <span class="nn">t</span>
+</span><span id="L-6"><a href="#L-6"><span class="linenos"> 6</span></a><span class="kn">from</span> <span class="nn">dataclasses</span> <span class="kn">import</span> <span class="n">dataclass</span><span class="p">,</span> <span class="n">field</span>
+</span><span id="L-7"><a href="#L-7"><span class="linenos"> 7</span></a>
+</span><span id="L-8"><a href="#L-8"><span class="linenos"> 8</span></a><span class="kn">from</span> <span class="nn">sqlglot</span> <span class="kn">import</span> <span class="n">Schema</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">maybe_parse</span>
+</span><span id="L-9"><a href="#L-9"><span class="linenos"> 9</span></a><span class="kn">from</span> <span class="nn">sqlglot.errors</span> <span class="kn">import</span> <span class="n">SqlglotError</span>
+</span><span id="L-10"><a href="#L-10"><span class="linenos"> 10</span></a><span class="kn">from</span> <span class="nn">sqlglot.optimizer</span> <span class="kn">import</span> <span class="n">Scope</span><span class="p">,</span> <span class="n">build_scope</span><span class="p">,</span> <span class="n">find_all_in_scope</span><span class="p">,</span> <span class="n">normalize_identifiers</span><span class="p">,</span> <span class="n">qualify</span>
+</span><span id="L-11"><a href="#L-11"><span class="linenos"> 11</span></a>
+</span><span id="L-12"><a href="#L-12"><span class="linenos"> 12</span></a><span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">TYPE_CHECKING</span><span class="p">:</span>
+</span><span id="L-13"><a href="#L-13"><span class="linenos"> 13</span></a> <span class="kn">from</span> <span class="nn">sqlglot.dialects.dialect</span> <span class="kn">import</span> <span class="n">DialectType</span>
</span><span id="L-14"><a href="#L-14"><span class="linenos"> 14</span></a>
-</span><span id="L-15"><a href="#L-15"><span class="linenos"> 15</span></a><span class="nd">@dataclass</span><span class="p">(</span><span class="n">frozen</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
-</span><span id="L-16"><a href="#L-16"><span class="linenos"> 16</span></a><span class="k">class</span> <span class="nc">Node</span><span class="p">:</span>
-</span><span id="L-17"><a href="#L-17"><span class="linenos"> 17</span></a> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>
-</span><span id="L-18"><a href="#L-18"><span class="linenos"> 18</span></a> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span>
-</span><span id="L-19"><a href="#L-19"><span class="linenos"> 19</span></a> <span class="n">source</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span>
-</span><span id="L-20"><a href="#L-20"><span class="linenos"> 20</span></a> <span class="n">downstream</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Node</span><span class="p">]</span> <span class="o">=</span> <span class="n">field</span><span class="p">(</span><span class="n">default_factory</span><span class="o">=</span><span class="nb">list</span><span class="p">)</span>
-</span><span id="L-21"><a href="#L-21"><span class="linenos"> 21</span></a> <span class="n">alias</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
-</span><span id="L-22"><a href="#L-22"><span class="linenos"> 22</span></a>
-</span><span id="L-23"><a href="#L-23"><span class="linenos"> 23</span></a> <span class="k">def</span> <span class="nf">walk</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">t</span><span class="o">.</span><span class="n">Iterator</span><span class="p">[</span><span class="n">Node</span><span class="p">]:</span>
-</span><span id="L-24"><a href="#L-24"><span class="linenos"> 24</span></a> <span class="k">yield</span> <span class="bp">self</span>
-</span><span id="L-25"><a href="#L-25"><span class="linenos"> 25</span></a>
-</span><span id="L-26"><a href="#L-26"><span class="linenos"> 26</span></a> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">downstream</span><span class="p">:</span>
-</span><span id="L-27"><a href="#L-27"><span class="linenos"> 27</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">Node</span><span class="p">):</span>
-</span><span id="L-28"><a href="#L-28"><span class="linenos"> 28</span></a> <span class="k">yield from</span> <span class="n">d</span><span class="o">.</span><span class="n">walk</span><span class="p">()</span>
-</span><span id="L-29"><a href="#L-29"><span class="linenos"> 29</span></a> <span class="k">else</span><span class="p">:</span>
-</span><span id="L-30"><a href="#L-30"><span class="linenos"> 30</span></a> <span class="k">yield</span> <span class="n">d</span>
-</span><span id="L-31"><a href="#L-31"><span class="linenos"> 31</span></a>
-</span><span id="L-32"><a href="#L-32"><span class="linenos"> 32</span></a> <span class="k">def</span> <span class="nf">to_html</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">GraphHTML</span><span class="p">:</span>
-</span><span id="L-33"><a href="#L-33"><span class="linenos"> 33</span></a> <span class="n">nodes</span> <span class="o">=</span> <span class="p">{}</span>
-</span><span id="L-34"><a href="#L-34"><span class="linenos"> 34</span></a> <span class="n">edges</span> <span class="o">=</span> <span class="p">[]</span>
+</span><span id="L-15"><a href="#L-15"><span class="linenos"> 15</span></a><span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s2">&quot;sqlglot&quot;</span><span class="p">)</span>
+</span><span id="L-16"><a href="#L-16"><span class="linenos"> 16</span></a>
+</span><span id="L-17"><a href="#L-17"><span class="linenos"> 17</span></a>
+</span><span id="L-18"><a href="#L-18"><span class="linenos"> 18</span></a><span class="nd">@dataclass</span><span class="p">(</span><span class="n">frozen</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
+</span><span id="L-19"><a href="#L-19"><span class="linenos"> 19</span></a><span class="k">class</span> <span class="nc">Node</span><span class="p">:</span>
+</span><span id="L-20"><a href="#L-20"><span class="linenos"> 20</span></a> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>
+</span><span id="L-21"><a href="#L-21"><span class="linenos"> 21</span></a> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span>
+</span><span id="L-22"><a href="#L-22"><span class="linenos"> 22</span></a> <span class="n">source</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span>
+</span><span id="L-23"><a href="#L-23"><span class="linenos"> 23</span></a> <span class="n">downstream</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Node</span><span class="p">]</span> <span class="o">=</span> <span class="n">field</span><span class="p">(</span><span class="n">default_factory</span><span class="o">=</span><span class="nb">list</span><span class="p">)</span>
+</span><span id="L-24"><a href="#L-24"><span class="linenos"> 24</span></a> <span class="n">source_name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
+</span><span id="L-25"><a href="#L-25"><span class="linenos"> 25</span></a> <span class="n">reference_node_name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
+</span><span id="L-26"><a href="#L-26"><span class="linenos"> 26</span></a>
+</span><span id="L-27"><a href="#L-27"><span class="linenos"> 27</span></a> <span class="k">def</span> <span class="nf">walk</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">t</span><span class="o">.</span><span class="n">Iterator</span><span class="p">[</span><span class="n">Node</span><span class="p">]:</span>
+</span><span id="L-28"><a href="#L-28"><span class="linenos"> 28</span></a> <span class="k">yield</span> <span class="bp">self</span>
+</span><span id="L-29"><a href="#L-29"><span class="linenos"> 29</span></a>
+</span><span id="L-30"><a href="#L-30"><span class="linenos"> 30</span></a> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">downstream</span><span class="p">:</span>
+</span><span id="L-31"><a href="#L-31"><span class="linenos"> 31</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">Node</span><span class="p">):</span>
+</span><span id="L-32"><a href="#L-32"><span class="linenos"> 32</span></a> <span class="k">yield from</span> <span class="n">d</span><span class="o">.</span><span class="n">walk</span><span class="p">()</span>
+</span><span id="L-33"><a href="#L-33"><span class="linenos"> 33</span></a> <span class="k">else</span><span class="p">:</span>
+</span><span id="L-34"><a href="#L-34"><span class="linenos"> 34</span></a> <span class="k">yield</span> <span class="n">d</span>
</span><span id="L-35"><a href="#L-35"><span class="linenos"> 35</span></a>
-</span><span id="L-36"><a href="#L-36"><span class="linenos"> 36</span></a> <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">walk</span><span class="p">():</span>
-</span><span id="L-37"><a href="#L-37"><span class="linenos"> 37</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
-</span><span id="L-38"><a href="#L-38"><span class="linenos"> 38</span></a> <span class="n">label</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;FROM </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="si">}</span><span class="s2">&quot;</span>
-</span><span id="L-39"><a href="#L-39"><span class="linenos"> 39</span></a> <span class="n">title</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&lt;pre&gt;SELECT </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> FROM </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="si">}</span><span class="s2">&lt;/pre&gt;&quot;</span>
-</span><span id="L-40"><a href="#L-40"><span class="linenos"> 40</span></a> <span class="n">group</span> <span class="o">=</span> <span class="mi">1</span>
-</span><span id="L-41"><a href="#L-41"><span class="linenos"> 41</span></a> <span class="k">else</span><span class="p">:</span>
-</span><span id="L-42"><a href="#L-42"><span class="linenos"> 42</span></a> <span class="n">label</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
-</span><span id="L-43"><a href="#L-43"><span class="linenos"> 43</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span>
-</span><span id="L-44"><a href="#L-44"><span class="linenos"> 44</span></a> <span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="p">(</span>
-</span><span id="L-45"><a href="#L-45"><span class="linenos"> 45</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Tag</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">n</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;&lt;b&gt;&quot;</span><span class="p">,</span> <span class="n">postfix</span><span class="o">=</span><span class="s2">&quot;&lt;/b&gt;&quot;</span><span class="p">)</span> <span class="k">if</span> <span class="n">n</span> <span class="ow">is</span> <span class="n">node</span><span class="o">.</span><span class="n">expression</span> <span class="k">else</span> <span class="n">n</span>
-</span><span id="L-46"><a href="#L-46"><span class="linenos"> 46</span></a> <span class="p">),</span>
-</span><span id="L-47"><a href="#L-47"><span class="linenos"> 47</span></a> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
-</span><span id="L-48"><a href="#L-48"><span class="linenos"> 48</span></a> <span class="p">)</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
-</span><span id="L-49"><a href="#L-49"><span class="linenos"> 49</span></a> <span class="n">title</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&lt;pre&gt;</span><span class="si">{</span><span class="n">source</span><span class="si">}</span><span class="s2">&lt;/pre&gt;&quot;</span>
-</span><span id="L-50"><a href="#L-50"><span class="linenos"> 50</span></a> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span>
-</span><span id="L-51"><a href="#L-51"><span class="linenos"> 51</span></a>
-</span><span id="L-52"><a href="#L-52"><span class="linenos"> 52</span></a> <span class="n">node_id</span> <span class="o">=</span> <span class="nb">id</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
-</span><span id="L-53"><a href="#L-53"><span class="linenos"> 53</span></a>
-</span><span id="L-54"><a href="#L-54"><span class="linenos"> 54</span></a> <span class="n">nodes</span><span class="p">[</span><span class="n">node_id</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
-</span><span id="L-55"><a href="#L-55"><span class="linenos"> 55</span></a> <span class="s2">&quot;id&quot;</span><span class="p">:</span> <span class="n">node_id</span><span class="p">,</span>
-</span><span id="L-56"><a href="#L-56"><span class="linenos"> 56</span></a> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="n">label</span><span class="p">,</span>
-</span><span id="L-57"><a href="#L-57"><span class="linenos"> 57</span></a> <span class="s2">&quot;title&quot;</span><span class="p">:</span> <span class="n">title</span><span class="p">,</span>
-</span><span id="L-58"><a href="#L-58"><span class="linenos"> 58</span></a> <span class="s2">&quot;group&quot;</span><span class="p">:</span> <span class="n">group</span><span class="p">,</span>
-</span><span id="L-59"><a href="#L-59"><span class="linenos"> 59</span></a> <span class="p">}</span>
-</span><span id="L-60"><a href="#L-60"><span class="linenos"> 60</span></a>
-</span><span id="L-61"><a href="#L-61"><span class="linenos"> 61</span></a> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="p">:</span>
-</span><span id="L-62"><a href="#L-62"><span class="linenos"> 62</span></a> <span class="n">edges</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;from&quot;</span><span class="p">:</span> <span class="n">node_id</span><span class="p">,</span> <span class="s2">&quot;to&quot;</span><span class="p">:</span> <span class="nb">id</span><span class="p">(</span><span class="n">d</span><span class="p">)})</span>
-</span><span id="L-63"><a href="#L-63"><span class="linenos"> 63</span></a> <span class="k">return</span> <span class="n">GraphHTML</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="n">edges</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span>
+</span><span id="L-36"><a href="#L-36"><span class="linenos"> 36</span></a> <span class="k">def</span> <span class="nf">to_html</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">GraphHTML</span><span class="p">:</span>
+</span><span id="L-37"><a href="#L-37"><span class="linenos"> 37</span></a> <span class="n">nodes</span> <span class="o">=</span> <span class="p">{}</span>
+</span><span id="L-38"><a href="#L-38"><span class="linenos"> 38</span></a> <span class="n">edges</span> <span class="o">=</span> <span class="p">[]</span>
+</span><span id="L-39"><a href="#L-39"><span class="linenos"> 39</span></a>
+</span><span id="L-40"><a href="#L-40"><span class="linenos"> 40</span></a> <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">walk</span><span class="p">():</span>
+</span><span id="L-41"><a href="#L-41"><span class="linenos"> 41</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
+</span><span id="L-42"><a href="#L-42"><span class="linenos"> 42</span></a> <span class="n">label</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;FROM </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="si">}</span><span class="s2">&quot;</span>
+</span><span id="L-43"><a href="#L-43"><span class="linenos"> 43</span></a> <span class="n">title</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&lt;pre&gt;SELECT </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> FROM </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="si">}</span><span class="s2">&lt;/pre&gt;&quot;</span>
+</span><span id="L-44"><a href="#L-44"><span class="linenos"> 44</span></a> <span class="n">group</span> <span class="o">=</span> <span class="mi">1</span>
+</span><span id="L-45"><a href="#L-45"><span class="linenos"> 45</span></a> <span class="k">else</span><span class="p">:</span>
+</span><span id="L-46"><a href="#L-46"><span class="linenos"> 46</span></a> <span class="n">label</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
+</span><span id="L-47"><a href="#L-47"><span class="linenos"> 47</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span>
+</span><span id="L-48"><a href="#L-48"><span class="linenos"> 48</span></a> <span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="p">(</span>
+</span><span id="L-49"><a href="#L-49"><span class="linenos"> 49</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Tag</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">n</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;&lt;b&gt;&quot;</span><span class="p">,</span> <span class="n">postfix</span><span class="o">=</span><span class="s2">&quot;&lt;/b&gt;&quot;</span><span class="p">)</span> <span class="k">if</span> <span class="n">n</span> <span class="ow">is</span> <span class="n">node</span><span class="o">.</span><span class="n">expression</span> <span class="k">else</span> <span class="n">n</span>
+</span><span id="L-50"><a href="#L-50"><span class="linenos"> 50</span></a> <span class="p">),</span>
+</span><span id="L-51"><a href="#L-51"><span class="linenos"> 51</span></a> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
+</span><span id="L-52"><a href="#L-52"><span class="linenos"> 52</span></a> <span class="p">)</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
+</span><span id="L-53"><a href="#L-53"><span class="linenos"> 53</span></a> <span class="n">title</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&lt;pre&gt;</span><span class="si">{</span><span class="n">source</span><span class="si">}</span><span class="s2">&lt;/pre&gt;&quot;</span>
+</span><span id="L-54"><a href="#L-54"><span class="linenos"> 54</span></a> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span>
+</span><span id="L-55"><a href="#L-55"><span class="linenos"> 55</span></a>
+</span><span id="L-56"><a href="#L-56"><span class="linenos"> 56</span></a> <span class="n">node_id</span> <span class="o">=</span> <span class="nb">id</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
+</span><span id="L-57"><a href="#L-57"><span class="linenos"> 57</span></a>
+</span><span id="L-58"><a href="#L-58"><span class="linenos"> 58</span></a> <span class="n">nodes</span><span class="p">[</span><span class="n">node_id</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
+</span><span id="L-59"><a href="#L-59"><span class="linenos"> 59</span></a> <span class="s2">&quot;id&quot;</span><span class="p">:</span> <span class="n">node_id</span><span class="p">,</span>
+</span><span id="L-60"><a href="#L-60"><span class="linenos"> 60</span></a> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="n">label</span><span class="p">,</span>
+</span><span id="L-61"><a href="#L-61"><span class="linenos"> 61</span></a> <span class="s2">&quot;title&quot;</span><span class="p">:</span> <span class="n">title</span><span class="p">,</span>
+</span><span id="L-62"><a href="#L-62"><span class="linenos"> 62</span></a> <span class="s2">&quot;group&quot;</span><span class="p">:</span> <span class="n">group</span><span class="p">,</span>
+</span><span id="L-63"><a href="#L-63"><span class="linenos"> 63</span></a> <span class="p">}</span>
</span><span id="L-64"><a href="#L-64"><span class="linenos"> 64</span></a>
-</span><span id="L-65"><a href="#L-65"><span class="linenos"> 65</span></a>
-</span><span id="L-66"><a href="#L-66"><span class="linenos"> 66</span></a><span class="k">def</span> <span class="nf">lineage</span><span class="p">(</span>
-</span><span id="L-67"><a href="#L-67"><span class="linenos"> 67</span></a> <span class="n">column</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">,</span>
-</span><span id="L-68"><a href="#L-68"><span class="linenos"> 68</span></a> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span>
-</span><span id="L-69"><a href="#L-69"><span class="linenos"> 69</span></a> <span class="n">schema</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">|</span> <span class="n">Schema</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
-</span><span id="L-70"><a href="#L-70"><span class="linenos"> 70</span></a> <span class="n">sources</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Subqueryable</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
-</span><span id="L-71"><a href="#L-71"><span class="linenos"> 71</span></a> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
-</span><span id="L-72"><a href="#L-72"><span class="linenos"> 72</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span>
-</span><span id="L-73"><a href="#L-73"><span class="linenos"> 73</span></a><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Node</span><span class="p">:</span>
-</span><span id="L-74"><a href="#L-74"><span class="linenos"> 74</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Build the lineage graph for a column of a SQL query.</span>
-</span><span id="L-75"><a href="#L-75"><span class="linenos"> 75</span></a>
-</span><span id="L-76"><a href="#L-76"><span class="linenos"> 76</span></a><span class="sd"> Args:</span>
-</span><span id="L-77"><a href="#L-77"><span class="linenos"> 77</span></a><span class="sd"> column: The column to build the lineage for.</span>
-</span><span id="L-78"><a href="#L-78"><span class="linenos"> 78</span></a><span class="sd"> sql: The SQL string or expression.</span>
-</span><span id="L-79"><a href="#L-79"><span class="linenos"> 79</span></a><span class="sd"> schema: The schema of tables.</span>
-</span><span id="L-80"><a href="#L-80"><span class="linenos"> 80</span></a><span class="sd"> sources: A mapping of queries which will be used to continue building lineage.</span>
-</span><span id="L-81"><a href="#L-81"><span class="linenos"> 81</span></a><span class="sd"> dialect: The dialect of input SQL.</span>
-</span><span id="L-82"><a href="#L-82"><span class="linenos"> 82</span></a><span class="sd"> **kwargs: Qualification optimizer kwargs.</span>
-</span><span id="L-83"><a href="#L-83"><span class="linenos"> 83</span></a>
-</span><span id="L-84"><a href="#L-84"><span class="linenos"> 84</span></a><span class="sd"> Returns:</span>
-</span><span id="L-85"><a href="#L-85"><span class="linenos"> 85</span></a><span class="sd"> A lineage node.</span>
-</span><span id="L-86"><a href="#L-86"><span class="linenos"> 86</span></a><span class="sd"> &quot;&quot;&quot;</span>
+</span><span id="L-65"><a href="#L-65"><span class="linenos"> 65</span></a> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="p">:</span>
+</span><span id="L-66"><a href="#L-66"><span class="linenos"> 66</span></a> <span class="n">edges</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;from&quot;</span><span class="p">:</span> <span class="n">node_id</span><span class="p">,</span> <span class="s2">&quot;to&quot;</span><span class="p">:</span> <span class="nb">id</span><span class="p">(</span><span class="n">d</span><span class="p">)})</span>
+</span><span id="L-67"><a href="#L-67"><span class="linenos"> 67</span></a> <span class="k">return</span> <span class="n">GraphHTML</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="n">edges</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span>
+</span><span id="L-68"><a href="#L-68"><span class="linenos"> 68</span></a>
+</span><span id="L-69"><a href="#L-69"><span class="linenos"> 69</span></a>
+</span><span id="L-70"><a href="#L-70"><span class="linenos"> 70</span></a><span class="k">def</span> <span class="nf">lineage</span><span class="p">(</span>
+</span><span id="L-71"><a href="#L-71"><span class="linenos"> 71</span></a> <span class="n">column</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">,</span>
+</span><span id="L-72"><a href="#L-72"><span class="linenos"> 72</span></a> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span>
+</span><span id="L-73"><a href="#L-73"><span class="linenos"> 73</span></a> <span class="n">schema</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">|</span> <span class="n">Schema</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="L-74"><a href="#L-74"><span class="linenos"> 74</span></a> <span class="n">sources</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Query</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="L-75"><a href="#L-75"><span class="linenos"> 75</span></a> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="L-76"><a href="#L-76"><span class="linenos"> 76</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span>
+</span><span id="L-77"><a href="#L-77"><span class="linenos"> 77</span></a><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Node</span><span class="p">:</span>
+</span><span id="L-78"><a href="#L-78"><span class="linenos"> 78</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Build the lineage graph for a column of a SQL query.</span>
+</span><span id="L-79"><a href="#L-79"><span class="linenos"> 79</span></a>
+</span><span id="L-80"><a href="#L-80"><span class="linenos"> 80</span></a><span class="sd"> Args:</span>
+</span><span id="L-81"><a href="#L-81"><span class="linenos"> 81</span></a><span class="sd"> column: The column to build the lineage for.</span>
+</span><span id="L-82"><a href="#L-82"><span class="linenos"> 82</span></a><span class="sd"> sql: The SQL string or expression.</span>
+</span><span id="L-83"><a href="#L-83"><span class="linenos"> 83</span></a><span class="sd"> schema: The schema of tables.</span>
+</span><span id="L-84"><a href="#L-84"><span class="linenos"> 84</span></a><span class="sd"> sources: A mapping of queries which will be used to continue building lineage.</span>
+</span><span id="L-85"><a href="#L-85"><span class="linenos"> 85</span></a><span class="sd"> dialect: The dialect of input SQL.</span>
+</span><span id="L-86"><a href="#L-86"><span class="linenos"> 86</span></a><span class="sd"> **kwargs: Qualification optimizer kwargs.</span>
</span><span id="L-87"><a href="#L-87"><span class="linenos"> 87</span></a>
-</span><span id="L-88"><a href="#L-88"><span class="linenos"> 88</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">maybe_parse</span><span class="p">(</span><span class="n">sql</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
-</span><span id="L-89"><a href="#L-89"><span class="linenos"> 89</span></a>
-</span><span id="L-90"><a href="#L-90"><span class="linenos"> 90</span></a> <span class="k">if</span> <span class="n">sources</span><span class="p">:</span>
-</span><span id="L-91"><a href="#L-91"><span class="linenos"> 91</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span>
-</span><span id="L-92"><a href="#L-92"><span class="linenos"> 92</span></a> <span class="n">expression</span><span class="p">,</span>
-</span><span id="L-93"><a href="#L-93"><span class="linenos"> 93</span></a> <span class="p">{</span>
-</span><span id="L-94"><a href="#L-94"><span class="linenos"> 94</span></a> <span class="n">k</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Subqueryable</span><span class="p">,</span> <span class="n">maybe_parse</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">))</span>
-</span><span id="L-95"><a href="#L-95"><span class="linenos"> 95</span></a> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">sources</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
-</span><span id="L-96"><a href="#L-96"><span class="linenos"> 96</span></a> <span class="p">},</span>
-</span><span id="L-97"><a href="#L-97"><span class="linenos"> 97</span></a> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span>
-</span><span id="L-98"><a href="#L-98"><span class="linenos"> 98</span></a> <span class="p">)</span>
-</span><span id="L-99"><a href="#L-99"><span class="linenos"> 99</span></a>
-</span><span id="L-100"><a href="#L-100"><span class="linenos">100</span></a> <span class="n">qualified</span> <span class="o">=</span> <span class="n">qualify</span><span class="o">.</span><span class="n">qualify</span><span class="p">(</span>
-</span><span id="L-101"><a href="#L-101"><span class="linenos">101</span></a> <span class="n">expression</span><span class="p">,</span>
-</span><span id="L-102"><a href="#L-102"><span class="linenos">102</span></a> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span>
-</span><span id="L-103"><a href="#L-103"><span class="linenos">103</span></a> <span class="n">schema</span><span class="o">=</span><span class="n">schema</span><span class="p">,</span>
-</span><span id="L-104"><a href="#L-104"><span class="linenos">104</span></a> <span class="o">**</span><span class="p">{</span><span class="s2">&quot;validate_qualify_columns&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span> <span class="s2">&quot;identify&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">},</span> <span class="c1"># type: ignore</span>
-</span><span id="L-105"><a href="#L-105"><span class="linenos">105</span></a> <span class="p">)</span>
-</span><span id="L-106"><a href="#L-106"><span class="linenos">106</span></a>
-</span><span id="L-107"><a href="#L-107"><span class="linenos">107</span></a> <span class="n">scope</span> <span class="o">=</span> <span class="n">build_scope</span><span class="p">(</span><span class="n">qualified</span><span class="p">)</span>
+</span><span id="L-88"><a href="#L-88"><span class="linenos"> 88</span></a><span class="sd"> Returns:</span>
+</span><span id="L-89"><a href="#L-89"><span class="linenos"> 89</span></a><span class="sd"> A lineage node.</span>
+</span><span id="L-90"><a href="#L-90"><span class="linenos"> 90</span></a><span class="sd"> &quot;&quot;&quot;</span>
+</span><span id="L-91"><a href="#L-91"><span class="linenos"> 91</span></a>
+</span><span id="L-92"><a href="#L-92"><span class="linenos"> 92</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">maybe_parse</span><span class="p">(</span><span class="n">sql</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
+</span><span id="L-93"><a href="#L-93"><span class="linenos"> 93</span></a> <span class="n">column</span> <span class="o">=</span> <span class="n">normalize_identifiers</span><span class="o">.</span><span class="n">normalize_identifiers</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span><span class="o">.</span><span class="n">name</span>
+</span><span id="L-94"><a href="#L-94"><span class="linenos"> 94</span></a>
+</span><span id="L-95"><a href="#L-95"><span class="linenos"> 95</span></a> <span class="k">if</span> <span class="n">sources</span><span class="p">:</span>
+</span><span id="L-96"><a href="#L-96"><span class="linenos"> 96</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span>
+</span><span id="L-97"><a href="#L-97"><span class="linenos"> 97</span></a> <span class="n">expression</span><span class="p">,</span>
+</span><span id="L-98"><a href="#L-98"><span class="linenos"> 98</span></a> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Query</span><span class="p">,</span> <span class="n">maybe_parse</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">))</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">sources</span><span class="o">.</span><span class="n">items</span><span class="p">()},</span>
+</span><span id="L-99"><a href="#L-99"><span class="linenos"> 99</span></a> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span>
+</span><span id="L-100"><a href="#L-100"><span class="linenos">100</span></a> <span class="p">)</span>
+</span><span id="L-101"><a href="#L-101"><span class="linenos">101</span></a>
+</span><span id="L-102"><a href="#L-102"><span class="linenos">102</span></a> <span class="n">qualified</span> <span class="o">=</span> <span class="n">qualify</span><span class="o">.</span><span class="n">qualify</span><span class="p">(</span>
+</span><span id="L-103"><a href="#L-103"><span class="linenos">103</span></a> <span class="n">expression</span><span class="p">,</span>
+</span><span id="L-104"><a href="#L-104"><span class="linenos">104</span></a> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span>
+</span><span id="L-105"><a href="#L-105"><span class="linenos">105</span></a> <span class="n">schema</span><span class="o">=</span><span class="n">schema</span><span class="p">,</span>
+</span><span id="L-106"><a href="#L-106"><span class="linenos">106</span></a> <span class="o">**</span><span class="p">{</span><span class="s2">&quot;validate_qualify_columns&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span> <span class="s2">&quot;identify&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">},</span> <span class="c1"># type: ignore</span>
+</span><span id="L-107"><a href="#L-107"><span class="linenos">107</span></a> <span class="p">)</span>
</span><span id="L-108"><a href="#L-108"><span class="linenos">108</span></a>
-</span><span id="L-109"><a href="#L-109"><span class="linenos">109</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">scope</span><span class="p">:</span>
-</span><span id="L-110"><a href="#L-110"><span class="linenos">110</span></a> <span class="k">raise</span> <span class="n">SqlglotError</span><span class="p">(</span><span class="s2">&quot;Cannot build lineage, sql must be SELECT&quot;</span><span class="p">)</span>
-</span><span id="L-111"><a href="#L-111"><span class="linenos">111</span></a>
-</span><span id="L-112"><a href="#L-112"><span class="linenos">112</span></a> <span class="k">def</span> <span class="nf">to_node</span><span class="p">(</span>
-</span><span id="L-113"><a href="#L-113"><span class="linenos">113</span></a> <span class="n">column</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">int</span><span class="p">,</span>
-</span><span id="L-114"><a href="#L-114"><span class="linenos">114</span></a> <span class="n">scope</span><span class="p">:</span> <span class="n">Scope</span><span class="p">,</span>
-</span><span id="L-115"><a href="#L-115"><span class="linenos">115</span></a> <span class="n">scope_name</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
-</span><span id="L-116"><a href="#L-116"><span class="linenos">116</span></a> <span class="n">upstream</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">Node</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
-</span><span id="L-117"><a href="#L-117"><span class="linenos">117</span></a> <span class="n">alias</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
-</span><span id="L-118"><a href="#L-118"><span class="linenos">118</span></a> <span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Node</span><span class="p">:</span>
-</span><span id="L-119"><a href="#L-119"><span class="linenos">119</span></a> <span class="n">aliases</span> <span class="o">=</span> <span class="p">{</span>
-</span><span id="L-120"><a href="#L-120"><span class="linenos">120</span></a> <span class="n">dt</span><span class="o">.</span><span class="n">alias</span><span class="p">:</span> <span class="n">dt</span><span class="o">.</span><span class="n">comments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>
-</span><span id="L-121"><a href="#L-121"><span class="linenos">121</span></a> <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">derived_tables</span>
-</span><span id="L-122"><a href="#L-122"><span class="linenos">122</span></a> <span class="k">if</span> <span class="n">dt</span><span class="o">.</span><span class="n">comments</span> <span class="ow">and</span> <span class="n">dt</span><span class="o">.</span><span class="n">comments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;source: &quot;</span><span class="p">)</span>
-</span><span id="L-123"><a href="#L-123"><span class="linenos">123</span></a> <span class="p">}</span>
-</span><span id="L-124"><a href="#L-124"><span class="linenos">124</span></a>
-</span><span id="L-125"><a href="#L-125"><span class="linenos">125</span></a> <span class="c1"># Find the specific select clause that is the source of the column we want.</span>
-</span><span id="L-126"><a href="#L-126"><span class="linenos">126</span></a> <span class="c1"># This can either be a specific, named select or a generic `*` clause.</span>
-</span><span id="L-127"><a href="#L-127"><span class="linenos">127</span></a> <span class="n">select</span> <span class="o">=</span> <span class="p">(</span>
-</span><span id="L-128"><a href="#L-128"><span class="linenos">128</span></a> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span><span class="p">[</span><span class="n">column</span><span class="p">]</span>
-</span><span id="L-129"><a href="#L-129"><span class="linenos">129</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
-</span><span id="L-130"><a href="#L-130"><span class="linenos">130</span></a> <span class="k">else</span> <span class="nb">next</span><span class="p">(</span>
-</span><span id="L-131"><a href="#L-131"><span class="linenos">131</span></a> <span class="p">(</span><span class="n">select</span> <span class="k">for</span> <span class="n">select</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span> <span class="k">if</span> <span class="n">select</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="n">column</span><span class="p">),</span>
-</span><span id="L-132"><a href="#L-132"><span class="linenos">132</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Star</span><span class="p">()</span> <span class="k">if</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">is_star</span> <span class="k">else</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span>
-</span><span id="L-133"><a href="#L-133"><span class="linenos">133</span></a> <span class="p">)</span>
-</span><span id="L-134"><a href="#L-134"><span class="linenos">134</span></a> <span class="p">)</span>
-</span><span id="L-135"><a href="#L-135"><span class="linenos">135</span></a>
-</span><span id="L-136"><a href="#L-136"><span class="linenos">136</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Union</span><span class="p">):</span>
-</span><span id="L-137"><a href="#L-137"><span class="linenos">137</span></a> <span class="n">upstream</span> <span class="o">=</span> <span class="n">upstream</span> <span class="ow">or</span> <span class="n">Node</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;UNION&quot;</span><span class="p">,</span> <span class="n">source</span><span class="o">=</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">select</span><span class="p">)</span>
-</span><span id="L-138"><a href="#L-138"><span class="linenos">138</span></a>
-</span><span id="L-139"><a href="#L-139"><span class="linenos">139</span></a> <span class="n">index</span> <span class="o">=</span> <span class="p">(</span>
-</span><span id="L-140"><a href="#L-140"><span class="linenos">140</span></a> <span class="n">column</span>
-</span><span id="L-141"><a href="#L-141"><span class="linenos">141</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
-</span><span id="L-142"><a href="#L-142"><span class="linenos">142</span></a> <span class="k">else</span> <span class="nb">next</span><span class="p">(</span>
-</span><span id="L-143"><a href="#L-143"><span class="linenos">143</span></a> <span class="p">(</span>
-</span><span id="L-144"><a href="#L-144"><span class="linenos">144</span></a> <span class="n">i</span>
-</span><span id="L-145"><a href="#L-145"><span class="linenos">145</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">select</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span><span class="p">)</span>
-</span><span id="L-146"><a href="#L-146"><span class="linenos">146</span></a> <span class="k">if</span> <span class="n">select</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="n">column</span> <span class="ow">or</span> <span class="n">select</span><span class="o">.</span><span class="n">is_star</span>
-</span><span id="L-147"><a href="#L-147"><span class="linenos">147</span></a> <span class="p">),</span>
-</span><span id="L-148"><a href="#L-148"><span class="linenos">148</span></a> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="c1"># mypy will not allow a None here, but a negative index should never be returned</span>
-</span><span id="L-149"><a href="#L-149"><span class="linenos">149</span></a> <span class="p">)</span>
-</span><span id="L-150"><a href="#L-150"><span class="linenos">150</span></a> <span class="p">)</span>
-</span><span id="L-151"><a href="#L-151"><span class="linenos">151</span></a>
-</span><span id="L-152"><a href="#L-152"><span class="linenos">152</span></a> <span class="k">if</span> <span class="n">index</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
-</span><span id="L-153"><a href="#L-153"><span class="linenos">153</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Could not find </span><span class="si">{</span><span class="n">column</span><span class="si">}</span><span class="s2"> in </span><span class="si">{</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
-</span><span id="L-154"><a href="#L-154"><span class="linenos">154</span></a>
-</span><span id="L-155"><a href="#L-155"><span class="linenos">155</span></a> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">union_scopes</span><span class="p">:</span>
-</span><span id="L-156"><a href="#L-156"><span class="linenos">156</span></a> <span class="n">to_node</span><span class="p">(</span><span class="n">index</span><span class="p">,</span> <span class="n">scope</span><span class="o">=</span><span class="n">s</span><span class="p">,</span> <span class="n">upstream</span><span class="o">=</span><span class="n">upstream</span><span class="p">,</span> <span class="n">alias</span><span class="o">=</span><span class="n">alias</span><span class="p">)</span>
-</span><span id="L-157"><a href="#L-157"><span class="linenos">157</span></a>
-</span><span id="L-158"><a href="#L-158"><span class="linenos">158</span></a> <span class="k">return</span> <span class="n">upstream</span>
-</span><span id="L-159"><a href="#L-159"><span class="linenos">159</span></a>
-</span><span id="L-160"><a href="#L-160"><span class="linenos">160</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">):</span>
-</span><span id="L-161"><a href="#L-161"><span class="linenos">161</span></a> <span class="c1"># For better ergonomics in our node labels, replace the full select with</span>
-</span><span id="L-162"><a href="#L-162"><span class="linenos">162</span></a> <span class="c1"># a version that has only the column we care about.</span>
-</span><span id="L-163"><a href="#L-163"><span class="linenos">163</span></a> <span class="c1"># &quot;x&quot;, SELECT x, y FROM foo</span>
-</span><span id="L-164"><a href="#L-164"><span class="linenos">164</span></a> <span class="c1"># =&gt; &quot;x&quot;, SELECT x FROM foo</span>
-</span><span id="L-165"><a href="#L-165"><span class="linenos">165</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">t</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">append</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
-</span><span id="L-166"><a href="#L-166"><span class="linenos">166</span></a> <span class="k">else</span><span class="p">:</span>
-</span><span id="L-167"><a href="#L-167"><span class="linenos">167</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span>
-</span><span id="L-168"><a href="#L-168"><span class="linenos">168</span></a>
-</span><span id="L-169"><a href="#L-169"><span class="linenos">169</span></a> <span class="c1"># Create the node for this step in the lineage chain, and attach it to the previous one.</span>
-</span><span id="L-170"><a href="#L-170"><span class="linenos">170</span></a> <span class="n">node</span> <span class="o">=</span> <span class="n">Node</span><span class="p">(</span>
-</span><span id="L-171"><a href="#L-171"><span class="linenos">171</span></a> <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">scope_name</span><span class="si">}</span><span class="s2">.</span><span class="si">{</span><span class="n">column</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">if</span> <span class="n">scope_name</span> <span class="k">else</span> <span class="nb">str</span><span class="p">(</span><span class="n">column</span><span class="p">),</span>
-</span><span id="L-172"><a href="#L-172"><span class="linenos">172</span></a> <span class="n">source</span><span class="o">=</span><span class="n">source</span><span class="p">,</span>
-</span><span id="L-173"><a href="#L-173"><span class="linenos">173</span></a> <span class="n">expression</span><span class="o">=</span><span class="n">select</span><span class="p">,</span>
-</span><span id="L-174"><a href="#L-174"><span class="linenos">174</span></a> <span class="n">alias</span><span class="o">=</span><span class="n">alias</span> <span class="ow">or</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
-</span><span id="L-175"><a href="#L-175"><span class="linenos">175</span></a> <span class="p">)</span>
+</span><span id="L-109"><a href="#L-109"><span class="linenos">109</span></a> <span class="n">scope</span> <span class="o">=</span> <span class="n">build_scope</span><span class="p">(</span><span class="n">qualified</span><span class="p">)</span>
+</span><span id="L-110"><a href="#L-110"><span class="linenos">110</span></a>
+</span><span id="L-111"><a href="#L-111"><span class="linenos">111</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">scope</span><span class="p">:</span>
+</span><span id="L-112"><a href="#L-112"><span class="linenos">112</span></a> <span class="k">raise</span> <span class="n">SqlglotError</span><span class="p">(</span><span class="s2">&quot;Cannot build lineage, sql must be SELECT&quot;</span><span class="p">)</span>
+</span><span id="L-113"><a href="#L-113"><span class="linenos">113</span></a>
+</span><span id="L-114"><a href="#L-114"><span class="linenos">114</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">any</span><span class="p">(</span><span class="n">select</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="n">column</span> <span class="k">for</span> <span class="n">select</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span><span class="p">):</span>
+</span><span id="L-115"><a href="#L-115"><span class="linenos">115</span></a> <span class="k">raise</span> <span class="n">SqlglotError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Cannot find column &#39;</span><span class="si">{</span><span class="n">column</span><span class="si">}</span><span class="s2">&#39; in query.&quot;</span><span class="p">)</span>
+</span><span id="L-116"><a href="#L-116"><span class="linenos">116</span></a>
+</span><span id="L-117"><a href="#L-117"><span class="linenos">117</span></a> <span class="k">return</span> <span class="n">to_node</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="n">scope</span><span class="p">,</span> <span class="n">dialect</span><span class="p">)</span>
+</span><span id="L-118"><a href="#L-118"><span class="linenos">118</span></a>
+</span><span id="L-119"><a href="#L-119"><span class="linenos">119</span></a>
+</span><span id="L-120"><a href="#L-120"><span class="linenos">120</span></a><span class="k">def</span> <span class="nf">to_node</span><span class="p">(</span>
+</span><span id="L-121"><a href="#L-121"><span class="linenos">121</span></a> <span class="n">column</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">int</span><span class="p">,</span>
+</span><span id="L-122"><a href="#L-122"><span class="linenos">122</span></a> <span class="n">scope</span><span class="p">:</span> <span class="n">Scope</span><span class="p">,</span>
+</span><span id="L-123"><a href="#L-123"><span class="linenos">123</span></a> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">,</span>
+</span><span id="L-124"><a href="#L-124"><span class="linenos">124</span></a> <span class="n">scope_name</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="L-125"><a href="#L-125"><span class="linenos">125</span></a> <span class="n">upstream</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">Node</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="L-126"><a href="#L-126"><span class="linenos">126</span></a> <span class="n">source_name</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="L-127"><a href="#L-127"><span class="linenos">127</span></a> <span class="n">reference_node_name</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="L-128"><a href="#L-128"><span class="linenos">128</span></a><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Node</span><span class="p">:</span>
+</span><span id="L-129"><a href="#L-129"><span class="linenos">129</span></a> <span class="n">source_names</span> <span class="o">=</span> <span class="p">{</span>
+</span><span id="L-130"><a href="#L-130"><span class="linenos">130</span></a> <span class="n">dt</span><span class="o">.</span><span class="n">alias</span><span class="p">:</span> <span class="n">dt</span><span class="o">.</span><span class="n">comments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>
+</span><span id="L-131"><a href="#L-131"><span class="linenos">131</span></a> <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">derived_tables</span>
+</span><span id="L-132"><a href="#L-132"><span class="linenos">132</span></a> <span class="k">if</span> <span class="n">dt</span><span class="o">.</span><span class="n">comments</span> <span class="ow">and</span> <span class="n">dt</span><span class="o">.</span><span class="n">comments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;source: &quot;</span><span class="p">)</span>
+</span><span id="L-133"><a href="#L-133"><span class="linenos">133</span></a> <span class="p">}</span>
+</span><span id="L-134"><a href="#L-134"><span class="linenos">134</span></a>
+</span><span id="L-135"><a href="#L-135"><span class="linenos">135</span></a> <span class="c1"># Find the specific select clause that is the source of the column we want.</span>
+</span><span id="L-136"><a href="#L-136"><span class="linenos">136</span></a> <span class="c1"># This can either be a specific, named select or a generic `*` clause.</span>
+</span><span id="L-137"><a href="#L-137"><span class="linenos">137</span></a> <span class="n">select</span> <span class="o">=</span> <span class="p">(</span>
+</span><span id="L-138"><a href="#L-138"><span class="linenos">138</span></a> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span><span class="p">[</span><span class="n">column</span><span class="p">]</span>
+</span><span id="L-139"><a href="#L-139"><span class="linenos">139</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
+</span><span id="L-140"><a href="#L-140"><span class="linenos">140</span></a> <span class="k">else</span> <span class="nb">next</span><span class="p">(</span>
+</span><span id="L-141"><a href="#L-141"><span class="linenos">141</span></a> <span class="p">(</span><span class="n">select</span> <span class="k">for</span> <span class="n">select</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span> <span class="k">if</span> <span class="n">select</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="n">column</span><span class="p">),</span>
+</span><span id="L-142"><a href="#L-142"><span class="linenos">142</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Star</span><span class="p">()</span> <span class="k">if</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">is_star</span> <span class="k">else</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span>
+</span><span id="L-143"><a href="#L-143"><span class="linenos">143</span></a> <span class="p">)</span>
+</span><span id="L-144"><a href="#L-144"><span class="linenos">144</span></a> <span class="p">)</span>
+</span><span id="L-145"><a href="#L-145"><span class="linenos">145</span></a>
+</span><span id="L-146"><a href="#L-146"><span class="linenos">146</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Union</span><span class="p">):</span>
+</span><span id="L-147"><a href="#L-147"><span class="linenos">147</span></a> <span class="n">upstream</span> <span class="o">=</span> <span class="n">upstream</span> <span class="ow">or</span> <span class="n">Node</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;UNION&quot;</span><span class="p">,</span> <span class="n">source</span><span class="o">=</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">select</span><span class="p">)</span>
+</span><span id="L-148"><a href="#L-148"><span class="linenos">148</span></a>
+</span><span id="L-149"><a href="#L-149"><span class="linenos">149</span></a> <span class="n">index</span> <span class="o">=</span> <span class="p">(</span>
+</span><span id="L-150"><a href="#L-150"><span class="linenos">150</span></a> <span class="n">column</span>
+</span><span id="L-151"><a href="#L-151"><span class="linenos">151</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
+</span><span id="L-152"><a href="#L-152"><span class="linenos">152</span></a> <span class="k">else</span> <span class="nb">next</span><span class="p">(</span>
+</span><span id="L-153"><a href="#L-153"><span class="linenos">153</span></a> <span class="p">(</span>
+</span><span id="L-154"><a href="#L-154"><span class="linenos">154</span></a> <span class="n">i</span>
+</span><span id="L-155"><a href="#L-155"><span class="linenos">155</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">select</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span><span class="p">)</span>
+</span><span id="L-156"><a href="#L-156"><span class="linenos">156</span></a> <span class="k">if</span> <span class="n">select</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="n">column</span> <span class="ow">or</span> <span class="n">select</span><span class="o">.</span><span class="n">is_star</span>
+</span><span id="L-157"><a href="#L-157"><span class="linenos">157</span></a> <span class="p">),</span>
+</span><span id="L-158"><a href="#L-158"><span class="linenos">158</span></a> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="c1"># mypy will not allow a None here, but a negative index should never be returned</span>
+</span><span id="L-159"><a href="#L-159"><span class="linenos">159</span></a> <span class="p">)</span>
+</span><span id="L-160"><a href="#L-160"><span class="linenos">160</span></a> <span class="p">)</span>
+</span><span id="L-161"><a href="#L-161"><span class="linenos">161</span></a>
+</span><span id="L-162"><a href="#L-162"><span class="linenos">162</span></a> <span class="k">if</span> <span class="n">index</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
+</span><span id="L-163"><a href="#L-163"><span class="linenos">163</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Could not find </span><span class="si">{</span><span class="n">column</span><span class="si">}</span><span class="s2"> in </span><span class="si">{</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
+</span><span id="L-164"><a href="#L-164"><span class="linenos">164</span></a>
+</span><span id="L-165"><a href="#L-165"><span class="linenos">165</span></a> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">union_scopes</span><span class="p">:</span>
+</span><span id="L-166"><a href="#L-166"><span class="linenos">166</span></a> <span class="n">to_node</span><span class="p">(</span>
+</span><span id="L-167"><a href="#L-167"><span class="linenos">167</span></a> <span class="n">index</span><span class="p">,</span>
+</span><span id="L-168"><a href="#L-168"><span class="linenos">168</span></a> <span class="n">scope</span><span class="o">=</span><span class="n">s</span><span class="p">,</span>
+</span><span id="L-169"><a href="#L-169"><span class="linenos">169</span></a> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span>
+</span><span id="L-170"><a href="#L-170"><span class="linenos">170</span></a> <span class="n">upstream</span><span class="o">=</span><span class="n">upstream</span><span class="p">,</span>
+</span><span id="L-171"><a href="#L-171"><span class="linenos">171</span></a> <span class="n">source_name</span><span class="o">=</span><span class="n">source_name</span><span class="p">,</span>
+</span><span id="L-172"><a href="#L-172"><span class="linenos">172</span></a> <span class="n">reference_node_name</span><span class="o">=</span><span class="n">reference_node_name</span><span class="p">,</span>
+</span><span id="L-173"><a href="#L-173"><span class="linenos">173</span></a> <span class="p">)</span>
+</span><span id="L-174"><a href="#L-174"><span class="linenos">174</span></a>
+</span><span id="L-175"><a href="#L-175"><span class="linenos">175</span></a> <span class="k">return</span> <span class="n">upstream</span>
</span><span id="L-176"><a href="#L-176"><span class="linenos">176</span></a>
-</span><span id="L-177"><a href="#L-177"><span class="linenos">177</span></a> <span class="k">if</span> <span class="n">upstream</span><span class="p">:</span>
-</span><span id="L-178"><a href="#L-178"><span class="linenos">178</span></a> <span class="n">upstream</span><span class="o">.</span><span class="n">downstream</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
-</span><span id="L-179"><a href="#L-179"><span class="linenos">179</span></a>
-</span><span id="L-180"><a href="#L-180"><span class="linenos">180</span></a> <span class="n">subquery_scopes</span> <span class="o">=</span> <span class="p">{</span>
-</span><span id="L-181"><a href="#L-181"><span class="linenos">181</span></a> <span class="nb">id</span><span class="p">(</span><span class="n">subquery_scope</span><span class="o">.</span><span class="n">expression</span><span class="p">):</span> <span class="n">subquery_scope</span>
-</span><span id="L-182"><a href="#L-182"><span class="linenos">182</span></a> <span class="k">for</span> <span class="n">subquery_scope</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">subquery_scopes</span>
-</span><span id="L-183"><a href="#L-183"><span class="linenos">183</span></a> <span class="p">}</span>
-</span><span id="L-184"><a href="#L-184"><span class="linenos">184</span></a>
-</span><span id="L-185"><a href="#L-185"><span class="linenos">185</span></a> <span class="k">for</span> <span class="n">subquery</span> <span class="ow">in</span> <span class="n">find_all_in_scope</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Subqueryable</span><span class="p">):</span>
-</span><span id="L-186"><a href="#L-186"><span class="linenos">186</span></a> <span class="n">subquery_scope</span> <span class="o">=</span> <span class="n">subquery_scopes</span><span class="p">[</span><span class="nb">id</span><span class="p">(</span><span class="n">subquery</span><span class="p">)]</span>
-</span><span id="L-187"><a href="#L-187"><span class="linenos">187</span></a>
-</span><span id="L-188"><a href="#L-188"><span class="linenos">188</span></a> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">subquery</span><span class="o">.</span><span class="n">named_selects</span><span class="p">:</span>
-</span><span id="L-189"><a href="#L-189"><span class="linenos">189</span></a> <span class="n">to_node</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">scope</span><span class="o">=</span><span class="n">subquery_scope</span><span class="p">,</span> <span class="n">upstream</span><span class="o">=</span><span class="n">node</span><span class="p">)</span>
-</span><span id="L-190"><a href="#L-190"><span class="linenos">190</span></a>
-</span><span id="L-191"><a href="#L-191"><span class="linenos">191</span></a> <span class="c1"># if the select is a star add all scope sources as downstreams</span>
-</span><span id="L-192"><a href="#L-192"><span class="linenos">192</span></a> <span class="k">if</span> <span class="n">select</span><span class="o">.</span><span class="n">is_star</span><span class="p">:</span>
-</span><span id="L-193"><a href="#L-193"><span class="linenos">193</span></a> <span class="k">for</span> <span class="n">source</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
-</span><span id="L-194"><a href="#L-194"><span class="linenos">194</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Scope</span><span class="p">):</span>
-</span><span id="L-195"><a href="#L-195"><span class="linenos">195</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">expression</span>
-</span><span id="L-196"><a href="#L-196"><span class="linenos">196</span></a> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Node</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">select</span><span class="o">.</span><span class="n">sql</span><span class="p">(),</span> <span class="n">source</span><span class="o">=</span><span class="n">source</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">source</span><span class="p">))</span>
+</span><span id="L-177"><a href="#L-177"><span class="linenos">177</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">):</span>
+</span><span id="L-178"><a href="#L-178"><span class="linenos">178</span></a> <span class="c1"># For better ergonomics in our node labels, replace the full select with</span>
+</span><span id="L-179"><a href="#L-179"><span class="linenos">179</span></a> <span class="c1"># a version that has only the column we care about.</span>
+</span><span id="L-180"><a href="#L-180"><span class="linenos">180</span></a> <span class="c1"># &quot;x&quot;, SELECT x, y FROM foo</span>
+</span><span id="L-181"><a href="#L-181"><span class="linenos">181</span></a> <span class="c1"># =&gt; &quot;x&quot;, SELECT x FROM foo</span>
+</span><span id="L-182"><a href="#L-182"><span class="linenos">182</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">t</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">append</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
+</span><span id="L-183"><a href="#L-183"><span class="linenos">183</span></a> <span class="k">else</span><span class="p">:</span>
+</span><span id="L-184"><a href="#L-184"><span class="linenos">184</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span>
+</span><span id="L-185"><a href="#L-185"><span class="linenos">185</span></a>
+</span><span id="L-186"><a href="#L-186"><span class="linenos">186</span></a> <span class="c1"># Create the node for this step in the lineage chain, and attach it to the previous one.</span>
+</span><span id="L-187"><a href="#L-187"><span class="linenos">187</span></a> <span class="n">node</span> <span class="o">=</span> <span class="n">Node</span><span class="p">(</span>
+</span><span id="L-188"><a href="#L-188"><span class="linenos">188</span></a> <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">scope_name</span><span class="si">}</span><span class="s2">.</span><span class="si">{</span><span class="n">column</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">if</span> <span class="n">scope_name</span> <span class="k">else</span> <span class="nb">str</span><span class="p">(</span><span class="n">column</span><span class="p">),</span>
+</span><span id="L-189"><a href="#L-189"><span class="linenos">189</span></a> <span class="n">source</span><span class="o">=</span><span class="n">source</span><span class="p">,</span>
+</span><span id="L-190"><a href="#L-190"><span class="linenos">190</span></a> <span class="n">expression</span><span class="o">=</span><span class="n">select</span><span class="p">,</span>
+</span><span id="L-191"><a href="#L-191"><span class="linenos">191</span></a> <span class="n">source_name</span><span class="o">=</span><span class="n">source_name</span> <span class="ow">or</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
+</span><span id="L-192"><a href="#L-192"><span class="linenos">192</span></a> <span class="n">reference_node_name</span><span class="o">=</span><span class="n">reference_node_name</span> <span class="ow">or</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
+</span><span id="L-193"><a href="#L-193"><span class="linenos">193</span></a> <span class="p">)</span>
+</span><span id="L-194"><a href="#L-194"><span class="linenos">194</span></a>
+</span><span id="L-195"><a href="#L-195"><span class="linenos">195</span></a> <span class="k">if</span> <span class="n">upstream</span><span class="p">:</span>
+</span><span id="L-196"><a href="#L-196"><span class="linenos">196</span></a> <span class="n">upstream</span><span class="o">.</span><span class="n">downstream</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
</span><span id="L-197"><a href="#L-197"><span class="linenos">197</span></a>
-</span><span id="L-198"><a href="#L-198"><span class="linenos">198</span></a> <span class="c1"># Find all columns that went into creating this one to list their lineage nodes.</span>
-</span><span id="L-199"><a href="#L-199"><span class="linenos">199</span></a> <span class="n">source_columns</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">find_all_in_scope</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">))</span>
-</span><span id="L-200"><a href="#L-200"><span class="linenos">200</span></a>
-</span><span id="L-201"><a href="#L-201"><span class="linenos">201</span></a> <span class="c1"># If the source is a UDTF find columns used in the UTDF to generate the table</span>
-</span><span id="L-202"><a href="#L-202"><span class="linenos">202</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">UDTF</span><span class="p">):</span>
-</span><span id="L-203"><a href="#L-203"><span class="linenos">203</span></a> <span class="n">source_columns</span> <span class="o">|=</span> <span class="nb">set</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">find_all</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">))</span>
-</span><span id="L-204"><a href="#L-204"><span class="linenos">204</span></a>
-</span><span id="L-205"><a href="#L-205"><span class="linenos">205</span></a> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">source_columns</span><span class="p">:</span>
-</span><span id="L-206"><a href="#L-206"><span class="linenos">206</span></a> <span class="n">table</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">table</span>
-</span><span id="L-207"><a href="#L-207"><span class="linenos">207</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">scope</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">table</span><span class="p">)</span>
-</span><span id="L-208"><a href="#L-208"><span class="linenos">208</span></a>
-</span><span id="L-209"><a href="#L-209"><span class="linenos">209</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Scope</span><span class="p">):</span>
-</span><span id="L-210"><a href="#L-210"><span class="linenos">210</span></a> <span class="c1"># The table itself came from a more specific scope. Recurse into that one using the unaliased column name.</span>
-</span><span id="L-211"><a href="#L-211"><span class="linenos">211</span></a> <span class="n">to_node</span><span class="p">(</span>
-</span><span id="L-212"><a href="#L-212"><span class="linenos">212</span></a> <span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
-</span><span id="L-213"><a href="#L-213"><span class="linenos">213</span></a> <span class="n">scope</span><span class="o">=</span><span class="n">source</span><span class="p">,</span>
-</span><span id="L-214"><a href="#L-214"><span class="linenos">214</span></a> <span class="n">scope_name</span><span class="o">=</span><span class="n">table</span><span class="p">,</span>
-</span><span id="L-215"><a href="#L-215"><span class="linenos">215</span></a> <span class="n">upstream</span><span class="o">=</span><span class="n">node</span><span class="p">,</span>
-</span><span id="L-216"><a href="#L-216"><span class="linenos">216</span></a> <span class="n">alias</span><span class="o">=</span><span class="n">aliases</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">table</span><span class="p">)</span> <span class="ow">or</span> <span class="n">alias</span><span class="p">,</span>
-</span><span id="L-217"><a href="#L-217"><span class="linenos">217</span></a> <span class="p">)</span>
-</span><span id="L-218"><a href="#L-218"><span class="linenos">218</span></a> <span class="k">else</span><span class="p">:</span>
-</span><span id="L-219"><a href="#L-219"><span class="linenos">219</span></a> <span class="c1"># The source is not a scope - we&#39;ve reached the end of the line. At this point, if a source is not found</span>
-</span><span id="L-220"><a href="#L-220"><span class="linenos">220</span></a> <span class="c1"># it means this column&#39;s lineage is unknown. This can happen if the definition of a source used in a query</span>
-</span><span id="L-221"><a href="#L-221"><span class="linenos">221</span></a> <span class="c1"># is not passed into the `sources` map.</span>
-</span><span id="L-222"><a href="#L-222"><span class="linenos">222</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">source</span> <span class="ow">or</span> <span class="n">exp</span><span class="o">.</span><span class="n">Placeholder</span><span class="p">()</span>
-</span><span id="L-223"><a href="#L-223"><span class="linenos">223</span></a> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Node</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">c</span><span class="o">.</span><span class="n">sql</span><span class="p">(),</span> <span class="n">source</span><span class="o">=</span><span class="n">source</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">source</span><span class="p">))</span>
+</span><span id="L-198"><a href="#L-198"><span class="linenos">198</span></a> <span class="n">subquery_scopes</span> <span class="o">=</span> <span class="p">{</span>
+</span><span id="L-199"><a href="#L-199"><span class="linenos">199</span></a> <span class="nb">id</span><span class="p">(</span><span class="n">subquery_scope</span><span class="o">.</span><span class="n">expression</span><span class="p">):</span> <span class="n">subquery_scope</span> <span class="k">for</span> <span class="n">subquery_scope</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">subquery_scopes</span>
+</span><span id="L-200"><a href="#L-200"><span class="linenos">200</span></a> <span class="p">}</span>
+</span><span id="L-201"><a href="#L-201"><span class="linenos">201</span></a>
+</span><span id="L-202"><a href="#L-202"><span class="linenos">202</span></a> <span class="k">for</span> <span class="n">subquery</span> <span class="ow">in</span> <span class="n">find_all_in_scope</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">UNWRAPPED_QUERIES</span><span class="p">):</span>
+</span><span id="L-203"><a href="#L-203"><span class="linenos">203</span></a> <span class="n">subquery_scope</span> <span class="o">=</span> <span class="n">subquery_scopes</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="nb">id</span><span class="p">(</span><span class="n">subquery</span><span class="p">))</span>
+</span><span id="L-204"><a href="#L-204"><span class="linenos">204</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">subquery_scope</span><span class="p">:</span>
+</span><span id="L-205"><a href="#L-205"><span class="linenos">205</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Unknown subquery scope: </span><span class="si">{</span><span class="n">subquery</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
+</span><span id="L-206"><a href="#L-206"><span class="linenos">206</span></a> <span class="k">continue</span>
+</span><span id="L-207"><a href="#L-207"><span class="linenos">207</span></a>
+</span><span id="L-208"><a href="#L-208"><span class="linenos">208</span></a> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">subquery</span><span class="o">.</span><span class="n">named_selects</span><span class="p">:</span>
+</span><span id="L-209"><a href="#L-209"><span class="linenos">209</span></a> <span class="n">to_node</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">scope</span><span class="o">=</span><span class="n">subquery_scope</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span> <span class="n">upstream</span><span class="o">=</span><span class="n">node</span><span class="p">)</span>
+</span><span id="L-210"><a href="#L-210"><span class="linenos">210</span></a>
+</span><span id="L-211"><a href="#L-211"><span class="linenos">211</span></a> <span class="c1"># if the select is a star add all scope sources as downstreams</span>
+</span><span id="L-212"><a href="#L-212"><span class="linenos">212</span></a> <span class="k">if</span> <span class="n">select</span><span class="o">.</span><span class="n">is_star</span><span class="p">:</span>
+</span><span id="L-213"><a href="#L-213"><span class="linenos">213</span></a> <span class="k">for</span> <span class="n">source</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
+</span><span id="L-214"><a href="#L-214"><span class="linenos">214</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Scope</span><span class="p">):</span>
+</span><span id="L-215"><a href="#L-215"><span class="linenos">215</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">expression</span>
+</span><span id="L-216"><a href="#L-216"><span class="linenos">216</span></a> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Node</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">select</span><span class="o">.</span><span class="n">sql</span><span class="p">(),</span> <span class="n">source</span><span class="o">=</span><span class="n">source</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">source</span><span class="p">))</span>
+</span><span id="L-217"><a href="#L-217"><span class="linenos">217</span></a>
+</span><span id="L-218"><a href="#L-218"><span class="linenos">218</span></a> <span class="c1"># Find all columns that went into creating this one to list their lineage nodes.</span>
+</span><span id="L-219"><a href="#L-219"><span class="linenos">219</span></a> <span class="n">source_columns</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">find_all_in_scope</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">))</span>
+</span><span id="L-220"><a href="#L-220"><span class="linenos">220</span></a>
+</span><span id="L-221"><a href="#L-221"><span class="linenos">221</span></a> <span class="c1"># If the source is a UDTF find columns used in the UTDF to generate the table</span>
+</span><span id="L-222"><a href="#L-222"><span class="linenos">222</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">UDTF</span><span class="p">):</span>
+</span><span id="L-223"><a href="#L-223"><span class="linenos">223</span></a> <span class="n">source_columns</span> <span class="o">|=</span> <span class="nb">set</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">find_all</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">))</span>
</span><span id="L-224"><a href="#L-224"><span class="linenos">224</span></a>
-</span><span id="L-225"><a href="#L-225"><span class="linenos">225</span></a> <span class="k">return</span> <span class="n">node</span>
-</span><span id="L-226"><a href="#L-226"><span class="linenos">226</span></a>
-</span><span id="L-227"><a href="#L-227"><span class="linenos">227</span></a> <span class="k">return</span> <span class="n">to_node</span><span class="p">(</span><span class="n">column</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="k">else</span> <span class="n">column</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">scope</span><span class="p">)</span>
+</span><span id="L-225"><a href="#L-225"><span class="linenos">225</span></a> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">source_columns</span><span class="p">:</span>
+</span><span id="L-226"><a href="#L-226"><span class="linenos">226</span></a> <span class="n">table</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">table</span>
+</span><span id="L-227"><a href="#L-227"><span class="linenos">227</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">scope</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">table</span><span class="p">)</span>
</span><span id="L-228"><a href="#L-228"><span class="linenos">228</span></a>
-</span><span id="L-229"><a href="#L-229"><span class="linenos">229</span></a>
-</span><span id="L-230"><a href="#L-230"><span class="linenos">230</span></a><span class="k">class</span> <span class="nc">GraphHTML</span><span class="p">:</span>
-</span><span id="L-231"><a href="#L-231"><span class="linenos">231</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Node to HTML generator using vis.js.</span>
-</span><span id="L-232"><a href="#L-232"><span class="linenos">232</span></a>
-</span><span id="L-233"><a href="#L-233"><span class="linenos">233</span></a><span class="sd"> https://visjs.github.io/vis-network/docs/network/</span>
-</span><span id="L-234"><a href="#L-234"><span class="linenos">234</span></a><span class="sd"> &quot;&quot;&quot;</span>
-</span><span id="L-235"><a href="#L-235"><span class="linenos">235</span></a>
-</span><span id="L-236"><a href="#L-236"><span class="linenos">236</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
-</span><span id="L-237"><a href="#L-237"><span class="linenos">237</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">nodes</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">,</span> <span class="n">edges</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">,</span> <span class="n">imports</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="n">options</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
-</span><span id="L-238"><a href="#L-238"><span class="linenos">238</span></a> <span class="p">):</span>
-</span><span id="L-239"><a href="#L-239"><span class="linenos">239</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">imports</span> <span class="o">=</span> <span class="n">imports</span>
-</span><span id="L-240"><a href="#L-240"><span class="linenos">240</span></a>
-</span><span id="L-241"><a href="#L-241"><span class="linenos">241</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="p">{</span>
-</span><span id="L-242"><a href="#L-242"><span class="linenos">242</span></a> <span class="s2">&quot;height&quot;</span><span class="p">:</span> <span class="s2">&quot;500px&quot;</span><span class="p">,</span>
-</span><span id="L-243"><a href="#L-243"><span class="linenos">243</span></a> <span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="s2">&quot;100%&quot;</span><span class="p">,</span>
-</span><span id="L-244"><a href="#L-244"><span class="linenos">244</span></a> <span class="s2">&quot;layout&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="L-245"><a href="#L-245"><span class="linenos">245</span></a> <span class="s2">&quot;hierarchical&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="L-246"><a href="#L-246"><span class="linenos">246</span></a> <span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
-</span><span id="L-247"><a href="#L-247"><span class="linenos">247</span></a> <span class="s2">&quot;nodeSpacing&quot;</span><span class="p">:</span> <span class="mi">200</span><span class="p">,</span>
-</span><span id="L-248"><a href="#L-248"><span class="linenos">248</span></a> <span class="s2">&quot;sortMethod&quot;</span><span class="p">:</span> <span class="s2">&quot;directed&quot;</span><span class="p">,</span>
-</span><span id="L-249"><a href="#L-249"><span class="linenos">249</span></a> <span class="p">},</span>
-</span><span id="L-250"><a href="#L-250"><span class="linenos">250</span></a> <span class="p">},</span>
-</span><span id="L-251"><a href="#L-251"><span class="linenos">251</span></a> <span class="s2">&quot;interaction&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="L-252"><a href="#L-252"><span class="linenos">252</span></a> <span class="s2">&quot;dragNodes&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
-</span><span id="L-253"><a href="#L-253"><span class="linenos">253</span></a> <span class="s2">&quot;selectable&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
-</span><span id="L-254"><a href="#L-254"><span class="linenos">254</span></a> <span class="p">},</span>
-</span><span id="L-255"><a href="#L-255"><span class="linenos">255</span></a> <span class="s2">&quot;physics&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="L-256"><a href="#L-256"><span class="linenos">256</span></a> <span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
-</span><span id="L-257"><a href="#L-257"><span class="linenos">257</span></a> <span class="p">},</span>
-</span><span id="L-258"><a href="#L-258"><span class="linenos">258</span></a> <span class="s2">&quot;edges&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="L-259"><a href="#L-259"><span class="linenos">259</span></a> <span class="s2">&quot;arrows&quot;</span><span class="p">:</span> <span class="s2">&quot;to&quot;</span><span class="p">,</span>
-</span><span id="L-260"><a href="#L-260"><span class="linenos">260</span></a> <span class="p">},</span>
-</span><span id="L-261"><a href="#L-261"><span class="linenos">261</span></a> <span class="s2">&quot;nodes&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="L-262"><a href="#L-262"><span class="linenos">262</span></a> <span class="s2">&quot;font&quot;</span><span class="p">:</span> <span class="s2">&quot;20px monaco&quot;</span><span class="p">,</span>
-</span><span id="L-263"><a href="#L-263"><span class="linenos">263</span></a> <span class="s2">&quot;shape&quot;</span><span class="p">:</span> <span class="s2">&quot;box&quot;</span><span class="p">,</span>
-</span><span id="L-264"><a href="#L-264"><span class="linenos">264</span></a> <span class="s2">&quot;widthConstraint&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="L-265"><a href="#L-265"><span class="linenos">265</span></a> <span class="s2">&quot;maximum&quot;</span><span class="p">:</span> <span class="mi">300</span><span class="p">,</span>
-</span><span id="L-266"><a href="#L-266"><span class="linenos">266</span></a> <span class="p">},</span>
-</span><span id="L-267"><a href="#L-267"><span class="linenos">267</span></a> <span class="p">},</span>
-</span><span id="L-268"><a href="#L-268"><span class="linenos">268</span></a> <span class="o">**</span><span class="p">(</span><span class="n">options</span> <span class="ow">or</span> <span class="p">{}),</span>
-</span><span id="L-269"><a href="#L-269"><span class="linenos">269</span></a> <span class="p">}</span>
-</span><span id="L-270"><a href="#L-270"><span class="linenos">270</span></a>
-</span><span id="L-271"><a href="#L-271"><span class="linenos">271</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">nodes</span> <span class="o">=</span> <span class="n">nodes</span>
-</span><span id="L-272"><a href="#L-272"><span class="linenos">272</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">edges</span> <span class="o">=</span> <span class="n">edges</span>
-</span><span id="L-273"><a href="#L-273"><span class="linenos">273</span></a>
-</span><span id="L-274"><a href="#L-274"><span class="linenos">274</span></a> <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-</span><span id="L-275"><a href="#L-275"><span class="linenos">275</span></a> <span class="n">nodes</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodes</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>
-</span><span id="L-276"><a href="#L-276"><span class="linenos">276</span></a> <span class="n">edges</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">edges</span><span class="p">)</span>
-</span><span id="L-277"><a href="#L-277"><span class="linenos">277</span></a> <span class="n">options</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="p">)</span>
-</span><span id="L-278"><a href="#L-278"><span class="linenos">278</span></a> <span class="n">imports</span> <span class="o">=</span> <span class="p">(</span>
-</span><span id="L-279"><a href="#L-279"><span class="linenos">279</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;&lt;script type=&quot;text/javascript&quot; src=&quot;https://unpkg.com/vis-data@latest/peer/umd/vis-data.min.js&quot;&gt;&lt;/script&gt;</span>
-</span><span id="L-280"><a href="#L-280"><span class="linenos">280</span></a><span class="sd"> &lt;script type=&quot;text/javascript&quot; src=&quot;https://unpkg.com/vis-network@latest/peer/umd/vis-network.min.js&quot;&gt;&lt;/script&gt;</span>
-</span><span id="L-281"><a href="#L-281"><span class="linenos">281</span></a><span class="sd"> &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://unpkg.com/vis-network/styles/vis-network.min.css&quot; /&gt;&quot;&quot;&quot;</span>
-</span><span id="L-282"><a href="#L-282"><span class="linenos">282</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">imports</span>
-</span><span id="L-283"><a href="#L-283"><span class="linenos">283</span></a> <span class="k">else</span> <span class="s2">&quot;&quot;</span>
-</span><span id="L-284"><a href="#L-284"><span class="linenos">284</span></a> <span class="p">)</span>
-</span><span id="L-285"><a href="#L-285"><span class="linenos">285</span></a>
-</span><span id="L-286"><a href="#L-286"><span class="linenos">286</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">&quot;&quot;&quot;&lt;div&gt;</span>
-</span><span id="L-287"><a href="#L-287"><span class="linenos">287</span></a><span class="s2"> &lt;div id=&quot;sqlglot-lineage&quot;&gt;&lt;/div&gt;</span>
-</span><span id="L-288"><a href="#L-288"><span class="linenos">288</span></a><span class="s2"> </span><span class="si">{</span><span class="n">imports</span><span class="si">}</span>
-</span><span id="L-289"><a href="#L-289"><span class="linenos">289</span></a><span class="s2"> &lt;script type=&quot;text/javascript&quot;&gt;</span>
-</span><span id="L-290"><a href="#L-290"><span class="linenos">290</span></a><span class="s2"> var nodes = new vis.DataSet(</span><span class="si">{</span><span class="n">nodes</span><span class="si">}</span><span class="s2">)</span>
-</span><span id="L-291"><a href="#L-291"><span class="linenos">291</span></a><span class="s2"> nodes.forEach(row =&gt; row[&quot;title&quot;] = new DOMParser().parseFromString(row[&quot;title&quot;], &quot;text/html&quot;).body.childNodes[0])</span>
-</span><span id="L-292"><a href="#L-292"><span class="linenos">292</span></a>
-</span><span id="L-293"><a href="#L-293"><span class="linenos">293</span></a><span class="s2"> new vis.Network(</span>
-</span><span id="L-294"><a href="#L-294"><span class="linenos">294</span></a><span class="s2"> document.getElementById(&quot;sqlglot-lineage&quot;),</span>
-</span><span id="L-295"><a href="#L-295"><span class="linenos">295</span></a><span class="s2"> </span><span class="se">{{</span>
-</span><span id="L-296"><a href="#L-296"><span class="linenos">296</span></a><span class="s2"> nodes: nodes,</span>
-</span><span id="L-297"><a href="#L-297"><span class="linenos">297</span></a><span class="s2"> edges: new vis.DataSet(</span><span class="si">{</span><span class="n">edges</span><span class="si">}</span><span class="s2">)</span>
-</span><span id="L-298"><a href="#L-298"><span class="linenos">298</span></a><span class="s2"> </span><span class="se">}}</span><span class="s2">,</span>
-</span><span id="L-299"><a href="#L-299"><span class="linenos">299</span></a><span class="s2"> </span><span class="si">{</span><span class="n">options</span><span class="si">}</span><span class="s2">,</span>
-</span><span id="L-300"><a href="#L-300"><span class="linenos">300</span></a><span class="s2"> )</span>
-</span><span id="L-301"><a href="#L-301"><span class="linenos">301</span></a><span class="s2"> &lt;/script&gt;</span>
-</span><span id="L-302"><a href="#L-302"><span class="linenos">302</span></a><span class="s2">&lt;/div&gt;&quot;&quot;&quot;</span>
-</span><span id="L-303"><a href="#L-303"><span class="linenos">303</span></a>
-</span><span id="L-304"><a href="#L-304"><span class="linenos">304</span></a> <span class="k">def</span> <span class="nf">_repr_html_</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
-</span><span id="L-305"><a href="#L-305"><span class="linenos">305</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__str__</span><span class="p">()</span>
+</span><span id="L-229"><a href="#L-229"><span class="linenos">229</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Scope</span><span class="p">):</span>
+</span><span id="L-230"><a href="#L-230"><span class="linenos">230</span></a> <span class="n">selected_node</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">scope</span><span class="o">.</span><span class="n">selected_sources</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">table</span><span class="p">,</span> <span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">))</span>
+</span><span id="L-231"><a href="#L-231"><span class="linenos">231</span></a> <span class="c1"># The table itself came from a more specific scope. Recurse into that one using the unaliased column name.</span>
+</span><span id="L-232"><a href="#L-232"><span class="linenos">232</span></a> <span class="n">to_node</span><span class="p">(</span>
+</span><span id="L-233"><a href="#L-233"><span class="linenos">233</span></a> <span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
+</span><span id="L-234"><a href="#L-234"><span class="linenos">234</span></a> <span class="n">scope</span><span class="o">=</span><span class="n">source</span><span class="p">,</span>
+</span><span id="L-235"><a href="#L-235"><span class="linenos">235</span></a> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span>
+</span><span id="L-236"><a href="#L-236"><span class="linenos">236</span></a> <span class="n">scope_name</span><span class="o">=</span><span class="n">table</span><span class="p">,</span>
+</span><span id="L-237"><a href="#L-237"><span class="linenos">237</span></a> <span class="n">upstream</span><span class="o">=</span><span class="n">node</span><span class="p">,</span>
+</span><span id="L-238"><a href="#L-238"><span class="linenos">238</span></a> <span class="n">source_name</span><span class="o">=</span><span class="n">source_names</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">table</span><span class="p">)</span> <span class="ow">or</span> <span class="n">source_name</span><span class="p">,</span>
+</span><span id="L-239"><a href="#L-239"><span class="linenos">239</span></a> <span class="n">reference_node_name</span><span class="o">=</span><span class="n">selected_node</span><span class="o">.</span><span class="n">name</span> <span class="k">if</span> <span class="n">selected_node</span> <span class="k">else</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="L-240"><a href="#L-240"><span class="linenos">240</span></a> <span class="p">)</span>
+</span><span id="L-241"><a href="#L-241"><span class="linenos">241</span></a> <span class="k">else</span><span class="p">:</span>
+</span><span id="L-242"><a href="#L-242"><span class="linenos">242</span></a> <span class="c1"># The source is not a scope - we&#39;ve reached the end of the line. At this point, if a source is not found</span>
+</span><span id="L-243"><a href="#L-243"><span class="linenos">243</span></a> <span class="c1"># it means this column&#39;s lineage is unknown. This can happen if the definition of a source used in a query</span>
+</span><span id="L-244"><a href="#L-244"><span class="linenos">244</span></a> <span class="c1"># is not passed into the `sources` map.</span>
+</span><span id="L-245"><a href="#L-245"><span class="linenos">245</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">source</span> <span class="ow">or</span> <span class="n">exp</span><span class="o">.</span><span class="n">Placeholder</span><span class="p">()</span>
+</span><span id="L-246"><a href="#L-246"><span class="linenos">246</span></a> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Node</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">c</span><span class="o">.</span><span class="n">sql</span><span class="p">(),</span> <span class="n">source</span><span class="o">=</span><span class="n">source</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">source</span><span class="p">))</span>
+</span><span id="L-247"><a href="#L-247"><span class="linenos">247</span></a>
+</span><span id="L-248"><a href="#L-248"><span class="linenos">248</span></a> <span class="k">return</span> <span class="n">node</span>
+</span><span id="L-249"><a href="#L-249"><span class="linenos">249</span></a>
+</span><span id="L-250"><a href="#L-250"><span class="linenos">250</span></a>
+</span><span id="L-251"><a href="#L-251"><span class="linenos">251</span></a><span class="k">class</span> <span class="nc">GraphHTML</span><span class="p">:</span>
+</span><span id="L-252"><a href="#L-252"><span class="linenos">252</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Node to HTML generator using vis.js.</span>
+</span><span id="L-253"><a href="#L-253"><span class="linenos">253</span></a>
+</span><span id="L-254"><a href="#L-254"><span class="linenos">254</span></a><span class="sd"> https://visjs.github.io/vis-network/docs/network/</span>
+</span><span id="L-255"><a href="#L-255"><span class="linenos">255</span></a><span class="sd"> &quot;&quot;&quot;</span>
+</span><span id="L-256"><a href="#L-256"><span class="linenos">256</span></a>
+</span><span id="L-257"><a href="#L-257"><span class="linenos">257</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
+</span><span id="L-258"><a href="#L-258"><span class="linenos">258</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">nodes</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">,</span> <span class="n">edges</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">,</span> <span class="n">imports</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="n">options</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
+</span><span id="L-259"><a href="#L-259"><span class="linenos">259</span></a> <span class="p">):</span>
+</span><span id="L-260"><a href="#L-260"><span class="linenos">260</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">imports</span> <span class="o">=</span> <span class="n">imports</span>
+</span><span id="L-261"><a href="#L-261"><span class="linenos">261</span></a>
+</span><span id="L-262"><a href="#L-262"><span class="linenos">262</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="p">{</span>
+</span><span id="L-263"><a href="#L-263"><span class="linenos">263</span></a> <span class="s2">&quot;height&quot;</span><span class="p">:</span> <span class="s2">&quot;500px&quot;</span><span class="p">,</span>
+</span><span id="L-264"><a href="#L-264"><span class="linenos">264</span></a> <span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="s2">&quot;100%&quot;</span><span class="p">,</span>
+</span><span id="L-265"><a href="#L-265"><span class="linenos">265</span></a> <span class="s2">&quot;layout&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="L-266"><a href="#L-266"><span class="linenos">266</span></a> <span class="s2">&quot;hierarchical&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="L-267"><a href="#L-267"><span class="linenos">267</span></a> <span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
+</span><span id="L-268"><a href="#L-268"><span class="linenos">268</span></a> <span class="s2">&quot;nodeSpacing&quot;</span><span class="p">:</span> <span class="mi">200</span><span class="p">,</span>
+</span><span id="L-269"><a href="#L-269"><span class="linenos">269</span></a> <span class="s2">&quot;sortMethod&quot;</span><span class="p">:</span> <span class="s2">&quot;directed&quot;</span><span class="p">,</span>
+</span><span id="L-270"><a href="#L-270"><span class="linenos">270</span></a> <span class="p">},</span>
+</span><span id="L-271"><a href="#L-271"><span class="linenos">271</span></a> <span class="p">},</span>
+</span><span id="L-272"><a href="#L-272"><span class="linenos">272</span></a> <span class="s2">&quot;interaction&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="L-273"><a href="#L-273"><span class="linenos">273</span></a> <span class="s2">&quot;dragNodes&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
+</span><span id="L-274"><a href="#L-274"><span class="linenos">274</span></a> <span class="s2">&quot;selectable&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
+</span><span id="L-275"><a href="#L-275"><span class="linenos">275</span></a> <span class="p">},</span>
+</span><span id="L-276"><a href="#L-276"><span class="linenos">276</span></a> <span class="s2">&quot;physics&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="L-277"><a href="#L-277"><span class="linenos">277</span></a> <span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
+</span><span id="L-278"><a href="#L-278"><span class="linenos">278</span></a> <span class="p">},</span>
+</span><span id="L-279"><a href="#L-279"><span class="linenos">279</span></a> <span class="s2">&quot;edges&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="L-280"><a href="#L-280"><span class="linenos">280</span></a> <span class="s2">&quot;arrows&quot;</span><span class="p">:</span> <span class="s2">&quot;to&quot;</span><span class="p">,</span>
+</span><span id="L-281"><a href="#L-281"><span class="linenos">281</span></a> <span class="p">},</span>
+</span><span id="L-282"><a href="#L-282"><span class="linenos">282</span></a> <span class="s2">&quot;nodes&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="L-283"><a href="#L-283"><span class="linenos">283</span></a> <span class="s2">&quot;font&quot;</span><span class="p">:</span> <span class="s2">&quot;20px monaco&quot;</span><span class="p">,</span>
+</span><span id="L-284"><a href="#L-284"><span class="linenos">284</span></a> <span class="s2">&quot;shape&quot;</span><span class="p">:</span> <span class="s2">&quot;box&quot;</span><span class="p">,</span>
+</span><span id="L-285"><a href="#L-285"><span class="linenos">285</span></a> <span class="s2">&quot;widthConstraint&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="L-286"><a href="#L-286"><span class="linenos">286</span></a> <span class="s2">&quot;maximum&quot;</span><span class="p">:</span> <span class="mi">300</span><span class="p">,</span>
+</span><span id="L-287"><a href="#L-287"><span class="linenos">287</span></a> <span class="p">},</span>
+</span><span id="L-288"><a href="#L-288"><span class="linenos">288</span></a> <span class="p">},</span>
+</span><span id="L-289"><a href="#L-289"><span class="linenos">289</span></a> <span class="o">**</span><span class="p">(</span><span class="n">options</span> <span class="ow">or</span> <span class="p">{}),</span>
+</span><span id="L-290"><a href="#L-290"><span class="linenos">290</span></a> <span class="p">}</span>
+</span><span id="L-291"><a href="#L-291"><span class="linenos">291</span></a>
+</span><span id="L-292"><a href="#L-292"><span class="linenos">292</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">nodes</span> <span class="o">=</span> <span class="n">nodes</span>
+</span><span id="L-293"><a href="#L-293"><span class="linenos">293</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">edges</span> <span class="o">=</span> <span class="n">edges</span>
+</span><span id="L-294"><a href="#L-294"><span class="linenos">294</span></a>
+</span><span id="L-295"><a href="#L-295"><span class="linenos">295</span></a> <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+</span><span id="L-296"><a href="#L-296"><span class="linenos">296</span></a> <span class="n">nodes</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodes</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>
+</span><span id="L-297"><a href="#L-297"><span class="linenos">297</span></a> <span class="n">edges</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">edges</span><span class="p">)</span>
+</span><span id="L-298"><a href="#L-298"><span class="linenos">298</span></a> <span class="n">options</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="p">)</span>
+</span><span id="L-299"><a href="#L-299"><span class="linenos">299</span></a> <span class="n">imports</span> <span class="o">=</span> <span class="p">(</span>
+</span><span id="L-300"><a href="#L-300"><span class="linenos">300</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;&lt;script type=&quot;text/javascript&quot; src=&quot;https://unpkg.com/vis-data@latest/peer/umd/vis-data.min.js&quot;&gt;&lt;/script&gt;</span>
+</span><span id="L-301"><a href="#L-301"><span class="linenos">301</span></a><span class="sd"> &lt;script type=&quot;text/javascript&quot; src=&quot;https://unpkg.com/vis-network@latest/peer/umd/vis-network.min.js&quot;&gt;&lt;/script&gt;</span>
+</span><span id="L-302"><a href="#L-302"><span class="linenos">302</span></a><span class="sd"> &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://unpkg.com/vis-network/styles/vis-network.min.css&quot; /&gt;&quot;&quot;&quot;</span>
+</span><span id="L-303"><a href="#L-303"><span class="linenos">303</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">imports</span>
+</span><span id="L-304"><a href="#L-304"><span class="linenos">304</span></a> <span class="k">else</span> <span class="s2">&quot;&quot;</span>
+</span><span id="L-305"><a href="#L-305"><span class="linenos">305</span></a> <span class="p">)</span>
+</span><span id="L-306"><a href="#L-306"><span class="linenos">306</span></a>
+</span><span id="L-307"><a href="#L-307"><span class="linenos">307</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">&quot;&quot;&quot;&lt;div&gt;</span>
+</span><span id="L-308"><a href="#L-308"><span class="linenos">308</span></a><span class="s2"> &lt;div id=&quot;sqlglot-lineage&quot;&gt;&lt;/div&gt;</span>
+</span><span id="L-309"><a href="#L-309"><span class="linenos">309</span></a><span class="s2"> </span><span class="si">{</span><span class="n">imports</span><span class="si">}</span>
+</span><span id="L-310"><a href="#L-310"><span class="linenos">310</span></a><span class="s2"> &lt;script type=&quot;text/javascript&quot;&gt;</span>
+</span><span id="L-311"><a href="#L-311"><span class="linenos">311</span></a><span class="s2"> var nodes = new vis.DataSet(</span><span class="si">{</span><span class="n">nodes</span><span class="si">}</span><span class="s2">)</span>
+</span><span id="L-312"><a href="#L-312"><span class="linenos">312</span></a><span class="s2"> nodes.forEach(row =&gt; row[&quot;title&quot;] = new DOMParser().parseFromString(row[&quot;title&quot;], &quot;text/html&quot;).body.childNodes[0])</span>
+</span><span id="L-313"><a href="#L-313"><span class="linenos">313</span></a>
+</span><span id="L-314"><a href="#L-314"><span class="linenos">314</span></a><span class="s2"> new vis.Network(</span>
+</span><span id="L-315"><a href="#L-315"><span class="linenos">315</span></a><span class="s2"> document.getElementById(&quot;sqlglot-lineage&quot;),</span>
+</span><span id="L-316"><a href="#L-316"><span class="linenos">316</span></a><span class="s2"> </span><span class="se">{{</span>
+</span><span id="L-317"><a href="#L-317"><span class="linenos">317</span></a><span class="s2"> nodes: nodes,</span>
+</span><span id="L-318"><a href="#L-318"><span class="linenos">318</span></a><span class="s2"> edges: new vis.DataSet(</span><span class="si">{</span><span class="n">edges</span><span class="si">}</span><span class="s2">)</span>
+</span><span id="L-319"><a href="#L-319"><span class="linenos">319</span></a><span class="s2"> </span><span class="se">}}</span><span class="s2">,</span>
+</span><span id="L-320"><a href="#L-320"><span class="linenos">320</span></a><span class="s2"> </span><span class="si">{</span><span class="n">options</span><span class="si">}</span><span class="s2">,</span>
+</span><span id="L-321"><a href="#L-321"><span class="linenos">321</span></a><span class="s2"> )</span>
+</span><span id="L-322"><a href="#L-322"><span class="linenos">322</span></a><span class="s2"> &lt;/script&gt;</span>
+</span><span id="L-323"><a href="#L-323"><span class="linenos">323</span></a><span class="s2">&lt;/div&gt;&quot;&quot;&quot;</span>
+</span><span id="L-324"><a href="#L-324"><span class="linenos">324</span></a>
+</span><span id="L-325"><a href="#L-325"><span class="linenos">325</span></a> <span class="k">def</span> <span class="nf">_repr_html_</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
+</span><span id="L-326"><a href="#L-326"><span class="linenos">326</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__str__</span><span class="p">()</span>
</span></pre></div>
</section>
+ <section id="logger">
+ <div class="attr variable">
+ <span class="name">logger</span> =
+<span class="default_value">&lt;Logger sqlglot (WARNING)&gt;</span>
+
+
+ </div>
+ <a class="headerlink" href="#logger"></a>
+
+
+
+ </section>
<section id="Node">
<input id="Node-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
<div class="attr class">
@@ -428,55 +470,56 @@
</div>
<a class="headerlink" href="#Node"></a>
- <div class="pdoc-code codehilite"><pre><span></span><span id="Node-16"><a href="#Node-16"><span class="linenos">16</span></a><span class="nd">@dataclass</span><span class="p">(</span><span class="n">frozen</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
-</span><span id="Node-17"><a href="#Node-17"><span class="linenos">17</span></a><span class="k">class</span> <span class="nc">Node</span><span class="p">:</span>
-</span><span id="Node-18"><a href="#Node-18"><span class="linenos">18</span></a> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>
-</span><span id="Node-19"><a href="#Node-19"><span class="linenos">19</span></a> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span>
-</span><span id="Node-20"><a href="#Node-20"><span class="linenos">20</span></a> <span class="n">source</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span>
-</span><span id="Node-21"><a href="#Node-21"><span class="linenos">21</span></a> <span class="n">downstream</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Node</span><span class="p">]</span> <span class="o">=</span> <span class="n">field</span><span class="p">(</span><span class="n">default_factory</span><span class="o">=</span><span class="nb">list</span><span class="p">)</span>
-</span><span id="Node-22"><a href="#Node-22"><span class="linenos">22</span></a> <span class="n">alias</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
-</span><span id="Node-23"><a href="#Node-23"><span class="linenos">23</span></a>
-</span><span id="Node-24"><a href="#Node-24"><span class="linenos">24</span></a> <span class="k">def</span> <span class="nf">walk</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">t</span><span class="o">.</span><span class="n">Iterator</span><span class="p">[</span><span class="n">Node</span><span class="p">]:</span>
-</span><span id="Node-25"><a href="#Node-25"><span class="linenos">25</span></a> <span class="k">yield</span> <span class="bp">self</span>
-</span><span id="Node-26"><a href="#Node-26"><span class="linenos">26</span></a>
-</span><span id="Node-27"><a href="#Node-27"><span class="linenos">27</span></a> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">downstream</span><span class="p">:</span>
-</span><span id="Node-28"><a href="#Node-28"><span class="linenos">28</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">Node</span><span class="p">):</span>
-</span><span id="Node-29"><a href="#Node-29"><span class="linenos">29</span></a> <span class="k">yield from</span> <span class="n">d</span><span class="o">.</span><span class="n">walk</span><span class="p">()</span>
-</span><span id="Node-30"><a href="#Node-30"><span class="linenos">30</span></a> <span class="k">else</span><span class="p">:</span>
-</span><span id="Node-31"><a href="#Node-31"><span class="linenos">31</span></a> <span class="k">yield</span> <span class="n">d</span>
-</span><span id="Node-32"><a href="#Node-32"><span class="linenos">32</span></a>
-</span><span id="Node-33"><a href="#Node-33"><span class="linenos">33</span></a> <span class="k">def</span> <span class="nf">to_html</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">GraphHTML</span><span class="p">:</span>
-</span><span id="Node-34"><a href="#Node-34"><span class="linenos">34</span></a> <span class="n">nodes</span> <span class="o">=</span> <span class="p">{}</span>
-</span><span id="Node-35"><a href="#Node-35"><span class="linenos">35</span></a> <span class="n">edges</span> <span class="o">=</span> <span class="p">[]</span>
+ <div class="pdoc-code codehilite"><pre><span></span><span id="Node-19"><a href="#Node-19"><span class="linenos">19</span></a><span class="nd">@dataclass</span><span class="p">(</span><span class="n">frozen</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
+</span><span id="Node-20"><a href="#Node-20"><span class="linenos">20</span></a><span class="k">class</span> <span class="nc">Node</span><span class="p">:</span>
+</span><span id="Node-21"><a href="#Node-21"><span class="linenos">21</span></a> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>
+</span><span id="Node-22"><a href="#Node-22"><span class="linenos">22</span></a> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span>
+</span><span id="Node-23"><a href="#Node-23"><span class="linenos">23</span></a> <span class="n">source</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span>
+</span><span id="Node-24"><a href="#Node-24"><span class="linenos">24</span></a> <span class="n">downstream</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Node</span><span class="p">]</span> <span class="o">=</span> <span class="n">field</span><span class="p">(</span><span class="n">default_factory</span><span class="o">=</span><span class="nb">list</span><span class="p">)</span>
+</span><span id="Node-25"><a href="#Node-25"><span class="linenos">25</span></a> <span class="n">source_name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
+</span><span id="Node-26"><a href="#Node-26"><span class="linenos">26</span></a> <span class="n">reference_node_name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
+</span><span id="Node-27"><a href="#Node-27"><span class="linenos">27</span></a>
+</span><span id="Node-28"><a href="#Node-28"><span class="linenos">28</span></a> <span class="k">def</span> <span class="nf">walk</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">t</span><span class="o">.</span><span class="n">Iterator</span><span class="p">[</span><span class="n">Node</span><span class="p">]:</span>
+</span><span id="Node-29"><a href="#Node-29"><span class="linenos">29</span></a> <span class="k">yield</span> <span class="bp">self</span>
+</span><span id="Node-30"><a href="#Node-30"><span class="linenos">30</span></a>
+</span><span id="Node-31"><a href="#Node-31"><span class="linenos">31</span></a> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">downstream</span><span class="p">:</span>
+</span><span id="Node-32"><a href="#Node-32"><span class="linenos">32</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">Node</span><span class="p">):</span>
+</span><span id="Node-33"><a href="#Node-33"><span class="linenos">33</span></a> <span class="k">yield from</span> <span class="n">d</span><span class="o">.</span><span class="n">walk</span><span class="p">()</span>
+</span><span id="Node-34"><a href="#Node-34"><span class="linenos">34</span></a> <span class="k">else</span><span class="p">:</span>
+</span><span id="Node-35"><a href="#Node-35"><span class="linenos">35</span></a> <span class="k">yield</span> <span class="n">d</span>
</span><span id="Node-36"><a href="#Node-36"><span class="linenos">36</span></a>
-</span><span id="Node-37"><a href="#Node-37"><span class="linenos">37</span></a> <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">walk</span><span class="p">():</span>
-</span><span id="Node-38"><a href="#Node-38"><span class="linenos">38</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
-</span><span id="Node-39"><a href="#Node-39"><span class="linenos">39</span></a> <span class="n">label</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;FROM </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="si">}</span><span class="s2">&quot;</span>
-</span><span id="Node-40"><a href="#Node-40"><span class="linenos">40</span></a> <span class="n">title</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&lt;pre&gt;SELECT </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> FROM </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="si">}</span><span class="s2">&lt;/pre&gt;&quot;</span>
-</span><span id="Node-41"><a href="#Node-41"><span class="linenos">41</span></a> <span class="n">group</span> <span class="o">=</span> <span class="mi">1</span>
-</span><span id="Node-42"><a href="#Node-42"><span class="linenos">42</span></a> <span class="k">else</span><span class="p">:</span>
-</span><span id="Node-43"><a href="#Node-43"><span class="linenos">43</span></a> <span class="n">label</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
-</span><span id="Node-44"><a href="#Node-44"><span class="linenos">44</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span>
-</span><span id="Node-45"><a href="#Node-45"><span class="linenos">45</span></a> <span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="p">(</span>
-</span><span id="Node-46"><a href="#Node-46"><span class="linenos">46</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Tag</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">n</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;&lt;b&gt;&quot;</span><span class="p">,</span> <span class="n">postfix</span><span class="o">=</span><span class="s2">&quot;&lt;/b&gt;&quot;</span><span class="p">)</span> <span class="k">if</span> <span class="n">n</span> <span class="ow">is</span> <span class="n">node</span><span class="o">.</span><span class="n">expression</span> <span class="k">else</span> <span class="n">n</span>
-</span><span id="Node-47"><a href="#Node-47"><span class="linenos">47</span></a> <span class="p">),</span>
-</span><span id="Node-48"><a href="#Node-48"><span class="linenos">48</span></a> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
-</span><span id="Node-49"><a href="#Node-49"><span class="linenos">49</span></a> <span class="p">)</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
-</span><span id="Node-50"><a href="#Node-50"><span class="linenos">50</span></a> <span class="n">title</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&lt;pre&gt;</span><span class="si">{</span><span class="n">source</span><span class="si">}</span><span class="s2">&lt;/pre&gt;&quot;</span>
-</span><span id="Node-51"><a href="#Node-51"><span class="linenos">51</span></a> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span>
-</span><span id="Node-52"><a href="#Node-52"><span class="linenos">52</span></a>
-</span><span id="Node-53"><a href="#Node-53"><span class="linenos">53</span></a> <span class="n">node_id</span> <span class="o">=</span> <span class="nb">id</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
-</span><span id="Node-54"><a href="#Node-54"><span class="linenos">54</span></a>
-</span><span id="Node-55"><a href="#Node-55"><span class="linenos">55</span></a> <span class="n">nodes</span><span class="p">[</span><span class="n">node_id</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
-</span><span id="Node-56"><a href="#Node-56"><span class="linenos">56</span></a> <span class="s2">&quot;id&quot;</span><span class="p">:</span> <span class="n">node_id</span><span class="p">,</span>
-</span><span id="Node-57"><a href="#Node-57"><span class="linenos">57</span></a> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="n">label</span><span class="p">,</span>
-</span><span id="Node-58"><a href="#Node-58"><span class="linenos">58</span></a> <span class="s2">&quot;title&quot;</span><span class="p">:</span> <span class="n">title</span><span class="p">,</span>
-</span><span id="Node-59"><a href="#Node-59"><span class="linenos">59</span></a> <span class="s2">&quot;group&quot;</span><span class="p">:</span> <span class="n">group</span><span class="p">,</span>
-</span><span id="Node-60"><a href="#Node-60"><span class="linenos">60</span></a> <span class="p">}</span>
-</span><span id="Node-61"><a href="#Node-61"><span class="linenos">61</span></a>
-</span><span id="Node-62"><a href="#Node-62"><span class="linenos">62</span></a> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="p">:</span>
-</span><span id="Node-63"><a href="#Node-63"><span class="linenos">63</span></a> <span class="n">edges</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;from&quot;</span><span class="p">:</span> <span class="n">node_id</span><span class="p">,</span> <span class="s2">&quot;to&quot;</span><span class="p">:</span> <span class="nb">id</span><span class="p">(</span><span class="n">d</span><span class="p">)})</span>
-</span><span id="Node-64"><a href="#Node-64"><span class="linenos">64</span></a> <span class="k">return</span> <span class="n">GraphHTML</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="n">edges</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span>
+</span><span id="Node-37"><a href="#Node-37"><span class="linenos">37</span></a> <span class="k">def</span> <span class="nf">to_html</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">GraphHTML</span><span class="p">:</span>
+</span><span id="Node-38"><a href="#Node-38"><span class="linenos">38</span></a> <span class="n">nodes</span> <span class="o">=</span> <span class="p">{}</span>
+</span><span id="Node-39"><a href="#Node-39"><span class="linenos">39</span></a> <span class="n">edges</span> <span class="o">=</span> <span class="p">[]</span>
+</span><span id="Node-40"><a href="#Node-40"><span class="linenos">40</span></a>
+</span><span id="Node-41"><a href="#Node-41"><span class="linenos">41</span></a> <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">walk</span><span class="p">():</span>
+</span><span id="Node-42"><a href="#Node-42"><span class="linenos">42</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
+</span><span id="Node-43"><a href="#Node-43"><span class="linenos">43</span></a> <span class="n">label</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;FROM </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="si">}</span><span class="s2">&quot;</span>
+</span><span id="Node-44"><a href="#Node-44"><span class="linenos">44</span></a> <span class="n">title</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&lt;pre&gt;SELECT </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> FROM </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="si">}</span><span class="s2">&lt;/pre&gt;&quot;</span>
+</span><span id="Node-45"><a href="#Node-45"><span class="linenos">45</span></a> <span class="n">group</span> <span class="o">=</span> <span class="mi">1</span>
+</span><span id="Node-46"><a href="#Node-46"><span class="linenos">46</span></a> <span class="k">else</span><span class="p">:</span>
+</span><span id="Node-47"><a href="#Node-47"><span class="linenos">47</span></a> <span class="n">label</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
+</span><span id="Node-48"><a href="#Node-48"><span class="linenos">48</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span>
+</span><span id="Node-49"><a href="#Node-49"><span class="linenos">49</span></a> <span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="p">(</span>
+</span><span id="Node-50"><a href="#Node-50"><span class="linenos">50</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Tag</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">n</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;&lt;b&gt;&quot;</span><span class="p">,</span> <span class="n">postfix</span><span class="o">=</span><span class="s2">&quot;&lt;/b&gt;&quot;</span><span class="p">)</span> <span class="k">if</span> <span class="n">n</span> <span class="ow">is</span> <span class="n">node</span><span class="o">.</span><span class="n">expression</span> <span class="k">else</span> <span class="n">n</span>
+</span><span id="Node-51"><a href="#Node-51"><span class="linenos">51</span></a> <span class="p">),</span>
+</span><span id="Node-52"><a href="#Node-52"><span class="linenos">52</span></a> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
+</span><span id="Node-53"><a href="#Node-53"><span class="linenos">53</span></a> <span class="p">)</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
+</span><span id="Node-54"><a href="#Node-54"><span class="linenos">54</span></a> <span class="n">title</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&lt;pre&gt;</span><span class="si">{</span><span class="n">source</span><span class="si">}</span><span class="s2">&lt;/pre&gt;&quot;</span>
+</span><span id="Node-55"><a href="#Node-55"><span class="linenos">55</span></a> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span>
+</span><span id="Node-56"><a href="#Node-56"><span class="linenos">56</span></a>
+</span><span id="Node-57"><a href="#Node-57"><span class="linenos">57</span></a> <span class="n">node_id</span> <span class="o">=</span> <span class="nb">id</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
+</span><span id="Node-58"><a href="#Node-58"><span class="linenos">58</span></a>
+</span><span id="Node-59"><a href="#Node-59"><span class="linenos">59</span></a> <span class="n">nodes</span><span class="p">[</span><span class="n">node_id</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
+</span><span id="Node-60"><a href="#Node-60"><span class="linenos">60</span></a> <span class="s2">&quot;id&quot;</span><span class="p">:</span> <span class="n">node_id</span><span class="p">,</span>
+</span><span id="Node-61"><a href="#Node-61"><span class="linenos">61</span></a> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="n">label</span><span class="p">,</span>
+</span><span id="Node-62"><a href="#Node-62"><span class="linenos">62</span></a> <span class="s2">&quot;title&quot;</span><span class="p">:</span> <span class="n">title</span><span class="p">,</span>
+</span><span id="Node-63"><a href="#Node-63"><span class="linenos">63</span></a> <span class="s2">&quot;group&quot;</span><span class="p">:</span> <span class="n">group</span><span class="p">,</span>
+</span><span id="Node-64"><a href="#Node-64"><span class="linenos">64</span></a> <span class="p">}</span>
+</span><span id="Node-65"><a href="#Node-65"><span class="linenos">65</span></a>
+</span><span id="Node-66"><a href="#Node-66"><span class="linenos">66</span></a> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="p">:</span>
+</span><span id="Node-67"><a href="#Node-67"><span class="linenos">67</span></a> <span class="n">edges</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;from&quot;</span><span class="p">:</span> <span class="n">node_id</span><span class="p">,</span> <span class="s2">&quot;to&quot;</span><span class="p">:</span> <span class="nb">id</span><span class="p">(</span><span class="n">d</span><span class="p">)})</span>
+</span><span id="Node-68"><a href="#Node-68"><span class="linenos">68</span></a> <span class="k">return</span> <span class="n">GraphHTML</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="n">edges</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span>
</span></pre></div>
@@ -485,7 +528,7 @@
<div id="Node.__init__" class="classattr">
<div class="attr function">
- <span class="name">Node</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>,</span><span class="param"> <span class="n">expression</span><span class="p">:</span> <span class="n"><a href="expressions.html#Expression">sqlglot.expressions.Expression</a></span>,</span><span class="param"> <span class="n">source</span><span class="p">:</span> <span class="n"><a href="expressions.html#Expression">sqlglot.expressions.Expression</a></span>,</span><span class="param"> <span class="n">downstream</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n"><a href="#Node">Node</a></span><span class="p">]</span> <span class="o">=</span> <span class="o">&lt;</span><span class="n">factory</span><span class="o">&gt;</span>,</span><span class="param"> <span class="n">alias</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span></span>)</span>
+ <span class="name">Node</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>,</span><span class="param"> <span class="n">expression</span><span class="p">:</span> <span class="n"><a href="expressions.html#Expression">sqlglot.expressions.Expression</a></span>,</span><span class="param"> <span class="n">source</span><span class="p">:</span> <span class="n"><a href="expressions.html#Expression">sqlglot.expressions.Expression</a></span>,</span><span class="param"> <span class="n">downstream</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n"><a href="#Node">Node</a></span><span class="p">]</span> <span class="o">=</span> <span class="o">&lt;</span><span class="n">factory</span><span class="o">&gt;</span>,</span><span class="param"> <span class="n">source_name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>,</span><span class="param"> <span class="n">reference_node_name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span></span>)</span>
</div>
@@ -538,14 +581,26 @@
</div>
- <div id="Node.alias" class="classattr">
+ <div id="Node.source_name" class="classattr">
+ <div class="attr variable">
+ <span class="name">source_name</span><span class="annotation">: str</span> =
+<span class="default_value">&#39;&#39;</span>
+
+
+ </div>
+ <a class="headerlink" href="#Node.source_name"></a>
+
+
+
+ </div>
+ <div id="Node.reference_node_name" class="classattr">
<div class="attr variable">
- <span class="name">alias</span><span class="annotation">: str</span> =
+ <span class="name">reference_node_name</span><span class="annotation">: str</span> =
<span class="default_value">&#39;&#39;</span>
</div>
- <a class="headerlink" href="#Node.alias"></a>
+ <a class="headerlink" href="#Node.reference_node_name"></a>
@@ -561,14 +616,14 @@
</div>
<a class="headerlink" href="#Node.walk"></a>
- <div class="pdoc-code codehilite"><pre><span></span><span id="Node.walk-24"><a href="#Node.walk-24"><span class="linenos">24</span></a> <span class="k">def</span> <span class="nf">walk</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">t</span><span class="o">.</span><span class="n">Iterator</span><span class="p">[</span><span class="n">Node</span><span class="p">]:</span>
-</span><span id="Node.walk-25"><a href="#Node.walk-25"><span class="linenos">25</span></a> <span class="k">yield</span> <span class="bp">self</span>
-</span><span id="Node.walk-26"><a href="#Node.walk-26"><span class="linenos">26</span></a>
-</span><span id="Node.walk-27"><a href="#Node.walk-27"><span class="linenos">27</span></a> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">downstream</span><span class="p">:</span>
-</span><span id="Node.walk-28"><a href="#Node.walk-28"><span class="linenos">28</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">Node</span><span class="p">):</span>
-</span><span id="Node.walk-29"><a href="#Node.walk-29"><span class="linenos">29</span></a> <span class="k">yield from</span> <span class="n">d</span><span class="o">.</span><span class="n">walk</span><span class="p">()</span>
-</span><span id="Node.walk-30"><a href="#Node.walk-30"><span class="linenos">30</span></a> <span class="k">else</span><span class="p">:</span>
-</span><span id="Node.walk-31"><a href="#Node.walk-31"><span class="linenos">31</span></a> <span class="k">yield</span> <span class="n">d</span>
+ <div class="pdoc-code codehilite"><pre><span></span><span id="Node.walk-28"><a href="#Node.walk-28"><span class="linenos">28</span></a> <span class="k">def</span> <span class="nf">walk</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">t</span><span class="o">.</span><span class="n">Iterator</span><span class="p">[</span><span class="n">Node</span><span class="p">]:</span>
+</span><span id="Node.walk-29"><a href="#Node.walk-29"><span class="linenos">29</span></a> <span class="k">yield</span> <span class="bp">self</span>
+</span><span id="Node.walk-30"><a href="#Node.walk-30"><span class="linenos">30</span></a>
+</span><span id="Node.walk-31"><a href="#Node.walk-31"><span class="linenos">31</span></a> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">downstream</span><span class="p">:</span>
+</span><span id="Node.walk-32"><a href="#Node.walk-32"><span class="linenos">32</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">Node</span><span class="p">):</span>
+</span><span id="Node.walk-33"><a href="#Node.walk-33"><span class="linenos">33</span></a> <span class="k">yield from</span> <span class="n">d</span><span class="o">.</span><span class="n">walk</span><span class="p">()</span>
+</span><span id="Node.walk-34"><a href="#Node.walk-34"><span class="linenos">34</span></a> <span class="k">else</span><span class="p">:</span>
+</span><span id="Node.walk-35"><a href="#Node.walk-35"><span class="linenos">35</span></a> <span class="k">yield</span> <span class="n">d</span>
</span></pre></div>
@@ -586,38 +641,38 @@
</div>
<a class="headerlink" href="#Node.to_html"></a>
- <div class="pdoc-code codehilite"><pre><span></span><span id="Node.to_html-33"><a href="#Node.to_html-33"><span class="linenos">33</span></a> <span class="k">def</span> <span class="nf">to_html</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">GraphHTML</span><span class="p">:</span>
-</span><span id="Node.to_html-34"><a href="#Node.to_html-34"><span class="linenos">34</span></a> <span class="n">nodes</span> <span class="o">=</span> <span class="p">{}</span>
-</span><span id="Node.to_html-35"><a href="#Node.to_html-35"><span class="linenos">35</span></a> <span class="n">edges</span> <span class="o">=</span> <span class="p">[]</span>
-</span><span id="Node.to_html-36"><a href="#Node.to_html-36"><span class="linenos">36</span></a>
-</span><span id="Node.to_html-37"><a href="#Node.to_html-37"><span class="linenos">37</span></a> <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">walk</span><span class="p">():</span>
-</span><span id="Node.to_html-38"><a href="#Node.to_html-38"><span class="linenos">38</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
-</span><span id="Node.to_html-39"><a href="#Node.to_html-39"><span class="linenos">39</span></a> <span class="n">label</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;FROM </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="si">}</span><span class="s2">&quot;</span>
-</span><span id="Node.to_html-40"><a href="#Node.to_html-40"><span class="linenos">40</span></a> <span class="n">title</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&lt;pre&gt;SELECT </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> FROM </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="si">}</span><span class="s2">&lt;/pre&gt;&quot;</span>
-</span><span id="Node.to_html-41"><a href="#Node.to_html-41"><span class="linenos">41</span></a> <span class="n">group</span> <span class="o">=</span> <span class="mi">1</span>
-</span><span id="Node.to_html-42"><a href="#Node.to_html-42"><span class="linenos">42</span></a> <span class="k">else</span><span class="p">:</span>
-</span><span id="Node.to_html-43"><a href="#Node.to_html-43"><span class="linenos">43</span></a> <span class="n">label</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
-</span><span id="Node.to_html-44"><a href="#Node.to_html-44"><span class="linenos">44</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span>
-</span><span id="Node.to_html-45"><a href="#Node.to_html-45"><span class="linenos">45</span></a> <span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="p">(</span>
-</span><span id="Node.to_html-46"><a href="#Node.to_html-46"><span class="linenos">46</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Tag</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">n</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;&lt;b&gt;&quot;</span><span class="p">,</span> <span class="n">postfix</span><span class="o">=</span><span class="s2">&quot;&lt;/b&gt;&quot;</span><span class="p">)</span> <span class="k">if</span> <span class="n">n</span> <span class="ow">is</span> <span class="n">node</span><span class="o">.</span><span class="n">expression</span> <span class="k">else</span> <span class="n">n</span>
-</span><span id="Node.to_html-47"><a href="#Node.to_html-47"><span class="linenos">47</span></a> <span class="p">),</span>
-</span><span id="Node.to_html-48"><a href="#Node.to_html-48"><span class="linenos">48</span></a> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
-</span><span id="Node.to_html-49"><a href="#Node.to_html-49"><span class="linenos">49</span></a> <span class="p">)</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
-</span><span id="Node.to_html-50"><a href="#Node.to_html-50"><span class="linenos">50</span></a> <span class="n">title</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&lt;pre&gt;</span><span class="si">{</span><span class="n">source</span><span class="si">}</span><span class="s2">&lt;/pre&gt;&quot;</span>
-</span><span id="Node.to_html-51"><a href="#Node.to_html-51"><span class="linenos">51</span></a> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span>
-</span><span id="Node.to_html-52"><a href="#Node.to_html-52"><span class="linenos">52</span></a>
-</span><span id="Node.to_html-53"><a href="#Node.to_html-53"><span class="linenos">53</span></a> <span class="n">node_id</span> <span class="o">=</span> <span class="nb">id</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
-</span><span id="Node.to_html-54"><a href="#Node.to_html-54"><span class="linenos">54</span></a>
-</span><span id="Node.to_html-55"><a href="#Node.to_html-55"><span class="linenos">55</span></a> <span class="n">nodes</span><span class="p">[</span><span class="n">node_id</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
-</span><span id="Node.to_html-56"><a href="#Node.to_html-56"><span class="linenos">56</span></a> <span class="s2">&quot;id&quot;</span><span class="p">:</span> <span class="n">node_id</span><span class="p">,</span>
-</span><span id="Node.to_html-57"><a href="#Node.to_html-57"><span class="linenos">57</span></a> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="n">label</span><span class="p">,</span>
-</span><span id="Node.to_html-58"><a href="#Node.to_html-58"><span class="linenos">58</span></a> <span class="s2">&quot;title&quot;</span><span class="p">:</span> <span class="n">title</span><span class="p">,</span>
-</span><span id="Node.to_html-59"><a href="#Node.to_html-59"><span class="linenos">59</span></a> <span class="s2">&quot;group&quot;</span><span class="p">:</span> <span class="n">group</span><span class="p">,</span>
-</span><span id="Node.to_html-60"><a href="#Node.to_html-60"><span class="linenos">60</span></a> <span class="p">}</span>
-</span><span id="Node.to_html-61"><a href="#Node.to_html-61"><span class="linenos">61</span></a>
-</span><span id="Node.to_html-62"><a href="#Node.to_html-62"><span class="linenos">62</span></a> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="p">:</span>
-</span><span id="Node.to_html-63"><a href="#Node.to_html-63"><span class="linenos">63</span></a> <span class="n">edges</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;from&quot;</span><span class="p">:</span> <span class="n">node_id</span><span class="p">,</span> <span class="s2">&quot;to&quot;</span><span class="p">:</span> <span class="nb">id</span><span class="p">(</span><span class="n">d</span><span class="p">)})</span>
-</span><span id="Node.to_html-64"><a href="#Node.to_html-64"><span class="linenos">64</span></a> <span class="k">return</span> <span class="n">GraphHTML</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="n">edges</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span>
+ <div class="pdoc-code codehilite"><pre><span></span><span id="Node.to_html-37"><a href="#Node.to_html-37"><span class="linenos">37</span></a> <span class="k">def</span> <span class="nf">to_html</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">GraphHTML</span><span class="p">:</span>
+</span><span id="Node.to_html-38"><a href="#Node.to_html-38"><span class="linenos">38</span></a> <span class="n">nodes</span> <span class="o">=</span> <span class="p">{}</span>
+</span><span id="Node.to_html-39"><a href="#Node.to_html-39"><span class="linenos">39</span></a> <span class="n">edges</span> <span class="o">=</span> <span class="p">[]</span>
+</span><span id="Node.to_html-40"><a href="#Node.to_html-40"><span class="linenos">40</span></a>
+</span><span id="Node.to_html-41"><a href="#Node.to_html-41"><span class="linenos">41</span></a> <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">walk</span><span class="p">():</span>
+</span><span id="Node.to_html-42"><a href="#Node.to_html-42"><span class="linenos">42</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
+</span><span id="Node.to_html-43"><a href="#Node.to_html-43"><span class="linenos">43</span></a> <span class="n">label</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;FROM </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="si">}</span><span class="s2">&quot;</span>
+</span><span id="Node.to_html-44"><a href="#Node.to_html-44"><span class="linenos">44</span></a> <span class="n">title</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&lt;pre&gt;SELECT </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> FROM </span><span class="si">{</span><span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="si">}</span><span class="s2">&lt;/pre&gt;&quot;</span>
+</span><span id="Node.to_html-45"><a href="#Node.to_html-45"><span class="linenos">45</span></a> <span class="n">group</span> <span class="o">=</span> <span class="mi">1</span>
+</span><span id="Node.to_html-46"><a href="#Node.to_html-46"><span class="linenos">46</span></a> <span class="k">else</span><span class="p">:</span>
+</span><span id="Node.to_html-47"><a href="#Node.to_html-47"><span class="linenos">47</span></a> <span class="n">label</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
+</span><span id="Node.to_html-48"><a href="#Node.to_html-48"><span class="linenos">48</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span>
+</span><span id="Node.to_html-49"><a href="#Node.to_html-49"><span class="linenos">49</span></a> <span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="p">(</span>
+</span><span id="Node.to_html-50"><a href="#Node.to_html-50"><span class="linenos">50</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Tag</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">n</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;&lt;b&gt;&quot;</span><span class="p">,</span> <span class="n">postfix</span><span class="o">=</span><span class="s2">&quot;&lt;/b&gt;&quot;</span><span class="p">)</span> <span class="k">if</span> <span class="n">n</span> <span class="ow">is</span> <span class="n">node</span><span class="o">.</span><span class="n">expression</span> <span class="k">else</span> <span class="n">n</span>
+</span><span id="Node.to_html-51"><a href="#Node.to_html-51"><span class="linenos">51</span></a> <span class="p">),</span>
+</span><span id="Node.to_html-52"><a href="#Node.to_html-52"><span class="linenos">52</span></a> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
+</span><span id="Node.to_html-53"><a href="#Node.to_html-53"><span class="linenos">53</span></a> <span class="p">)</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
+</span><span id="Node.to_html-54"><a href="#Node.to_html-54"><span class="linenos">54</span></a> <span class="n">title</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;&lt;pre&gt;</span><span class="si">{</span><span class="n">source</span><span class="si">}</span><span class="s2">&lt;/pre&gt;&quot;</span>
+</span><span id="Node.to_html-55"><a href="#Node.to_html-55"><span class="linenos">55</span></a> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span>
+</span><span id="Node.to_html-56"><a href="#Node.to_html-56"><span class="linenos">56</span></a>
+</span><span id="Node.to_html-57"><a href="#Node.to_html-57"><span class="linenos">57</span></a> <span class="n">node_id</span> <span class="o">=</span> <span class="nb">id</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
+</span><span id="Node.to_html-58"><a href="#Node.to_html-58"><span class="linenos">58</span></a>
+</span><span id="Node.to_html-59"><a href="#Node.to_html-59"><span class="linenos">59</span></a> <span class="n">nodes</span><span class="p">[</span><span class="n">node_id</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
+</span><span id="Node.to_html-60"><a href="#Node.to_html-60"><span class="linenos">60</span></a> <span class="s2">&quot;id&quot;</span><span class="p">:</span> <span class="n">node_id</span><span class="p">,</span>
+</span><span id="Node.to_html-61"><a href="#Node.to_html-61"><span class="linenos">61</span></a> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="n">label</span><span class="p">,</span>
+</span><span id="Node.to_html-62"><a href="#Node.to_html-62"><span class="linenos">62</span></a> <span class="s2">&quot;title&quot;</span><span class="p">:</span> <span class="n">title</span><span class="p">,</span>
+</span><span id="Node.to_html-63"><a href="#Node.to_html-63"><span class="linenos">63</span></a> <span class="s2">&quot;group&quot;</span><span class="p">:</span> <span class="n">group</span><span class="p">,</span>
+</span><span id="Node.to_html-64"><a href="#Node.to_html-64"><span class="linenos">64</span></a> <span class="p">}</span>
+</span><span id="Node.to_html-65"><a href="#Node.to_html-65"><span class="linenos">65</span></a>
+</span><span id="Node.to_html-66"><a href="#Node.to_html-66"><span class="linenos">66</span></a> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="p">:</span>
+</span><span id="Node.to_html-67"><a href="#Node.to_html-67"><span class="linenos">67</span></a> <span class="n">edges</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s2">&quot;from&quot;</span><span class="p">:</span> <span class="n">node_id</span><span class="p">,</span> <span class="s2">&quot;to&quot;</span><span class="p">:</span> <span class="nb">id</span><span class="p">(</span><span class="n">d</span><span class="p">)})</span>
+</span><span id="Node.to_html-68"><a href="#Node.to_html-68"><span class="linenos">68</span></a> <span class="k">return</span> <span class="n">GraphHTML</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="n">edges</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span>
</span></pre></div>
@@ -630,174 +685,60 @@
<div class="attr function">
<span class="def">def</span>
- <span class="name">lineage</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">column</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n"><a href="expressions.html#Column">sqlglot.expressions.Column</a></span>,</span><span class="param"> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n"><a href="expressions.html#Expression">sqlglot.expressions.Expression</a></span>,</span><span class="param"> <span class="n">schema</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n">Dict</span><span class="p">,</span> <span class="n"><a href="schema.html#Schema">sqlglot.schema.Schema</a></span><span class="p">,</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">sources</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span> <span class="o">|</span> <span class="n"><a href="expressions.html#Subqueryable">sqlglot.expressions.Subqueryable</a></span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">dialect</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n"><a href="dialects/dialect.html#Dialect">sqlglot.dialects.dialect.Dialect</a></span><span class="p">,</span> <span class="n">Type</span><span class="p">[</span><span class="n"><a href="dialects/dialect.html#Dialect">sqlglot.dialects.dialect.Dialect</a></span><span class="p">],</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#Node">Node</a></span>:</span></span>
+ <span class="name">lineage</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">column</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n"><a href="expressions.html#Column">sqlglot.expressions.Column</a></span>,</span><span class="param"> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n"><a href="expressions.html#Expression">sqlglot.expressions.Expression</a></span>,</span><span class="param"> <span class="n">schema</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n">Dict</span><span class="p">,</span> <span class="n"><a href="schema.html#Schema">sqlglot.schema.Schema</a></span><span class="p">,</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">sources</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span> <span class="o">|</span> <span class="n"><a href="expressions.html#Query">sqlglot.expressions.Query</a></span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">dialect</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n"><a href="dialects/dialect.html#Dialect">sqlglot.dialects.dialect.Dialect</a></span><span class="p">,</span> <span class="n">Type</span><span class="p">[</span><span class="n"><a href="dialects/dialect.html#Dialect">sqlglot.dialects.dialect.Dialect</a></span><span class="p">],</span> <span class="n">NoneType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">) -> <span class="n"><a href="#Node">Node</a></span>:</span></span>
<label class="view-source-button" for="lineage-view-source"><span>View Source</span></label>
</div>
<a class="headerlink" href="#lineage"></a>
- <div class="pdoc-code codehilite"><pre><span></span><span id="lineage-67"><a href="#lineage-67"><span class="linenos"> 67</span></a><span class="k">def</span> <span class="nf">lineage</span><span class="p">(</span>
-</span><span id="lineage-68"><a href="#lineage-68"><span class="linenos"> 68</span></a> <span class="n">column</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">,</span>
-</span><span id="lineage-69"><a href="#lineage-69"><span class="linenos"> 69</span></a> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span>
-</span><span id="lineage-70"><a href="#lineage-70"><span class="linenos"> 70</span></a> <span class="n">schema</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">|</span> <span class="n">Schema</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
-</span><span id="lineage-71"><a href="#lineage-71"><span class="linenos"> 71</span></a> <span class="n">sources</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Subqueryable</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
-</span><span id="lineage-72"><a href="#lineage-72"><span class="linenos"> 72</span></a> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
-</span><span id="lineage-73"><a href="#lineage-73"><span class="linenos"> 73</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span>
-</span><span id="lineage-74"><a href="#lineage-74"><span class="linenos"> 74</span></a><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Node</span><span class="p">:</span>
-</span><span id="lineage-75"><a href="#lineage-75"><span class="linenos"> 75</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Build the lineage graph for a column of a SQL query.</span>
-</span><span id="lineage-76"><a href="#lineage-76"><span class="linenos"> 76</span></a>
-</span><span id="lineage-77"><a href="#lineage-77"><span class="linenos"> 77</span></a><span class="sd"> Args:</span>
-</span><span id="lineage-78"><a href="#lineage-78"><span class="linenos"> 78</span></a><span class="sd"> column: The column to build the lineage for.</span>
-</span><span id="lineage-79"><a href="#lineage-79"><span class="linenos"> 79</span></a><span class="sd"> sql: The SQL string or expression.</span>
-</span><span id="lineage-80"><a href="#lineage-80"><span class="linenos"> 80</span></a><span class="sd"> schema: The schema of tables.</span>
-</span><span id="lineage-81"><a href="#lineage-81"><span class="linenos"> 81</span></a><span class="sd"> sources: A mapping of queries which will be used to continue building lineage.</span>
-</span><span id="lineage-82"><a href="#lineage-82"><span class="linenos"> 82</span></a><span class="sd"> dialect: The dialect of input SQL.</span>
-</span><span id="lineage-83"><a href="#lineage-83"><span class="linenos"> 83</span></a><span class="sd"> **kwargs: Qualification optimizer kwargs.</span>
-</span><span id="lineage-84"><a href="#lineage-84"><span class="linenos"> 84</span></a>
-</span><span id="lineage-85"><a href="#lineage-85"><span class="linenos"> 85</span></a><span class="sd"> Returns:</span>
-</span><span id="lineage-86"><a href="#lineage-86"><span class="linenos"> 86</span></a><span class="sd"> A lineage node.</span>
-</span><span id="lineage-87"><a href="#lineage-87"><span class="linenos"> 87</span></a><span class="sd"> &quot;&quot;&quot;</span>
+ <div class="pdoc-code codehilite"><pre><span></span><span id="lineage-71"><a href="#lineage-71"><span class="linenos"> 71</span></a><span class="k">def</span> <span class="nf">lineage</span><span class="p">(</span>
+</span><span id="lineage-72"><a href="#lineage-72"><span class="linenos"> 72</span></a> <span class="n">column</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">,</span>
+</span><span id="lineage-73"><a href="#lineage-73"><span class="linenos"> 73</span></a> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span>
+</span><span id="lineage-74"><a href="#lineage-74"><span class="linenos"> 74</span></a> <span class="n">schema</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">|</span> <span class="n">Schema</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="lineage-75"><a href="#lineage-75"><span class="linenos"> 75</span></a> <span class="n">sources</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Query</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="lineage-76"><a href="#lineage-76"><span class="linenos"> 76</span></a> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="lineage-77"><a href="#lineage-77"><span class="linenos"> 77</span></a> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span>
+</span><span id="lineage-78"><a href="#lineage-78"><span class="linenos"> 78</span></a><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Node</span><span class="p">:</span>
+</span><span id="lineage-79"><a href="#lineage-79"><span class="linenos"> 79</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Build the lineage graph for a column of a SQL query.</span>
+</span><span id="lineage-80"><a href="#lineage-80"><span class="linenos"> 80</span></a>
+</span><span id="lineage-81"><a href="#lineage-81"><span class="linenos"> 81</span></a><span class="sd"> Args:</span>
+</span><span id="lineage-82"><a href="#lineage-82"><span class="linenos"> 82</span></a><span class="sd"> column: The column to build the lineage for.</span>
+</span><span id="lineage-83"><a href="#lineage-83"><span class="linenos"> 83</span></a><span class="sd"> sql: The SQL string or expression.</span>
+</span><span id="lineage-84"><a href="#lineage-84"><span class="linenos"> 84</span></a><span class="sd"> schema: The schema of tables.</span>
+</span><span id="lineage-85"><a href="#lineage-85"><span class="linenos"> 85</span></a><span class="sd"> sources: A mapping of queries which will be used to continue building lineage.</span>
+</span><span id="lineage-86"><a href="#lineage-86"><span class="linenos"> 86</span></a><span class="sd"> dialect: The dialect of input SQL.</span>
+</span><span id="lineage-87"><a href="#lineage-87"><span class="linenos"> 87</span></a><span class="sd"> **kwargs: Qualification optimizer kwargs.</span>
</span><span id="lineage-88"><a href="#lineage-88"><span class="linenos"> 88</span></a>
-</span><span id="lineage-89"><a href="#lineage-89"><span class="linenos"> 89</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">maybe_parse</span><span class="p">(</span><span class="n">sql</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
-</span><span id="lineage-90"><a href="#lineage-90"><span class="linenos"> 90</span></a>
-</span><span id="lineage-91"><a href="#lineage-91"><span class="linenos"> 91</span></a> <span class="k">if</span> <span class="n">sources</span><span class="p">:</span>
-</span><span id="lineage-92"><a href="#lineage-92"><span class="linenos"> 92</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span>
-</span><span id="lineage-93"><a href="#lineage-93"><span class="linenos"> 93</span></a> <span class="n">expression</span><span class="p">,</span>
-</span><span id="lineage-94"><a href="#lineage-94"><span class="linenos"> 94</span></a> <span class="p">{</span>
-</span><span id="lineage-95"><a href="#lineage-95"><span class="linenos"> 95</span></a> <span class="n">k</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Subqueryable</span><span class="p">,</span> <span class="n">maybe_parse</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">))</span>
-</span><span id="lineage-96"><a href="#lineage-96"><span class="linenos"> 96</span></a> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">sources</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
-</span><span id="lineage-97"><a href="#lineage-97"><span class="linenos"> 97</span></a> <span class="p">},</span>
-</span><span id="lineage-98"><a href="#lineage-98"><span class="linenos"> 98</span></a> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span>
-</span><span id="lineage-99"><a href="#lineage-99"><span class="linenos"> 99</span></a> <span class="p">)</span>
-</span><span id="lineage-100"><a href="#lineage-100"><span class="linenos">100</span></a>
-</span><span id="lineage-101"><a href="#lineage-101"><span class="linenos">101</span></a> <span class="n">qualified</span> <span class="o">=</span> <span class="n">qualify</span><span class="o">.</span><span class="n">qualify</span><span class="p">(</span>
-</span><span id="lineage-102"><a href="#lineage-102"><span class="linenos">102</span></a> <span class="n">expression</span><span class="p">,</span>
-</span><span id="lineage-103"><a href="#lineage-103"><span class="linenos">103</span></a> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span>
-</span><span id="lineage-104"><a href="#lineage-104"><span class="linenos">104</span></a> <span class="n">schema</span><span class="o">=</span><span class="n">schema</span><span class="p">,</span>
-</span><span id="lineage-105"><a href="#lineage-105"><span class="linenos">105</span></a> <span class="o">**</span><span class="p">{</span><span class="s2">&quot;validate_qualify_columns&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span> <span class="s2">&quot;identify&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">},</span> <span class="c1"># type: ignore</span>
-</span><span id="lineage-106"><a href="#lineage-106"><span class="linenos">106</span></a> <span class="p">)</span>
-</span><span id="lineage-107"><a href="#lineage-107"><span class="linenos">107</span></a>
-</span><span id="lineage-108"><a href="#lineage-108"><span class="linenos">108</span></a> <span class="n">scope</span> <span class="o">=</span> <span class="n">build_scope</span><span class="p">(</span><span class="n">qualified</span><span class="p">)</span>
+</span><span id="lineage-89"><a href="#lineage-89"><span class="linenos"> 89</span></a><span class="sd"> Returns:</span>
+</span><span id="lineage-90"><a href="#lineage-90"><span class="linenos"> 90</span></a><span class="sd"> A lineage node.</span>
+</span><span id="lineage-91"><a href="#lineage-91"><span class="linenos"> 91</span></a><span class="sd"> &quot;&quot;&quot;</span>
+</span><span id="lineage-92"><a href="#lineage-92"><span class="linenos"> 92</span></a>
+</span><span id="lineage-93"><a href="#lineage-93"><span class="linenos"> 93</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">maybe_parse</span><span class="p">(</span><span class="n">sql</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span>
+</span><span id="lineage-94"><a href="#lineage-94"><span class="linenos"> 94</span></a> <span class="n">column</span> <span class="o">=</span> <span class="n">normalize_identifiers</span><span class="o">.</span><span class="n">normalize_identifiers</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span><span class="o">.</span><span class="n">name</span>
+</span><span id="lineage-95"><a href="#lineage-95"><span class="linenos"> 95</span></a>
+</span><span id="lineage-96"><a href="#lineage-96"><span class="linenos"> 96</span></a> <span class="k">if</span> <span class="n">sources</span><span class="p">:</span>
+</span><span id="lineage-97"><a href="#lineage-97"><span class="linenos"> 97</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">expand</span><span class="p">(</span>
+</span><span id="lineage-98"><a href="#lineage-98"><span class="linenos"> 98</span></a> <span class="n">expression</span><span class="p">,</span>
+</span><span id="lineage-99"><a href="#lineage-99"><span class="linenos"> 99</span></a> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Query</span><span class="p">,</span> <span class="n">maybe_parse</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">))</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">sources</span><span class="o">.</span><span class="n">items</span><span class="p">()},</span>
+</span><span id="lineage-100"><a href="#lineage-100"><span class="linenos">100</span></a> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span>
+</span><span id="lineage-101"><a href="#lineage-101"><span class="linenos">101</span></a> <span class="p">)</span>
+</span><span id="lineage-102"><a href="#lineage-102"><span class="linenos">102</span></a>
+</span><span id="lineage-103"><a href="#lineage-103"><span class="linenos">103</span></a> <span class="n">qualified</span> <span class="o">=</span> <span class="n">qualify</span><span class="o">.</span><span class="n">qualify</span><span class="p">(</span>
+</span><span id="lineage-104"><a href="#lineage-104"><span class="linenos">104</span></a> <span class="n">expression</span><span class="p">,</span>
+</span><span id="lineage-105"><a href="#lineage-105"><span class="linenos">105</span></a> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span>
+</span><span id="lineage-106"><a href="#lineage-106"><span class="linenos">106</span></a> <span class="n">schema</span><span class="o">=</span><span class="n">schema</span><span class="p">,</span>
+</span><span id="lineage-107"><a href="#lineage-107"><span class="linenos">107</span></a> <span class="o">**</span><span class="p">{</span><span class="s2">&quot;validate_qualify_columns&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span> <span class="s2">&quot;identify&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">},</span> <span class="c1"># type: ignore</span>
+</span><span id="lineage-108"><a href="#lineage-108"><span class="linenos">108</span></a> <span class="p">)</span>
</span><span id="lineage-109"><a href="#lineage-109"><span class="linenos">109</span></a>
-</span><span id="lineage-110"><a href="#lineage-110"><span class="linenos">110</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">scope</span><span class="p">:</span>
-</span><span id="lineage-111"><a href="#lineage-111"><span class="linenos">111</span></a> <span class="k">raise</span> <span class="n">SqlglotError</span><span class="p">(</span><span class="s2">&quot;Cannot build lineage, sql must be SELECT&quot;</span><span class="p">)</span>
-</span><span id="lineage-112"><a href="#lineage-112"><span class="linenos">112</span></a>
-</span><span id="lineage-113"><a href="#lineage-113"><span class="linenos">113</span></a> <span class="k">def</span> <span class="nf">to_node</span><span class="p">(</span>
-</span><span id="lineage-114"><a href="#lineage-114"><span class="linenos">114</span></a> <span class="n">column</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">int</span><span class="p">,</span>
-</span><span id="lineage-115"><a href="#lineage-115"><span class="linenos">115</span></a> <span class="n">scope</span><span class="p">:</span> <span class="n">Scope</span><span class="p">,</span>
-</span><span id="lineage-116"><a href="#lineage-116"><span class="linenos">116</span></a> <span class="n">scope_name</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
-</span><span id="lineage-117"><a href="#lineage-117"><span class="linenos">117</span></a> <span class="n">upstream</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">Node</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
-</span><span id="lineage-118"><a href="#lineage-118"><span class="linenos">118</span></a> <span class="n">alias</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
-</span><span id="lineage-119"><a href="#lineage-119"><span class="linenos">119</span></a> <span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Node</span><span class="p">:</span>
-</span><span id="lineage-120"><a href="#lineage-120"><span class="linenos">120</span></a> <span class="n">aliases</span> <span class="o">=</span> <span class="p">{</span>
-</span><span id="lineage-121"><a href="#lineage-121"><span class="linenos">121</span></a> <span class="n">dt</span><span class="o">.</span><span class="n">alias</span><span class="p">:</span> <span class="n">dt</span><span class="o">.</span><span class="n">comments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>
-</span><span id="lineage-122"><a href="#lineage-122"><span class="linenos">122</span></a> <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">derived_tables</span>
-</span><span id="lineage-123"><a href="#lineage-123"><span class="linenos">123</span></a> <span class="k">if</span> <span class="n">dt</span><span class="o">.</span><span class="n">comments</span> <span class="ow">and</span> <span class="n">dt</span><span class="o">.</span><span class="n">comments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;source: &quot;</span><span class="p">)</span>
-</span><span id="lineage-124"><a href="#lineage-124"><span class="linenos">124</span></a> <span class="p">}</span>
-</span><span id="lineage-125"><a href="#lineage-125"><span class="linenos">125</span></a>
-</span><span id="lineage-126"><a href="#lineage-126"><span class="linenos">126</span></a> <span class="c1"># Find the specific select clause that is the source of the column we want.</span>
-</span><span id="lineage-127"><a href="#lineage-127"><span class="linenos">127</span></a> <span class="c1"># This can either be a specific, named select or a generic `*` clause.</span>
-</span><span id="lineage-128"><a href="#lineage-128"><span class="linenos">128</span></a> <span class="n">select</span> <span class="o">=</span> <span class="p">(</span>
-</span><span id="lineage-129"><a href="#lineage-129"><span class="linenos">129</span></a> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span><span class="p">[</span><span class="n">column</span><span class="p">]</span>
-</span><span id="lineage-130"><a href="#lineage-130"><span class="linenos">130</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
-</span><span id="lineage-131"><a href="#lineage-131"><span class="linenos">131</span></a> <span class="k">else</span> <span class="nb">next</span><span class="p">(</span>
-</span><span id="lineage-132"><a href="#lineage-132"><span class="linenos">132</span></a> <span class="p">(</span><span class="n">select</span> <span class="k">for</span> <span class="n">select</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span> <span class="k">if</span> <span class="n">select</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="n">column</span><span class="p">),</span>
-</span><span id="lineage-133"><a href="#lineage-133"><span class="linenos">133</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Star</span><span class="p">()</span> <span class="k">if</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">is_star</span> <span class="k">else</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span>
-</span><span id="lineage-134"><a href="#lineage-134"><span class="linenos">134</span></a> <span class="p">)</span>
-</span><span id="lineage-135"><a href="#lineage-135"><span class="linenos">135</span></a> <span class="p">)</span>
-</span><span id="lineage-136"><a href="#lineage-136"><span class="linenos">136</span></a>
-</span><span id="lineage-137"><a href="#lineage-137"><span class="linenos">137</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Union</span><span class="p">):</span>
-</span><span id="lineage-138"><a href="#lineage-138"><span class="linenos">138</span></a> <span class="n">upstream</span> <span class="o">=</span> <span class="n">upstream</span> <span class="ow">or</span> <span class="n">Node</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;UNION&quot;</span><span class="p">,</span> <span class="n">source</span><span class="o">=</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">select</span><span class="p">)</span>
-</span><span id="lineage-139"><a href="#lineage-139"><span class="linenos">139</span></a>
-</span><span id="lineage-140"><a href="#lineage-140"><span class="linenos">140</span></a> <span class="n">index</span> <span class="o">=</span> <span class="p">(</span>
-</span><span id="lineage-141"><a href="#lineage-141"><span class="linenos">141</span></a> <span class="n">column</span>
-</span><span id="lineage-142"><a href="#lineage-142"><span class="linenos">142</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
-</span><span id="lineage-143"><a href="#lineage-143"><span class="linenos">143</span></a> <span class="k">else</span> <span class="nb">next</span><span class="p">(</span>
-</span><span id="lineage-144"><a href="#lineage-144"><span class="linenos">144</span></a> <span class="p">(</span>
-</span><span id="lineage-145"><a href="#lineage-145"><span class="linenos">145</span></a> <span class="n">i</span>
-</span><span id="lineage-146"><a href="#lineage-146"><span class="linenos">146</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">select</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span><span class="p">)</span>
-</span><span id="lineage-147"><a href="#lineage-147"><span class="linenos">147</span></a> <span class="k">if</span> <span class="n">select</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="n">column</span> <span class="ow">or</span> <span class="n">select</span><span class="o">.</span><span class="n">is_star</span>
-</span><span id="lineage-148"><a href="#lineage-148"><span class="linenos">148</span></a> <span class="p">),</span>
-</span><span id="lineage-149"><a href="#lineage-149"><span class="linenos">149</span></a> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="c1"># mypy will not allow a None here, but a negative index should never be returned</span>
-</span><span id="lineage-150"><a href="#lineage-150"><span class="linenos">150</span></a> <span class="p">)</span>
-</span><span id="lineage-151"><a href="#lineage-151"><span class="linenos">151</span></a> <span class="p">)</span>
-</span><span id="lineage-152"><a href="#lineage-152"><span class="linenos">152</span></a>
-</span><span id="lineage-153"><a href="#lineage-153"><span class="linenos">153</span></a> <span class="k">if</span> <span class="n">index</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
-</span><span id="lineage-154"><a href="#lineage-154"><span class="linenos">154</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Could not find </span><span class="si">{</span><span class="n">column</span><span class="si">}</span><span class="s2"> in </span><span class="si">{</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
-</span><span id="lineage-155"><a href="#lineage-155"><span class="linenos">155</span></a>
-</span><span id="lineage-156"><a href="#lineage-156"><span class="linenos">156</span></a> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">union_scopes</span><span class="p">:</span>
-</span><span id="lineage-157"><a href="#lineage-157"><span class="linenos">157</span></a> <span class="n">to_node</span><span class="p">(</span><span class="n">index</span><span class="p">,</span> <span class="n">scope</span><span class="o">=</span><span class="n">s</span><span class="p">,</span> <span class="n">upstream</span><span class="o">=</span><span class="n">upstream</span><span class="p">,</span> <span class="n">alias</span><span class="o">=</span><span class="n">alias</span><span class="p">)</span>
-</span><span id="lineage-158"><a href="#lineage-158"><span class="linenos">158</span></a>
-</span><span id="lineage-159"><a href="#lineage-159"><span class="linenos">159</span></a> <span class="k">return</span> <span class="n">upstream</span>
-</span><span id="lineage-160"><a href="#lineage-160"><span class="linenos">160</span></a>
-</span><span id="lineage-161"><a href="#lineage-161"><span class="linenos">161</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">):</span>
-</span><span id="lineage-162"><a href="#lineage-162"><span class="linenos">162</span></a> <span class="c1"># For better ergonomics in our node labels, replace the full select with</span>
-</span><span id="lineage-163"><a href="#lineage-163"><span class="linenos">163</span></a> <span class="c1"># a version that has only the column we care about.</span>
-</span><span id="lineage-164"><a href="#lineage-164"><span class="linenos">164</span></a> <span class="c1"># &quot;x&quot;, SELECT x, y FROM foo</span>
-</span><span id="lineage-165"><a href="#lineage-165"><span class="linenos">165</span></a> <span class="c1"># =&gt; &quot;x&quot;, SELECT x FROM foo</span>
-</span><span id="lineage-166"><a href="#lineage-166"><span class="linenos">166</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">t</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">append</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
-</span><span id="lineage-167"><a href="#lineage-167"><span class="linenos">167</span></a> <span class="k">else</span><span class="p">:</span>
-</span><span id="lineage-168"><a href="#lineage-168"><span class="linenos">168</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span>
-</span><span id="lineage-169"><a href="#lineage-169"><span class="linenos">169</span></a>
-</span><span id="lineage-170"><a href="#lineage-170"><span class="linenos">170</span></a> <span class="c1"># Create the node for this step in the lineage chain, and attach it to the previous one.</span>
-</span><span id="lineage-171"><a href="#lineage-171"><span class="linenos">171</span></a> <span class="n">node</span> <span class="o">=</span> <span class="n">Node</span><span class="p">(</span>
-</span><span id="lineage-172"><a href="#lineage-172"><span class="linenos">172</span></a> <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">scope_name</span><span class="si">}</span><span class="s2">.</span><span class="si">{</span><span class="n">column</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">if</span> <span class="n">scope_name</span> <span class="k">else</span> <span class="nb">str</span><span class="p">(</span><span class="n">column</span><span class="p">),</span>
-</span><span id="lineage-173"><a href="#lineage-173"><span class="linenos">173</span></a> <span class="n">source</span><span class="o">=</span><span class="n">source</span><span class="p">,</span>
-</span><span id="lineage-174"><a href="#lineage-174"><span class="linenos">174</span></a> <span class="n">expression</span><span class="o">=</span><span class="n">select</span><span class="p">,</span>
-</span><span id="lineage-175"><a href="#lineage-175"><span class="linenos">175</span></a> <span class="n">alias</span><span class="o">=</span><span class="n">alias</span> <span class="ow">or</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
-</span><span id="lineage-176"><a href="#lineage-176"><span class="linenos">176</span></a> <span class="p">)</span>
-</span><span id="lineage-177"><a href="#lineage-177"><span class="linenos">177</span></a>
-</span><span id="lineage-178"><a href="#lineage-178"><span class="linenos">178</span></a> <span class="k">if</span> <span class="n">upstream</span><span class="p">:</span>
-</span><span id="lineage-179"><a href="#lineage-179"><span class="linenos">179</span></a> <span class="n">upstream</span><span class="o">.</span><span class="n">downstream</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
-</span><span id="lineage-180"><a href="#lineage-180"><span class="linenos">180</span></a>
-</span><span id="lineage-181"><a href="#lineage-181"><span class="linenos">181</span></a> <span class="n">subquery_scopes</span> <span class="o">=</span> <span class="p">{</span>
-</span><span id="lineage-182"><a href="#lineage-182"><span class="linenos">182</span></a> <span class="nb">id</span><span class="p">(</span><span class="n">subquery_scope</span><span class="o">.</span><span class="n">expression</span><span class="p">):</span> <span class="n">subquery_scope</span>
-</span><span id="lineage-183"><a href="#lineage-183"><span class="linenos">183</span></a> <span class="k">for</span> <span class="n">subquery_scope</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">subquery_scopes</span>
-</span><span id="lineage-184"><a href="#lineage-184"><span class="linenos">184</span></a> <span class="p">}</span>
-</span><span id="lineage-185"><a href="#lineage-185"><span class="linenos">185</span></a>
-</span><span id="lineage-186"><a href="#lineage-186"><span class="linenos">186</span></a> <span class="k">for</span> <span class="n">subquery</span> <span class="ow">in</span> <span class="n">find_all_in_scope</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Subqueryable</span><span class="p">):</span>
-</span><span id="lineage-187"><a href="#lineage-187"><span class="linenos">187</span></a> <span class="n">subquery_scope</span> <span class="o">=</span> <span class="n">subquery_scopes</span><span class="p">[</span><span class="nb">id</span><span class="p">(</span><span class="n">subquery</span><span class="p">)]</span>
-</span><span id="lineage-188"><a href="#lineage-188"><span class="linenos">188</span></a>
-</span><span id="lineage-189"><a href="#lineage-189"><span class="linenos">189</span></a> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">subquery</span><span class="o">.</span><span class="n">named_selects</span><span class="p">:</span>
-</span><span id="lineage-190"><a href="#lineage-190"><span class="linenos">190</span></a> <span class="n">to_node</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">scope</span><span class="o">=</span><span class="n">subquery_scope</span><span class="p">,</span> <span class="n">upstream</span><span class="o">=</span><span class="n">node</span><span class="p">)</span>
-</span><span id="lineage-191"><a href="#lineage-191"><span class="linenos">191</span></a>
-</span><span id="lineage-192"><a href="#lineage-192"><span class="linenos">192</span></a> <span class="c1"># if the select is a star add all scope sources as downstreams</span>
-</span><span id="lineage-193"><a href="#lineage-193"><span class="linenos">193</span></a> <span class="k">if</span> <span class="n">select</span><span class="o">.</span><span class="n">is_star</span><span class="p">:</span>
-</span><span id="lineage-194"><a href="#lineage-194"><span class="linenos">194</span></a> <span class="k">for</span> <span class="n">source</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
-</span><span id="lineage-195"><a href="#lineage-195"><span class="linenos">195</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Scope</span><span class="p">):</span>
-</span><span id="lineage-196"><a href="#lineage-196"><span class="linenos">196</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">expression</span>
-</span><span id="lineage-197"><a href="#lineage-197"><span class="linenos">197</span></a> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Node</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">select</span><span class="o">.</span><span class="n">sql</span><span class="p">(),</span> <span class="n">source</span><span class="o">=</span><span class="n">source</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">source</span><span class="p">))</span>
-</span><span id="lineage-198"><a href="#lineage-198"><span class="linenos">198</span></a>
-</span><span id="lineage-199"><a href="#lineage-199"><span class="linenos">199</span></a> <span class="c1"># Find all columns that went into creating this one to list their lineage nodes.</span>
-</span><span id="lineage-200"><a href="#lineage-200"><span class="linenos">200</span></a> <span class="n">source_columns</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">find_all_in_scope</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">))</span>
-</span><span id="lineage-201"><a href="#lineage-201"><span class="linenos">201</span></a>
-</span><span id="lineage-202"><a href="#lineage-202"><span class="linenos">202</span></a> <span class="c1"># If the source is a UDTF find columns used in the UTDF to generate the table</span>
-</span><span id="lineage-203"><a href="#lineage-203"><span class="linenos">203</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">UDTF</span><span class="p">):</span>
-</span><span id="lineage-204"><a href="#lineage-204"><span class="linenos">204</span></a> <span class="n">source_columns</span> <span class="o">|=</span> <span class="nb">set</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">find_all</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">))</span>
-</span><span id="lineage-205"><a href="#lineage-205"><span class="linenos">205</span></a>
-</span><span id="lineage-206"><a href="#lineage-206"><span class="linenos">206</span></a> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">source_columns</span><span class="p">:</span>
-</span><span id="lineage-207"><a href="#lineage-207"><span class="linenos">207</span></a> <span class="n">table</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">table</span>
-</span><span id="lineage-208"><a href="#lineage-208"><span class="linenos">208</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">scope</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">table</span><span class="p">)</span>
-</span><span id="lineage-209"><a href="#lineage-209"><span class="linenos">209</span></a>
-</span><span id="lineage-210"><a href="#lineage-210"><span class="linenos">210</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Scope</span><span class="p">):</span>
-</span><span id="lineage-211"><a href="#lineage-211"><span class="linenos">211</span></a> <span class="c1"># The table itself came from a more specific scope. Recurse into that one using the unaliased column name.</span>
-</span><span id="lineage-212"><a href="#lineage-212"><span class="linenos">212</span></a> <span class="n">to_node</span><span class="p">(</span>
-</span><span id="lineage-213"><a href="#lineage-213"><span class="linenos">213</span></a> <span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
-</span><span id="lineage-214"><a href="#lineage-214"><span class="linenos">214</span></a> <span class="n">scope</span><span class="o">=</span><span class="n">source</span><span class="p">,</span>
-</span><span id="lineage-215"><a href="#lineage-215"><span class="linenos">215</span></a> <span class="n">scope_name</span><span class="o">=</span><span class="n">table</span><span class="p">,</span>
-</span><span id="lineage-216"><a href="#lineage-216"><span class="linenos">216</span></a> <span class="n">upstream</span><span class="o">=</span><span class="n">node</span><span class="p">,</span>
-</span><span id="lineage-217"><a href="#lineage-217"><span class="linenos">217</span></a> <span class="n">alias</span><span class="o">=</span><span class="n">aliases</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">table</span><span class="p">)</span> <span class="ow">or</span> <span class="n">alias</span><span class="p">,</span>
-</span><span id="lineage-218"><a href="#lineage-218"><span class="linenos">218</span></a> <span class="p">)</span>
-</span><span id="lineage-219"><a href="#lineage-219"><span class="linenos">219</span></a> <span class="k">else</span><span class="p">:</span>
-</span><span id="lineage-220"><a href="#lineage-220"><span class="linenos">220</span></a> <span class="c1"># The source is not a scope - we&#39;ve reached the end of the line. At this point, if a source is not found</span>
-</span><span id="lineage-221"><a href="#lineage-221"><span class="linenos">221</span></a> <span class="c1"># it means this column&#39;s lineage is unknown. This can happen if the definition of a source used in a query</span>
-</span><span id="lineage-222"><a href="#lineage-222"><span class="linenos">222</span></a> <span class="c1"># is not passed into the `sources` map.</span>
-</span><span id="lineage-223"><a href="#lineage-223"><span class="linenos">223</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">source</span> <span class="ow">or</span> <span class="n">exp</span><span class="o">.</span><span class="n">Placeholder</span><span class="p">()</span>
-</span><span id="lineage-224"><a href="#lineage-224"><span class="linenos">224</span></a> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Node</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">c</span><span class="o">.</span><span class="n">sql</span><span class="p">(),</span> <span class="n">source</span><span class="o">=</span><span class="n">source</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">source</span><span class="p">))</span>
-</span><span id="lineage-225"><a href="#lineage-225"><span class="linenos">225</span></a>
-</span><span id="lineage-226"><a href="#lineage-226"><span class="linenos">226</span></a> <span class="k">return</span> <span class="n">node</span>
-</span><span id="lineage-227"><a href="#lineage-227"><span class="linenos">227</span></a>
-</span><span id="lineage-228"><a href="#lineage-228"><span class="linenos">228</span></a> <span class="k">return</span> <span class="n">to_node</span><span class="p">(</span><span class="n">column</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="k">else</span> <span class="n">column</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">scope</span><span class="p">)</span>
+</span><span id="lineage-110"><a href="#lineage-110"><span class="linenos">110</span></a> <span class="n">scope</span> <span class="o">=</span> <span class="n">build_scope</span><span class="p">(</span><span class="n">qualified</span><span class="p">)</span>
+</span><span id="lineage-111"><a href="#lineage-111"><span class="linenos">111</span></a>
+</span><span id="lineage-112"><a href="#lineage-112"><span class="linenos">112</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">scope</span><span class="p">:</span>
+</span><span id="lineage-113"><a href="#lineage-113"><span class="linenos">113</span></a> <span class="k">raise</span> <span class="n">SqlglotError</span><span class="p">(</span><span class="s2">&quot;Cannot build lineage, sql must be SELECT&quot;</span><span class="p">)</span>
+</span><span id="lineage-114"><a href="#lineage-114"><span class="linenos">114</span></a>
+</span><span id="lineage-115"><a href="#lineage-115"><span class="linenos">115</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">any</span><span class="p">(</span><span class="n">select</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="n">column</span> <span class="k">for</span> <span class="n">select</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span><span class="p">):</span>
+</span><span id="lineage-116"><a href="#lineage-116"><span class="linenos">116</span></a> <span class="k">raise</span> <span class="n">SqlglotError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Cannot find column &#39;</span><span class="si">{</span><span class="n">column</span><span class="si">}</span><span class="s2">&#39; in query.&quot;</span><span class="p">)</span>
+</span><span id="lineage-117"><a href="#lineage-117"><span class="linenos">117</span></a>
+</span><span id="lineage-118"><a href="#lineage-118"><span class="linenos">118</span></a> <span class="k">return</span> <span class="n">to_node</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="n">scope</span><span class="p">,</span> <span class="n">dialect</span><span class="p">)</span>
</span></pre></div>
@@ -823,6 +764,152 @@
</section>
+ <section id="to_node">
+ <input id="to_node-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
+<div class="attr function">
+
+ <span class="def">def</span>
+ <span class="name">to_node</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">column</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">int</span>,</span><span class="param"> <span class="n">scope</span><span class="p">:</span> <span class="n"><a href="optimizer/scope.html#Scope">sqlglot.optimizer.scope.Scope</a></span>,</span><span class="param"> <span class="n">dialect</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n"><a href="dialects/dialect.html#Dialect">sqlglot.dialects.dialect.Dialect</a></span><span class="p">,</span> <span class="n">Type</span><span class="p">[</span><span class="n"><a href="dialects/dialect.html#Dialect">sqlglot.dialects.dialect.Dialect</a></span><span class="p">],</span> <span class="n">NoneType</span><span class="p">]</span>,</span><span class="param"> <span class="n">scope_name</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">upstream</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n"><a href="#Node">Node</a></span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">source_name</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>,</span><span class="param"> <span class="n">reference_node_name</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span></span><span class="return-annotation">) -> <span class="n"><a href="#Node">Node</a></span>:</span></span>
+
+ <label class="view-source-button" for="to_node-view-source"><span>View Source</span></label>
+
+ </div>
+ <a class="headerlink" href="#to_node"></a>
+ <div class="pdoc-code codehilite"><pre><span></span><span id="to_node-121"><a href="#to_node-121"><span class="linenos">121</span></a><span class="k">def</span> <span class="nf">to_node</span><span class="p">(</span>
+</span><span id="to_node-122"><a href="#to_node-122"><span class="linenos">122</span></a> <span class="n">column</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">int</span><span class="p">,</span>
+</span><span id="to_node-123"><a href="#to_node-123"><span class="linenos">123</span></a> <span class="n">scope</span><span class="p">:</span> <span class="n">Scope</span><span class="p">,</span>
+</span><span id="to_node-124"><a href="#to_node-124"><span class="linenos">124</span></a> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">,</span>
+</span><span id="to_node-125"><a href="#to_node-125"><span class="linenos">125</span></a> <span class="n">scope_name</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="to_node-126"><a href="#to_node-126"><span class="linenos">126</span></a> <span class="n">upstream</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">Node</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="to_node-127"><a href="#to_node-127"><span class="linenos">127</span></a> <span class="n">source_name</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="to_node-128"><a href="#to_node-128"><span class="linenos">128</span></a> <span class="n">reference_node_name</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="to_node-129"><a href="#to_node-129"><span class="linenos">129</span></a><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Node</span><span class="p">:</span>
+</span><span id="to_node-130"><a href="#to_node-130"><span class="linenos">130</span></a> <span class="n">source_names</span> <span class="o">=</span> <span class="p">{</span>
+</span><span id="to_node-131"><a href="#to_node-131"><span class="linenos">131</span></a> <span class="n">dt</span><span class="o">.</span><span class="n">alias</span><span class="p">:</span> <span class="n">dt</span><span class="o">.</span><span class="n">comments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>
+</span><span id="to_node-132"><a href="#to_node-132"><span class="linenos">132</span></a> <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">derived_tables</span>
+</span><span id="to_node-133"><a href="#to_node-133"><span class="linenos">133</span></a> <span class="k">if</span> <span class="n">dt</span><span class="o">.</span><span class="n">comments</span> <span class="ow">and</span> <span class="n">dt</span><span class="o">.</span><span class="n">comments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;source: &quot;</span><span class="p">)</span>
+</span><span id="to_node-134"><a href="#to_node-134"><span class="linenos">134</span></a> <span class="p">}</span>
+</span><span id="to_node-135"><a href="#to_node-135"><span class="linenos">135</span></a>
+</span><span id="to_node-136"><a href="#to_node-136"><span class="linenos">136</span></a> <span class="c1"># Find the specific select clause that is the source of the column we want.</span>
+</span><span id="to_node-137"><a href="#to_node-137"><span class="linenos">137</span></a> <span class="c1"># This can either be a specific, named select or a generic `*` clause.</span>
+</span><span id="to_node-138"><a href="#to_node-138"><span class="linenos">138</span></a> <span class="n">select</span> <span class="o">=</span> <span class="p">(</span>
+</span><span id="to_node-139"><a href="#to_node-139"><span class="linenos">139</span></a> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span><span class="p">[</span><span class="n">column</span><span class="p">]</span>
+</span><span id="to_node-140"><a href="#to_node-140"><span class="linenos">140</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
+</span><span id="to_node-141"><a href="#to_node-141"><span class="linenos">141</span></a> <span class="k">else</span> <span class="nb">next</span><span class="p">(</span>
+</span><span id="to_node-142"><a href="#to_node-142"><span class="linenos">142</span></a> <span class="p">(</span><span class="n">select</span> <span class="k">for</span> <span class="n">select</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span> <span class="k">if</span> <span class="n">select</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="n">column</span><span class="p">),</span>
+</span><span id="to_node-143"><a href="#to_node-143"><span class="linenos">143</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Star</span><span class="p">()</span> <span class="k">if</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">is_star</span> <span class="k">else</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span>
+</span><span id="to_node-144"><a href="#to_node-144"><span class="linenos">144</span></a> <span class="p">)</span>
+</span><span id="to_node-145"><a href="#to_node-145"><span class="linenos">145</span></a> <span class="p">)</span>
+</span><span id="to_node-146"><a href="#to_node-146"><span class="linenos">146</span></a>
+</span><span id="to_node-147"><a href="#to_node-147"><span class="linenos">147</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Union</span><span class="p">):</span>
+</span><span id="to_node-148"><a href="#to_node-148"><span class="linenos">148</span></a> <span class="n">upstream</span> <span class="o">=</span> <span class="n">upstream</span> <span class="ow">or</span> <span class="n">Node</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;UNION&quot;</span><span class="p">,</span> <span class="n">source</span><span class="o">=</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">select</span><span class="p">)</span>
+</span><span id="to_node-149"><a href="#to_node-149"><span class="linenos">149</span></a>
+</span><span id="to_node-150"><a href="#to_node-150"><span class="linenos">150</span></a> <span class="n">index</span> <span class="o">=</span> <span class="p">(</span>
+</span><span id="to_node-151"><a href="#to_node-151"><span class="linenos">151</span></a> <span class="n">column</span>
+</span><span id="to_node-152"><a href="#to_node-152"><span class="linenos">152</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">column</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
+</span><span id="to_node-153"><a href="#to_node-153"><span class="linenos">153</span></a> <span class="k">else</span> <span class="nb">next</span><span class="p">(</span>
+</span><span id="to_node-154"><a href="#to_node-154"><span class="linenos">154</span></a> <span class="p">(</span>
+</span><span id="to_node-155"><a href="#to_node-155"><span class="linenos">155</span></a> <span class="n">i</span>
+</span><span id="to_node-156"><a href="#to_node-156"><span class="linenos">156</span></a> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">select</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">selects</span><span class="p">)</span>
+</span><span id="to_node-157"><a href="#to_node-157"><span class="linenos">157</span></a> <span class="k">if</span> <span class="n">select</span><span class="o">.</span><span class="n">alias_or_name</span> <span class="o">==</span> <span class="n">column</span> <span class="ow">or</span> <span class="n">select</span><span class="o">.</span><span class="n">is_star</span>
+</span><span id="to_node-158"><a href="#to_node-158"><span class="linenos">158</span></a> <span class="p">),</span>
+</span><span id="to_node-159"><a href="#to_node-159"><span class="linenos">159</span></a> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="c1"># mypy will not allow a None here, but a negative index should never be returned</span>
+</span><span id="to_node-160"><a href="#to_node-160"><span class="linenos">160</span></a> <span class="p">)</span>
+</span><span id="to_node-161"><a href="#to_node-161"><span class="linenos">161</span></a> <span class="p">)</span>
+</span><span id="to_node-162"><a href="#to_node-162"><span class="linenos">162</span></a>
+</span><span id="to_node-163"><a href="#to_node-163"><span class="linenos">163</span></a> <span class="k">if</span> <span class="n">index</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
+</span><span id="to_node-164"><a href="#to_node-164"><span class="linenos">164</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Could not find </span><span class="si">{</span><span class="n">column</span><span class="si">}</span><span class="s2"> in </span><span class="si">{</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
+</span><span id="to_node-165"><a href="#to_node-165"><span class="linenos">165</span></a>
+</span><span id="to_node-166"><a href="#to_node-166"><span class="linenos">166</span></a> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">union_scopes</span><span class="p">:</span>
+</span><span id="to_node-167"><a href="#to_node-167"><span class="linenos">167</span></a> <span class="n">to_node</span><span class="p">(</span>
+</span><span id="to_node-168"><a href="#to_node-168"><span class="linenos">168</span></a> <span class="n">index</span><span class="p">,</span>
+</span><span id="to_node-169"><a href="#to_node-169"><span class="linenos">169</span></a> <span class="n">scope</span><span class="o">=</span><span class="n">s</span><span class="p">,</span>
+</span><span id="to_node-170"><a href="#to_node-170"><span class="linenos">170</span></a> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span>
+</span><span id="to_node-171"><a href="#to_node-171"><span class="linenos">171</span></a> <span class="n">upstream</span><span class="o">=</span><span class="n">upstream</span><span class="p">,</span>
+</span><span id="to_node-172"><a href="#to_node-172"><span class="linenos">172</span></a> <span class="n">source_name</span><span class="o">=</span><span class="n">source_name</span><span class="p">,</span>
+</span><span id="to_node-173"><a href="#to_node-173"><span class="linenos">173</span></a> <span class="n">reference_node_name</span><span class="o">=</span><span class="n">reference_node_name</span><span class="p">,</span>
+</span><span id="to_node-174"><a href="#to_node-174"><span class="linenos">174</span></a> <span class="p">)</span>
+</span><span id="to_node-175"><a href="#to_node-175"><span class="linenos">175</span></a>
+</span><span id="to_node-176"><a href="#to_node-176"><span class="linenos">176</span></a> <span class="k">return</span> <span class="n">upstream</span>
+</span><span id="to_node-177"><a href="#to_node-177"><span class="linenos">177</span></a>
+</span><span id="to_node-178"><a href="#to_node-178"><span class="linenos">178</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">):</span>
+</span><span id="to_node-179"><a href="#to_node-179"><span class="linenos">179</span></a> <span class="c1"># For better ergonomics in our node labels, replace the full select with</span>
+</span><span id="to_node-180"><a href="#to_node-180"><span class="linenos">180</span></a> <span class="c1"># a version that has only the column we care about.</span>
+</span><span id="to_node-181"><a href="#to_node-181"><span class="linenos">181</span></a> <span class="c1"># &quot;x&quot;, SELECT x, y FROM foo</span>
+</span><span id="to_node-182"><a href="#to_node-182"><span class="linenos">182</span></a> <span class="c1"># =&gt; &quot;x&quot;, SELECT x FROM foo</span>
+</span><span id="to_node-183"><a href="#to_node-183"><span class="linenos">183</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">t</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">append</span><span class="o">=</span><span class="kc">False</span><span class="p">))</span>
+</span><span id="to_node-184"><a href="#to_node-184"><span class="linenos">184</span></a> <span class="k">else</span><span class="p">:</span>
+</span><span id="to_node-185"><a href="#to_node-185"><span class="linenos">185</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">scope</span><span class="o">.</span><span class="n">expression</span>
+</span><span id="to_node-186"><a href="#to_node-186"><span class="linenos">186</span></a>
+</span><span id="to_node-187"><a href="#to_node-187"><span class="linenos">187</span></a> <span class="c1"># Create the node for this step in the lineage chain, and attach it to the previous one.</span>
+</span><span id="to_node-188"><a href="#to_node-188"><span class="linenos">188</span></a> <span class="n">node</span> <span class="o">=</span> <span class="n">Node</span><span class="p">(</span>
+</span><span id="to_node-189"><a href="#to_node-189"><span class="linenos">189</span></a> <span class="n">name</span><span class="o">=</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">scope_name</span><span class="si">}</span><span class="s2">.</span><span class="si">{</span><span class="n">column</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">if</span> <span class="n">scope_name</span> <span class="k">else</span> <span class="nb">str</span><span class="p">(</span><span class="n">column</span><span class="p">),</span>
+</span><span id="to_node-190"><a href="#to_node-190"><span class="linenos">190</span></a> <span class="n">source</span><span class="o">=</span><span class="n">source</span><span class="p">,</span>
+</span><span id="to_node-191"><a href="#to_node-191"><span class="linenos">191</span></a> <span class="n">expression</span><span class="o">=</span><span class="n">select</span><span class="p">,</span>
+</span><span id="to_node-192"><a href="#to_node-192"><span class="linenos">192</span></a> <span class="n">source_name</span><span class="o">=</span><span class="n">source_name</span> <span class="ow">or</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
+</span><span id="to_node-193"><a href="#to_node-193"><span class="linenos">193</span></a> <span class="n">reference_node_name</span><span class="o">=</span><span class="n">reference_node_name</span> <span class="ow">or</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
+</span><span id="to_node-194"><a href="#to_node-194"><span class="linenos">194</span></a> <span class="p">)</span>
+</span><span id="to_node-195"><a href="#to_node-195"><span class="linenos">195</span></a>
+</span><span id="to_node-196"><a href="#to_node-196"><span class="linenos">196</span></a> <span class="k">if</span> <span class="n">upstream</span><span class="p">:</span>
+</span><span id="to_node-197"><a href="#to_node-197"><span class="linenos">197</span></a> <span class="n">upstream</span><span class="o">.</span><span class="n">downstream</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
+</span><span id="to_node-198"><a href="#to_node-198"><span class="linenos">198</span></a>
+</span><span id="to_node-199"><a href="#to_node-199"><span class="linenos">199</span></a> <span class="n">subquery_scopes</span> <span class="o">=</span> <span class="p">{</span>
+</span><span id="to_node-200"><a href="#to_node-200"><span class="linenos">200</span></a> <span class="nb">id</span><span class="p">(</span><span class="n">subquery_scope</span><span class="o">.</span><span class="n">expression</span><span class="p">):</span> <span class="n">subquery_scope</span> <span class="k">for</span> <span class="n">subquery_scope</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">subquery_scopes</span>
+</span><span id="to_node-201"><a href="#to_node-201"><span class="linenos">201</span></a> <span class="p">}</span>
+</span><span id="to_node-202"><a href="#to_node-202"><span class="linenos">202</span></a>
+</span><span id="to_node-203"><a href="#to_node-203"><span class="linenos">203</span></a> <span class="k">for</span> <span class="n">subquery</span> <span class="ow">in</span> <span class="n">find_all_in_scope</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">UNWRAPPED_QUERIES</span><span class="p">):</span>
+</span><span id="to_node-204"><a href="#to_node-204"><span class="linenos">204</span></a> <span class="n">subquery_scope</span> <span class="o">=</span> <span class="n">subquery_scopes</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="nb">id</span><span class="p">(</span><span class="n">subquery</span><span class="p">))</span>
+</span><span id="to_node-205"><a href="#to_node-205"><span class="linenos">205</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">subquery_scope</span><span class="p">:</span>
+</span><span id="to_node-206"><a href="#to_node-206"><span class="linenos">206</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Unknown subquery scope: </span><span class="si">{</span><span class="n">subquery</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
+</span><span id="to_node-207"><a href="#to_node-207"><span class="linenos">207</span></a> <span class="k">continue</span>
+</span><span id="to_node-208"><a href="#to_node-208"><span class="linenos">208</span></a>
+</span><span id="to_node-209"><a href="#to_node-209"><span class="linenos">209</span></a> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">subquery</span><span class="o">.</span><span class="n">named_selects</span><span class="p">:</span>
+</span><span id="to_node-210"><a href="#to_node-210"><span class="linenos">210</span></a> <span class="n">to_node</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">scope</span><span class="o">=</span><span class="n">subquery_scope</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span> <span class="n">upstream</span><span class="o">=</span><span class="n">node</span><span class="p">)</span>
+</span><span id="to_node-211"><a href="#to_node-211"><span class="linenos">211</span></a>
+</span><span id="to_node-212"><a href="#to_node-212"><span class="linenos">212</span></a> <span class="c1"># if the select is a star add all scope sources as downstreams</span>
+</span><span id="to_node-213"><a href="#to_node-213"><span class="linenos">213</span></a> <span class="k">if</span> <span class="n">select</span><span class="o">.</span><span class="n">is_star</span><span class="p">:</span>
+</span><span id="to_node-214"><a href="#to_node-214"><span class="linenos">214</span></a> <span class="k">for</span> <span class="n">source</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
+</span><span id="to_node-215"><a href="#to_node-215"><span class="linenos">215</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Scope</span><span class="p">):</span>
+</span><span id="to_node-216"><a href="#to_node-216"><span class="linenos">216</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">expression</span>
+</span><span id="to_node-217"><a href="#to_node-217"><span class="linenos">217</span></a> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Node</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">select</span><span class="o">.</span><span class="n">sql</span><span class="p">(),</span> <span class="n">source</span><span class="o">=</span><span class="n">source</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">source</span><span class="p">))</span>
+</span><span id="to_node-218"><a href="#to_node-218"><span class="linenos">218</span></a>
+</span><span id="to_node-219"><a href="#to_node-219"><span class="linenos">219</span></a> <span class="c1"># Find all columns that went into creating this one to list their lineage nodes.</span>
+</span><span id="to_node-220"><a href="#to_node-220"><span class="linenos">220</span></a> <span class="n">source_columns</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">find_all_in_scope</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">))</span>
+</span><span id="to_node-221"><a href="#to_node-221"><span class="linenos">221</span></a>
+</span><span id="to_node-222"><a href="#to_node-222"><span class="linenos">222</span></a> <span class="c1"># If the source is a UDTF find columns used in the UTDF to generate the table</span>
+</span><span id="to_node-223"><a href="#to_node-223"><span class="linenos">223</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">UDTF</span><span class="p">):</span>
+</span><span id="to_node-224"><a href="#to_node-224"><span class="linenos">224</span></a> <span class="n">source_columns</span> <span class="o">|=</span> <span class="nb">set</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">find_all</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Column</span><span class="p">))</span>
+</span><span id="to_node-225"><a href="#to_node-225"><span class="linenos">225</span></a>
+</span><span id="to_node-226"><a href="#to_node-226"><span class="linenos">226</span></a> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">source_columns</span><span class="p">:</span>
+</span><span id="to_node-227"><a href="#to_node-227"><span class="linenos">227</span></a> <span class="n">table</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">table</span>
+</span><span id="to_node-228"><a href="#to_node-228"><span class="linenos">228</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">scope</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">table</span><span class="p">)</span>
+</span><span id="to_node-229"><a href="#to_node-229"><span class="linenos">229</span></a>
+</span><span id="to_node-230"><a href="#to_node-230"><span class="linenos">230</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Scope</span><span class="p">):</span>
+</span><span id="to_node-231"><a href="#to_node-231"><span class="linenos">231</span></a> <span class="n">selected_node</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">scope</span><span class="o">.</span><span class="n">selected_sources</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">table</span><span class="p">,</span> <span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">))</span>
+</span><span id="to_node-232"><a href="#to_node-232"><span class="linenos">232</span></a> <span class="c1"># The table itself came from a more specific scope. Recurse into that one using the unaliased column name.</span>
+</span><span id="to_node-233"><a href="#to_node-233"><span class="linenos">233</span></a> <span class="n">to_node</span><span class="p">(</span>
+</span><span id="to_node-234"><a href="#to_node-234"><span class="linenos">234</span></a> <span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
+</span><span id="to_node-235"><a href="#to_node-235"><span class="linenos">235</span></a> <span class="n">scope</span><span class="o">=</span><span class="n">source</span><span class="p">,</span>
+</span><span id="to_node-236"><a href="#to_node-236"><span class="linenos">236</span></a> <span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span>
+</span><span id="to_node-237"><a href="#to_node-237"><span class="linenos">237</span></a> <span class="n">scope_name</span><span class="o">=</span><span class="n">table</span><span class="p">,</span>
+</span><span id="to_node-238"><a href="#to_node-238"><span class="linenos">238</span></a> <span class="n">upstream</span><span class="o">=</span><span class="n">node</span><span class="p">,</span>
+</span><span id="to_node-239"><a href="#to_node-239"><span class="linenos">239</span></a> <span class="n">source_name</span><span class="o">=</span><span class="n">source_names</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">table</span><span class="p">)</span> <span class="ow">or</span> <span class="n">source_name</span><span class="p">,</span>
+</span><span id="to_node-240"><a href="#to_node-240"><span class="linenos">240</span></a> <span class="n">reference_node_name</span><span class="o">=</span><span class="n">selected_node</span><span class="o">.</span><span class="n">name</span> <span class="k">if</span> <span class="n">selected_node</span> <span class="k">else</span> <span class="kc">None</span><span class="p">,</span>
+</span><span id="to_node-241"><a href="#to_node-241"><span class="linenos">241</span></a> <span class="p">)</span>
+</span><span id="to_node-242"><a href="#to_node-242"><span class="linenos">242</span></a> <span class="k">else</span><span class="p">:</span>
+</span><span id="to_node-243"><a href="#to_node-243"><span class="linenos">243</span></a> <span class="c1"># The source is not a scope - we&#39;ve reached the end of the line. At this point, if a source is not found</span>
+</span><span id="to_node-244"><a href="#to_node-244"><span class="linenos">244</span></a> <span class="c1"># it means this column&#39;s lineage is unknown. This can happen if the definition of a source used in a query</span>
+</span><span id="to_node-245"><a href="#to_node-245"><span class="linenos">245</span></a> <span class="c1"># is not passed into the `sources` map.</span>
+</span><span id="to_node-246"><a href="#to_node-246"><span class="linenos">246</span></a> <span class="n">source</span> <span class="o">=</span> <span class="n">source</span> <span class="ow">or</span> <span class="n">exp</span><span class="o">.</span><span class="n">Placeholder</span><span class="p">()</span>
+</span><span id="to_node-247"><a href="#to_node-247"><span class="linenos">247</span></a> <span class="n">node</span><span class="o">.</span><span class="n">downstream</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Node</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">c</span><span class="o">.</span><span class="n">sql</span><span class="p">(),</span> <span class="n">source</span><span class="o">=</span><span class="n">source</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">source</span><span class="p">))</span>
+</span><span id="to_node-248"><a href="#to_node-248"><span class="linenos">248</span></a>
+</span><span id="to_node-249"><a href="#to_node-249"><span class="linenos">249</span></a> <span class="k">return</span> <span class="n">node</span>
+</span></pre></div>
+
+
+
+
+ </section>
<section id="GraphHTML">
<input id="GraphHTML-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
<div class="attr class">
@@ -834,82 +921,82 @@
</div>
<a class="headerlink" href="#GraphHTML"></a>
- <div class="pdoc-code codehilite"><pre><span></span><span id="GraphHTML-231"><a href="#GraphHTML-231"><span class="linenos">231</span></a><span class="k">class</span> <span class="nc">GraphHTML</span><span class="p">:</span>
-</span><span id="GraphHTML-232"><a href="#GraphHTML-232"><span class="linenos">232</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Node to HTML generator using vis.js.</span>
-</span><span id="GraphHTML-233"><a href="#GraphHTML-233"><span class="linenos">233</span></a>
-</span><span id="GraphHTML-234"><a href="#GraphHTML-234"><span class="linenos">234</span></a><span class="sd"> https://visjs.github.io/vis-network/docs/network/</span>
-</span><span id="GraphHTML-235"><a href="#GraphHTML-235"><span class="linenos">235</span></a><span class="sd"> &quot;&quot;&quot;</span>
-</span><span id="GraphHTML-236"><a href="#GraphHTML-236"><span class="linenos">236</span></a>
-</span><span id="GraphHTML-237"><a href="#GraphHTML-237"><span class="linenos">237</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
-</span><span id="GraphHTML-238"><a href="#GraphHTML-238"><span class="linenos">238</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">nodes</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">,</span> <span class="n">edges</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">,</span> <span class="n">imports</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="n">options</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
-</span><span id="GraphHTML-239"><a href="#GraphHTML-239"><span class="linenos">239</span></a> <span class="p">):</span>
-</span><span id="GraphHTML-240"><a href="#GraphHTML-240"><span class="linenos">240</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">imports</span> <span class="o">=</span> <span class="n">imports</span>
-</span><span id="GraphHTML-241"><a href="#GraphHTML-241"><span class="linenos">241</span></a>
-</span><span id="GraphHTML-242"><a href="#GraphHTML-242"><span class="linenos">242</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="p">{</span>
-</span><span id="GraphHTML-243"><a href="#GraphHTML-243"><span class="linenos">243</span></a> <span class="s2">&quot;height&quot;</span><span class="p">:</span> <span class="s2">&quot;500px&quot;</span><span class="p">,</span>
-</span><span id="GraphHTML-244"><a href="#GraphHTML-244"><span class="linenos">244</span></a> <span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="s2">&quot;100%&quot;</span><span class="p">,</span>
-</span><span id="GraphHTML-245"><a href="#GraphHTML-245"><span class="linenos">245</span></a> <span class="s2">&quot;layout&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML-246"><a href="#GraphHTML-246"><span class="linenos">246</span></a> <span class="s2">&quot;hierarchical&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML-247"><a href="#GraphHTML-247"><span class="linenos">247</span></a> <span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
-</span><span id="GraphHTML-248"><a href="#GraphHTML-248"><span class="linenos">248</span></a> <span class="s2">&quot;nodeSpacing&quot;</span><span class="p">:</span> <span class="mi">200</span><span class="p">,</span>
-</span><span id="GraphHTML-249"><a href="#GraphHTML-249"><span class="linenos">249</span></a> <span class="s2">&quot;sortMethod&quot;</span><span class="p">:</span> <span class="s2">&quot;directed&quot;</span><span class="p">,</span>
-</span><span id="GraphHTML-250"><a href="#GraphHTML-250"><span class="linenos">250</span></a> <span class="p">},</span>
-</span><span id="GraphHTML-251"><a href="#GraphHTML-251"><span class="linenos">251</span></a> <span class="p">},</span>
-</span><span id="GraphHTML-252"><a href="#GraphHTML-252"><span class="linenos">252</span></a> <span class="s2">&quot;interaction&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML-253"><a href="#GraphHTML-253"><span class="linenos">253</span></a> <span class="s2">&quot;dragNodes&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
-</span><span id="GraphHTML-254"><a href="#GraphHTML-254"><span class="linenos">254</span></a> <span class="s2">&quot;selectable&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
-</span><span id="GraphHTML-255"><a href="#GraphHTML-255"><span class="linenos">255</span></a> <span class="p">},</span>
-</span><span id="GraphHTML-256"><a href="#GraphHTML-256"><span class="linenos">256</span></a> <span class="s2">&quot;physics&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML-257"><a href="#GraphHTML-257"><span class="linenos">257</span></a> <span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
-</span><span id="GraphHTML-258"><a href="#GraphHTML-258"><span class="linenos">258</span></a> <span class="p">},</span>
-</span><span id="GraphHTML-259"><a href="#GraphHTML-259"><span class="linenos">259</span></a> <span class="s2">&quot;edges&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML-260"><a href="#GraphHTML-260"><span class="linenos">260</span></a> <span class="s2">&quot;arrows&quot;</span><span class="p">:</span> <span class="s2">&quot;to&quot;</span><span class="p">,</span>
-</span><span id="GraphHTML-261"><a href="#GraphHTML-261"><span class="linenos">261</span></a> <span class="p">},</span>
-</span><span id="GraphHTML-262"><a href="#GraphHTML-262"><span class="linenos">262</span></a> <span class="s2">&quot;nodes&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML-263"><a href="#GraphHTML-263"><span class="linenos">263</span></a> <span class="s2">&quot;font&quot;</span><span class="p">:</span> <span class="s2">&quot;20px monaco&quot;</span><span class="p">,</span>
-</span><span id="GraphHTML-264"><a href="#GraphHTML-264"><span class="linenos">264</span></a> <span class="s2">&quot;shape&quot;</span><span class="p">:</span> <span class="s2">&quot;box&quot;</span><span class="p">,</span>
-</span><span id="GraphHTML-265"><a href="#GraphHTML-265"><span class="linenos">265</span></a> <span class="s2">&quot;widthConstraint&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML-266"><a href="#GraphHTML-266"><span class="linenos">266</span></a> <span class="s2">&quot;maximum&quot;</span><span class="p">:</span> <span class="mi">300</span><span class="p">,</span>
-</span><span id="GraphHTML-267"><a href="#GraphHTML-267"><span class="linenos">267</span></a> <span class="p">},</span>
-</span><span id="GraphHTML-268"><a href="#GraphHTML-268"><span class="linenos">268</span></a> <span class="p">},</span>
-</span><span id="GraphHTML-269"><a href="#GraphHTML-269"><span class="linenos">269</span></a> <span class="o">**</span><span class="p">(</span><span class="n">options</span> <span class="ow">or</span> <span class="p">{}),</span>
-</span><span id="GraphHTML-270"><a href="#GraphHTML-270"><span class="linenos">270</span></a> <span class="p">}</span>
-</span><span id="GraphHTML-271"><a href="#GraphHTML-271"><span class="linenos">271</span></a>
-</span><span id="GraphHTML-272"><a href="#GraphHTML-272"><span class="linenos">272</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">nodes</span> <span class="o">=</span> <span class="n">nodes</span>
-</span><span id="GraphHTML-273"><a href="#GraphHTML-273"><span class="linenos">273</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">edges</span> <span class="o">=</span> <span class="n">edges</span>
-</span><span id="GraphHTML-274"><a href="#GraphHTML-274"><span class="linenos">274</span></a>
-</span><span id="GraphHTML-275"><a href="#GraphHTML-275"><span class="linenos">275</span></a> <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-</span><span id="GraphHTML-276"><a href="#GraphHTML-276"><span class="linenos">276</span></a> <span class="n">nodes</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodes</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>
-</span><span id="GraphHTML-277"><a href="#GraphHTML-277"><span class="linenos">277</span></a> <span class="n">edges</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">edges</span><span class="p">)</span>
-</span><span id="GraphHTML-278"><a href="#GraphHTML-278"><span class="linenos">278</span></a> <span class="n">options</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="p">)</span>
-</span><span id="GraphHTML-279"><a href="#GraphHTML-279"><span class="linenos">279</span></a> <span class="n">imports</span> <span class="o">=</span> <span class="p">(</span>
-</span><span id="GraphHTML-280"><a href="#GraphHTML-280"><span class="linenos">280</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;&lt;script type=&quot;text/javascript&quot; src=&quot;https://unpkg.com/vis-data@latest/peer/umd/vis-data.min.js&quot;&gt;&lt;/script&gt;</span>
-</span><span id="GraphHTML-281"><a href="#GraphHTML-281"><span class="linenos">281</span></a><span class="sd"> &lt;script type=&quot;text/javascript&quot; src=&quot;https://unpkg.com/vis-network@latest/peer/umd/vis-network.min.js&quot;&gt;&lt;/script&gt;</span>
-</span><span id="GraphHTML-282"><a href="#GraphHTML-282"><span class="linenos">282</span></a><span class="sd"> &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://unpkg.com/vis-network/styles/vis-network.min.css&quot; /&gt;&quot;&quot;&quot;</span>
-</span><span id="GraphHTML-283"><a href="#GraphHTML-283"><span class="linenos">283</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">imports</span>
-</span><span id="GraphHTML-284"><a href="#GraphHTML-284"><span class="linenos">284</span></a> <span class="k">else</span> <span class="s2">&quot;&quot;</span>
-</span><span id="GraphHTML-285"><a href="#GraphHTML-285"><span class="linenos">285</span></a> <span class="p">)</span>
-</span><span id="GraphHTML-286"><a href="#GraphHTML-286"><span class="linenos">286</span></a>
-</span><span id="GraphHTML-287"><a href="#GraphHTML-287"><span class="linenos">287</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">&quot;&quot;&quot;&lt;div&gt;</span>
-</span><span id="GraphHTML-288"><a href="#GraphHTML-288"><span class="linenos">288</span></a><span class="s2"> &lt;div id=&quot;sqlglot-lineage&quot;&gt;&lt;/div&gt;</span>
-</span><span id="GraphHTML-289"><a href="#GraphHTML-289"><span class="linenos">289</span></a><span class="s2"> </span><span class="si">{</span><span class="n">imports</span><span class="si">}</span>
-</span><span id="GraphHTML-290"><a href="#GraphHTML-290"><span class="linenos">290</span></a><span class="s2"> &lt;script type=&quot;text/javascript&quot;&gt;</span>
-</span><span id="GraphHTML-291"><a href="#GraphHTML-291"><span class="linenos">291</span></a><span class="s2"> var nodes = new vis.DataSet(</span><span class="si">{</span><span class="n">nodes</span><span class="si">}</span><span class="s2">)</span>
-</span><span id="GraphHTML-292"><a href="#GraphHTML-292"><span class="linenos">292</span></a><span class="s2"> nodes.forEach(row =&gt; row[&quot;title&quot;] = new DOMParser().parseFromString(row[&quot;title&quot;], &quot;text/html&quot;).body.childNodes[0])</span>
-</span><span id="GraphHTML-293"><a href="#GraphHTML-293"><span class="linenos">293</span></a>
-</span><span id="GraphHTML-294"><a href="#GraphHTML-294"><span class="linenos">294</span></a><span class="s2"> new vis.Network(</span>
-</span><span id="GraphHTML-295"><a href="#GraphHTML-295"><span class="linenos">295</span></a><span class="s2"> document.getElementById(&quot;sqlglot-lineage&quot;),</span>
-</span><span id="GraphHTML-296"><a href="#GraphHTML-296"><span class="linenos">296</span></a><span class="s2"> </span><span class="se">{{</span>
-</span><span id="GraphHTML-297"><a href="#GraphHTML-297"><span class="linenos">297</span></a><span class="s2"> nodes: nodes,</span>
-</span><span id="GraphHTML-298"><a href="#GraphHTML-298"><span class="linenos">298</span></a><span class="s2"> edges: new vis.DataSet(</span><span class="si">{</span><span class="n">edges</span><span class="si">}</span><span class="s2">)</span>
-</span><span id="GraphHTML-299"><a href="#GraphHTML-299"><span class="linenos">299</span></a><span class="s2"> </span><span class="se">}}</span><span class="s2">,</span>
-</span><span id="GraphHTML-300"><a href="#GraphHTML-300"><span class="linenos">300</span></a><span class="s2"> </span><span class="si">{</span><span class="n">options</span><span class="si">}</span><span class="s2">,</span>
-</span><span id="GraphHTML-301"><a href="#GraphHTML-301"><span class="linenos">301</span></a><span class="s2"> )</span>
-</span><span id="GraphHTML-302"><a href="#GraphHTML-302"><span class="linenos">302</span></a><span class="s2"> &lt;/script&gt;</span>
-</span><span id="GraphHTML-303"><a href="#GraphHTML-303"><span class="linenos">303</span></a><span class="s2">&lt;/div&gt;&quot;&quot;&quot;</span>
-</span><span id="GraphHTML-304"><a href="#GraphHTML-304"><span class="linenos">304</span></a>
-</span><span id="GraphHTML-305"><a href="#GraphHTML-305"><span class="linenos">305</span></a> <span class="k">def</span> <span class="nf">_repr_html_</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
-</span><span id="GraphHTML-306"><a href="#GraphHTML-306"><span class="linenos">306</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__str__</span><span class="p">()</span>
+ <div class="pdoc-code codehilite"><pre><span></span><span id="GraphHTML-252"><a href="#GraphHTML-252"><span class="linenos">252</span></a><span class="k">class</span> <span class="nc">GraphHTML</span><span class="p">:</span>
+</span><span id="GraphHTML-253"><a href="#GraphHTML-253"><span class="linenos">253</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;Node to HTML generator using vis.js.</span>
+</span><span id="GraphHTML-254"><a href="#GraphHTML-254"><span class="linenos">254</span></a>
+</span><span id="GraphHTML-255"><a href="#GraphHTML-255"><span class="linenos">255</span></a><span class="sd"> https://visjs.github.io/vis-network/docs/network/</span>
+</span><span id="GraphHTML-256"><a href="#GraphHTML-256"><span class="linenos">256</span></a><span class="sd"> &quot;&quot;&quot;</span>
+</span><span id="GraphHTML-257"><a href="#GraphHTML-257"><span class="linenos">257</span></a>
+</span><span id="GraphHTML-258"><a href="#GraphHTML-258"><span class="linenos">258</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
+</span><span id="GraphHTML-259"><a href="#GraphHTML-259"><span class="linenos">259</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">nodes</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">,</span> <span class="n">edges</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">,</span> <span class="n">imports</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="n">options</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
+</span><span id="GraphHTML-260"><a href="#GraphHTML-260"><span class="linenos">260</span></a> <span class="p">):</span>
+</span><span id="GraphHTML-261"><a href="#GraphHTML-261"><span class="linenos">261</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">imports</span> <span class="o">=</span> <span class="n">imports</span>
+</span><span id="GraphHTML-262"><a href="#GraphHTML-262"><span class="linenos">262</span></a>
+</span><span id="GraphHTML-263"><a href="#GraphHTML-263"><span class="linenos">263</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="p">{</span>
+</span><span id="GraphHTML-264"><a href="#GraphHTML-264"><span class="linenos">264</span></a> <span class="s2">&quot;height&quot;</span><span class="p">:</span> <span class="s2">&quot;500px&quot;</span><span class="p">,</span>
+</span><span id="GraphHTML-265"><a href="#GraphHTML-265"><span class="linenos">265</span></a> <span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="s2">&quot;100%&quot;</span><span class="p">,</span>
+</span><span id="GraphHTML-266"><a href="#GraphHTML-266"><span class="linenos">266</span></a> <span class="s2">&quot;layout&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML-267"><a href="#GraphHTML-267"><span class="linenos">267</span></a> <span class="s2">&quot;hierarchical&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML-268"><a href="#GraphHTML-268"><span class="linenos">268</span></a> <span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
+</span><span id="GraphHTML-269"><a href="#GraphHTML-269"><span class="linenos">269</span></a> <span class="s2">&quot;nodeSpacing&quot;</span><span class="p">:</span> <span class="mi">200</span><span class="p">,</span>
+</span><span id="GraphHTML-270"><a href="#GraphHTML-270"><span class="linenos">270</span></a> <span class="s2">&quot;sortMethod&quot;</span><span class="p">:</span> <span class="s2">&quot;directed&quot;</span><span class="p">,</span>
+</span><span id="GraphHTML-271"><a href="#GraphHTML-271"><span class="linenos">271</span></a> <span class="p">},</span>
+</span><span id="GraphHTML-272"><a href="#GraphHTML-272"><span class="linenos">272</span></a> <span class="p">},</span>
+</span><span id="GraphHTML-273"><a href="#GraphHTML-273"><span class="linenos">273</span></a> <span class="s2">&quot;interaction&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML-274"><a href="#GraphHTML-274"><span class="linenos">274</span></a> <span class="s2">&quot;dragNodes&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
+</span><span id="GraphHTML-275"><a href="#GraphHTML-275"><span class="linenos">275</span></a> <span class="s2">&quot;selectable&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
+</span><span id="GraphHTML-276"><a href="#GraphHTML-276"><span class="linenos">276</span></a> <span class="p">},</span>
+</span><span id="GraphHTML-277"><a href="#GraphHTML-277"><span class="linenos">277</span></a> <span class="s2">&quot;physics&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML-278"><a href="#GraphHTML-278"><span class="linenos">278</span></a> <span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
+</span><span id="GraphHTML-279"><a href="#GraphHTML-279"><span class="linenos">279</span></a> <span class="p">},</span>
+</span><span id="GraphHTML-280"><a href="#GraphHTML-280"><span class="linenos">280</span></a> <span class="s2">&quot;edges&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML-281"><a href="#GraphHTML-281"><span class="linenos">281</span></a> <span class="s2">&quot;arrows&quot;</span><span class="p">:</span> <span class="s2">&quot;to&quot;</span><span class="p">,</span>
+</span><span id="GraphHTML-282"><a href="#GraphHTML-282"><span class="linenos">282</span></a> <span class="p">},</span>
+</span><span id="GraphHTML-283"><a href="#GraphHTML-283"><span class="linenos">283</span></a> <span class="s2">&quot;nodes&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML-284"><a href="#GraphHTML-284"><span class="linenos">284</span></a> <span class="s2">&quot;font&quot;</span><span class="p">:</span> <span class="s2">&quot;20px monaco&quot;</span><span class="p">,</span>
+</span><span id="GraphHTML-285"><a href="#GraphHTML-285"><span class="linenos">285</span></a> <span class="s2">&quot;shape&quot;</span><span class="p">:</span> <span class="s2">&quot;box&quot;</span><span class="p">,</span>
+</span><span id="GraphHTML-286"><a href="#GraphHTML-286"><span class="linenos">286</span></a> <span class="s2">&quot;widthConstraint&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML-287"><a href="#GraphHTML-287"><span class="linenos">287</span></a> <span class="s2">&quot;maximum&quot;</span><span class="p">:</span> <span class="mi">300</span><span class="p">,</span>
+</span><span id="GraphHTML-288"><a href="#GraphHTML-288"><span class="linenos">288</span></a> <span class="p">},</span>
+</span><span id="GraphHTML-289"><a href="#GraphHTML-289"><span class="linenos">289</span></a> <span class="p">},</span>
+</span><span id="GraphHTML-290"><a href="#GraphHTML-290"><span class="linenos">290</span></a> <span class="o">**</span><span class="p">(</span><span class="n">options</span> <span class="ow">or</span> <span class="p">{}),</span>
+</span><span id="GraphHTML-291"><a href="#GraphHTML-291"><span class="linenos">291</span></a> <span class="p">}</span>
+</span><span id="GraphHTML-292"><a href="#GraphHTML-292"><span class="linenos">292</span></a>
+</span><span id="GraphHTML-293"><a href="#GraphHTML-293"><span class="linenos">293</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">nodes</span> <span class="o">=</span> <span class="n">nodes</span>
+</span><span id="GraphHTML-294"><a href="#GraphHTML-294"><span class="linenos">294</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">edges</span> <span class="o">=</span> <span class="n">edges</span>
+</span><span id="GraphHTML-295"><a href="#GraphHTML-295"><span class="linenos">295</span></a>
+</span><span id="GraphHTML-296"><a href="#GraphHTML-296"><span class="linenos">296</span></a> <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+</span><span id="GraphHTML-297"><a href="#GraphHTML-297"><span class="linenos">297</span></a> <span class="n">nodes</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodes</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>
+</span><span id="GraphHTML-298"><a href="#GraphHTML-298"><span class="linenos">298</span></a> <span class="n">edges</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">edges</span><span class="p">)</span>
+</span><span id="GraphHTML-299"><a href="#GraphHTML-299"><span class="linenos">299</span></a> <span class="n">options</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="p">)</span>
+</span><span id="GraphHTML-300"><a href="#GraphHTML-300"><span class="linenos">300</span></a> <span class="n">imports</span> <span class="o">=</span> <span class="p">(</span>
+</span><span id="GraphHTML-301"><a href="#GraphHTML-301"><span class="linenos">301</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;&lt;script type=&quot;text/javascript&quot; src=&quot;https://unpkg.com/vis-data@latest/peer/umd/vis-data.min.js&quot;&gt;&lt;/script&gt;</span>
+</span><span id="GraphHTML-302"><a href="#GraphHTML-302"><span class="linenos">302</span></a><span class="sd"> &lt;script type=&quot;text/javascript&quot; src=&quot;https://unpkg.com/vis-network@latest/peer/umd/vis-network.min.js&quot;&gt;&lt;/script&gt;</span>
+</span><span id="GraphHTML-303"><a href="#GraphHTML-303"><span class="linenos">303</span></a><span class="sd"> &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://unpkg.com/vis-network/styles/vis-network.min.css&quot; /&gt;&quot;&quot;&quot;</span>
+</span><span id="GraphHTML-304"><a href="#GraphHTML-304"><span class="linenos">304</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">imports</span>
+</span><span id="GraphHTML-305"><a href="#GraphHTML-305"><span class="linenos">305</span></a> <span class="k">else</span> <span class="s2">&quot;&quot;</span>
+</span><span id="GraphHTML-306"><a href="#GraphHTML-306"><span class="linenos">306</span></a> <span class="p">)</span>
+</span><span id="GraphHTML-307"><a href="#GraphHTML-307"><span class="linenos">307</span></a>
+</span><span id="GraphHTML-308"><a href="#GraphHTML-308"><span class="linenos">308</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">&quot;&quot;&quot;&lt;div&gt;</span>
+</span><span id="GraphHTML-309"><a href="#GraphHTML-309"><span class="linenos">309</span></a><span class="s2"> &lt;div id=&quot;sqlglot-lineage&quot;&gt;&lt;/div&gt;</span>
+</span><span id="GraphHTML-310"><a href="#GraphHTML-310"><span class="linenos">310</span></a><span class="s2"> </span><span class="si">{</span><span class="n">imports</span><span class="si">}</span>
+</span><span id="GraphHTML-311"><a href="#GraphHTML-311"><span class="linenos">311</span></a><span class="s2"> &lt;script type=&quot;text/javascript&quot;&gt;</span>
+</span><span id="GraphHTML-312"><a href="#GraphHTML-312"><span class="linenos">312</span></a><span class="s2"> var nodes = new vis.DataSet(</span><span class="si">{</span><span class="n">nodes</span><span class="si">}</span><span class="s2">)</span>
+</span><span id="GraphHTML-313"><a href="#GraphHTML-313"><span class="linenos">313</span></a><span class="s2"> nodes.forEach(row =&gt; row[&quot;title&quot;] = new DOMParser().parseFromString(row[&quot;title&quot;], &quot;text/html&quot;).body.childNodes[0])</span>
+</span><span id="GraphHTML-314"><a href="#GraphHTML-314"><span class="linenos">314</span></a>
+</span><span id="GraphHTML-315"><a href="#GraphHTML-315"><span class="linenos">315</span></a><span class="s2"> new vis.Network(</span>
+</span><span id="GraphHTML-316"><a href="#GraphHTML-316"><span class="linenos">316</span></a><span class="s2"> document.getElementById(&quot;sqlglot-lineage&quot;),</span>
+</span><span id="GraphHTML-317"><a href="#GraphHTML-317"><span class="linenos">317</span></a><span class="s2"> </span><span class="se">{{</span>
+</span><span id="GraphHTML-318"><a href="#GraphHTML-318"><span class="linenos">318</span></a><span class="s2"> nodes: nodes,</span>
+</span><span id="GraphHTML-319"><a href="#GraphHTML-319"><span class="linenos">319</span></a><span class="s2"> edges: new vis.DataSet(</span><span class="si">{</span><span class="n">edges</span><span class="si">}</span><span class="s2">)</span>
+</span><span id="GraphHTML-320"><a href="#GraphHTML-320"><span class="linenos">320</span></a><span class="s2"> </span><span class="se">}}</span><span class="s2">,</span>
+</span><span id="GraphHTML-321"><a href="#GraphHTML-321"><span class="linenos">321</span></a><span class="s2"> </span><span class="si">{</span><span class="n">options</span><span class="si">}</span><span class="s2">,</span>
+</span><span id="GraphHTML-322"><a href="#GraphHTML-322"><span class="linenos">322</span></a><span class="s2"> )</span>
+</span><span id="GraphHTML-323"><a href="#GraphHTML-323"><span class="linenos">323</span></a><span class="s2"> &lt;/script&gt;</span>
+</span><span id="GraphHTML-324"><a href="#GraphHTML-324"><span class="linenos">324</span></a><span class="s2">&lt;/div&gt;&quot;&quot;&quot;</span>
+</span><span id="GraphHTML-325"><a href="#GraphHTML-325"><span class="linenos">325</span></a>
+</span><span id="GraphHTML-326"><a href="#GraphHTML-326"><span class="linenos">326</span></a> <span class="k">def</span> <span class="nf">_repr_html_</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
+</span><span id="GraphHTML-327"><a href="#GraphHTML-327"><span class="linenos">327</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__str__</span><span class="p">()</span>
</span></pre></div>
@@ -929,43 +1016,43 @@
</div>
<a class="headerlink" href="#GraphHTML.__init__"></a>
- <div class="pdoc-code codehilite"><pre><span></span><span id="GraphHTML.__init__-237"><a href="#GraphHTML.__init__-237"><span class="linenos">237</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
-</span><span id="GraphHTML.__init__-238"><a href="#GraphHTML.__init__-238"><span class="linenos">238</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">nodes</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">,</span> <span class="n">edges</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">,</span> <span class="n">imports</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="n">options</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
-</span><span id="GraphHTML.__init__-239"><a href="#GraphHTML.__init__-239"><span class="linenos">239</span></a> <span class="p">):</span>
-</span><span id="GraphHTML.__init__-240"><a href="#GraphHTML.__init__-240"><span class="linenos">240</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">imports</span> <span class="o">=</span> <span class="n">imports</span>
-</span><span id="GraphHTML.__init__-241"><a href="#GraphHTML.__init__-241"><span class="linenos">241</span></a>
-</span><span id="GraphHTML.__init__-242"><a href="#GraphHTML.__init__-242"><span class="linenos">242</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="p">{</span>
-</span><span id="GraphHTML.__init__-243"><a href="#GraphHTML.__init__-243"><span class="linenos">243</span></a> <span class="s2">&quot;height&quot;</span><span class="p">:</span> <span class="s2">&quot;500px&quot;</span><span class="p">,</span>
-</span><span id="GraphHTML.__init__-244"><a href="#GraphHTML.__init__-244"><span class="linenos">244</span></a> <span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="s2">&quot;100%&quot;</span><span class="p">,</span>
-</span><span id="GraphHTML.__init__-245"><a href="#GraphHTML.__init__-245"><span class="linenos">245</span></a> <span class="s2">&quot;layout&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML.__init__-246"><a href="#GraphHTML.__init__-246"><span class="linenos">246</span></a> <span class="s2">&quot;hierarchical&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML.__init__-247"><a href="#GraphHTML.__init__-247"><span class="linenos">247</span></a> <span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
-</span><span id="GraphHTML.__init__-248"><a href="#GraphHTML.__init__-248"><span class="linenos">248</span></a> <span class="s2">&quot;nodeSpacing&quot;</span><span class="p">:</span> <span class="mi">200</span><span class="p">,</span>
-</span><span id="GraphHTML.__init__-249"><a href="#GraphHTML.__init__-249"><span class="linenos">249</span></a> <span class="s2">&quot;sortMethod&quot;</span><span class="p">:</span> <span class="s2">&quot;directed&quot;</span><span class="p">,</span>
-</span><span id="GraphHTML.__init__-250"><a href="#GraphHTML.__init__-250"><span class="linenos">250</span></a> <span class="p">},</span>
-</span><span id="GraphHTML.__init__-251"><a href="#GraphHTML.__init__-251"><span class="linenos">251</span></a> <span class="p">},</span>
-</span><span id="GraphHTML.__init__-252"><a href="#GraphHTML.__init__-252"><span class="linenos">252</span></a> <span class="s2">&quot;interaction&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML.__init__-253"><a href="#GraphHTML.__init__-253"><span class="linenos">253</span></a> <span class="s2">&quot;dragNodes&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
-</span><span id="GraphHTML.__init__-254"><a href="#GraphHTML.__init__-254"><span class="linenos">254</span></a> <span class="s2">&quot;selectable&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
-</span><span id="GraphHTML.__init__-255"><a href="#GraphHTML.__init__-255"><span class="linenos">255</span></a> <span class="p">},</span>
-</span><span id="GraphHTML.__init__-256"><a href="#GraphHTML.__init__-256"><span class="linenos">256</span></a> <span class="s2">&quot;physics&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML.__init__-257"><a href="#GraphHTML.__init__-257"><span class="linenos">257</span></a> <span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
-</span><span id="GraphHTML.__init__-258"><a href="#GraphHTML.__init__-258"><span class="linenos">258</span></a> <span class="p">},</span>
-</span><span id="GraphHTML.__init__-259"><a href="#GraphHTML.__init__-259"><span class="linenos">259</span></a> <span class="s2">&quot;edges&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML.__init__-260"><a href="#GraphHTML.__init__-260"><span class="linenos">260</span></a> <span class="s2">&quot;arrows&quot;</span><span class="p">:</span> <span class="s2">&quot;to&quot;</span><span class="p">,</span>
-</span><span id="GraphHTML.__init__-261"><a href="#GraphHTML.__init__-261"><span class="linenos">261</span></a> <span class="p">},</span>
-</span><span id="GraphHTML.__init__-262"><a href="#GraphHTML.__init__-262"><span class="linenos">262</span></a> <span class="s2">&quot;nodes&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML.__init__-263"><a href="#GraphHTML.__init__-263"><span class="linenos">263</span></a> <span class="s2">&quot;font&quot;</span><span class="p">:</span> <span class="s2">&quot;20px monaco&quot;</span><span class="p">,</span>
-</span><span id="GraphHTML.__init__-264"><a href="#GraphHTML.__init__-264"><span class="linenos">264</span></a> <span class="s2">&quot;shape&quot;</span><span class="p">:</span> <span class="s2">&quot;box&quot;</span><span class="p">,</span>
-</span><span id="GraphHTML.__init__-265"><a href="#GraphHTML.__init__-265"><span class="linenos">265</span></a> <span class="s2">&quot;widthConstraint&quot;</span><span class="p">:</span> <span class="p">{</span>
-</span><span id="GraphHTML.__init__-266"><a href="#GraphHTML.__init__-266"><span class="linenos">266</span></a> <span class="s2">&quot;maximum&quot;</span><span class="p">:</span> <span class="mi">300</span><span class="p">,</span>
-</span><span id="GraphHTML.__init__-267"><a href="#GraphHTML.__init__-267"><span class="linenos">267</span></a> <span class="p">},</span>
-</span><span id="GraphHTML.__init__-268"><a href="#GraphHTML.__init__-268"><span class="linenos">268</span></a> <span class="p">},</span>
-</span><span id="GraphHTML.__init__-269"><a href="#GraphHTML.__init__-269"><span class="linenos">269</span></a> <span class="o">**</span><span class="p">(</span><span class="n">options</span> <span class="ow">or</span> <span class="p">{}),</span>
-</span><span id="GraphHTML.__init__-270"><a href="#GraphHTML.__init__-270"><span class="linenos">270</span></a> <span class="p">}</span>
-</span><span id="GraphHTML.__init__-271"><a href="#GraphHTML.__init__-271"><span class="linenos">271</span></a>
-</span><span id="GraphHTML.__init__-272"><a href="#GraphHTML.__init__-272"><span class="linenos">272</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">nodes</span> <span class="o">=</span> <span class="n">nodes</span>
-</span><span id="GraphHTML.__init__-273"><a href="#GraphHTML.__init__-273"><span class="linenos">273</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">edges</span> <span class="o">=</span> <span class="n">edges</span>
+ <div class="pdoc-code codehilite"><pre><span></span><span id="GraphHTML.__init__-258"><a href="#GraphHTML.__init__-258"><span class="linenos">258</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
+</span><span id="GraphHTML.__init__-259"><a href="#GraphHTML.__init__-259"><span class="linenos">259</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">nodes</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">,</span> <span class="n">edges</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">,</span> <span class="n">imports</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="n">options</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
+</span><span id="GraphHTML.__init__-260"><a href="#GraphHTML.__init__-260"><span class="linenos">260</span></a> <span class="p">):</span>
+</span><span id="GraphHTML.__init__-261"><a href="#GraphHTML.__init__-261"><span class="linenos">261</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">imports</span> <span class="o">=</span> <span class="n">imports</span>
+</span><span id="GraphHTML.__init__-262"><a href="#GraphHTML.__init__-262"><span class="linenos">262</span></a>
+</span><span id="GraphHTML.__init__-263"><a href="#GraphHTML.__init__-263"><span class="linenos">263</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="p">{</span>
+</span><span id="GraphHTML.__init__-264"><a href="#GraphHTML.__init__-264"><span class="linenos">264</span></a> <span class="s2">&quot;height&quot;</span><span class="p">:</span> <span class="s2">&quot;500px&quot;</span><span class="p">,</span>
+</span><span id="GraphHTML.__init__-265"><a href="#GraphHTML.__init__-265"><span class="linenos">265</span></a> <span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="s2">&quot;100%&quot;</span><span class="p">,</span>
+</span><span id="GraphHTML.__init__-266"><a href="#GraphHTML.__init__-266"><span class="linenos">266</span></a> <span class="s2">&quot;layout&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML.__init__-267"><a href="#GraphHTML.__init__-267"><span class="linenos">267</span></a> <span class="s2">&quot;hierarchical&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML.__init__-268"><a href="#GraphHTML.__init__-268"><span class="linenos">268</span></a> <span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
+</span><span id="GraphHTML.__init__-269"><a href="#GraphHTML.__init__-269"><span class="linenos">269</span></a> <span class="s2">&quot;nodeSpacing&quot;</span><span class="p">:</span> <span class="mi">200</span><span class="p">,</span>
+</span><span id="GraphHTML.__init__-270"><a href="#GraphHTML.__init__-270"><span class="linenos">270</span></a> <span class="s2">&quot;sortMethod&quot;</span><span class="p">:</span> <span class="s2">&quot;directed&quot;</span><span class="p">,</span>
+</span><span id="GraphHTML.__init__-271"><a href="#GraphHTML.__init__-271"><span class="linenos">271</span></a> <span class="p">},</span>
+</span><span id="GraphHTML.__init__-272"><a href="#GraphHTML.__init__-272"><span class="linenos">272</span></a> <span class="p">},</span>
+</span><span id="GraphHTML.__init__-273"><a href="#GraphHTML.__init__-273"><span class="linenos">273</span></a> <span class="s2">&quot;interaction&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML.__init__-274"><a href="#GraphHTML.__init__-274"><span class="linenos">274</span></a> <span class="s2">&quot;dragNodes&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
+</span><span id="GraphHTML.__init__-275"><a href="#GraphHTML.__init__-275"><span class="linenos">275</span></a> <span class="s2">&quot;selectable&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
+</span><span id="GraphHTML.__init__-276"><a href="#GraphHTML.__init__-276"><span class="linenos">276</span></a> <span class="p">},</span>
+</span><span id="GraphHTML.__init__-277"><a href="#GraphHTML.__init__-277"><span class="linenos">277</span></a> <span class="s2">&quot;physics&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML.__init__-278"><a href="#GraphHTML.__init__-278"><span class="linenos">278</span></a> <span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
+</span><span id="GraphHTML.__init__-279"><a href="#GraphHTML.__init__-279"><span class="linenos">279</span></a> <span class="p">},</span>
+</span><span id="GraphHTML.__init__-280"><a href="#GraphHTML.__init__-280"><span class="linenos">280</span></a> <span class="s2">&quot;edges&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML.__init__-281"><a href="#GraphHTML.__init__-281"><span class="linenos">281</span></a> <span class="s2">&quot;arrows&quot;</span><span class="p">:</span> <span class="s2">&quot;to&quot;</span><span class="p">,</span>
+</span><span id="GraphHTML.__init__-282"><a href="#GraphHTML.__init__-282"><span class="linenos">282</span></a> <span class="p">},</span>
+</span><span id="GraphHTML.__init__-283"><a href="#GraphHTML.__init__-283"><span class="linenos">283</span></a> <span class="s2">&quot;nodes&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML.__init__-284"><a href="#GraphHTML.__init__-284"><span class="linenos">284</span></a> <span class="s2">&quot;font&quot;</span><span class="p">:</span> <span class="s2">&quot;20px monaco&quot;</span><span class="p">,</span>
+</span><span id="GraphHTML.__init__-285"><a href="#GraphHTML.__init__-285"><span class="linenos">285</span></a> <span class="s2">&quot;shape&quot;</span><span class="p">:</span> <span class="s2">&quot;box&quot;</span><span class="p">,</span>
+</span><span id="GraphHTML.__init__-286"><a href="#GraphHTML.__init__-286"><span class="linenos">286</span></a> <span class="s2">&quot;widthConstraint&quot;</span><span class="p">:</span> <span class="p">{</span>
+</span><span id="GraphHTML.__init__-287"><a href="#GraphHTML.__init__-287"><span class="linenos">287</span></a> <span class="s2">&quot;maximum&quot;</span><span class="p">:</span> <span class="mi">300</span><span class="p">,</span>
+</span><span id="GraphHTML.__init__-288"><a href="#GraphHTML.__init__-288"><span class="linenos">288</span></a> <span class="p">},</span>
+</span><span id="GraphHTML.__init__-289"><a href="#GraphHTML.__init__-289"><span class="linenos">289</span></a> <span class="p">},</span>
+</span><span id="GraphHTML.__init__-290"><a href="#GraphHTML.__init__-290"><span class="linenos">290</span></a> <span class="o">**</span><span class="p">(</span><span class="n">options</span> <span class="ow">or</span> <span class="p">{}),</span>
+</span><span id="GraphHTML.__init__-291"><a href="#GraphHTML.__init__-291"><span class="linenos">291</span></a> <span class="p">}</span>
+</span><span id="GraphHTML.__init__-292"><a href="#GraphHTML.__init__-292"><span class="linenos">292</span></a>
+</span><span id="GraphHTML.__init__-293"><a href="#GraphHTML.__init__-293"><span class="linenos">293</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">nodes</span> <span class="o">=</span> <span class="n">nodes</span>
+</span><span id="GraphHTML.__init__-294"><a href="#GraphHTML.__init__-294"><span class="linenos">294</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">edges</span> <span class="o">=</span> <span class="n">edges</span>
</span></pre></div>