diff options
Diffstat (limited to '')
-rw-r--r-- | docs/sqlglot/optimizer/isolate_table_selects.html | 74 |
1 files changed, 42 insertions, 32 deletions
diff --git a/docs/sqlglot/optimizer/isolate_table_selects.html b/docs/sqlglot/optimizer/isolate_table_selects.html index 2d6be53..7c54854 100644 --- a/docs/sqlglot/optimizer/isolate_table_selects.html +++ b/docs/sqlglot/optimizer/isolate_table_selects.html @@ -70,22 +70,27 @@ </span><span id="L-12"><a href="#L-12"><span class="linenos">12</span></a> <span class="k">continue</span> </span><span id="L-13"><a href="#L-13"><span class="linenos">13</span></a> </span><span id="L-14"><a href="#L-14"><span class="linenos">14</span></a> <span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">source</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">selected_sources</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="L-15"><a href="#L-15"><span class="linenos">15</span></a> <span class="k">if</span> <span class="ow">not</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">Table</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">schema</span><span class="o">.</span><span class="n">column_names</span><span class="p">(</span><span class="n">source</span><span class="p">):</span> -</span><span id="L-16"><a href="#L-16"><span class="linenos">16</span></a> <span class="k">continue</span> -</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="k">if</span> <span class="ow">not</span> <span class="n">source</span><span class="o">.</span><span class="n">alias</span><span class="p">:</span> -</span><span id="L-19"><a href="#L-19"><span class="linenos">19</span></a> <span class="k">raise</span> <span class="n">OptimizeError</span><span class="p">(</span><span class="s2">"Tables require an alias. Run qualify_tables optimization."</span><span class="p">)</span> -</span><span id="L-20"><a href="#L-20"><span class="linenos">20</span></a> -</span><span id="L-21"><a href="#L-21"><span class="linenos">21</span></a> <span class="n">source</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span> -</span><span id="L-22"><a href="#L-22"><span class="linenos">22</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="s2">"*"</span><span class="p">)</span> -</span><span id="L-23"><a href="#L-23"><span class="linenos">23</span></a> <span class="o">.</span><span class="n">from_</span><span class="p">(</span> -</span><span id="L-24"><a href="#L-24"><span class="linenos">24</span></a> <span class="n">alias</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">source</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">,</span> <span class="n">table</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> -</span><span id="L-25"><a href="#L-25"><span class="linenos">25</span></a> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> -</span><span id="L-26"><a href="#L-26"><span class="linenos">26</span></a> <span class="p">)</span> -</span><span id="L-27"><a href="#L-27"><span class="linenos">27</span></a> <span class="o">.</span><span class="n">subquery</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">alias</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> -</span><span id="L-28"><a href="#L-28"><span class="linenos">28</span></a> <span class="p">)</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">return</span> <span class="n">expression</span> +</span><span id="L-15"><a href="#L-15"><span class="linenos">15</span></a> <span class="k">if</span> <span class="p">(</span> +</span><span id="L-16"><a href="#L-16"><span class="linenos">16</span></a> <span class="ow">not</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">Table</span><span class="p">)</span> +</span><span id="L-17"><a href="#L-17"><span class="linenos">17</span></a> <span class="ow">or</span> <span class="ow">not</span> <span class="n">schema</span><span class="o">.</span><span class="n">column_names</span><span class="p">(</span><span class="n">source</span><span class="p">)</span> +</span><span id="L-18"><a href="#L-18"><span class="linenos">18</span></a> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">parent</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Subquery</span><span class="p">)</span> +</span><span id="L-19"><a href="#L-19"><span class="linenos">19</span></a> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">parent</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-20"><a href="#L-20"><span class="linenos">20</span></a> <span class="p">):</span> +</span><span id="L-21"><a href="#L-21"><span class="linenos">21</span></a> <span class="k">continue</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">if</span> <span class="ow">not</span> <span class="n">source</span><span class="o">.</span><span class="n">alias</span><span class="p">:</span> +</span><span id="L-24"><a href="#L-24"><span class="linenos">24</span></a> <span class="k">raise</span> <span class="n">OptimizeError</span><span class="p">(</span><span class="s2">"Tables require an alias. Run qualify_tables optimization."</span><span class="p">)</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="n">source</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span> +</span><span id="L-27"><a href="#L-27"><span class="linenos">27</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="s2">"*"</span><span class="p">)</span> +</span><span id="L-28"><a href="#L-28"><span class="linenos">28</span></a> <span class="o">.</span><span class="n">from_</span><span class="p">(</span> +</span><span id="L-29"><a href="#L-29"><span class="linenos">29</span></a> <span class="n">alias</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">source</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">,</span> <span class="n">table</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> +</span><span id="L-30"><a href="#L-30"><span class="linenos">30</span></a> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> +</span><span id="L-31"><a href="#L-31"><span class="linenos">31</span></a> <span class="p">)</span> +</span><span id="L-32"><a href="#L-32"><span class="linenos">32</span></a> <span class="o">.</span><span class="n">subquery</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">alias</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span><span id="L-33"><a href="#L-33"><span class="linenos">33</span></a> <span class="p">)</span> +</span><span id="L-34"><a href="#L-34"><span class="linenos">34</span></a> +</span><span id="L-35"><a href="#L-35"><span class="linenos">35</span></a> <span class="k">return</span> <span class="n">expression</span> </span></pre></div> @@ -109,22 +114,27 @@ </span><span id="isolate_table_selects-13"><a href="#isolate_table_selects-13"><span class="linenos">13</span></a> <span class="k">continue</span> </span><span id="isolate_table_selects-14"><a href="#isolate_table_selects-14"><span class="linenos">14</span></a> </span><span id="isolate_table_selects-15"><a href="#isolate_table_selects-15"><span class="linenos">15</span></a> <span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">source</span> <span class="ow">in</span> <span class="n">scope</span><span class="o">.</span><span class="n">selected_sources</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="isolate_table_selects-16"><a href="#isolate_table_selects-16"><span class="linenos">16</span></a> <span class="k">if</span> <span class="ow">not</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">Table</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">schema</span><span class="o">.</span><span class="n">column_names</span><span class="p">(</span><span class="n">source</span><span class="p">):</span> -</span><span id="isolate_table_selects-17"><a href="#isolate_table_selects-17"><span class="linenos">17</span></a> <span class="k">continue</span> -</span><span id="isolate_table_selects-18"><a href="#isolate_table_selects-18"><span class="linenos">18</span></a> -</span><span id="isolate_table_selects-19"><a href="#isolate_table_selects-19"><span class="linenos">19</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">source</span><span class="o">.</span><span class="n">alias</span><span class="p">:</span> -</span><span id="isolate_table_selects-20"><a href="#isolate_table_selects-20"><span class="linenos">20</span></a> <span class="k">raise</span> <span class="n">OptimizeError</span><span class="p">(</span><span class="s2">"Tables require an alias. Run qualify_tables optimization."</span><span class="p">)</span> -</span><span id="isolate_table_selects-21"><a href="#isolate_table_selects-21"><span class="linenos">21</span></a> -</span><span id="isolate_table_selects-22"><a href="#isolate_table_selects-22"><span class="linenos">22</span></a> <span class="n">source</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span> -</span><span id="isolate_table_selects-23"><a href="#isolate_table_selects-23"><span class="linenos">23</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="s2">"*"</span><span class="p">)</span> -</span><span id="isolate_table_selects-24"><a href="#isolate_table_selects-24"><span class="linenos">24</span></a> <span class="o">.</span><span class="n">from_</span><span class="p">(</span> -</span><span id="isolate_table_selects-25"><a href="#isolate_table_selects-25"><span class="linenos">25</span></a> <span class="n">alias</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">source</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">,</span> <span class="n">table</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> -</span><span id="isolate_table_selects-26"><a href="#isolate_table_selects-26"><span class="linenos">26</span></a> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> -</span><span id="isolate_table_selects-27"><a href="#isolate_table_selects-27"><span class="linenos">27</span></a> <span class="p">)</span> -</span><span id="isolate_table_selects-28"><a href="#isolate_table_selects-28"><span class="linenos">28</span></a> <span class="o">.</span><span class="n">subquery</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">alias</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> -</span><span id="isolate_table_selects-29"><a href="#isolate_table_selects-29"><span class="linenos">29</span></a> <span class="p">)</span> -</span><span id="isolate_table_selects-30"><a href="#isolate_table_selects-30"><span class="linenos">30</span></a> -</span><span id="isolate_table_selects-31"><a href="#isolate_table_selects-31"><span class="linenos">31</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="isolate_table_selects-16"><a href="#isolate_table_selects-16"><span class="linenos">16</span></a> <span class="k">if</span> <span class="p">(</span> +</span><span id="isolate_table_selects-17"><a href="#isolate_table_selects-17"><span class="linenos">17</span></a> <span class="ow">not</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">Table</span><span class="p">)</span> +</span><span id="isolate_table_selects-18"><a href="#isolate_table_selects-18"><span class="linenos">18</span></a> <span class="ow">or</span> <span class="ow">not</span> <span class="n">schema</span><span class="o">.</span><span class="n">column_names</span><span class="p">(</span><span class="n">source</span><span class="p">)</span> +</span><span id="isolate_table_selects-19"><a href="#isolate_table_selects-19"><span class="linenos">19</span></a> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">parent</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Subquery</span><span class="p">)</span> +</span><span id="isolate_table_selects-20"><a href="#isolate_table_selects-20"><span class="linenos">20</span></a> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">parent</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="isolate_table_selects-21"><a href="#isolate_table_selects-21"><span class="linenos">21</span></a> <span class="p">):</span> +</span><span id="isolate_table_selects-22"><a href="#isolate_table_selects-22"><span class="linenos">22</span></a> <span class="k">continue</span> +</span><span id="isolate_table_selects-23"><a href="#isolate_table_selects-23"><span class="linenos">23</span></a> +</span><span id="isolate_table_selects-24"><a href="#isolate_table_selects-24"><span class="linenos">24</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">source</span><span class="o">.</span><span class="n">alias</span><span class="p">:</span> +</span><span id="isolate_table_selects-25"><a href="#isolate_table_selects-25"><span class="linenos">25</span></a> <span class="k">raise</span> <span class="n">OptimizeError</span><span class="p">(</span><span class="s2">"Tables require an alias. Run qualify_tables optimization."</span><span class="p">)</span> +</span><span id="isolate_table_selects-26"><a href="#isolate_table_selects-26"><span class="linenos">26</span></a> +</span><span id="isolate_table_selects-27"><a href="#isolate_table_selects-27"><span class="linenos">27</span></a> <span class="n">source</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span> +</span><span id="isolate_table_selects-28"><a href="#isolate_table_selects-28"><span class="linenos">28</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="s2">"*"</span><span class="p">)</span> +</span><span id="isolate_table_selects-29"><a href="#isolate_table_selects-29"><span class="linenos">29</span></a> <span class="o">.</span><span class="n">from_</span><span class="p">(</span> +</span><span id="isolate_table_selects-30"><a href="#isolate_table_selects-30"><span class="linenos">30</span></a> <span class="n">alias</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">source</span><span class="o">.</span><span class="n">alias_or_name</span><span class="p">,</span> <span class="n">table</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> +</span><span id="isolate_table_selects-31"><a href="#isolate_table_selects-31"><span class="linenos">31</span></a> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> +</span><span id="isolate_table_selects-32"><a href="#isolate_table_selects-32"><span class="linenos">32</span></a> <span class="p">)</span> +</span><span id="isolate_table_selects-33"><a href="#isolate_table_selects-33"><span class="linenos">33</span></a> <span class="o">.</span><span class="n">subquery</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">alias</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span><span id="isolate_table_selects-34"><a href="#isolate_table_selects-34"><span class="linenos">34</span></a> <span class="p">)</span> +</span><span id="isolate_table_selects-35"><a href="#isolate_table_selects-35"><span class="linenos">35</span></a> +</span><span id="isolate_table_selects-36"><a href="#isolate_table_selects-36"><span class="linenos">36</span></a> <span class="k">return</span> <span class="n">expression</span> </span></pre></div> |