Adding upstream version 17.4.1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
d28371fcc4
commit
5c63f2bde9
78 changed files with 35859 additions and 34717 deletions
|
@ -354,6 +354,9 @@
|
|||
<li>
|
||||
<a class="function" href="#concat_to_dpipe_sql">concat_to_dpipe_sql</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="function" href="#regexp_extract_sql">regexp_extract_sql</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="function" href="#pivot_column_names">pivot_column_names</a>
|
||||
</li>
|
||||
|
@ -1002,27 +1005,36 @@
|
|||
</span><span id="L-620"><a href="#L-620"><span class="linenos">620</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">this</span><span class="p">)</span>
|
||||
</span><span id="L-621"><a href="#L-621"><span class="linenos">621</span></a>
|
||||
</span><span id="L-622"><a href="#L-622"><span class="linenos">622</span></a>
|
||||
</span><span id="L-623"><a href="#L-623"><span class="linenos">623</span></a><span class="c1"># Spark, DuckDB use (almost) the same naming scheme for the output columns of the PIVOT operator</span>
|
||||
</span><span id="L-624"><a href="#L-624"><span class="linenos">624</span></a><span class="k">def</span> <span class="nf">pivot_column_names</span><span class="p">(</span><span class="n">aggregations</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">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">],</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
|
||||
</span><span id="L-625"><a href="#L-625"><span class="linenos">625</span></a> <span class="n">names</span> <span class="o">=</span> <span class="p">[]</span>
|
||||
</span><span id="L-626"><a href="#L-626"><span class="linenos">626</span></a> <span class="k">for</span> <span class="n">agg</span> <span class="ow">in</span> <span class="n">aggregations</span><span class="p">:</span>
|
||||
</span><span id="L-627"><a href="#L-627"><span class="linenos">627</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">agg</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Alias</span><span class="p">):</span>
|
||||
</span><span id="L-628"><a href="#L-628"><span class="linenos">628</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg</span><span class="o">.</span><span class="n">alias</span><span class="p">)</span>
|
||||
</span><span id="L-629"><a href="#L-629"><span class="linenos">629</span></a> <span class="k">else</span><span class="p">:</span>
|
||||
</span><span id="L-630"><a href="#L-630"><span class="linenos">630</span></a><span class="w"> </span><span class="sd">"""</span>
|
||||
</span><span id="L-631"><a href="#L-631"><span class="linenos">631</span></a><span class="sd"> This case corresponds to aggregations without aliases being used as suffixes</span>
|
||||
</span><span id="L-632"><a href="#L-632"><span class="linenos">632</span></a><span class="sd"> (e.g. col_avg(foo)). We need to unquote identifiers because they're going to</span>
|
||||
</span><span id="L-633"><a href="#L-633"><span class="linenos">633</span></a><span class="sd"> be quoted in the base parser's `_parse_pivot` method, due to `to_identifier`.</span>
|
||||
</span><span id="L-634"><a href="#L-634"><span class="linenos">634</span></a><span class="sd"> Otherwise, we'd end up with `col_avg(`foo`)` (notice the double quotes).</span>
|
||||
</span><span id="L-635"><a href="#L-635"><span class="linenos">635</span></a><span class="sd"> """</span>
|
||||
</span><span id="L-636"><a href="#L-636"><span class="linenos">636</span></a> <span class="n">agg_all_unquoted</span> <span class="o">=</span> <span class="n">agg</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span>
|
||||
</span><span id="L-637"><a href="#L-637"><span class="linenos">637</span></a> <span class="k">lambda</span> <span class="n">node</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">quoted</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
|
||||
</span><span id="L-638"><a href="#L-638"><span class="linenos">638</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">)</span>
|
||||
</span><span id="L-639"><a href="#L-639"><span class="linenos">639</span></a> <span class="k">else</span> <span class="n">node</span>
|
||||
</span><span id="L-640"><a href="#L-640"><span class="linenos">640</span></a> <span class="p">)</span>
|
||||
</span><span id="L-641"><a href="#L-641"><span class="linenos">641</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg_all_unquoted</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="n">normalize_functions</span><span class="o">=</span><span class="s2">"lower"</span><span class="p">))</span>
|
||||
</span><span id="L-642"><a href="#L-642"><span class="linenos">642</span></a>
|
||||
</span><span id="L-643"><a href="#L-643"><span class="linenos">643</span></a> <span class="k">return</span> <span class="n">names</span>
|
||||
</span><span id="L-623"><a href="#L-623"><span class="linenos">623</span></a><span class="k">def</span> <span class="nf">regexp_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">RegexpExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span>
|
||||
</span><span id="L-624"><a href="#L-624"><span class="linenos">624</span></a> <span class="n">bad_args</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="p">(</span><span class="s2">"position"</span><span class="p">,</span> <span class="s2">"occurrence"</span><span class="p">,</span> <span class="s2">"parameters"</span><span class="p">)))</span>
|
||||
</span><span id="L-625"><a href="#L-625"><span class="linenos">625</span></a> <span class="k">if</span> <span class="n">bad_args</span><span class="p">:</span>
|
||||
</span><span id="L-626"><a href="#L-626"><span class="linenos">626</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"REGEXP_EXTRACT does not support the following arg(s): </span><span class="si">{</span><span class="n">bad_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
|
||||
</span><span id="L-627"><a href="#L-627"><span class="linenos">627</span></a>
|
||||
</span><span id="L-628"><a href="#L-628"><span class="linenos">628</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span>
|
||||
</span><span id="L-629"><a href="#L-629"><span class="linenos">629</span></a> <span class="s2">"REGEXP_EXTRACT"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</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">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"group"</span><span class="p">)</span>
|
||||
</span><span id="L-630"><a href="#L-630"><span class="linenos">630</span></a> <span class="p">)</span>
|
||||
</span><span id="L-631"><a href="#L-631"><span class="linenos">631</span></a>
|
||||
</span><span id="L-632"><a href="#L-632"><span class="linenos">632</span></a>
|
||||
</span><span id="L-633"><a href="#L-633"><span class="linenos">633</span></a><span class="k">def</span> <span class="nf">pivot_column_names</span><span class="p">(</span><span class="n">aggregations</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">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">],</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
|
||||
</span><span id="L-634"><a href="#L-634"><span class="linenos">634</span></a> <span class="n">names</span> <span class="o">=</span> <span class="p">[]</span>
|
||||
</span><span id="L-635"><a href="#L-635"><span class="linenos">635</span></a> <span class="k">for</span> <span class="n">agg</span> <span class="ow">in</span> <span class="n">aggregations</span><span class="p">:</span>
|
||||
</span><span id="L-636"><a href="#L-636"><span class="linenos">636</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">agg</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Alias</span><span class="p">):</span>
|
||||
</span><span id="L-637"><a href="#L-637"><span class="linenos">637</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg</span><span class="o">.</span><span class="n">alias</span><span class="p">)</span>
|
||||
</span><span id="L-638"><a href="#L-638"><span class="linenos">638</span></a> <span class="k">else</span><span class="p">:</span>
|
||||
</span><span id="L-639"><a href="#L-639"><span class="linenos">639</span></a><span class="w"> </span><span class="sd">"""</span>
|
||||
</span><span id="L-640"><a href="#L-640"><span class="linenos">640</span></a><span class="sd"> This case corresponds to aggregations without aliases being used as suffixes</span>
|
||||
</span><span id="L-641"><a href="#L-641"><span class="linenos">641</span></a><span class="sd"> (e.g. col_avg(foo)). We need to unquote identifiers because they're going to</span>
|
||||
</span><span id="L-642"><a href="#L-642"><span class="linenos">642</span></a><span class="sd"> be quoted in the base parser's `_parse_pivot` method, due to `to_identifier`.</span>
|
||||
</span><span id="L-643"><a href="#L-643"><span class="linenos">643</span></a><span class="sd"> Otherwise, we'd end up with `col_avg(`foo`)` (notice the double quotes).</span>
|
||||
</span><span id="L-644"><a href="#L-644"><span class="linenos">644</span></a><span class="sd"> """</span>
|
||||
</span><span id="L-645"><a href="#L-645"><span class="linenos">645</span></a> <span class="n">agg_all_unquoted</span> <span class="o">=</span> <span class="n">agg</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span>
|
||||
</span><span id="L-646"><a href="#L-646"><span class="linenos">646</span></a> <span class="k">lambda</span> <span class="n">node</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">quoted</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
|
||||
</span><span id="L-647"><a href="#L-647"><span class="linenos">647</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">)</span>
|
||||
</span><span id="L-648"><a href="#L-648"><span class="linenos">648</span></a> <span class="k">else</span> <span class="n">node</span>
|
||||
</span><span id="L-649"><a href="#L-649"><span class="linenos">649</span></a> <span class="p">)</span>
|
||||
</span><span id="L-650"><a href="#L-650"><span class="linenos">650</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg_all_unquoted</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="n">normalize_functions</span><span class="o">=</span><span class="s2">"lower"</span><span class="p">))</span>
|
||||
</span><span id="L-651"><a href="#L-651"><span class="linenos">651</span></a>
|
||||
</span><span id="L-652"><a href="#L-652"><span class="linenos">652</span></a> <span class="k">return</span> <span class="n">names</span>
|
||||
</span></pre></div>
|
||||
|
||||
|
||||
|
@ -3209,6 +3221,31 @@ columns are removed from the create statement.</p>
|
|||
|
||||
|
||||
|
||||
</section>
|
||||
<section id="regexp_extract_sql">
|
||||
<input id="regexp_extract_sql-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">regexp_extract_sql</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span><span class="p">:</span> <span class="n"><a href="../generator.html#Generator">sqlglot.generator.Generator</a></span>,</span><span class="param"> <span class="n">expression</span><span class="p">:</span> <span class="n"><a href="../expressions.html#RegexpExtract">sqlglot.expressions.RegexpExtract</a></span></span><span class="return-annotation">) -> <span class="nb">str</span>:</span></span>
|
||||
|
||||
<label class="view-source-button" for="regexp_extract_sql-view-source"><span>View Source</span></label>
|
||||
|
||||
</div>
|
||||
<a class="headerlink" href="#regexp_extract_sql"></a>
|
||||
<div class="pdoc-code codehilite"><pre><span></span><span id="regexp_extract_sql-624"><a href="#regexp_extract_sql-624"><span class="linenos">624</span></a><span class="k">def</span> <span class="nf">regexp_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">RegexpExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span>
|
||||
</span><span id="regexp_extract_sql-625"><a href="#regexp_extract_sql-625"><span class="linenos">625</span></a> <span class="n">bad_args</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="p">(</span><span class="s2">"position"</span><span class="p">,</span> <span class="s2">"occurrence"</span><span class="p">,</span> <span class="s2">"parameters"</span><span class="p">)))</span>
|
||||
</span><span id="regexp_extract_sql-626"><a href="#regexp_extract_sql-626"><span class="linenos">626</span></a> <span class="k">if</span> <span class="n">bad_args</span><span class="p">:</span>
|
||||
</span><span id="regexp_extract_sql-627"><a href="#regexp_extract_sql-627"><span class="linenos">627</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"REGEXP_EXTRACT does not support the following arg(s): </span><span class="si">{</span><span class="n">bad_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
|
||||
</span><span id="regexp_extract_sql-628"><a href="#regexp_extract_sql-628"><span class="linenos">628</span></a>
|
||||
</span><span id="regexp_extract_sql-629"><a href="#regexp_extract_sql-629"><span class="linenos">629</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span>
|
||||
</span><span id="regexp_extract_sql-630"><a href="#regexp_extract_sql-630"><span class="linenos">630</span></a> <span class="s2">"REGEXP_EXTRACT"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</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">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"group"</span><span class="p">)</span>
|
||||
</span><span id="regexp_extract_sql-631"><a href="#regexp_extract_sql-631"><span class="linenos">631</span></a> <span class="p">)</span>
|
||||
</span></pre></div>
|
||||
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
<section id="pivot_column_names">
|
||||
<input id="pivot_column_names-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
|
||||
|
@ -3221,26 +3258,26 @@ columns are removed from the create statement.</p>
|
|||
|
||||
</div>
|
||||
<a class="headerlink" href="#pivot_column_names"></a>
|
||||
<div class="pdoc-code codehilite"><pre><span></span><span id="pivot_column_names-625"><a href="#pivot_column_names-625"><span class="linenos">625</span></a><span class="k">def</span> <span class="nf">pivot_column_names</span><span class="p">(</span><span class="n">aggregations</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">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">],</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
|
||||
</span><span id="pivot_column_names-626"><a href="#pivot_column_names-626"><span class="linenos">626</span></a> <span class="n">names</span> <span class="o">=</span> <span class="p">[]</span>
|
||||
</span><span id="pivot_column_names-627"><a href="#pivot_column_names-627"><span class="linenos">627</span></a> <span class="k">for</span> <span class="n">agg</span> <span class="ow">in</span> <span class="n">aggregations</span><span class="p">:</span>
|
||||
</span><span id="pivot_column_names-628"><a href="#pivot_column_names-628"><span class="linenos">628</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">agg</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Alias</span><span class="p">):</span>
|
||||
</span><span id="pivot_column_names-629"><a href="#pivot_column_names-629"><span class="linenos">629</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg</span><span class="o">.</span><span class="n">alias</span><span class="p">)</span>
|
||||
</span><span id="pivot_column_names-630"><a href="#pivot_column_names-630"><span class="linenos">630</span></a> <span class="k">else</span><span class="p">:</span>
|
||||
</span><span id="pivot_column_names-631"><a href="#pivot_column_names-631"><span class="linenos">631</span></a><span class="w"> </span><span class="sd">"""</span>
|
||||
</span><span id="pivot_column_names-632"><a href="#pivot_column_names-632"><span class="linenos">632</span></a><span class="sd"> This case corresponds to aggregations without aliases being used as suffixes</span>
|
||||
</span><span id="pivot_column_names-633"><a href="#pivot_column_names-633"><span class="linenos">633</span></a><span class="sd"> (e.g. col_avg(foo)). We need to unquote identifiers because they're going to</span>
|
||||
</span><span id="pivot_column_names-634"><a href="#pivot_column_names-634"><span class="linenos">634</span></a><span class="sd"> be quoted in the base parser's `_parse_pivot` method, due to `to_identifier`.</span>
|
||||
</span><span id="pivot_column_names-635"><a href="#pivot_column_names-635"><span class="linenos">635</span></a><span class="sd"> Otherwise, we'd end up with `col_avg(`foo`)` (notice the double quotes).</span>
|
||||
</span><span id="pivot_column_names-636"><a href="#pivot_column_names-636"><span class="linenos">636</span></a><span class="sd"> """</span>
|
||||
</span><span id="pivot_column_names-637"><a href="#pivot_column_names-637"><span class="linenos">637</span></a> <span class="n">agg_all_unquoted</span> <span class="o">=</span> <span class="n">agg</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span>
|
||||
</span><span id="pivot_column_names-638"><a href="#pivot_column_names-638"><span class="linenos">638</span></a> <span class="k">lambda</span> <span class="n">node</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">quoted</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
|
||||
</span><span id="pivot_column_names-639"><a href="#pivot_column_names-639"><span class="linenos">639</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">)</span>
|
||||
</span><span id="pivot_column_names-640"><a href="#pivot_column_names-640"><span class="linenos">640</span></a> <span class="k">else</span> <span class="n">node</span>
|
||||
</span><span id="pivot_column_names-641"><a href="#pivot_column_names-641"><span class="linenos">641</span></a> <span class="p">)</span>
|
||||
</span><span id="pivot_column_names-642"><a href="#pivot_column_names-642"><span class="linenos">642</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg_all_unquoted</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="n">normalize_functions</span><span class="o">=</span><span class="s2">"lower"</span><span class="p">))</span>
|
||||
</span><span id="pivot_column_names-643"><a href="#pivot_column_names-643"><span class="linenos">643</span></a>
|
||||
</span><span id="pivot_column_names-644"><a href="#pivot_column_names-644"><span class="linenos">644</span></a> <span class="k">return</span> <span class="n">names</span>
|
||||
<div class="pdoc-code codehilite"><pre><span></span><span id="pivot_column_names-634"><a href="#pivot_column_names-634"><span class="linenos">634</span></a><span class="k">def</span> <span class="nf">pivot_column_names</span><span class="p">(</span><span class="n">aggregations</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">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">],</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
|
||||
</span><span id="pivot_column_names-635"><a href="#pivot_column_names-635"><span class="linenos">635</span></a> <span class="n">names</span> <span class="o">=</span> <span class="p">[]</span>
|
||||
</span><span id="pivot_column_names-636"><a href="#pivot_column_names-636"><span class="linenos">636</span></a> <span class="k">for</span> <span class="n">agg</span> <span class="ow">in</span> <span class="n">aggregations</span><span class="p">:</span>
|
||||
</span><span id="pivot_column_names-637"><a href="#pivot_column_names-637"><span class="linenos">637</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">agg</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Alias</span><span class="p">):</span>
|
||||
</span><span id="pivot_column_names-638"><a href="#pivot_column_names-638"><span class="linenos">638</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg</span><span class="o">.</span><span class="n">alias</span><span class="p">)</span>
|
||||
</span><span id="pivot_column_names-639"><a href="#pivot_column_names-639"><span class="linenos">639</span></a> <span class="k">else</span><span class="p">:</span>
|
||||
</span><span id="pivot_column_names-640"><a href="#pivot_column_names-640"><span class="linenos">640</span></a><span class="w"> </span><span class="sd">"""</span>
|
||||
</span><span id="pivot_column_names-641"><a href="#pivot_column_names-641"><span class="linenos">641</span></a><span class="sd"> This case corresponds to aggregations without aliases being used as suffixes</span>
|
||||
</span><span id="pivot_column_names-642"><a href="#pivot_column_names-642"><span class="linenos">642</span></a><span class="sd"> (e.g. col_avg(foo)). We need to unquote identifiers because they're going to</span>
|
||||
</span><span id="pivot_column_names-643"><a href="#pivot_column_names-643"><span class="linenos">643</span></a><span class="sd"> be quoted in the base parser's `_parse_pivot` method, due to `to_identifier`.</span>
|
||||
</span><span id="pivot_column_names-644"><a href="#pivot_column_names-644"><span class="linenos">644</span></a><span class="sd"> Otherwise, we'd end up with `col_avg(`foo`)` (notice the double quotes).</span>
|
||||
</span><span id="pivot_column_names-645"><a href="#pivot_column_names-645"><span class="linenos">645</span></a><span class="sd"> """</span>
|
||||
</span><span id="pivot_column_names-646"><a href="#pivot_column_names-646"><span class="linenos">646</span></a> <span class="n">agg_all_unquoted</span> <span class="o">=</span> <span class="n">agg</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span>
|
||||
</span><span id="pivot_column_names-647"><a href="#pivot_column_names-647"><span class="linenos">647</span></a> <span class="k">lambda</span> <span class="n">node</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">quoted</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
|
||||
</span><span id="pivot_column_names-648"><a href="#pivot_column_names-648"><span class="linenos">648</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">)</span>
|
||||
</span><span id="pivot_column_names-649"><a href="#pivot_column_names-649"><span class="linenos">649</span></a> <span class="k">else</span> <span class="n">node</span>
|
||||
</span><span id="pivot_column_names-650"><a href="#pivot_column_names-650"><span class="linenos">650</span></a> <span class="p">)</span>
|
||||
</span><span id="pivot_column_names-651"><a href="#pivot_column_names-651"><span class="linenos">651</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg_all_unquoted</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="n">normalize_functions</span><span class="o">=</span><span class="s2">"lower"</span><span class="p">))</span>
|
||||
</span><span id="pivot_column_names-652"><a href="#pivot_column_names-652"><span class="linenos">652</span></a>
|
||||
</span><span id="pivot_column_names-653"><a href="#pivot_column_names-653"><span class="linenos">653</span></a> <span class="k">return</span> <span class="n">names</span>
|
||||
</span></pre></div>
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue