diff options
Diffstat (limited to 'docs/sqlglot/dialects/presto.html')
-rw-r--r-- | docs/sqlglot/dialects/presto.html | 1058 |
1 files changed, 629 insertions, 429 deletions
diff --git a/docs/sqlglot/dialects/presto.html b/docs/sqlglot/dialects/presto.html index d23baf6..63ae5ce 100644 --- a/docs/sqlglot/dialects/presto.html +++ b/docs/sqlglot/dialects/presto.html @@ -151,6 +151,9 @@ <a class="variable" href="#Presto.Generator.TRANSFORMS">TRANSFORMS</a> </li> <li> + <a class="variable" href="#Presto.Generator.RESERVED_KEYWORDS">RESERVED_KEYWORDS</a> + </li> + <li> <a class="function" href="#Presto.Generator.strtounix_sql">strtounix_sql</a> </li> <li> @@ -714,114 +717,175 @@ </span><span id="L-443"><a href="#L-443"><span class="linenos">443</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Xor</span><span class="p">:</span> <span class="n">bool_xor_sql</span><span class="p">,</span> </span><span id="L-444"><a href="#L-444"><span class="linenos">444</span></a> <span class="p">}</span> </span><span id="L-445"><a href="#L-445"><span class="linenos">445</span></a> -</span><span id="L-446"><a href="#L-446"><span class="linenos">446</span></a> <span class="k">def</span> <span class="nf">strtounix_sql</span><span class="p">(</span><span class="bp">self</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">StrToUnix</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-447"><a href="#L-447"><span class="linenos">447</span></a> <span class="c1"># Since `TO_UNIXTIME` requires a `TIMESTAMP`, we need to parse the argument into one.</span> -</span><span id="L-448"><a href="#L-448"><span class="linenos">448</span></a> <span class="c1"># To do this, we first try to `DATE_PARSE` it, but since this can fail when there's a</span> -</span><span id="L-449"><a href="#L-449"><span class="linenos">449</span></a> <span class="c1"># timezone involved, we wrap it in a `TRY` call and use `PARSE_DATETIME` as a fallback,</span> -</span><span id="L-450"><a href="#L-450"><span class="linenos">450</span></a> <span class="c1"># which seems to be using the same time mapping as Hive, as per:</span> -</span><span id="L-451"><a href="#L-451"><span class="linenos">451</span></a> <span class="c1"># https://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html</span> -</span><span id="L-452"><a href="#L-452"><span class="linenos">452</span></a> <span class="n">value_as_text</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</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">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TEXT</span><span class="p">)</span> -</span><span id="L-453"><a href="#L-453"><span class="linenos">453</span></a> <span class="n">parse_without_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DATE_PARSE"</span><span class="p">,</span> <span class="n">value_as_text</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">))</span> -</span><span id="L-454"><a href="#L-454"><span class="linenos">454</span></a> <span class="n">parse_with_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span> -</span><span id="L-455"><a href="#L-455"><span class="linenos">455</span></a> <span class="s2">"PARSE_DATETIME"</span><span class="p">,</span> -</span><span id="L-456"><a href="#L-456"><span class="linenos">456</span></a> <span class="n">value_as_text</span><span class="p">,</span> -</span><span id="L-457"><a href="#L-457"><span class="linenos">457</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_MAPPING</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_TRIE</span><span class="p">),</span> -</span><span id="L-458"><a href="#L-458"><span class="linenos">458</span></a> <span class="p">)</span> -</span><span id="L-459"><a href="#L-459"><span class="linenos">459</span></a> <span class="n">coalesced</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"COALESCE"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"TRY"</span><span class="p">,</span> <span class="n">parse_without_tz</span><span class="p">),</span> <span class="n">parse_with_tz</span><span class="p">)</span> -</span><span id="L-460"><a href="#L-460"><span class="linenos">460</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 class="s2">"TO_UNIXTIME"</span><span class="p">,</span> <span class="n">coalesced</span><span class="p">)</span> -</span><span id="L-461"><a href="#L-461"><span class="linenos">461</span></a> -</span><span id="L-462"><a href="#L-462"><span class="linenos">462</span></a> <span class="k">def</span> <span class="nf">bracket_sql</span><span class="p">(</span><span class="bp">self</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">Bracket</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-463"><a href="#L-463"><span class="linenos">463</span></a> <span class="k">if</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">"safe"</span><span class="p">):</span> -</span><span id="L-464"><a href="#L-464"><span class="linenos">464</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-465"><a href="#L-465"><span class="linenos">465</span></a> <span class="s2">"ELEMENT_AT"</span><span class="p">,</span> -</span><span id="L-466"><a href="#L-466"><span class="linenos">466</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="L-467"><a href="#L-467"><span class="linenos">467</span></a> <span class="n">seq_get</span><span class="p">(</span> -</span><span id="L-468"><a href="#L-468"><span class="linenos">468</span></a> <span class="n">apply_index_offset</span><span class="p">(</span> -</span><span id="L-469"><a href="#L-469"><span class="linenos">469</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="L-470"><a href="#L-470"><span class="linenos">470</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> -</span><span id="L-471"><a href="#L-471"><span class="linenos">471</span></a> <span class="mi">1</span> <span class="o">-</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">"offset"</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> -</span><span id="L-472"><a href="#L-472"><span class="linenos">472</span></a> <span class="p">),</span> -</span><span id="L-473"><a href="#L-473"><span class="linenos">473</span></a> <span class="mi">0</span><span class="p">,</span> -</span><span id="L-474"><a href="#L-474"><span class="linenos">474</span></a> <span class="p">),</span> -</span><span id="L-475"><a href="#L-475"><span class="linenos">475</span></a> <span class="p">)</span> -</span><span id="L-476"><a href="#L-476"><span class="linenos">476</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">bracket_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="L-477"><a href="#L-477"><span class="linenos">477</span></a> -</span><span id="L-478"><a href="#L-478"><span class="linenos">478</span></a> <span class="k">def</span> <span class="nf">struct_sql</span><span class="p">(</span><span class="bp">self</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">Struct</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-479"><a href="#L-479"><span class="linenos">479</span></a> <span class="kn">from</span> <span class="nn">sqlglot.optimizer.annotate_types</span> <span class="kn">import</span> <span class="n">annotate_types</span> -</span><span id="L-480"><a href="#L-480"><span class="linenos">480</span></a> -</span><span id="L-481"><a href="#L-481"><span class="linenos">481</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">annotate_types</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="L-482"><a href="#L-482"><span class="linenos">482</span></a> <span class="n">values</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="L-483"><a href="#L-483"><span class="linenos">483</span></a> <span class="n">schema</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="L-484"><a href="#L-484"><span class="linenos">484</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-485"><a href="#L-485"><span class="linenos">485</span></a> -</span><span id="L-486"><a href="#L-486"><span class="linenos">486</span></a> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> -</span><span id="L-487"><a href="#L-487"><span class="linenos">487</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">PropertyEQ</span><span class="p">):</span> -</span><span id="L-488"><a href="#L-488"><span class="linenos">488</span></a> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">UNKNOWN</span><span class="p">):</span> -</span><span id="L-489"><a href="#L-489"><span class="linenos">489</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="L-490"><a href="#L-490"><span class="linenos">490</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="L-491"><a href="#L-491"><span class="linenos">491</span></a> <span class="n">schema</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="L-492"><a href="#L-492"><span class="linenos">492</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="s2">"expression"</span><span class="p">))</span> -</span><span id="L-493"><a href="#L-493"><span class="linenos">493</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="L-494"><a href="#L-494"><span class="linenos">494</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">))</span> -</span><span id="L-495"><a href="#L-495"><span class="linenos">495</span></a> -</span><span id="L-496"><a href="#L-496"><span class="linenos">496</span></a> <span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">)</span> -</span><span id="L-497"><a href="#L-497"><span class="linenos">497</span></a> -</span><span id="L-498"><a href="#L-498"><span class="linenos">498</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">size</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span> <span class="o">!=</span> <span class="n">size</span><span class="p">:</span> -</span><span id="L-499"><a href="#L-499"><span class="linenos">499</span></a> <span class="k">if</span> <span class="n">unknown_type</span><span class="p">:</span> -</span><span id="L-500"><a href="#L-500"><span class="linenos">500</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span> -</span><span id="L-501"><a href="#L-501"><span class="linenos">501</span></a> <span class="s2">"Cannot convert untyped key-value definitions (try annotate_types)."</span> -</span><span id="L-502"><a href="#L-502"><span class="linenos">502</span></a> <span class="p">)</span> -</span><span id="L-503"><a href="#L-503"><span class="linenos">503</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 class="s2">"ROW"</span><span class="p">,</span> <span class="o">*</span><span class="n">values</span><span class="p">)</span> -</span><span id="L-504"><a href="#L-504"><span class="linenos">504</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"CAST(ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">values</span><span class="p">)</span><span class="si">}</span><span class="s2">) AS ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span><span class="si">}</span><span class="s2">))"</span> -</span><span id="L-505"><a href="#L-505"><span class="linenos">505</span></a> -</span><span id="L-506"><a href="#L-506"><span class="linenos">506</span></a> <span class="k">def</span> <span class="nf">interval_sql</span><span class="p">(</span><span class="bp">self</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">Interval</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-507"><a href="#L-507"><span class="linenos">507</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"unit"</span><span class="p">)</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"WEEK"</span><span class="p">):</span> -</span><span id="L-508"><a href="#L-508"><span class="linenos">508</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"(</span><span class="si">{</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> * INTERVAL '7' DAY)"</span> -</span><span id="L-509"><a href="#L-509"><span class="linenos">509</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">interval_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="L-510"><a href="#L-510"><span class="linenos">510</span></a> -</span><span id="L-511"><a href="#L-511"><span class="linenos">511</span></a> <span class="k">def</span> <span class="nf">transaction_sql</span><span class="p">(</span><span class="bp">self</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">Transaction</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-512"><a href="#L-512"><span class="linenos">512</span></a> <span class="n">modes</span> <span class="o">=</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">"modes"</span><span class="p">)</span> -</span><span id="L-513"><a href="#L-513"><span class="linenos">513</span></a> <span class="n">modes</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" </span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">modes</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">modes</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="L-514"><a href="#L-514"><span class="linenos">514</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"START TRANSACTION</span><span class="si">{</span><span class="n">modes</span><span class="si">}</span><span class="s2">"</span> -</span><span id="L-515"><a href="#L-515"><span class="linenos">515</span></a> -</span><span id="L-516"><a href="#L-516"><span class="linenos">516</span></a> <span class="k">def</span> <span class="nf">generateseries_sql</span><span class="p">(</span><span class="bp">self</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">GenerateSeries</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-517"><a href="#L-517"><span class="linenos">517</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"start"</span><span class="p">]</span> -</span><span id="L-518"><a href="#L-518"><span class="linenos">518</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"end"</span><span class="p">]</span> -</span><span id="L-519"><a href="#L-519"><span class="linenos">519</span></a> <span class="n">step</span> <span class="o">=</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">"step"</span><span class="p">)</span> -</span><span id="L-520"><a href="#L-520"><span class="linenos">520</span></a> -</span><span id="L-521"><a href="#L-521"><span class="linenos">521</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> -</span><span id="L-522"><a href="#L-522"><span class="linenos">522</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span> -</span><span id="L-523"><a href="#L-523"><span class="linenos">523</span></a> <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> -</span><span id="L-524"><a href="#L-524"><span class="linenos">524</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">end</span><span class="o">.</span><span class="n">to</span> -</span><span id="L-525"><a href="#L-525"><span class="linenos">525</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="L-526"><a href="#L-526"><span class="linenos">526</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-527"><a href="#L-527"><span class="linenos">527</span></a> -</span><span id="L-528"><a href="#L-528"><span class="linenos">528</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">and</span> <span class="n">target_type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"timestamp"</span><span class="p">):</span> -</span><span id="L-529"><a href="#L-529"><span class="linenos">529</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">is</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span><span class="p">:</span> -</span><span id="L-530"><a href="#L-530"><span class="linenos">530</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> -</span><span id="L-531"><a href="#L-531"><span class="linenos">531</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="L-532"><a href="#L-532"><span class="linenos">532</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> -</span><span id="L-533"><a href="#L-533"><span class="linenos">533</span></a> -</span><span id="L-534"><a href="#L-534"><span class="linenos">534</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 class="s2">"SEQUENCE"</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">step</span><span class="p">)</span> -</span><span id="L-535"><a href="#L-535"><span class="linenos">535</span></a> -</span><span id="L-536"><a href="#L-536"><span class="linenos">536</span></a> <span class="k">def</span> <span class="nf">offset_limit_modifiers</span><span class="p">(</span> -</span><span id="L-537"><a href="#L-537"><span class="linenos">537</span></a> <span class="bp">self</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">Expression</span><span class="p">,</span> <span class="n">fetch</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">limit</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">exp</span><span class="o">.</span><span class="n">Fetch</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Limit</span><span class="p">]</span> -</span><span id="L-538"><a href="#L-538"><span class="linenos">538</span></a> <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-539"><a href="#L-539"><span class="linenos">539</span></a> <span class="k">return</span> <span class="p">[</span> -</span><span id="L-540"><a href="#L-540"><span class="linenos">540</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"offset"</span><span class="p">),</span> -</span><span id="L-541"><a href="#L-541"><span class="linenos">541</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">limit</span><span class="p">),</span> -</span><span id="L-542"><a href="#L-542"><span class="linenos">542</span></a> <span class="p">]</span> -</span><span id="L-543"><a href="#L-543"><span class="linenos">543</span></a> -</span><span id="L-544"><a href="#L-544"><span class="linenos">544</span></a> <span class="k">def</span> <span class="nf">create_sql</span><span class="p">(</span><span class="bp">self</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">Create</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-545"><a href="#L-545"><span class="linenos">545</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-546"><a href="#L-546"><span class="linenos">546</span></a><span class="sd"> Presto doesn't support CREATE VIEW with expressions (ex: `CREATE VIEW x (cola)` then `(cola)` is the expression),</span> -</span><span id="L-547"><a href="#L-547"><span class="linenos">547</span></a><span class="sd"> so we need to remove them</span> -</span><span id="L-548"><a href="#L-548"><span class="linenos">548</span></a><span class="sd"> """</span> -</span><span id="L-549"><a href="#L-549"><span class="linenos">549</span></a> <span class="n">kind</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"kind"</span><span class="p">]</span> -</span><span id="L-550"><a href="#L-550"><span class="linenos">550</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> -</span><span id="L-551"><a href="#L-551"><span class="linenos">551</span></a> <span class="k">if</span> <span class="n">kind</span> <span class="o">==</span> <span class="s2">"VIEW"</span> <span class="ow">and</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> -</span><span id="L-552"><a href="#L-552"><span class="linenos">552</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> -</span><span id="L-553"><a href="#L-553"><span class="linenos">553</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">create_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-446"><a href="#L-446"><span class="linenos">446</span></a> <span class="n">RESERVED_KEYWORDS</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="L-447"><a href="#L-447"><span class="linenos">447</span></a> <span class="s2">"alter"</span><span class="p">,</span> +</span><span id="L-448"><a href="#L-448"><span class="linenos">448</span></a> <span class="s2">"and"</span><span class="p">,</span> +</span><span id="L-449"><a href="#L-449"><span class="linenos">449</span></a> <span class="s2">"as"</span><span class="p">,</span> +</span><span id="L-450"><a href="#L-450"><span class="linenos">450</span></a> <span class="s2">"between"</span><span class="p">,</span> +</span><span id="L-451"><a href="#L-451"><span class="linenos">451</span></a> <span class="s2">"by"</span><span class="p">,</span> +</span><span id="L-452"><a href="#L-452"><span class="linenos">452</span></a> <span class="s2">"case"</span><span class="p">,</span> +</span><span id="L-453"><a href="#L-453"><span class="linenos">453</span></a> <span class="s2">"cast"</span><span class="p">,</span> +</span><span id="L-454"><a href="#L-454"><span class="linenos">454</span></a> <span class="s2">"constraint"</span><span class="p">,</span> +</span><span id="L-455"><a href="#L-455"><span class="linenos">455</span></a> <span class="s2">"create"</span><span class="p">,</span> +</span><span id="L-456"><a href="#L-456"><span class="linenos">456</span></a> <span class="s2">"cross"</span><span class="p">,</span> +</span><span id="L-457"><a href="#L-457"><span class="linenos">457</span></a> <span class="s2">"current_time"</span><span class="p">,</span> +</span><span id="L-458"><a href="#L-458"><span class="linenos">458</span></a> <span class="s2">"current_timestamp"</span><span class="p">,</span> +</span><span id="L-459"><a href="#L-459"><span class="linenos">459</span></a> <span class="s2">"deallocate"</span><span class="p">,</span> +</span><span id="L-460"><a href="#L-460"><span class="linenos">460</span></a> <span class="s2">"delete"</span><span class="p">,</span> +</span><span id="L-461"><a href="#L-461"><span class="linenos">461</span></a> <span class="s2">"describe"</span><span class="p">,</span> +</span><span id="L-462"><a href="#L-462"><span class="linenos">462</span></a> <span class="s2">"distinct"</span><span class="p">,</span> +</span><span id="L-463"><a href="#L-463"><span class="linenos">463</span></a> <span class="s2">"drop"</span><span class="p">,</span> +</span><span id="L-464"><a href="#L-464"><span class="linenos">464</span></a> <span class="s2">"else"</span><span class="p">,</span> +</span><span id="L-465"><a href="#L-465"><span class="linenos">465</span></a> <span class="s2">"end"</span><span class="p">,</span> +</span><span id="L-466"><a href="#L-466"><span class="linenos">466</span></a> <span class="s2">"escape"</span><span class="p">,</span> +</span><span id="L-467"><a href="#L-467"><span class="linenos">467</span></a> <span class="s2">"except"</span><span class="p">,</span> +</span><span id="L-468"><a href="#L-468"><span class="linenos">468</span></a> <span class="s2">"execute"</span><span class="p">,</span> +</span><span id="L-469"><a href="#L-469"><span class="linenos">469</span></a> <span class="s2">"exists"</span><span class="p">,</span> +</span><span id="L-470"><a href="#L-470"><span class="linenos">470</span></a> <span class="s2">"extract"</span><span class="p">,</span> +</span><span id="L-471"><a href="#L-471"><span class="linenos">471</span></a> <span class="s2">"false"</span><span class="p">,</span> +</span><span id="L-472"><a href="#L-472"><span class="linenos">472</span></a> <span class="s2">"for"</span><span class="p">,</span> +</span><span id="L-473"><a href="#L-473"><span class="linenos">473</span></a> <span class="s2">"from"</span><span class="p">,</span> +</span><span id="L-474"><a href="#L-474"><span class="linenos">474</span></a> <span class="s2">"full"</span><span class="p">,</span> +</span><span id="L-475"><a href="#L-475"><span class="linenos">475</span></a> <span class="s2">"group"</span><span class="p">,</span> +</span><span id="L-476"><a href="#L-476"><span class="linenos">476</span></a> <span class="s2">"having"</span><span class="p">,</span> +</span><span id="L-477"><a href="#L-477"><span class="linenos">477</span></a> <span class="s2">"in"</span><span class="p">,</span> +</span><span id="L-478"><a href="#L-478"><span class="linenos">478</span></a> <span class="s2">"inner"</span><span class="p">,</span> +</span><span id="L-479"><a href="#L-479"><span class="linenos">479</span></a> <span class="s2">"insert"</span><span class="p">,</span> +</span><span id="L-480"><a href="#L-480"><span class="linenos">480</span></a> <span class="s2">"intersect"</span><span class="p">,</span> +</span><span id="L-481"><a href="#L-481"><span class="linenos">481</span></a> <span class="s2">"into"</span><span class="p">,</span> +</span><span id="L-482"><a href="#L-482"><span class="linenos">482</span></a> <span class="s2">"is"</span><span class="p">,</span> +</span><span id="L-483"><a href="#L-483"><span class="linenos">483</span></a> <span class="s2">"join"</span><span class="p">,</span> +</span><span id="L-484"><a href="#L-484"><span class="linenos">484</span></a> <span class="s2">"left"</span><span class="p">,</span> +</span><span id="L-485"><a href="#L-485"><span class="linenos">485</span></a> <span class="s2">"like"</span><span class="p">,</span> +</span><span id="L-486"><a href="#L-486"><span class="linenos">486</span></a> <span class="s2">"natural"</span><span class="p">,</span> +</span><span id="L-487"><a href="#L-487"><span class="linenos">487</span></a> <span class="s2">"not"</span><span class="p">,</span> +</span><span id="L-488"><a href="#L-488"><span class="linenos">488</span></a> <span class="s2">"null"</span><span class="p">,</span> +</span><span id="L-489"><a href="#L-489"><span class="linenos">489</span></a> <span class="s2">"on"</span><span class="p">,</span> +</span><span id="L-490"><a href="#L-490"><span class="linenos">490</span></a> <span class="s2">"or"</span><span class="p">,</span> +</span><span id="L-491"><a href="#L-491"><span class="linenos">491</span></a> <span class="s2">"order"</span><span class="p">,</span> +</span><span id="L-492"><a href="#L-492"><span class="linenos">492</span></a> <span class="s2">"outer"</span><span class="p">,</span> +</span><span id="L-493"><a href="#L-493"><span class="linenos">493</span></a> <span class="s2">"prepare"</span><span class="p">,</span> +</span><span id="L-494"><a href="#L-494"><span class="linenos">494</span></a> <span class="s2">"right"</span><span class="p">,</span> +</span><span id="L-495"><a href="#L-495"><span class="linenos">495</span></a> <span class="s2">"select"</span><span class="p">,</span> +</span><span id="L-496"><a href="#L-496"><span class="linenos">496</span></a> <span class="s2">"table"</span><span class="p">,</span> +</span><span id="L-497"><a href="#L-497"><span class="linenos">497</span></a> <span class="s2">"then"</span><span class="p">,</span> +</span><span id="L-498"><a href="#L-498"><span class="linenos">498</span></a> <span class="s2">"true"</span><span class="p">,</span> +</span><span id="L-499"><a href="#L-499"><span class="linenos">499</span></a> <span class="s2">"union"</span><span class="p">,</span> +</span><span id="L-500"><a href="#L-500"><span class="linenos">500</span></a> <span class="s2">"using"</span><span class="p">,</span> +</span><span id="L-501"><a href="#L-501"><span class="linenos">501</span></a> <span class="s2">"values"</span><span class="p">,</span> +</span><span id="L-502"><a href="#L-502"><span class="linenos">502</span></a> <span class="s2">"when"</span><span class="p">,</span> +</span><span id="L-503"><a href="#L-503"><span class="linenos">503</span></a> <span class="s2">"where"</span><span class="p">,</span> +</span><span id="L-504"><a href="#L-504"><span class="linenos">504</span></a> <span class="s2">"with"</span><span class="p">,</span> +</span><span id="L-505"><a href="#L-505"><span class="linenos">505</span></a> <span class="p">}</span> +</span><span id="L-506"><a href="#L-506"><span class="linenos">506</span></a> +</span><span id="L-507"><a href="#L-507"><span class="linenos">507</span></a> <span class="k">def</span> <span class="nf">strtounix_sql</span><span class="p">(</span><span class="bp">self</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">StrToUnix</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-508"><a href="#L-508"><span class="linenos">508</span></a> <span class="c1"># Since `TO_UNIXTIME` requires a `TIMESTAMP`, we need to parse the argument into one.</span> +</span><span id="L-509"><a href="#L-509"><span class="linenos">509</span></a> <span class="c1"># To do this, we first try to `DATE_PARSE` it, but since this can fail when there's a</span> +</span><span id="L-510"><a href="#L-510"><span class="linenos">510</span></a> <span class="c1"># timezone involved, we wrap it in a `TRY` call and use `PARSE_DATETIME` as a fallback,</span> +</span><span id="L-511"><a href="#L-511"><span class="linenos">511</span></a> <span class="c1"># which seems to be using the same time mapping as Hive, as per:</span> +</span><span id="L-512"><a href="#L-512"><span class="linenos">512</span></a> <span class="c1"># https://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html</span> +</span><span id="L-513"><a href="#L-513"><span class="linenos">513</span></a> <span class="n">value_as_text</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</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">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TEXT</span><span class="p">)</span> +</span><span id="L-514"><a href="#L-514"><span class="linenos">514</span></a> <span class="n">parse_without_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DATE_PARSE"</span><span class="p">,</span> <span class="n">value_as_text</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">))</span> +</span><span id="L-515"><a href="#L-515"><span class="linenos">515</span></a> <span class="n">parse_with_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span> +</span><span id="L-516"><a href="#L-516"><span class="linenos">516</span></a> <span class="s2">"PARSE_DATETIME"</span><span class="p">,</span> +</span><span id="L-517"><a href="#L-517"><span class="linenos">517</span></a> <span class="n">value_as_text</span><span class="p">,</span> +</span><span id="L-518"><a href="#L-518"><span class="linenos">518</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_MAPPING</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_TRIE</span><span class="p">),</span> +</span><span id="L-519"><a href="#L-519"><span class="linenos">519</span></a> <span class="p">)</span> +</span><span id="L-520"><a href="#L-520"><span class="linenos">520</span></a> <span class="n">coalesced</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"COALESCE"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"TRY"</span><span class="p">,</span> <span class="n">parse_without_tz</span><span class="p">),</span> <span class="n">parse_with_tz</span><span class="p">)</span> +</span><span id="L-521"><a href="#L-521"><span class="linenos">521</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 class="s2">"TO_UNIXTIME"</span><span class="p">,</span> <span class="n">coalesced</span><span class="p">)</span> +</span><span id="L-522"><a href="#L-522"><span class="linenos">522</span></a> +</span><span id="L-523"><a href="#L-523"><span class="linenos">523</span></a> <span class="k">def</span> <span class="nf">bracket_sql</span><span class="p">(</span><span class="bp">self</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">Bracket</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-524"><a href="#L-524"><span class="linenos">524</span></a> <span class="k">if</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">"safe"</span><span class="p">):</span> +</span><span id="L-525"><a href="#L-525"><span class="linenos">525</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-526"><a href="#L-526"><span class="linenos">526</span></a> <span class="s2">"ELEMENT_AT"</span><span class="p">,</span> +</span><span id="L-527"><a href="#L-527"><span class="linenos">527</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="L-528"><a href="#L-528"><span class="linenos">528</span></a> <span class="n">seq_get</span><span class="p">(</span> +</span><span id="L-529"><a href="#L-529"><span class="linenos">529</span></a> <span class="n">apply_index_offset</span><span class="p">(</span> +</span><span id="L-530"><a href="#L-530"><span class="linenos">530</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="L-531"><a href="#L-531"><span class="linenos">531</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> +</span><span id="L-532"><a href="#L-532"><span class="linenos">532</span></a> <span class="mi">1</span> <span class="o">-</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">"offset"</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> +</span><span id="L-533"><a href="#L-533"><span class="linenos">533</span></a> <span class="p">),</span> +</span><span id="L-534"><a href="#L-534"><span class="linenos">534</span></a> <span class="mi">0</span><span class="p">,</span> +</span><span id="L-535"><a href="#L-535"><span class="linenos">535</span></a> <span class="p">),</span> +</span><span id="L-536"><a href="#L-536"><span class="linenos">536</span></a> <span class="p">)</span> +</span><span id="L-537"><a href="#L-537"><span class="linenos">537</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">bracket_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-538"><a href="#L-538"><span class="linenos">538</span></a> +</span><span id="L-539"><a href="#L-539"><span class="linenos">539</span></a> <span class="k">def</span> <span class="nf">struct_sql</span><span class="p">(</span><span class="bp">self</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">Struct</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-540"><a href="#L-540"><span class="linenos">540</span></a> <span class="kn">from</span> <span class="nn">sqlglot.optimizer.annotate_types</span> <span class="kn">import</span> <span class="n">annotate_types</span> +</span><span id="L-541"><a href="#L-541"><span class="linenos">541</span></a> +</span><span id="L-542"><a href="#L-542"><span class="linenos">542</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">annotate_types</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-543"><a href="#L-543"><span class="linenos">543</span></a> <span class="n">values</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="L-544"><a href="#L-544"><span class="linenos">544</span></a> <span class="n">schema</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="L-545"><a href="#L-545"><span class="linenos">545</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-546"><a href="#L-546"><span class="linenos">546</span></a> +</span><span id="L-547"><a href="#L-547"><span class="linenos">547</span></a> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="L-548"><a href="#L-548"><span class="linenos">548</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">PropertyEQ</span><span class="p">):</span> +</span><span id="L-549"><a href="#L-549"><span class="linenos">549</span></a> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">UNKNOWN</span><span class="p">):</span> +</span><span id="L-550"><a href="#L-550"><span class="linenos">550</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="L-551"><a href="#L-551"><span class="linenos">551</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="L-552"><a href="#L-552"><span class="linenos">552</span></a> <span class="n">schema</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="L-553"><a href="#L-553"><span class="linenos">553</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="s2">"expression"</span><span class="p">))</span> +</span><span id="L-554"><a href="#L-554"><span class="linenos">554</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="L-555"><a href="#L-555"><span class="linenos">555</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">))</span> +</span><span id="L-556"><a href="#L-556"><span class="linenos">556</span></a> +</span><span id="L-557"><a href="#L-557"><span class="linenos">557</span></a> <span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">)</span> +</span><span id="L-558"><a href="#L-558"><span class="linenos">558</span></a> +</span><span id="L-559"><a href="#L-559"><span class="linenos">559</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">size</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span> <span class="o">!=</span> <span class="n">size</span><span class="p">:</span> +</span><span id="L-560"><a href="#L-560"><span class="linenos">560</span></a> <span class="k">if</span> <span class="n">unknown_type</span><span class="p">:</span> +</span><span id="L-561"><a href="#L-561"><span class="linenos">561</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span> +</span><span id="L-562"><a href="#L-562"><span class="linenos">562</span></a> <span class="s2">"Cannot convert untyped key-value definitions (try annotate_types)."</span> +</span><span id="L-563"><a href="#L-563"><span class="linenos">563</span></a> <span class="p">)</span> +</span><span id="L-564"><a href="#L-564"><span class="linenos">564</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 class="s2">"ROW"</span><span class="p">,</span> <span class="o">*</span><span class="n">values</span><span class="p">)</span> +</span><span id="L-565"><a href="#L-565"><span class="linenos">565</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"CAST(ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">values</span><span class="p">)</span><span class="si">}</span><span class="s2">) AS ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span><span class="si">}</span><span class="s2">))"</span> +</span><span id="L-566"><a href="#L-566"><span class="linenos">566</span></a> +</span><span id="L-567"><a href="#L-567"><span class="linenos">567</span></a> <span class="k">def</span> <span class="nf">interval_sql</span><span class="p">(</span><span class="bp">self</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">Interval</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-568"><a href="#L-568"><span class="linenos">568</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"unit"</span><span class="p">)</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"WEEK"</span><span class="p">):</span> +</span><span id="L-569"><a href="#L-569"><span class="linenos">569</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"(</span><span class="si">{</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> * INTERVAL '7' DAY)"</span> +</span><span id="L-570"><a href="#L-570"><span class="linenos">570</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">interval_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-571"><a href="#L-571"><span class="linenos">571</span></a> +</span><span id="L-572"><a href="#L-572"><span class="linenos">572</span></a> <span class="k">def</span> <span class="nf">transaction_sql</span><span class="p">(</span><span class="bp">self</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">Transaction</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-573"><a href="#L-573"><span class="linenos">573</span></a> <span class="n">modes</span> <span class="o">=</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">"modes"</span><span class="p">)</span> +</span><span id="L-574"><a href="#L-574"><span class="linenos">574</span></a> <span class="n">modes</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" </span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">modes</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">modes</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="L-575"><a href="#L-575"><span class="linenos">575</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"START TRANSACTION</span><span class="si">{</span><span class="n">modes</span><span class="si">}</span><span class="s2">"</span> +</span><span id="L-576"><a href="#L-576"><span class="linenos">576</span></a> +</span><span id="L-577"><a href="#L-577"><span class="linenos">577</span></a> <span class="k">def</span> <span class="nf">generateseries_sql</span><span class="p">(</span><span class="bp">self</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">GenerateSeries</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-578"><a href="#L-578"><span class="linenos">578</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"start"</span><span class="p">]</span> +</span><span id="L-579"><a href="#L-579"><span class="linenos">579</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"end"</span><span class="p">]</span> +</span><span id="L-580"><a href="#L-580"><span class="linenos">580</span></a> <span class="n">step</span> <span class="o">=</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">"step"</span><span class="p">)</span> +</span><span id="L-581"><a href="#L-581"><span class="linenos">581</span></a> +</span><span id="L-582"><a href="#L-582"><span class="linenos">582</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> +</span><span id="L-583"><a href="#L-583"><span class="linenos">583</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span> +</span><span id="L-584"><a href="#L-584"><span class="linenos">584</span></a> <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> +</span><span id="L-585"><a href="#L-585"><span class="linenos">585</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">end</span><span class="o">.</span><span class="n">to</span> +</span><span id="L-586"><a href="#L-586"><span class="linenos">586</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="L-587"><a href="#L-587"><span class="linenos">587</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="L-588"><a href="#L-588"><span class="linenos">588</span></a> +</span><span id="L-589"><a href="#L-589"><span class="linenos">589</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">and</span> <span class="n">target_type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"timestamp"</span><span class="p">):</span> +</span><span id="L-590"><a href="#L-590"><span class="linenos">590</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">is</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span><span class="p">:</span> +</span><span id="L-591"><a href="#L-591"><span class="linenos">591</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> +</span><span id="L-592"><a href="#L-592"><span class="linenos">592</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="L-593"><a href="#L-593"><span class="linenos">593</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> +</span><span id="L-594"><a href="#L-594"><span class="linenos">594</span></a> +</span><span id="L-595"><a href="#L-595"><span class="linenos">595</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 class="s2">"SEQUENCE"</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">step</span><span class="p">)</span> +</span><span id="L-596"><a href="#L-596"><span class="linenos">596</span></a> +</span><span id="L-597"><a href="#L-597"><span class="linenos">597</span></a> <span class="k">def</span> <span class="nf">offset_limit_modifiers</span><span class="p">(</span> +</span><span id="L-598"><a href="#L-598"><span class="linenos">598</span></a> <span class="bp">self</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">Expression</span><span class="p">,</span> <span class="n">fetch</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">limit</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">exp</span><span class="o">.</span><span class="n">Fetch</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Limit</span><span class="p">]</span> +</span><span id="L-599"><a href="#L-599"><span class="linenos">599</span></a> <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-600"><a href="#L-600"><span class="linenos">600</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="L-601"><a href="#L-601"><span class="linenos">601</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"offset"</span><span class="p">),</span> +</span><span id="L-602"><a href="#L-602"><span class="linenos">602</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">limit</span><span class="p">),</span> +</span><span id="L-603"><a href="#L-603"><span class="linenos">603</span></a> <span class="p">]</span> +</span><span id="L-604"><a href="#L-604"><span class="linenos">604</span></a> +</span><span id="L-605"><a href="#L-605"><span class="linenos">605</span></a> <span class="k">def</span> <span class="nf">create_sql</span><span class="p">(</span><span class="bp">self</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">Create</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-606"><a href="#L-606"><span class="linenos">606</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-607"><a href="#L-607"><span class="linenos">607</span></a><span class="sd"> Presto doesn't support CREATE VIEW with expressions (ex: `CREATE VIEW x (cola)` then `(cola)` is the expression),</span> +</span><span id="L-608"><a href="#L-608"><span class="linenos">608</span></a><span class="sd"> so we need to remove them</span> +</span><span id="L-609"><a href="#L-609"><span class="linenos">609</span></a><span class="sd"> """</span> +</span><span id="L-610"><a href="#L-610"><span class="linenos">610</span></a> <span class="n">kind</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"kind"</span><span class="p">]</span> +</span><span id="L-611"><a href="#L-611"><span class="linenos">611</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="L-612"><a href="#L-612"><span class="linenos">612</span></a> <span class="k">if</span> <span class="n">kind</span> <span class="o">==</span> <span class="s2">"VIEW"</span> <span class="ow">and</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="L-613"><a href="#L-613"><span class="linenos">613</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="L-614"><a href="#L-614"><span class="linenos">614</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">create_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -1088,114 +1152,175 @@ </span><span id="Presto-444"><a href="#Presto-444"><span class="linenos">444</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Xor</span><span class="p">:</span> <span class="n">bool_xor_sql</span><span class="p">,</span> </span><span id="Presto-445"><a href="#Presto-445"><span class="linenos">445</span></a> <span class="p">}</span> </span><span id="Presto-446"><a href="#Presto-446"><span class="linenos">446</span></a> -</span><span id="Presto-447"><a href="#Presto-447"><span class="linenos">447</span></a> <span class="k">def</span> <span class="nf">strtounix_sql</span><span class="p">(</span><span class="bp">self</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">StrToUnix</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto-448"><a href="#Presto-448"><span class="linenos">448</span></a> <span class="c1"># Since `TO_UNIXTIME` requires a `TIMESTAMP`, we need to parse the argument into one.</span> -</span><span id="Presto-449"><a href="#Presto-449"><span class="linenos">449</span></a> <span class="c1"># To do this, we first try to `DATE_PARSE` it, but since this can fail when there's a</span> -</span><span id="Presto-450"><a href="#Presto-450"><span class="linenos">450</span></a> <span class="c1"># timezone involved, we wrap it in a `TRY` call and use `PARSE_DATETIME` as a fallback,</span> -</span><span id="Presto-451"><a href="#Presto-451"><span class="linenos">451</span></a> <span class="c1"># which seems to be using the same time mapping as Hive, as per:</span> -</span><span id="Presto-452"><a href="#Presto-452"><span class="linenos">452</span></a> <span class="c1"># https://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html</span> -</span><span id="Presto-453"><a href="#Presto-453"><span class="linenos">453</span></a> <span class="n">value_as_text</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</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">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TEXT</span><span class="p">)</span> -</span><span id="Presto-454"><a href="#Presto-454"><span class="linenos">454</span></a> <span class="n">parse_without_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DATE_PARSE"</span><span class="p">,</span> <span class="n">value_as_text</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">))</span> -</span><span id="Presto-455"><a href="#Presto-455"><span class="linenos">455</span></a> <span class="n">parse_with_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span> -</span><span id="Presto-456"><a href="#Presto-456"><span class="linenos">456</span></a> <span class="s2">"PARSE_DATETIME"</span><span class="p">,</span> -</span><span id="Presto-457"><a href="#Presto-457"><span class="linenos">457</span></a> <span class="n">value_as_text</span><span class="p">,</span> -</span><span id="Presto-458"><a href="#Presto-458"><span class="linenos">458</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_MAPPING</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_TRIE</span><span class="p">),</span> -</span><span id="Presto-459"><a href="#Presto-459"><span class="linenos">459</span></a> <span class="p">)</span> -</span><span id="Presto-460"><a href="#Presto-460"><span class="linenos">460</span></a> <span class="n">coalesced</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"COALESCE"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"TRY"</span><span class="p">,</span> <span class="n">parse_without_tz</span><span class="p">),</span> <span class="n">parse_with_tz</span><span class="p">)</span> -</span><span id="Presto-461"><a href="#Presto-461"><span class="linenos">461</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 class="s2">"TO_UNIXTIME"</span><span class="p">,</span> <span class="n">coalesced</span><span class="p">)</span> -</span><span id="Presto-462"><a href="#Presto-462"><span class="linenos">462</span></a> -</span><span id="Presto-463"><a href="#Presto-463"><span class="linenos">463</span></a> <span class="k">def</span> <span class="nf">bracket_sql</span><span class="p">(</span><span class="bp">self</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">Bracket</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto-464"><a href="#Presto-464"><span class="linenos">464</span></a> <span class="k">if</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">"safe"</span><span class="p">):</span> -</span><span id="Presto-465"><a href="#Presto-465"><span class="linenos">465</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="Presto-466"><a href="#Presto-466"><span class="linenos">466</span></a> <span class="s2">"ELEMENT_AT"</span><span class="p">,</span> -</span><span id="Presto-467"><a href="#Presto-467"><span class="linenos">467</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="Presto-468"><a href="#Presto-468"><span class="linenos">468</span></a> <span class="n">seq_get</span><span class="p">(</span> -</span><span id="Presto-469"><a href="#Presto-469"><span class="linenos">469</span></a> <span class="n">apply_index_offset</span><span class="p">(</span> -</span><span id="Presto-470"><a href="#Presto-470"><span class="linenos">470</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="Presto-471"><a href="#Presto-471"><span class="linenos">471</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> -</span><span id="Presto-472"><a href="#Presto-472"><span class="linenos">472</span></a> <span class="mi">1</span> <span class="o">-</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">"offset"</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> -</span><span id="Presto-473"><a href="#Presto-473"><span class="linenos">473</span></a> <span class="p">),</span> -</span><span id="Presto-474"><a href="#Presto-474"><span class="linenos">474</span></a> <span class="mi">0</span><span class="p">,</span> -</span><span id="Presto-475"><a href="#Presto-475"><span class="linenos">475</span></a> <span class="p">),</span> -</span><span id="Presto-476"><a href="#Presto-476"><span class="linenos">476</span></a> <span class="p">)</span> -</span><span id="Presto-477"><a href="#Presto-477"><span class="linenos">477</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">bracket_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="Presto-478"><a href="#Presto-478"><span class="linenos">478</span></a> -</span><span id="Presto-479"><a href="#Presto-479"><span class="linenos">479</span></a> <span class="k">def</span> <span class="nf">struct_sql</span><span class="p">(</span><span class="bp">self</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">Struct</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto-480"><a href="#Presto-480"><span class="linenos">480</span></a> <span class="kn">from</span> <span class="nn">sqlglot.optimizer.annotate_types</span> <span class="kn">import</span> <span class="n">annotate_types</span> -</span><span id="Presto-481"><a href="#Presto-481"><span class="linenos">481</span></a> -</span><span id="Presto-482"><a href="#Presto-482"><span class="linenos">482</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">annotate_types</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="Presto-483"><a href="#Presto-483"><span class="linenos">483</span></a> <span class="n">values</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="Presto-484"><a href="#Presto-484"><span class="linenos">484</span></a> <span class="n">schema</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="Presto-485"><a href="#Presto-485"><span class="linenos">485</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Presto-486"><a href="#Presto-486"><span class="linenos">486</span></a> -</span><span id="Presto-487"><a href="#Presto-487"><span class="linenos">487</span></a> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> -</span><span id="Presto-488"><a href="#Presto-488"><span class="linenos">488</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">PropertyEQ</span><span class="p">):</span> -</span><span id="Presto-489"><a href="#Presto-489"><span class="linenos">489</span></a> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">UNKNOWN</span><span class="p">):</span> -</span><span id="Presto-490"><a href="#Presto-490"><span class="linenos">490</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Presto-491"><a href="#Presto-491"><span class="linenos">491</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Presto-492"><a href="#Presto-492"><span class="linenos">492</span></a> <span class="n">schema</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="Presto-493"><a href="#Presto-493"><span class="linenos">493</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="s2">"expression"</span><span class="p">))</span> -</span><span id="Presto-494"><a href="#Presto-494"><span class="linenos">494</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Presto-495"><a href="#Presto-495"><span class="linenos">495</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">))</span> -</span><span id="Presto-496"><a href="#Presto-496"><span class="linenos">496</span></a> -</span><span id="Presto-497"><a href="#Presto-497"><span class="linenos">497</span></a> <span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">)</span> -</span><span id="Presto-498"><a href="#Presto-498"><span class="linenos">498</span></a> -</span><span id="Presto-499"><a href="#Presto-499"><span class="linenos">499</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">size</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span> <span class="o">!=</span> <span class="n">size</span><span class="p">:</span> -</span><span id="Presto-500"><a href="#Presto-500"><span class="linenos">500</span></a> <span class="k">if</span> <span class="n">unknown_type</span><span class="p">:</span> -</span><span id="Presto-501"><a href="#Presto-501"><span class="linenos">501</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span> -</span><span id="Presto-502"><a href="#Presto-502"><span class="linenos">502</span></a> <span class="s2">"Cannot convert untyped key-value definitions (try annotate_types)."</span> -</span><span id="Presto-503"><a href="#Presto-503"><span class="linenos">503</span></a> <span class="p">)</span> -</span><span id="Presto-504"><a href="#Presto-504"><span class="linenos">504</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 class="s2">"ROW"</span><span class="p">,</span> <span class="o">*</span><span class="n">values</span><span class="p">)</span> -</span><span id="Presto-505"><a href="#Presto-505"><span class="linenos">505</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"CAST(ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">values</span><span class="p">)</span><span class="si">}</span><span class="s2">) AS ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span><span class="si">}</span><span class="s2">))"</span> -</span><span id="Presto-506"><a href="#Presto-506"><span class="linenos">506</span></a> -</span><span id="Presto-507"><a href="#Presto-507"><span class="linenos">507</span></a> <span class="k">def</span> <span class="nf">interval_sql</span><span class="p">(</span><span class="bp">self</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">Interval</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto-508"><a href="#Presto-508"><span class="linenos">508</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"unit"</span><span class="p">)</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"WEEK"</span><span class="p">):</span> -</span><span id="Presto-509"><a href="#Presto-509"><span class="linenos">509</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"(</span><span class="si">{</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> * INTERVAL '7' DAY)"</span> -</span><span id="Presto-510"><a href="#Presto-510"><span class="linenos">510</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">interval_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="Presto-511"><a href="#Presto-511"><span class="linenos">511</span></a> -</span><span id="Presto-512"><a href="#Presto-512"><span class="linenos">512</span></a> <span class="k">def</span> <span class="nf">transaction_sql</span><span class="p">(</span><span class="bp">self</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">Transaction</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto-513"><a href="#Presto-513"><span class="linenos">513</span></a> <span class="n">modes</span> <span class="o">=</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">"modes"</span><span class="p">)</span> -</span><span id="Presto-514"><a href="#Presto-514"><span class="linenos">514</span></a> <span class="n">modes</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" </span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">modes</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">modes</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="Presto-515"><a href="#Presto-515"><span class="linenos">515</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"START TRANSACTION</span><span class="si">{</span><span class="n">modes</span><span class="si">}</span><span class="s2">"</span> -</span><span id="Presto-516"><a href="#Presto-516"><span class="linenos">516</span></a> -</span><span id="Presto-517"><a href="#Presto-517"><span class="linenos">517</span></a> <span class="k">def</span> <span class="nf">generateseries_sql</span><span class="p">(</span><span class="bp">self</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">GenerateSeries</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto-518"><a href="#Presto-518"><span class="linenos">518</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"start"</span><span class="p">]</span> -</span><span id="Presto-519"><a href="#Presto-519"><span class="linenos">519</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"end"</span><span class="p">]</span> -</span><span id="Presto-520"><a href="#Presto-520"><span class="linenos">520</span></a> <span class="n">step</span> <span class="o">=</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">"step"</span><span class="p">)</span> -</span><span id="Presto-521"><a href="#Presto-521"><span class="linenos">521</span></a> -</span><span id="Presto-522"><a href="#Presto-522"><span class="linenos">522</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> -</span><span id="Presto-523"><a href="#Presto-523"><span class="linenos">523</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span> -</span><span id="Presto-524"><a href="#Presto-524"><span class="linenos">524</span></a> <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> -</span><span id="Presto-525"><a href="#Presto-525"><span class="linenos">525</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">end</span><span class="o">.</span><span class="n">to</span> -</span><span id="Presto-526"><a href="#Presto-526"><span class="linenos">526</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Presto-527"><a href="#Presto-527"><span class="linenos">527</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="Presto-528"><a href="#Presto-528"><span class="linenos">528</span></a> -</span><span id="Presto-529"><a href="#Presto-529"><span class="linenos">529</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">and</span> <span class="n">target_type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"timestamp"</span><span class="p">):</span> -</span><span id="Presto-530"><a href="#Presto-530"><span class="linenos">530</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">is</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span><span class="p">:</span> -</span><span id="Presto-531"><a href="#Presto-531"><span class="linenos">531</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> -</span><span id="Presto-532"><a href="#Presto-532"><span class="linenos">532</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Presto-533"><a href="#Presto-533"><span class="linenos">533</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> -</span><span id="Presto-534"><a href="#Presto-534"><span class="linenos">534</span></a> -</span><span id="Presto-535"><a href="#Presto-535"><span class="linenos">535</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 class="s2">"SEQUENCE"</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">step</span><span class="p">)</span> -</span><span id="Presto-536"><a href="#Presto-536"><span class="linenos">536</span></a> -</span><span id="Presto-537"><a href="#Presto-537"><span class="linenos">537</span></a> <span class="k">def</span> <span class="nf">offset_limit_modifiers</span><span class="p">(</span> -</span><span id="Presto-538"><a href="#Presto-538"><span class="linenos">538</span></a> <span class="bp">self</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">Expression</span><span class="p">,</span> <span class="n">fetch</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">limit</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">exp</span><span class="o">.</span><span class="n">Fetch</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Limit</span><span class="p">]</span> -</span><span id="Presto-539"><a href="#Presto-539"><span class="linenos">539</span></a> <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="Presto-540"><a href="#Presto-540"><span class="linenos">540</span></a> <span class="k">return</span> <span class="p">[</span> -</span><span id="Presto-541"><a href="#Presto-541"><span class="linenos">541</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"offset"</span><span class="p">),</span> -</span><span id="Presto-542"><a href="#Presto-542"><span class="linenos">542</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">limit</span><span class="p">),</span> -</span><span id="Presto-543"><a href="#Presto-543"><span class="linenos">543</span></a> <span class="p">]</span> -</span><span id="Presto-544"><a href="#Presto-544"><span class="linenos">544</span></a> -</span><span id="Presto-545"><a href="#Presto-545"><span class="linenos">545</span></a> <span class="k">def</span> <span class="nf">create_sql</span><span class="p">(</span><span class="bp">self</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">Create</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto-546"><a href="#Presto-546"><span class="linenos">546</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Presto-547"><a href="#Presto-547"><span class="linenos">547</span></a><span class="sd"> Presto doesn't support CREATE VIEW with expressions (ex: `CREATE VIEW x (cola)` then `(cola)` is the expression),</span> -</span><span id="Presto-548"><a href="#Presto-548"><span class="linenos">548</span></a><span class="sd"> so we need to remove them</span> -</span><span id="Presto-549"><a href="#Presto-549"><span class="linenos">549</span></a><span class="sd"> """</span> -</span><span id="Presto-550"><a href="#Presto-550"><span class="linenos">550</span></a> <span class="n">kind</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"kind"</span><span class="p">]</span> -</span><span id="Presto-551"><a href="#Presto-551"><span class="linenos">551</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> -</span><span id="Presto-552"><a href="#Presto-552"><span class="linenos">552</span></a> <span class="k">if</span> <span class="n">kind</span> <span class="o">==</span> <span class="s2">"VIEW"</span> <span class="ow">and</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> -</span><span id="Presto-553"><a href="#Presto-553"><span class="linenos">553</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> -</span><span id="Presto-554"><a href="#Presto-554"><span class="linenos">554</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">create_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Presto-447"><a href="#Presto-447"><span class="linenos">447</span></a> <span class="n">RESERVED_KEYWORDS</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="Presto-448"><a href="#Presto-448"><span class="linenos">448</span></a> <span class="s2">"alter"</span><span class="p">,</span> +</span><span id="Presto-449"><a href="#Presto-449"><span class="linenos">449</span></a> <span class="s2">"and"</span><span class="p">,</span> +</span><span id="Presto-450"><a href="#Presto-450"><span class="linenos">450</span></a> <span class="s2">"as"</span><span class="p">,</span> +</span><span id="Presto-451"><a href="#Presto-451"><span class="linenos">451</span></a> <span class="s2">"between"</span><span class="p">,</span> +</span><span id="Presto-452"><a href="#Presto-452"><span class="linenos">452</span></a> <span class="s2">"by"</span><span class="p">,</span> +</span><span id="Presto-453"><a href="#Presto-453"><span class="linenos">453</span></a> <span class="s2">"case"</span><span class="p">,</span> +</span><span id="Presto-454"><a href="#Presto-454"><span class="linenos">454</span></a> <span class="s2">"cast"</span><span class="p">,</span> +</span><span id="Presto-455"><a href="#Presto-455"><span class="linenos">455</span></a> <span class="s2">"constraint"</span><span class="p">,</span> +</span><span id="Presto-456"><a href="#Presto-456"><span class="linenos">456</span></a> <span class="s2">"create"</span><span class="p">,</span> +</span><span id="Presto-457"><a href="#Presto-457"><span class="linenos">457</span></a> <span class="s2">"cross"</span><span class="p">,</span> +</span><span id="Presto-458"><a href="#Presto-458"><span class="linenos">458</span></a> <span class="s2">"current_time"</span><span class="p">,</span> +</span><span id="Presto-459"><a href="#Presto-459"><span class="linenos">459</span></a> <span class="s2">"current_timestamp"</span><span class="p">,</span> +</span><span id="Presto-460"><a href="#Presto-460"><span class="linenos">460</span></a> <span class="s2">"deallocate"</span><span class="p">,</span> +</span><span id="Presto-461"><a href="#Presto-461"><span class="linenos">461</span></a> <span class="s2">"delete"</span><span class="p">,</span> +</span><span id="Presto-462"><a href="#Presto-462"><span class="linenos">462</span></a> <span class="s2">"describe"</span><span class="p">,</span> +</span><span id="Presto-463"><a href="#Presto-463"><span class="linenos">463</span></a> <span class="s2">"distinct"</span><span class="p">,</span> +</span><span id="Presto-464"><a href="#Presto-464"><span class="linenos">464</span></a> <span class="s2">"drop"</span><span class="p">,</span> +</span><span id="Presto-465"><a href="#Presto-465"><span class="linenos">465</span></a> <span class="s2">"else"</span><span class="p">,</span> +</span><span id="Presto-466"><a href="#Presto-466"><span class="linenos">466</span></a> <span class="s2">"end"</span><span class="p">,</span> +</span><span id="Presto-467"><a href="#Presto-467"><span class="linenos">467</span></a> <span class="s2">"escape"</span><span class="p">,</span> +</span><span id="Presto-468"><a href="#Presto-468"><span class="linenos">468</span></a> <span class="s2">"except"</span><span class="p">,</span> +</span><span id="Presto-469"><a href="#Presto-469"><span class="linenos">469</span></a> <span class="s2">"execute"</span><span class="p">,</span> +</span><span id="Presto-470"><a href="#Presto-470"><span class="linenos">470</span></a> <span class="s2">"exists"</span><span class="p">,</span> +</span><span id="Presto-471"><a href="#Presto-471"><span class="linenos">471</span></a> <span class="s2">"extract"</span><span class="p">,</span> +</span><span id="Presto-472"><a href="#Presto-472"><span class="linenos">472</span></a> <span class="s2">"false"</span><span class="p">,</span> +</span><span id="Presto-473"><a href="#Presto-473"><span class="linenos">473</span></a> <span class="s2">"for"</span><span class="p">,</span> +</span><span id="Presto-474"><a href="#Presto-474"><span class="linenos">474</span></a> <span class="s2">"from"</span><span class="p">,</span> +</span><span id="Presto-475"><a href="#Presto-475"><span class="linenos">475</span></a> <span class="s2">"full"</span><span class="p">,</span> +</span><span id="Presto-476"><a href="#Presto-476"><span class="linenos">476</span></a> <span class="s2">"group"</span><span class="p">,</span> +</span><span id="Presto-477"><a href="#Presto-477"><span class="linenos">477</span></a> <span class="s2">"having"</span><span class="p">,</span> +</span><span id="Presto-478"><a href="#Presto-478"><span class="linenos">478</span></a> <span class="s2">"in"</span><span class="p">,</span> +</span><span id="Presto-479"><a href="#Presto-479"><span class="linenos">479</span></a> <span class="s2">"inner"</span><span class="p">,</span> +</span><span id="Presto-480"><a href="#Presto-480"><span class="linenos">480</span></a> <span class="s2">"insert"</span><span class="p">,</span> +</span><span id="Presto-481"><a href="#Presto-481"><span class="linenos">481</span></a> <span class="s2">"intersect"</span><span class="p">,</span> +</span><span id="Presto-482"><a href="#Presto-482"><span class="linenos">482</span></a> <span class="s2">"into"</span><span class="p">,</span> +</span><span id="Presto-483"><a href="#Presto-483"><span class="linenos">483</span></a> <span class="s2">"is"</span><span class="p">,</span> +</span><span id="Presto-484"><a href="#Presto-484"><span class="linenos">484</span></a> <span class="s2">"join"</span><span class="p">,</span> +</span><span id="Presto-485"><a href="#Presto-485"><span class="linenos">485</span></a> <span class="s2">"left"</span><span class="p">,</span> +</span><span id="Presto-486"><a href="#Presto-486"><span class="linenos">486</span></a> <span class="s2">"like"</span><span class="p">,</span> +</span><span id="Presto-487"><a href="#Presto-487"><span class="linenos">487</span></a> <span class="s2">"natural"</span><span class="p">,</span> +</span><span id="Presto-488"><a href="#Presto-488"><span class="linenos">488</span></a> <span class="s2">"not"</span><span class="p">,</span> +</span><span id="Presto-489"><a href="#Presto-489"><span class="linenos">489</span></a> <span class="s2">"null"</span><span class="p">,</span> +</span><span id="Presto-490"><a href="#Presto-490"><span class="linenos">490</span></a> <span class="s2">"on"</span><span class="p">,</span> +</span><span id="Presto-491"><a href="#Presto-491"><span class="linenos">491</span></a> <span class="s2">"or"</span><span class="p">,</span> +</span><span id="Presto-492"><a href="#Presto-492"><span class="linenos">492</span></a> <span class="s2">"order"</span><span class="p">,</span> +</span><span id="Presto-493"><a href="#Presto-493"><span class="linenos">493</span></a> <span class="s2">"outer"</span><span class="p">,</span> +</span><span id="Presto-494"><a href="#Presto-494"><span class="linenos">494</span></a> <span class="s2">"prepare"</span><span class="p">,</span> +</span><span id="Presto-495"><a href="#Presto-495"><span class="linenos">495</span></a> <span class="s2">"right"</span><span class="p">,</span> +</span><span id="Presto-496"><a href="#Presto-496"><span class="linenos">496</span></a> <span class="s2">"select"</span><span class="p">,</span> +</span><span id="Presto-497"><a href="#Presto-497"><span class="linenos">497</span></a> <span class="s2">"table"</span><span class="p">,</span> +</span><span id="Presto-498"><a href="#Presto-498"><span class="linenos">498</span></a> <span class="s2">"then"</span><span class="p">,</span> +</span><span id="Presto-499"><a href="#Presto-499"><span class="linenos">499</span></a> <span class="s2">"true"</span><span class="p">,</span> +</span><span id="Presto-500"><a href="#Presto-500"><span class="linenos">500</span></a> <span class="s2">"union"</span><span class="p">,</span> +</span><span id="Presto-501"><a href="#Presto-501"><span class="linenos">501</span></a> <span class="s2">"using"</span><span class="p">,</span> +</span><span id="Presto-502"><a href="#Presto-502"><span class="linenos">502</span></a> <span class="s2">"values"</span><span class="p">,</span> +</span><span id="Presto-503"><a href="#Presto-503"><span class="linenos">503</span></a> <span class="s2">"when"</span><span class="p">,</span> +</span><span id="Presto-504"><a href="#Presto-504"><span class="linenos">504</span></a> <span class="s2">"where"</span><span class="p">,</span> +</span><span id="Presto-505"><a href="#Presto-505"><span class="linenos">505</span></a> <span class="s2">"with"</span><span class="p">,</span> +</span><span id="Presto-506"><a href="#Presto-506"><span class="linenos">506</span></a> <span class="p">}</span> +</span><span id="Presto-507"><a href="#Presto-507"><span class="linenos">507</span></a> +</span><span id="Presto-508"><a href="#Presto-508"><span class="linenos">508</span></a> <span class="k">def</span> <span class="nf">strtounix_sql</span><span class="p">(</span><span class="bp">self</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">StrToUnix</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto-509"><a href="#Presto-509"><span class="linenos">509</span></a> <span class="c1"># Since `TO_UNIXTIME` requires a `TIMESTAMP`, we need to parse the argument into one.</span> +</span><span id="Presto-510"><a href="#Presto-510"><span class="linenos">510</span></a> <span class="c1"># To do this, we first try to `DATE_PARSE` it, but since this can fail when there's a</span> +</span><span id="Presto-511"><a href="#Presto-511"><span class="linenos">511</span></a> <span class="c1"># timezone involved, we wrap it in a `TRY` call and use `PARSE_DATETIME` as a fallback,</span> +</span><span id="Presto-512"><a href="#Presto-512"><span class="linenos">512</span></a> <span class="c1"># which seems to be using the same time mapping as Hive, as per:</span> +</span><span id="Presto-513"><a href="#Presto-513"><span class="linenos">513</span></a> <span class="c1"># https://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html</span> +</span><span id="Presto-514"><a href="#Presto-514"><span class="linenos">514</span></a> <span class="n">value_as_text</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</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">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TEXT</span><span class="p">)</span> +</span><span id="Presto-515"><a href="#Presto-515"><span class="linenos">515</span></a> <span class="n">parse_without_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DATE_PARSE"</span><span class="p">,</span> <span class="n">value_as_text</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">))</span> +</span><span id="Presto-516"><a href="#Presto-516"><span class="linenos">516</span></a> <span class="n">parse_with_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span> +</span><span id="Presto-517"><a href="#Presto-517"><span class="linenos">517</span></a> <span class="s2">"PARSE_DATETIME"</span><span class="p">,</span> +</span><span id="Presto-518"><a href="#Presto-518"><span class="linenos">518</span></a> <span class="n">value_as_text</span><span class="p">,</span> +</span><span id="Presto-519"><a href="#Presto-519"><span class="linenos">519</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_MAPPING</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_TRIE</span><span class="p">),</span> +</span><span id="Presto-520"><a href="#Presto-520"><span class="linenos">520</span></a> <span class="p">)</span> +</span><span id="Presto-521"><a href="#Presto-521"><span class="linenos">521</span></a> <span class="n">coalesced</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"COALESCE"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"TRY"</span><span class="p">,</span> <span class="n">parse_without_tz</span><span class="p">),</span> <span class="n">parse_with_tz</span><span class="p">)</span> +</span><span id="Presto-522"><a href="#Presto-522"><span class="linenos">522</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 class="s2">"TO_UNIXTIME"</span><span class="p">,</span> <span class="n">coalesced</span><span class="p">)</span> +</span><span id="Presto-523"><a href="#Presto-523"><span class="linenos">523</span></a> +</span><span id="Presto-524"><a href="#Presto-524"><span class="linenos">524</span></a> <span class="k">def</span> <span class="nf">bracket_sql</span><span class="p">(</span><span class="bp">self</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">Bracket</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto-525"><a href="#Presto-525"><span class="linenos">525</span></a> <span class="k">if</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">"safe"</span><span class="p">):</span> +</span><span id="Presto-526"><a href="#Presto-526"><span class="linenos">526</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="Presto-527"><a href="#Presto-527"><span class="linenos">527</span></a> <span class="s2">"ELEMENT_AT"</span><span class="p">,</span> +</span><span id="Presto-528"><a href="#Presto-528"><span class="linenos">528</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="Presto-529"><a href="#Presto-529"><span class="linenos">529</span></a> <span class="n">seq_get</span><span class="p">(</span> +</span><span id="Presto-530"><a href="#Presto-530"><span class="linenos">530</span></a> <span class="n">apply_index_offset</span><span class="p">(</span> +</span><span id="Presto-531"><a href="#Presto-531"><span class="linenos">531</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="Presto-532"><a href="#Presto-532"><span class="linenos">532</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> +</span><span id="Presto-533"><a href="#Presto-533"><span class="linenos">533</span></a> <span class="mi">1</span> <span class="o">-</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">"offset"</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> +</span><span id="Presto-534"><a href="#Presto-534"><span class="linenos">534</span></a> <span class="p">),</span> +</span><span id="Presto-535"><a href="#Presto-535"><span class="linenos">535</span></a> <span class="mi">0</span><span class="p">,</span> +</span><span id="Presto-536"><a href="#Presto-536"><span class="linenos">536</span></a> <span class="p">),</span> +</span><span id="Presto-537"><a href="#Presto-537"><span class="linenos">537</span></a> <span class="p">)</span> +</span><span id="Presto-538"><a href="#Presto-538"><span class="linenos">538</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">bracket_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Presto-539"><a href="#Presto-539"><span class="linenos">539</span></a> +</span><span id="Presto-540"><a href="#Presto-540"><span class="linenos">540</span></a> <span class="k">def</span> <span class="nf">struct_sql</span><span class="p">(</span><span class="bp">self</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">Struct</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto-541"><a href="#Presto-541"><span class="linenos">541</span></a> <span class="kn">from</span> <span class="nn">sqlglot.optimizer.annotate_types</span> <span class="kn">import</span> <span class="n">annotate_types</span> +</span><span id="Presto-542"><a href="#Presto-542"><span class="linenos">542</span></a> +</span><span id="Presto-543"><a href="#Presto-543"><span class="linenos">543</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">annotate_types</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Presto-544"><a href="#Presto-544"><span class="linenos">544</span></a> <span class="n">values</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="Presto-545"><a href="#Presto-545"><span class="linenos">545</span></a> <span class="n">schema</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="Presto-546"><a href="#Presto-546"><span class="linenos">546</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Presto-547"><a href="#Presto-547"><span class="linenos">547</span></a> +</span><span id="Presto-548"><a href="#Presto-548"><span class="linenos">548</span></a> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="Presto-549"><a href="#Presto-549"><span class="linenos">549</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">PropertyEQ</span><span class="p">):</span> +</span><span id="Presto-550"><a href="#Presto-550"><span class="linenos">550</span></a> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">UNKNOWN</span><span class="p">):</span> +</span><span id="Presto-551"><a href="#Presto-551"><span class="linenos">551</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Presto-552"><a href="#Presto-552"><span class="linenos">552</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Presto-553"><a href="#Presto-553"><span class="linenos">553</span></a> <span class="n">schema</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="Presto-554"><a href="#Presto-554"><span class="linenos">554</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="s2">"expression"</span><span class="p">))</span> +</span><span id="Presto-555"><a href="#Presto-555"><span class="linenos">555</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Presto-556"><a href="#Presto-556"><span class="linenos">556</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">))</span> +</span><span id="Presto-557"><a href="#Presto-557"><span class="linenos">557</span></a> +</span><span id="Presto-558"><a href="#Presto-558"><span class="linenos">558</span></a> <span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">)</span> +</span><span id="Presto-559"><a href="#Presto-559"><span class="linenos">559</span></a> +</span><span id="Presto-560"><a href="#Presto-560"><span class="linenos">560</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">size</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span> <span class="o">!=</span> <span class="n">size</span><span class="p">:</span> +</span><span id="Presto-561"><a href="#Presto-561"><span class="linenos">561</span></a> <span class="k">if</span> <span class="n">unknown_type</span><span class="p">:</span> +</span><span id="Presto-562"><a href="#Presto-562"><span class="linenos">562</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span> +</span><span id="Presto-563"><a href="#Presto-563"><span class="linenos">563</span></a> <span class="s2">"Cannot convert untyped key-value definitions (try annotate_types)."</span> +</span><span id="Presto-564"><a href="#Presto-564"><span class="linenos">564</span></a> <span class="p">)</span> +</span><span id="Presto-565"><a href="#Presto-565"><span class="linenos">565</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 class="s2">"ROW"</span><span class="p">,</span> <span class="o">*</span><span class="n">values</span><span class="p">)</span> +</span><span id="Presto-566"><a href="#Presto-566"><span class="linenos">566</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"CAST(ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">values</span><span class="p">)</span><span class="si">}</span><span class="s2">) AS ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span><span class="si">}</span><span class="s2">))"</span> +</span><span id="Presto-567"><a href="#Presto-567"><span class="linenos">567</span></a> +</span><span id="Presto-568"><a href="#Presto-568"><span class="linenos">568</span></a> <span class="k">def</span> <span class="nf">interval_sql</span><span class="p">(</span><span class="bp">self</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">Interval</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto-569"><a href="#Presto-569"><span class="linenos">569</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"unit"</span><span class="p">)</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"WEEK"</span><span class="p">):</span> +</span><span id="Presto-570"><a href="#Presto-570"><span class="linenos">570</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"(</span><span class="si">{</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> * INTERVAL '7' DAY)"</span> +</span><span id="Presto-571"><a href="#Presto-571"><span class="linenos">571</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">interval_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Presto-572"><a href="#Presto-572"><span class="linenos">572</span></a> +</span><span id="Presto-573"><a href="#Presto-573"><span class="linenos">573</span></a> <span class="k">def</span> <span class="nf">transaction_sql</span><span class="p">(</span><span class="bp">self</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">Transaction</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto-574"><a href="#Presto-574"><span class="linenos">574</span></a> <span class="n">modes</span> <span class="o">=</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">"modes"</span><span class="p">)</span> +</span><span id="Presto-575"><a href="#Presto-575"><span class="linenos">575</span></a> <span class="n">modes</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" </span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">modes</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">modes</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="Presto-576"><a href="#Presto-576"><span class="linenos">576</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"START TRANSACTION</span><span class="si">{</span><span class="n">modes</span><span class="si">}</span><span class="s2">"</span> +</span><span id="Presto-577"><a href="#Presto-577"><span class="linenos">577</span></a> +</span><span id="Presto-578"><a href="#Presto-578"><span class="linenos">578</span></a> <span class="k">def</span> <span class="nf">generateseries_sql</span><span class="p">(</span><span class="bp">self</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">GenerateSeries</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto-579"><a href="#Presto-579"><span class="linenos">579</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"start"</span><span class="p">]</span> +</span><span id="Presto-580"><a href="#Presto-580"><span class="linenos">580</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"end"</span><span class="p">]</span> +</span><span id="Presto-581"><a href="#Presto-581"><span class="linenos">581</span></a> <span class="n">step</span> <span class="o">=</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">"step"</span><span class="p">)</span> +</span><span id="Presto-582"><a href="#Presto-582"><span class="linenos">582</span></a> +</span><span id="Presto-583"><a href="#Presto-583"><span class="linenos">583</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> +</span><span id="Presto-584"><a href="#Presto-584"><span class="linenos">584</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span> +</span><span id="Presto-585"><a href="#Presto-585"><span class="linenos">585</span></a> <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> +</span><span id="Presto-586"><a href="#Presto-586"><span class="linenos">586</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">end</span><span class="o">.</span><span class="n">to</span> +</span><span id="Presto-587"><a href="#Presto-587"><span class="linenos">587</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Presto-588"><a href="#Presto-588"><span class="linenos">588</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="Presto-589"><a href="#Presto-589"><span class="linenos">589</span></a> +</span><span id="Presto-590"><a href="#Presto-590"><span class="linenos">590</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">and</span> <span class="n">target_type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"timestamp"</span><span class="p">):</span> +</span><span id="Presto-591"><a href="#Presto-591"><span class="linenos">591</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">is</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span><span class="p">:</span> +</span><span id="Presto-592"><a href="#Presto-592"><span class="linenos">592</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> +</span><span id="Presto-593"><a href="#Presto-593"><span class="linenos">593</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Presto-594"><a href="#Presto-594"><span class="linenos">594</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> +</span><span id="Presto-595"><a href="#Presto-595"><span class="linenos">595</span></a> +</span><span id="Presto-596"><a href="#Presto-596"><span class="linenos">596</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 class="s2">"SEQUENCE"</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">step</span><span class="p">)</span> +</span><span id="Presto-597"><a href="#Presto-597"><span class="linenos">597</span></a> +</span><span id="Presto-598"><a href="#Presto-598"><span class="linenos">598</span></a> <span class="k">def</span> <span class="nf">offset_limit_modifiers</span><span class="p">(</span> +</span><span id="Presto-599"><a href="#Presto-599"><span class="linenos">599</span></a> <span class="bp">self</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">Expression</span><span class="p">,</span> <span class="n">fetch</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">limit</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">exp</span><span class="o">.</span><span class="n">Fetch</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Limit</span><span class="p">]</span> +</span><span id="Presto-600"><a href="#Presto-600"><span class="linenos">600</span></a> <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="Presto-601"><a href="#Presto-601"><span class="linenos">601</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="Presto-602"><a href="#Presto-602"><span class="linenos">602</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"offset"</span><span class="p">),</span> +</span><span id="Presto-603"><a href="#Presto-603"><span class="linenos">603</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">limit</span><span class="p">),</span> +</span><span id="Presto-604"><a href="#Presto-604"><span class="linenos">604</span></a> <span class="p">]</span> +</span><span id="Presto-605"><a href="#Presto-605"><span class="linenos">605</span></a> +</span><span id="Presto-606"><a href="#Presto-606"><span class="linenos">606</span></a> <span class="k">def</span> <span class="nf">create_sql</span><span class="p">(</span><span class="bp">self</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">Create</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto-607"><a href="#Presto-607"><span class="linenos">607</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Presto-608"><a href="#Presto-608"><span class="linenos">608</span></a><span class="sd"> Presto doesn't support CREATE VIEW with expressions (ex: `CREATE VIEW x (cola)` then `(cola)` is the expression),</span> +</span><span id="Presto-609"><a href="#Presto-609"><span class="linenos">609</span></a><span class="sd"> so we need to remove them</span> +</span><span id="Presto-610"><a href="#Presto-610"><span class="linenos">610</span></a><span class="sd"> """</span> +</span><span id="Presto-611"><a href="#Presto-611"><span class="linenos">611</span></a> <span class="n">kind</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"kind"</span><span class="p">]</span> +</span><span id="Presto-612"><a href="#Presto-612"><span class="linenos">612</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="Presto-613"><a href="#Presto-613"><span class="linenos">613</span></a> <span class="k">if</span> <span class="n">kind</span> <span class="o">==</span> <span class="s2">"VIEW"</span> <span class="ow">and</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="Presto-614"><a href="#Presto-614"><span class="linenos">614</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="Presto-615"><a href="#Presto-615"><span class="linenos">615</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">create_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -1851,7 +1976,7 @@ Default: 3</li> <div class="attr variable"> <span class="name">TABLE_ALIAS_TOKENS</span> = <input id="Presto.Parser.TABLE_ALIAS_TOKENS-view-value" class="view-value-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> - <label class="view-value-button pdoc-button" for="Presto.Parser.TABLE_ALIAS_TOKENS-view-value"></label><span class="default_value">{<TokenType.IPADDRESS: 'IPADDRESS'>, <TokenType.VARIANT: 'VARIANT'>, <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, <TokenType.SHOW: 'SHOW'>, <TokenType.VOLATILE: 'VOLATILE'>, <TokenType.TIMESTAMP: 'TIMESTAMP'>, <TokenType.USE: 'USE'>, <TokenType.UTINYINT: 'UTINYINT'>, <TokenType.REFERENCES: 'REFERENCES'>, <TokenType.INTERVAL: 'INTERVAL'>, <TokenType.BIGINT: 'BIGINT'>, <TokenType.SETTINGS: 'SETTINGS'>, <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, <TokenType.USMALLINT: 'USMALLINT'>, <TokenType.TIMESTAMP_S: 'TIMESTAMP_S'>, <TokenType.TSRANGE: 'TSRANGE'>, <TokenType.ESCAPE: 'ESCAPE'>, <TokenType.TIMESTAMP_NS: 'TIMESTAMP_NS'>, <TokenType.MONEY: 'MONEY'>, <TokenType.GEOMETRY: 'GEOMETRY'>, <TokenType.FIRST: 'FIRST'>, <TokenType.FUNCTION: 'FUNCTION'>, <TokenType.YEAR: 'YEAR'>, <TokenType.ANTI: 'ANTI'>, <TokenType.USERDEFINED: 'USERDEFINED'>, <TokenType.IDENTIFIER: 'IDENTIFIER'>, <TokenType.BIGSERIAL: 'BIGSERIAL'>, <TokenType.STRUCT: 'STRUCT'>, <TokenType.FINAL: 'FINAL'>, <TokenType.TRUNCATE: 'TRUNCATE'>, <TokenType.ASC: 'ASC'>, <TokenType.OBJECT: 'OBJECT'>, <TokenType.INT128: 'INT128'>, <TokenType.BOOLEAN: 'BOOLEAN'>, <TokenType.MODEL: 'MODEL'>, <TokenType.DELETE: 'DELETE'>, <TokenType.ISNULL: 'ISNULL'>, <TokenType.DATETIME: 'DATETIME'>, <TokenType.DEFAULT: 'DEFAULT'>, <TokenType.CHAR: 'CHAR'>, <TokenType.DECIMAL: 'DECIMAL'>, <TokenType.AGGREGATEFUNCTION: 'AGGREGATEFUNCTION'>, <TokenType.SIMPLEAGGREGATEFUNCTION: 'SIMPLEAGGREGATEFUNCTION'>, <TokenType.DATABASE: 'DATABASE'>, <TokenType.PSEUDO_TYPE: 'PSEUDO_TYPE'>, <TokenType.ARRAY: 'ARRAY'>, <TokenType.TABLE: 'TABLE'>, <TokenType.CASE: 'CASE'>, <TokenType.ENUM16: 'ENUM16'>, <TokenType.FIXEDSTRING: 'FIXEDSTRING'>, <TokenType.NESTED: 'NESTED'>, <TokenType.INT8RANGE: 'INT8RANGE'>, <TokenType.CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'>, <TokenType.COLUMN: 'COLUMN'>, <TokenType.RECURSIVE: 'RECURSIVE'>, <TokenType.UINT128: 'UINT128'>, <TokenType.BINARY: 'BINARY'>, <TokenType.BIT: 'BIT'>, <TokenType.HLLSKETCH: 'HLLSKETCH'>, <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, <TokenType.CACHE: 'CACHE'>, <TokenType.VIEW: 'VIEW'>, <TokenType.PARTITION: 'PARTITION'>, <TokenType.NVARCHAR: 'NVARCHAR'>, <TokenType.MERGE: 'MERGE'>, <TokenType.SMALLINT: 'SMALLINT'>, <TokenType.CURRENT_TIME: 'CURRENT_TIME'>, <TokenType.SERIAL: 'SERIAL'>, <TokenType.INET: 'INET'>, <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, <TokenType.FALSE: 'FALSE'>, <TokenType.DESCRIBE: 'DESCRIBE'>, <TokenType.ROWS: 'ROWS'>, <TokenType.EXECUTE: 'EXECUTE'>, <TokenType.DATETIME64: 'DATETIME64'>, <TokenType.SEQUENCE: 'SEQUENCE'>, <TokenType.HSTORE: 'HSTORE'>, <TokenType.FORMAT: 'FORMAT'>, <TokenType.IPV4: 'IPV4'>, <TokenType.ORDINALITY: 'ORDINALITY'>, <TokenType.SOME: 'SOME'>, <TokenType.RANGE: 'RANGE'>, <TokenType.IPPREFIX: 'IPPREFIX'>, <TokenType.PROCEDURE: 'PROCEDURE'>, <TokenType.INT4RANGE: 'INT4RANGE'>, <TokenType.NEXT: 'NEXT'>, <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, <TokenType.OVERLAPS: 'OVERLAPS'>, <TokenType.UINT: 'UINT'>, <TokenType.DIV: 'DIV'>, <TokenType.SUPER: 'SUPER'>, <TokenType.JSONB: 'JSONB'>, <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <TokenType.TOP: 'TOP'>, <TokenType.PIVOT: 'PIVOT'>, <TokenType.KEEP: 'KEEP'>, <TokenType.VARBINARY: 'VARBINARY'>, <TokenType.TINYTEXT: 'TINYTEXT'>, <TokenType.TIMESTAMP_MS: 'TIMESTAMP_MS'>, <TokenType.FLOAT: 'FLOAT'>, <TokenType.TEXT: 'TEXT'>, <TokenType.UNKNOWN: 'UNKNOWN'>, <TokenType.STORAGE_INTEGRATION: 'STORAGE_INTEGRATION'>, <TokenType.BEGIN: 'BEGIN'>, <TokenType.VARCHAR: 'VARCHAR'>, <TokenType.XML: 'XML'>, <TokenType.LOAD: 'LOAD'>, <TokenType.UNIQUEIDENTIFIER: 'UNIQUEIDENTIFIER'>, <TokenType.LONGTEXT: 'LONGTEXT'>, <TokenType.IPV6: 'IPV6'>, <TokenType.COMMAND: 'COMMAND'>, <TokenType.FILTER: 'FILTER'>, <TokenType.COMMENT: 'COMMENT'>, <TokenType.LONGBLOB: 'LONGBLOB'>, <TokenType.INT256: 'INT256'>, <TokenType.TINYINT: 'TINYINT'>, <TokenType.UNIQUE: 'UNIQUE'>, <TokenType.NAME: 'NAME'>, <TokenType.TIMETZ: 'TIMETZ'>, <TokenType.ROW: 'ROW'>, <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, <TokenType.CURRENT_DATE: 'CURRENT_DATE'>, <TokenType.TIME: 'TIME'>, <TokenType.DATE32: 'DATE32'>, <TokenType.VAR: 'VAR'>, <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, <TokenType.JSON: 'JSON'>, <TokenType.LOWCARDINALITY: 'LOWCARDINALITY'>, <TokenType.ROWVERSION: 'ROWVERSION'>, <TokenType.MAP: 'MAP'>, <TokenType.DATERANGE: 'DATERANGE'>, <TokenType.TRUE: 'TRUE'>, <TokenType.TSTZRANGE: 'TSTZRANGE'>, <TokenType.UDECIMAL: 'UDECIMAL'>, <TokenType.TINYBLOB: 'TINYBLOB'>, <TokenType.CONSTRAINT: 'CONSTRAINT'>, <TokenType.END: 'END'>, <TokenType.SEMI: 'SEMI'>, <TokenType.NCHAR: 'NCHAR'>, <TokenType.SMALLSERIAL: 'SMALLSERIAL'>, <TokenType.BPCHAR: 'BPCHAR'>, <TokenType.SET: 'SET'>, <TokenType.SCHEMA: 'SCHEMA'>, <TokenType.TEMPORARY: 'TEMPORARY'>, <TokenType.SMALLMONEY: 'SMALLMONEY'>, <TokenType.CURRENT_DATETIME: 'CURRENT_DATETIME'>, <TokenType.REPLACE: 'REPLACE'>, <TokenType.ENUM8: 'ENUM8'>, <TokenType.CURRENT_USER: 'CURRENT_USER'>, <TokenType.UMEDIUMINT: 'UMEDIUMINT'>, <TokenType.IMAGE: 'IMAGE'>, <TokenType.INT: 'INT'>, <TokenType.DESC: 'DESC'>, <TokenType.ALL: 'ALL'>, <TokenType.UPDATE: 'UPDATE'>, <TokenType.OBJECT_IDENTIFIER: 'OBJECT_IDENTIFIER'>, <TokenType.REFRESH: 'REFRESH'>, <TokenType.MEDIUMINT: 'MEDIUMINT'>, <TokenType.FOREIGN_KEY: 'FOREIGN_KEY'>, <TokenType.PERCENT: 'PERCENT'>, <TokenType.ENUM: 'ENUM'>, <TokenType.ANY: 'ANY'>, <TokenType.MEDIUMBLOB: 'MEDIUMBLOB'>, <TokenType.NUMRANGE: 'NUMRANGE'>, <TokenType.DATE: 'DATE'>, <TokenType.EXISTS: 'EXISTS'>, <TokenType.AUTO_INCREMENT: 'AUTO_INCREMENT'>, <TokenType.DOUBLE: 'DOUBLE'>, <TokenType.UBIGINT: 'UBIGINT'>, <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, <TokenType.PRAGMA: 'PRAGMA'>, <TokenType.DICTIONARY: 'DICTIONARY'>, <TokenType.IS: 'IS'>, <TokenType.COLLATE: 'COLLATE'>, <TokenType.UINT256: 'UINT256'>, <TokenType.UUID: 'UUID'>, <TokenType.COMMIT: 'COMMIT'>, <TokenType.OVERWRITE: 'OVERWRITE'>, <TokenType.UNPIVOT: 'UNPIVOT'>, <TokenType.KILL: 'KILL'>, <TokenType.NULLABLE: 'NULLABLE'>, <TokenType.OPERATOR: 'OPERATOR'>, <TokenType.NULL: 'NULL'>, <TokenType.INDEX: 'INDEX'>}</span> + <label class="view-value-button pdoc-button" for="Presto.Parser.TABLE_ALIAS_TOKENS-view-value"></label><span class="default_value">{<TokenType.BIGINT: 'BIGINT'>, <TokenType.RANGE: 'RANGE'>, <TokenType.SMALLINT: 'SMALLINT'>, <TokenType.ROW: 'ROW'>, <TokenType.COMMENT: 'COMMENT'>, <TokenType.PROCEDURE: 'PROCEDURE'>, <TokenType.HLLSKETCH: 'HLLSKETCH'>, <TokenType.COMMIT: 'COMMIT'>, <TokenType.TABLE: 'TABLE'>, <TokenType.CONSTRAINT: 'CONSTRAINT'>, <TokenType.REFERENCES: 'REFERENCES'>, <TokenType.UNIQUEIDENTIFIER: 'UNIQUEIDENTIFIER'>, <TokenType.MONEY: 'MONEY'>, <TokenType.IPV4: 'IPV4'>, <TokenType.SETTINGS: 'SETTINGS'>, <TokenType.NAME: 'NAME'>, <TokenType.UINT128: 'UINT128'>, <TokenType.FALSE: 'FALSE'>, <TokenType.ENUM16: 'ENUM16'>, <TokenType.TIMESTAMP_MS: 'TIMESTAMP_MS'>, <TokenType.UINT256: 'UINT256'>, <TokenType.CASE: 'CASE'>, <TokenType.ISNULL: 'ISNULL'>, <TokenType.ANTI: 'ANTI'>, <TokenType.FINAL: 'FINAL'>, <TokenType.IPV6: 'IPV6'>, <TokenType.GEOMETRY: 'GEOMETRY'>, <TokenType.BIGDECIMAL: 'BIGDECIMAL'>, <TokenType.CURRENT_DATETIME: 'CURRENT_DATETIME'>, <TokenType.MODEL: 'MODEL'>, <TokenType.VARIANT: 'VARIANT'>, <TokenType.DESC: 'DESC'>, <TokenType.IS: 'IS'>, <TokenType.TIMESTAMP_NS: 'TIMESTAMP_NS'>, <TokenType.LOWCARDINALITY: 'LOWCARDINALITY'>, <TokenType.BIGSERIAL: 'BIGSERIAL'>, <TokenType.LONGTEXT: 'LONGTEXT'>, <TokenType.TIMETZ: 'TIMETZ'>, <TokenType.ROWVERSION: 'ROWVERSION'>, <TokenType.UTINYINT: 'UTINYINT'>, <TokenType.JSONB: 'JSONB'>, <TokenType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <TokenType.DATETIME: 'DATETIME'>, <TokenType.NUMMULTIRANGE: 'NUMMULTIRANGE'>, <TokenType.USE: 'USE'>, <TokenType.USMALLINT: 'USMALLINT'>, <TokenType.SMALLSERIAL: 'SMALLSERIAL'>, <TokenType.DECIMAL: 'DECIMAL'>, <TokenType.KILL: 'KILL'>, <TokenType.EXECUTE: 'EXECUTE'>, <TokenType.COLLATE: 'COLLATE'>, <TokenType.OVERWRITE: 'OVERWRITE'>, <TokenType.SOME: 'SOME'>, <TokenType.NEXT: 'NEXT'>, <TokenType.BOOLEAN: 'BOOLEAN'>, <TokenType.AGGREGATEFUNCTION: 'AGGREGATEFUNCTION'>, <TokenType.INET: 'INET'>, <TokenType.CURRENT_TIME: 'CURRENT_TIME'>, <TokenType.FORMAT: 'FORMAT'>, <TokenType.DATEMULTIRANGE: 'DATEMULTIRANGE'>, <TokenType.KEEP: 'KEEP'>, <TokenType.MEDIUMBLOB: 'MEDIUMBLOB'>, <TokenType.ROWS: 'ROWS'>, <TokenType.IMAGE: 'IMAGE'>, <TokenType.TRUE: 'TRUE'>, <TokenType.AUTO_INCREMENT: 'AUTO_INCREMENT'>, <TokenType.SEQUENCE: 'SEQUENCE'>, <TokenType.OBJECT_IDENTIFIER: 'OBJECT_IDENTIFIER'>, <TokenType.DEFAULT: 'DEFAULT'>, <TokenType.DATE32: 'DATE32'>, <TokenType.INT128: 'INT128'>, <TokenType.FIRST: 'FIRST'>, <TokenType.FIXEDSTRING: 'FIXEDSTRING'>, <TokenType.NCHAR: 'NCHAR'>, <TokenType.STRUCT: 'STRUCT'>, <TokenType.UINT: 'UINT'>, <TokenType.BINARY: 'BINARY'>, <TokenType.DATETIME64: 'DATETIME64'>, <TokenType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>, <TokenType.OVERLAPS: 'OVERLAPS'>, <TokenType.STORAGE_INTEGRATION: 'STORAGE_INTEGRATION'>, <TokenType.EXISTS: 'EXISTS'>, <TokenType.TSMULTIRANGE: 'TSMULTIRANGE'>, <TokenType.MERGE: 'MERGE'>, <TokenType.ARRAY: 'ARRAY'>, <TokenType.XML: 'XML'>, <TokenType.ASC: 'ASC'>, <TokenType.UBIGINT: 'UBIGINT'>, <TokenType.CHAR: 'CHAR'>, <TokenType.TIMESTAMP: 'TIMESTAMP'>, <TokenType.PSEUDO_TYPE: 'PSEUDO_TYPE'>, <TokenType.HSTORE: 'HSTORE'>, <TokenType.UPDATE: 'UPDATE'>, <TokenType.PRAGMA: 'PRAGMA'>, <TokenType.DESCRIBE: 'DESCRIBE'>, <TokenType.VIEW: 'VIEW'>, <TokenType.VARCHAR: 'VARCHAR'>, <TokenType.REPLACE: 'REPLACE'>, <TokenType.NUMRANGE: 'NUMRANGE'>, <TokenType.SEMI: 'SEMI'>, <TokenType.TSTZRANGE: 'TSTZRANGE'>, <TokenType.CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'>, <TokenType.TIME: 'TIME'>, <TokenType.MEDIUMTEXT: 'MEDIUMTEXT'>, <TokenType.TSRANGE: 'TSRANGE'>, <TokenType.TOP: 'TOP'>, <TokenType.FOREIGN_KEY: 'FOREIGN_KEY'>, <TokenType.BPCHAR: 'BPCHAR'>, <TokenType.INT4RANGE: 'INT4RANGE'>, <TokenType.TEXT: 'TEXT'>, <TokenType.USERDEFINED: 'USERDEFINED'>, <TokenType.NVARCHAR: 'NVARCHAR'>, <TokenType.REFRESH: 'REFRESH'>, <TokenType.SMALLMONEY: 'SMALLMONEY'>, <TokenType.OBJECT: 'OBJECT'>, <TokenType.COLUMN: 'COLUMN'>, <TokenType.INDEX: 'INDEX'>, <TokenType.INT256: 'INT256'>, <TokenType.LONGBLOB: 'LONGBLOB'>, <TokenType.VARBINARY: 'VARBINARY'>, <TokenType.VAR: 'VAR'>, <TokenType.BIT: 'BIT'>, <TokenType.SIMPLEAGGREGATEFUNCTION: 'SIMPLEAGGREGATEFUNCTION'>, <TokenType.NULL: 'NULL'>, <TokenType.NULLABLE: 'NULLABLE'>, <TokenType.NESTED: 'NESTED'>, <TokenType.MAP: 'MAP'>, <TokenType.CACHE: 'CACHE'>, <TokenType.DIV: 'DIV'>, <TokenType.IDENTIFIER: 'IDENTIFIER'>, <TokenType.TRUNCATE: 'TRUNCATE'>, <TokenType.DOUBLE: 'DOUBLE'>, <TokenType.ENUM: 'ENUM'>, <TokenType.IPPREFIX: 'IPPREFIX'>, <TokenType.PIVOT: 'PIVOT'>, <TokenType.TINYINT: 'TINYINT'>, <TokenType.ORDINALITY: 'ORDINALITY'>, <TokenType.DATABASE: 'DATABASE'>, <TokenType.SET: 'SET'>, <TokenType.PARTITION: 'PARTITION'>, <TokenType.UMEDIUMINT: 'UMEDIUMINT'>, <TokenType.DATERANGE: 'DATERANGE'>, <TokenType.YEAR: 'YEAR'>, <TokenType.BEGIN: 'BEGIN'>, <TokenType.DICTIONARY: 'DICTIONARY'>, <TokenType.SERIAL: 'SERIAL'>, <TokenType.INT: 'INT'>, <TokenType.DELETE: 'DELETE'>, <TokenType.TINYBLOB: 'TINYBLOB'>, <TokenType.FLOAT: 'FLOAT'>, <TokenType.PERCENT: 'PERCENT'>, <TokenType.CURRENT_DATE: 'CURRENT_DATE'>, <TokenType.INTERVAL: 'INTERVAL'>, <TokenType.VOLATILE: 'VOLATILE'>, <TokenType.RECURSIVE: 'RECURSIVE'>, <TokenType.LOAD: 'LOAD'>, <TokenType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <TokenType.SUPER: 'SUPER'>, <TokenType.FILTER: 'FILTER'>, <TokenType.GEOGRAPHY: 'GEOGRAPHY'>, <TokenType.ESCAPE: 'ESCAPE'>, <TokenType.FUNCTION: 'FUNCTION'>, <TokenType.ANY: 'ANY'>, <TokenType.DATE: 'DATE'>, <TokenType.TINYTEXT: 'TINYTEXT'>, <TokenType.TIMESTAMP_S: 'TIMESTAMP_S'>, <TokenType.UNIQUE: 'UNIQUE'>, <TokenType.UNPIVOT: 'UNPIVOT'>, <TokenType.TEMPORARY: 'TEMPORARY'>, <TokenType.INT4MULTIRANGE: 'INT4MULTIRANGE'>, <TokenType.IPADDRESS: 'IPADDRESS'>, <TokenType.UDECIMAL: 'UDECIMAL'>, <TokenType.OPERATOR: 'OPERATOR'>, <TokenType.ALL: 'ALL'>, <TokenType.MEDIUMINT: 'MEDIUMINT'>, <TokenType.CURRENT_USER: 'CURRENT_USER'>, <TokenType.UNKNOWN: 'UNKNOWN'>, <TokenType.UUID: 'UUID'>, <TokenType.COMMAND: 'COMMAND'>, <TokenType.INT8RANGE: 'INT8RANGE'>, <TokenType.ENUM8: 'ENUM8'>, <TokenType.SCHEMA: 'SCHEMA'>, <TokenType.END: 'END'>, <TokenType.JSON: 'JSON'>, <TokenType.INT8MULTIRANGE: 'INT8MULTIRANGE'>, <TokenType.SHOW: 'SHOW'>}</span> </div> @@ -1984,6 +2109,7 @@ Default: 3</li> <dd id="Presto.Parser.JSON_ARROWS_REQUIRE_JSON_TYPE" class="variable"><a href="../parser.html#Parser.JSON_ARROWS_REQUIRE_JSON_TYPE">JSON_ARROWS_REQUIRE_JSON_TYPE</a></dd> <dd id="Presto.Parser.SUPPORTS_IMPLICIT_UNNEST" class="variable"><a href="../parser.html#Parser.SUPPORTS_IMPLICIT_UNNEST">SUPPORTS_IMPLICIT_UNNEST</a></dd> <dd id="Presto.Parser.INTERVAL_SPANS" class="variable"><a href="../parser.html#Parser.INTERVAL_SPANS">INTERVAL_SPANS</a></dd> + <dd id="Presto.Parser.SUPPORTS_PARTITION_SELECTION" class="variable"><a href="../parser.html#Parser.SUPPORTS_PARTITION_SELECTION">SUPPORTS_PARTITION_SELECTION</a></dd> <dd id="Presto.Parser.error_level" class="variable"><a href="../parser.html#Parser.error_level">error_level</a></dd> <dd id="Presto.Parser.error_message_context" class="variable"><a href="../parser.html#Parser.error_message_context">error_message_context</a></dd> <dd id="Presto.Parser.max_errors" class="variable"><a href="../parser.html#Parser.max_errors">max_errors</a></dd> @@ -2172,114 +2298,175 @@ Default: 3</li> </span><span id="Presto.Generator-444"><a href="#Presto.Generator-444"><span class="linenos">444</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Xor</span><span class="p">:</span> <span class="n">bool_xor_sql</span><span class="p">,</span> </span><span id="Presto.Generator-445"><a href="#Presto.Generator-445"><span class="linenos">445</span></a> <span class="p">}</span> </span><span id="Presto.Generator-446"><a href="#Presto.Generator-446"><span class="linenos">446</span></a> -</span><span id="Presto.Generator-447"><a href="#Presto.Generator-447"><span class="linenos">447</span></a> <span class="k">def</span> <span class="nf">strtounix_sql</span><span class="p">(</span><span class="bp">self</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">StrToUnix</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator-448"><a href="#Presto.Generator-448"><span class="linenos">448</span></a> <span class="c1"># Since `TO_UNIXTIME` requires a `TIMESTAMP`, we need to parse the argument into one.</span> -</span><span id="Presto.Generator-449"><a href="#Presto.Generator-449"><span class="linenos">449</span></a> <span class="c1"># To do this, we first try to `DATE_PARSE` it, but since this can fail when there's a</span> -</span><span id="Presto.Generator-450"><a href="#Presto.Generator-450"><span class="linenos">450</span></a> <span class="c1"># timezone involved, we wrap it in a `TRY` call and use `PARSE_DATETIME` as a fallback,</span> -</span><span id="Presto.Generator-451"><a href="#Presto.Generator-451"><span class="linenos">451</span></a> <span class="c1"># which seems to be using the same time mapping as Hive, as per:</span> -</span><span id="Presto.Generator-452"><a href="#Presto.Generator-452"><span class="linenos">452</span></a> <span class="c1"># https://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html</span> -</span><span id="Presto.Generator-453"><a href="#Presto.Generator-453"><span class="linenos">453</span></a> <span class="n">value_as_text</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</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">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TEXT</span><span class="p">)</span> -</span><span id="Presto.Generator-454"><a href="#Presto.Generator-454"><span class="linenos">454</span></a> <span class="n">parse_without_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DATE_PARSE"</span><span class="p">,</span> <span class="n">value_as_text</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">))</span> -</span><span id="Presto.Generator-455"><a href="#Presto.Generator-455"><span class="linenos">455</span></a> <span class="n">parse_with_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span> -</span><span id="Presto.Generator-456"><a href="#Presto.Generator-456"><span class="linenos">456</span></a> <span class="s2">"PARSE_DATETIME"</span><span class="p">,</span> -</span><span id="Presto.Generator-457"><a href="#Presto.Generator-457"><span class="linenos">457</span></a> <span class="n">value_as_text</span><span class="p">,</span> -</span><span id="Presto.Generator-458"><a href="#Presto.Generator-458"><span class="linenos">458</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_MAPPING</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_TRIE</span><span class="p">),</span> -</span><span id="Presto.Generator-459"><a href="#Presto.Generator-459"><span class="linenos">459</span></a> <span class="p">)</span> -</span><span id="Presto.Generator-460"><a href="#Presto.Generator-460"><span class="linenos">460</span></a> <span class="n">coalesced</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"COALESCE"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"TRY"</span><span class="p">,</span> <span class="n">parse_without_tz</span><span class="p">),</span> <span class="n">parse_with_tz</span><span class="p">)</span> -</span><span id="Presto.Generator-461"><a href="#Presto.Generator-461"><span class="linenos">461</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 class="s2">"TO_UNIXTIME"</span><span class="p">,</span> <span class="n">coalesced</span><span class="p">)</span> -</span><span id="Presto.Generator-462"><a href="#Presto.Generator-462"><span class="linenos">462</span></a> -</span><span id="Presto.Generator-463"><a href="#Presto.Generator-463"><span class="linenos">463</span></a> <span class="k">def</span> <span class="nf">bracket_sql</span><span class="p">(</span><span class="bp">self</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">Bracket</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator-464"><a href="#Presto.Generator-464"><span class="linenos">464</span></a> <span class="k">if</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">"safe"</span><span class="p">):</span> -</span><span id="Presto.Generator-465"><a href="#Presto.Generator-465"><span class="linenos">465</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="Presto.Generator-466"><a href="#Presto.Generator-466"><span class="linenos">466</span></a> <span class="s2">"ELEMENT_AT"</span><span class="p">,</span> -</span><span id="Presto.Generator-467"><a href="#Presto.Generator-467"><span class="linenos">467</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="Presto.Generator-468"><a href="#Presto.Generator-468"><span class="linenos">468</span></a> <span class="n">seq_get</span><span class="p">(</span> -</span><span id="Presto.Generator-469"><a href="#Presto.Generator-469"><span class="linenos">469</span></a> <span class="n">apply_index_offset</span><span class="p">(</span> -</span><span id="Presto.Generator-470"><a href="#Presto.Generator-470"><span class="linenos">470</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="Presto.Generator-471"><a href="#Presto.Generator-471"><span class="linenos">471</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> -</span><span id="Presto.Generator-472"><a href="#Presto.Generator-472"><span class="linenos">472</span></a> <span class="mi">1</span> <span class="o">-</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">"offset"</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> -</span><span id="Presto.Generator-473"><a href="#Presto.Generator-473"><span class="linenos">473</span></a> <span class="p">),</span> -</span><span id="Presto.Generator-474"><a href="#Presto.Generator-474"><span class="linenos">474</span></a> <span class="mi">0</span><span class="p">,</span> -</span><span id="Presto.Generator-475"><a href="#Presto.Generator-475"><span class="linenos">475</span></a> <span class="p">),</span> -</span><span id="Presto.Generator-476"><a href="#Presto.Generator-476"><span class="linenos">476</span></a> <span class="p">)</span> -</span><span id="Presto.Generator-477"><a href="#Presto.Generator-477"><span class="linenos">477</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">bracket_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="Presto.Generator-478"><a href="#Presto.Generator-478"><span class="linenos">478</span></a> -</span><span id="Presto.Generator-479"><a href="#Presto.Generator-479"><span class="linenos">479</span></a> <span class="k">def</span> <span class="nf">struct_sql</span><span class="p">(</span><span class="bp">self</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">Struct</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator-480"><a href="#Presto.Generator-480"><span class="linenos">480</span></a> <span class="kn">from</span> <span class="nn">sqlglot.optimizer.annotate_types</span> <span class="kn">import</span> <span class="n">annotate_types</span> -</span><span id="Presto.Generator-481"><a href="#Presto.Generator-481"><span class="linenos">481</span></a> -</span><span id="Presto.Generator-482"><a href="#Presto.Generator-482"><span class="linenos">482</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">annotate_types</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="Presto.Generator-483"><a href="#Presto.Generator-483"><span class="linenos">483</span></a> <span class="n">values</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="Presto.Generator-484"><a href="#Presto.Generator-484"><span class="linenos">484</span></a> <span class="n">schema</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="Presto.Generator-485"><a href="#Presto.Generator-485"><span class="linenos">485</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Presto.Generator-486"><a href="#Presto.Generator-486"><span class="linenos">486</span></a> -</span><span id="Presto.Generator-487"><a href="#Presto.Generator-487"><span class="linenos">487</span></a> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> -</span><span id="Presto.Generator-488"><a href="#Presto.Generator-488"><span class="linenos">488</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">PropertyEQ</span><span class="p">):</span> -</span><span id="Presto.Generator-489"><a href="#Presto.Generator-489"><span class="linenos">489</span></a> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">UNKNOWN</span><span class="p">):</span> -</span><span id="Presto.Generator-490"><a href="#Presto.Generator-490"><span class="linenos">490</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Presto.Generator-491"><a href="#Presto.Generator-491"><span class="linenos">491</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Presto.Generator-492"><a href="#Presto.Generator-492"><span class="linenos">492</span></a> <span class="n">schema</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="Presto.Generator-493"><a href="#Presto.Generator-493"><span class="linenos">493</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="s2">"expression"</span><span class="p">))</span> -</span><span id="Presto.Generator-494"><a href="#Presto.Generator-494"><span class="linenos">494</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Presto.Generator-495"><a href="#Presto.Generator-495"><span class="linenos">495</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">))</span> -</span><span id="Presto.Generator-496"><a href="#Presto.Generator-496"><span class="linenos">496</span></a> -</span><span id="Presto.Generator-497"><a href="#Presto.Generator-497"><span class="linenos">497</span></a> <span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">)</span> -</span><span id="Presto.Generator-498"><a href="#Presto.Generator-498"><span class="linenos">498</span></a> -</span><span id="Presto.Generator-499"><a href="#Presto.Generator-499"><span class="linenos">499</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">size</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span> <span class="o">!=</span> <span class="n">size</span><span class="p">:</span> -</span><span id="Presto.Generator-500"><a href="#Presto.Generator-500"><span class="linenos">500</span></a> <span class="k">if</span> <span class="n">unknown_type</span><span class="p">:</span> -</span><span id="Presto.Generator-501"><a href="#Presto.Generator-501"><span class="linenos">501</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span> -</span><span id="Presto.Generator-502"><a href="#Presto.Generator-502"><span class="linenos">502</span></a> <span class="s2">"Cannot convert untyped key-value definitions (try annotate_types)."</span> -</span><span id="Presto.Generator-503"><a href="#Presto.Generator-503"><span class="linenos">503</span></a> <span class="p">)</span> -</span><span id="Presto.Generator-504"><a href="#Presto.Generator-504"><span class="linenos">504</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 class="s2">"ROW"</span><span class="p">,</span> <span class="o">*</span><span class="n">values</span><span class="p">)</span> -</span><span id="Presto.Generator-505"><a href="#Presto.Generator-505"><span class="linenos">505</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"CAST(ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">values</span><span class="p">)</span><span class="si">}</span><span class="s2">) AS ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span><span class="si">}</span><span class="s2">))"</span> -</span><span id="Presto.Generator-506"><a href="#Presto.Generator-506"><span class="linenos">506</span></a> -</span><span id="Presto.Generator-507"><a href="#Presto.Generator-507"><span class="linenos">507</span></a> <span class="k">def</span> <span class="nf">interval_sql</span><span class="p">(</span><span class="bp">self</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">Interval</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator-508"><a href="#Presto.Generator-508"><span class="linenos">508</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"unit"</span><span class="p">)</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"WEEK"</span><span class="p">):</span> -</span><span id="Presto.Generator-509"><a href="#Presto.Generator-509"><span class="linenos">509</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"(</span><span class="si">{</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> * INTERVAL '7' DAY)"</span> -</span><span id="Presto.Generator-510"><a href="#Presto.Generator-510"><span class="linenos">510</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">interval_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="Presto.Generator-511"><a href="#Presto.Generator-511"><span class="linenos">511</span></a> -</span><span id="Presto.Generator-512"><a href="#Presto.Generator-512"><span class="linenos">512</span></a> <span class="k">def</span> <span class="nf">transaction_sql</span><span class="p">(</span><span class="bp">self</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">Transaction</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator-513"><a href="#Presto.Generator-513"><span class="linenos">513</span></a> <span class="n">modes</span> <span class="o">=</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">"modes"</span><span class="p">)</span> -</span><span id="Presto.Generator-514"><a href="#Presto.Generator-514"><span class="linenos">514</span></a> <span class="n">modes</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" </span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">modes</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">modes</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="Presto.Generator-515"><a href="#Presto.Generator-515"><span class="linenos">515</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"START TRANSACTION</span><span class="si">{</span><span class="n">modes</span><span class="si">}</span><span class="s2">"</span> -</span><span id="Presto.Generator-516"><a href="#Presto.Generator-516"><span class="linenos">516</span></a> -</span><span id="Presto.Generator-517"><a href="#Presto.Generator-517"><span class="linenos">517</span></a> <span class="k">def</span> <span class="nf">generateseries_sql</span><span class="p">(</span><span class="bp">self</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">GenerateSeries</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator-518"><a href="#Presto.Generator-518"><span class="linenos">518</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"start"</span><span class="p">]</span> -</span><span id="Presto.Generator-519"><a href="#Presto.Generator-519"><span class="linenos">519</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"end"</span><span class="p">]</span> -</span><span id="Presto.Generator-520"><a href="#Presto.Generator-520"><span class="linenos">520</span></a> <span class="n">step</span> <span class="o">=</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">"step"</span><span class="p">)</span> -</span><span id="Presto.Generator-521"><a href="#Presto.Generator-521"><span class="linenos">521</span></a> -</span><span id="Presto.Generator-522"><a href="#Presto.Generator-522"><span class="linenos">522</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> -</span><span id="Presto.Generator-523"><a href="#Presto.Generator-523"><span class="linenos">523</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span> -</span><span id="Presto.Generator-524"><a href="#Presto.Generator-524"><span class="linenos">524</span></a> <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> -</span><span id="Presto.Generator-525"><a href="#Presto.Generator-525"><span class="linenos">525</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">end</span><span class="o">.</span><span class="n">to</span> -</span><span id="Presto.Generator-526"><a href="#Presto.Generator-526"><span class="linenos">526</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Presto.Generator-527"><a href="#Presto.Generator-527"><span class="linenos">527</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="Presto.Generator-528"><a href="#Presto.Generator-528"><span class="linenos">528</span></a> -</span><span id="Presto.Generator-529"><a href="#Presto.Generator-529"><span class="linenos">529</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">and</span> <span class="n">target_type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"timestamp"</span><span class="p">):</span> -</span><span id="Presto.Generator-530"><a href="#Presto.Generator-530"><span class="linenos">530</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">is</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span><span class="p">:</span> -</span><span id="Presto.Generator-531"><a href="#Presto.Generator-531"><span class="linenos">531</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> -</span><span id="Presto.Generator-532"><a href="#Presto.Generator-532"><span class="linenos">532</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Presto.Generator-533"><a href="#Presto.Generator-533"><span class="linenos">533</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> -</span><span id="Presto.Generator-534"><a href="#Presto.Generator-534"><span class="linenos">534</span></a> -</span><span id="Presto.Generator-535"><a href="#Presto.Generator-535"><span class="linenos">535</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 class="s2">"SEQUENCE"</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">step</span><span class="p">)</span> -</span><span id="Presto.Generator-536"><a href="#Presto.Generator-536"><span class="linenos">536</span></a> -</span><span id="Presto.Generator-537"><a href="#Presto.Generator-537"><span class="linenos">537</span></a> <span class="k">def</span> <span class="nf">offset_limit_modifiers</span><span class="p">(</span> -</span><span id="Presto.Generator-538"><a href="#Presto.Generator-538"><span class="linenos">538</span></a> <span class="bp">self</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">Expression</span><span class="p">,</span> <span class="n">fetch</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">limit</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">exp</span><span class="o">.</span><span class="n">Fetch</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Limit</span><span class="p">]</span> -</span><span id="Presto.Generator-539"><a href="#Presto.Generator-539"><span class="linenos">539</span></a> <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="Presto.Generator-540"><a href="#Presto.Generator-540"><span class="linenos">540</span></a> <span class="k">return</span> <span class="p">[</span> -</span><span id="Presto.Generator-541"><a href="#Presto.Generator-541"><span class="linenos">541</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"offset"</span><span class="p">),</span> -</span><span id="Presto.Generator-542"><a href="#Presto.Generator-542"><span class="linenos">542</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">limit</span><span class="p">),</span> -</span><span id="Presto.Generator-543"><a href="#Presto.Generator-543"><span class="linenos">543</span></a> <span class="p">]</span> -</span><span id="Presto.Generator-544"><a href="#Presto.Generator-544"><span class="linenos">544</span></a> -</span><span id="Presto.Generator-545"><a href="#Presto.Generator-545"><span class="linenos">545</span></a> <span class="k">def</span> <span class="nf">create_sql</span><span class="p">(</span><span class="bp">self</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">Create</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator-546"><a href="#Presto.Generator-546"><span class="linenos">546</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Presto.Generator-547"><a href="#Presto.Generator-547"><span class="linenos">547</span></a><span class="sd"> Presto doesn't support CREATE VIEW with expressions (ex: `CREATE VIEW x (cola)` then `(cola)` is the expression),</span> -</span><span id="Presto.Generator-548"><a href="#Presto.Generator-548"><span class="linenos">548</span></a><span class="sd"> so we need to remove them</span> -</span><span id="Presto.Generator-549"><a href="#Presto.Generator-549"><span class="linenos">549</span></a><span class="sd"> """</span> -</span><span id="Presto.Generator-550"><a href="#Presto.Generator-550"><span class="linenos">550</span></a> <span class="n">kind</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"kind"</span><span class="p">]</span> -</span><span id="Presto.Generator-551"><a href="#Presto.Generator-551"><span class="linenos">551</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> -</span><span id="Presto.Generator-552"><a href="#Presto.Generator-552"><span class="linenos">552</span></a> <span class="k">if</span> <span class="n">kind</span> <span class="o">==</span> <span class="s2">"VIEW"</span> <span class="ow">and</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> -</span><span id="Presto.Generator-553"><a href="#Presto.Generator-553"><span class="linenos">553</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> -</span><span id="Presto.Generator-554"><a href="#Presto.Generator-554"><span class="linenos">554</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">create_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Presto.Generator-447"><a href="#Presto.Generator-447"><span class="linenos">447</span></a> <span class="n">RESERVED_KEYWORDS</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="Presto.Generator-448"><a href="#Presto.Generator-448"><span class="linenos">448</span></a> <span class="s2">"alter"</span><span class="p">,</span> +</span><span id="Presto.Generator-449"><a href="#Presto.Generator-449"><span class="linenos">449</span></a> <span class="s2">"and"</span><span class="p">,</span> +</span><span id="Presto.Generator-450"><a href="#Presto.Generator-450"><span class="linenos">450</span></a> <span class="s2">"as"</span><span class="p">,</span> +</span><span id="Presto.Generator-451"><a href="#Presto.Generator-451"><span class="linenos">451</span></a> <span class="s2">"between"</span><span class="p">,</span> +</span><span id="Presto.Generator-452"><a href="#Presto.Generator-452"><span class="linenos">452</span></a> <span class="s2">"by"</span><span class="p">,</span> +</span><span id="Presto.Generator-453"><a href="#Presto.Generator-453"><span class="linenos">453</span></a> <span class="s2">"case"</span><span class="p">,</span> +</span><span id="Presto.Generator-454"><a href="#Presto.Generator-454"><span class="linenos">454</span></a> <span class="s2">"cast"</span><span class="p">,</span> +</span><span id="Presto.Generator-455"><a href="#Presto.Generator-455"><span class="linenos">455</span></a> <span class="s2">"constraint"</span><span class="p">,</span> +</span><span id="Presto.Generator-456"><a href="#Presto.Generator-456"><span class="linenos">456</span></a> <span class="s2">"create"</span><span class="p">,</span> +</span><span id="Presto.Generator-457"><a href="#Presto.Generator-457"><span class="linenos">457</span></a> <span class="s2">"cross"</span><span class="p">,</span> +</span><span id="Presto.Generator-458"><a href="#Presto.Generator-458"><span class="linenos">458</span></a> <span class="s2">"current_time"</span><span class="p">,</span> +</span><span id="Presto.Generator-459"><a href="#Presto.Generator-459"><span class="linenos">459</span></a> <span class="s2">"current_timestamp"</span><span class="p">,</span> +</span><span id="Presto.Generator-460"><a href="#Presto.Generator-460"><span class="linenos">460</span></a> <span class="s2">"deallocate"</span><span class="p">,</span> +</span><span id="Presto.Generator-461"><a href="#Presto.Generator-461"><span class="linenos">461</span></a> <span class="s2">"delete"</span><span class="p">,</span> +</span><span id="Presto.Generator-462"><a href="#Presto.Generator-462"><span class="linenos">462</span></a> <span class="s2">"describe"</span><span class="p">,</span> +</span><span id="Presto.Generator-463"><a href="#Presto.Generator-463"><span class="linenos">463</span></a> <span class="s2">"distinct"</span><span class="p">,</span> +</span><span id="Presto.Generator-464"><a href="#Presto.Generator-464"><span class="linenos">464</span></a> <span class="s2">"drop"</span><span class="p">,</span> +</span><span id="Presto.Generator-465"><a href="#Presto.Generator-465"><span class="linenos">465</span></a> <span class="s2">"else"</span><span class="p">,</span> +</span><span id="Presto.Generator-466"><a href="#Presto.Generator-466"><span class="linenos">466</span></a> <span class="s2">"end"</span><span class="p">,</span> +</span><span id="Presto.Generator-467"><a href="#Presto.Generator-467"><span class="linenos">467</span></a> <span class="s2">"escape"</span><span class="p">,</span> +</span><span id="Presto.Generator-468"><a href="#Presto.Generator-468"><span class="linenos">468</span></a> <span class="s2">"except"</span><span class="p">,</span> +</span><span id="Presto.Generator-469"><a href="#Presto.Generator-469"><span class="linenos">469</span></a> <span class="s2">"execute"</span><span class="p">,</span> +</span><span id="Presto.Generator-470"><a href="#Presto.Generator-470"><span class="linenos">470</span></a> <span class="s2">"exists"</span><span class="p">,</span> +</span><span id="Presto.Generator-471"><a href="#Presto.Generator-471"><span class="linenos">471</span></a> <span class="s2">"extract"</span><span class="p">,</span> +</span><span id="Presto.Generator-472"><a href="#Presto.Generator-472"><span class="linenos">472</span></a> <span class="s2">"false"</span><span class="p">,</span> +</span><span id="Presto.Generator-473"><a href="#Presto.Generator-473"><span class="linenos">473</span></a> <span class="s2">"for"</span><span class="p">,</span> +</span><span id="Presto.Generator-474"><a href="#Presto.Generator-474"><span class="linenos">474</span></a> <span class="s2">"from"</span><span class="p">,</span> +</span><span id="Presto.Generator-475"><a href="#Presto.Generator-475"><span class="linenos">475</span></a> <span class="s2">"full"</span><span class="p">,</span> +</span><span id="Presto.Generator-476"><a href="#Presto.Generator-476"><span class="linenos">476</span></a> <span class="s2">"group"</span><span class="p">,</span> +</span><span id="Presto.Generator-477"><a href="#Presto.Generator-477"><span class="linenos">477</span></a> <span class="s2">"having"</span><span class="p">,</span> +</span><span id="Presto.Generator-478"><a href="#Presto.Generator-478"><span class="linenos">478</span></a> <span class="s2">"in"</span><span class="p">,</span> +</span><span id="Presto.Generator-479"><a href="#Presto.Generator-479"><span class="linenos">479</span></a> <span class="s2">"inner"</span><span class="p">,</span> +</span><span id="Presto.Generator-480"><a href="#Presto.Generator-480"><span class="linenos">480</span></a> <span class="s2">"insert"</span><span class="p">,</span> +</span><span id="Presto.Generator-481"><a href="#Presto.Generator-481"><span class="linenos">481</span></a> <span class="s2">"intersect"</span><span class="p">,</span> +</span><span id="Presto.Generator-482"><a href="#Presto.Generator-482"><span class="linenos">482</span></a> <span class="s2">"into"</span><span class="p">,</span> +</span><span id="Presto.Generator-483"><a href="#Presto.Generator-483"><span class="linenos">483</span></a> <span class="s2">"is"</span><span class="p">,</span> +</span><span id="Presto.Generator-484"><a href="#Presto.Generator-484"><span class="linenos">484</span></a> <span class="s2">"join"</span><span class="p">,</span> +</span><span id="Presto.Generator-485"><a href="#Presto.Generator-485"><span class="linenos">485</span></a> <span class="s2">"left"</span><span class="p">,</span> +</span><span id="Presto.Generator-486"><a href="#Presto.Generator-486"><span class="linenos">486</span></a> <span class="s2">"like"</span><span class="p">,</span> +</span><span id="Presto.Generator-487"><a href="#Presto.Generator-487"><span class="linenos">487</span></a> <span class="s2">"natural"</span><span class="p">,</span> +</span><span id="Presto.Generator-488"><a href="#Presto.Generator-488"><span class="linenos">488</span></a> <span class="s2">"not"</span><span class="p">,</span> +</span><span id="Presto.Generator-489"><a href="#Presto.Generator-489"><span class="linenos">489</span></a> <span class="s2">"null"</span><span class="p">,</span> +</span><span id="Presto.Generator-490"><a href="#Presto.Generator-490"><span class="linenos">490</span></a> <span class="s2">"on"</span><span class="p">,</span> +</span><span id="Presto.Generator-491"><a href="#Presto.Generator-491"><span class="linenos">491</span></a> <span class="s2">"or"</span><span class="p">,</span> +</span><span id="Presto.Generator-492"><a href="#Presto.Generator-492"><span class="linenos">492</span></a> <span class="s2">"order"</span><span class="p">,</span> +</span><span id="Presto.Generator-493"><a href="#Presto.Generator-493"><span class="linenos">493</span></a> <span class="s2">"outer"</span><span class="p">,</span> +</span><span id="Presto.Generator-494"><a href="#Presto.Generator-494"><span class="linenos">494</span></a> <span class="s2">"prepare"</span><span class="p">,</span> +</span><span id="Presto.Generator-495"><a href="#Presto.Generator-495"><span class="linenos">495</span></a> <span class="s2">"right"</span><span class="p">,</span> +</span><span id="Presto.Generator-496"><a href="#Presto.Generator-496"><span class="linenos">496</span></a> <span class="s2">"select"</span><span class="p">,</span> +</span><span id="Presto.Generator-497"><a href="#Presto.Generator-497"><span class="linenos">497</span></a> <span class="s2">"table"</span><span class="p">,</span> +</span><span id="Presto.Generator-498"><a href="#Presto.Generator-498"><span class="linenos">498</span></a> <span class="s2">"then"</span><span class="p">,</span> +</span><span id="Presto.Generator-499"><a href="#Presto.Generator-499"><span class="linenos">499</span></a> <span class="s2">"true"</span><span class="p">,</span> +</span><span id="Presto.Generator-500"><a href="#Presto.Generator-500"><span class="linenos">500</span></a> <span class="s2">"union"</span><span class="p">,</span> +</span><span id="Presto.Generator-501"><a href="#Presto.Generator-501"><span class="linenos">501</span></a> <span class="s2">"using"</span><span class="p">,</span> +</span><span id="Presto.Generator-502"><a href="#Presto.Generator-502"><span class="linenos">502</span></a> <span class="s2">"values"</span><span class="p">,</span> +</span><span id="Presto.Generator-503"><a href="#Presto.Generator-503"><span class="linenos">503</span></a> <span class="s2">"when"</span><span class="p">,</span> +</span><span id="Presto.Generator-504"><a href="#Presto.Generator-504"><span class="linenos">504</span></a> <span class="s2">"where"</span><span class="p">,</span> +</span><span id="Presto.Generator-505"><a href="#Presto.Generator-505"><span class="linenos">505</span></a> <span class="s2">"with"</span><span class="p">,</span> +</span><span id="Presto.Generator-506"><a href="#Presto.Generator-506"><span class="linenos">506</span></a> <span class="p">}</span> +</span><span id="Presto.Generator-507"><a href="#Presto.Generator-507"><span class="linenos">507</span></a> +</span><span id="Presto.Generator-508"><a href="#Presto.Generator-508"><span class="linenos">508</span></a> <span class="k">def</span> <span class="nf">strtounix_sql</span><span class="p">(</span><span class="bp">self</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">StrToUnix</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator-509"><a href="#Presto.Generator-509"><span class="linenos">509</span></a> <span class="c1"># Since `TO_UNIXTIME` requires a `TIMESTAMP`, we need to parse the argument into one.</span> +</span><span id="Presto.Generator-510"><a href="#Presto.Generator-510"><span class="linenos">510</span></a> <span class="c1"># To do this, we first try to `DATE_PARSE` it, but since this can fail when there's a</span> +</span><span id="Presto.Generator-511"><a href="#Presto.Generator-511"><span class="linenos">511</span></a> <span class="c1"># timezone involved, we wrap it in a `TRY` call and use `PARSE_DATETIME` as a fallback,</span> +</span><span id="Presto.Generator-512"><a href="#Presto.Generator-512"><span class="linenos">512</span></a> <span class="c1"># which seems to be using the same time mapping as Hive, as per:</span> +</span><span id="Presto.Generator-513"><a href="#Presto.Generator-513"><span class="linenos">513</span></a> <span class="c1"># https://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html</span> +</span><span id="Presto.Generator-514"><a href="#Presto.Generator-514"><span class="linenos">514</span></a> <span class="n">value_as_text</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</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">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TEXT</span><span class="p">)</span> +</span><span id="Presto.Generator-515"><a href="#Presto.Generator-515"><span class="linenos">515</span></a> <span class="n">parse_without_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DATE_PARSE"</span><span class="p">,</span> <span class="n">value_as_text</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">))</span> +</span><span id="Presto.Generator-516"><a href="#Presto.Generator-516"><span class="linenos">516</span></a> <span class="n">parse_with_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span> +</span><span id="Presto.Generator-517"><a href="#Presto.Generator-517"><span class="linenos">517</span></a> <span class="s2">"PARSE_DATETIME"</span><span class="p">,</span> +</span><span id="Presto.Generator-518"><a href="#Presto.Generator-518"><span class="linenos">518</span></a> <span class="n">value_as_text</span><span class="p">,</span> +</span><span id="Presto.Generator-519"><a href="#Presto.Generator-519"><span class="linenos">519</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_MAPPING</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_TRIE</span><span class="p">),</span> +</span><span id="Presto.Generator-520"><a href="#Presto.Generator-520"><span class="linenos">520</span></a> <span class="p">)</span> +</span><span id="Presto.Generator-521"><a href="#Presto.Generator-521"><span class="linenos">521</span></a> <span class="n">coalesced</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"COALESCE"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"TRY"</span><span class="p">,</span> <span class="n">parse_without_tz</span><span class="p">),</span> <span class="n">parse_with_tz</span><span class="p">)</span> +</span><span id="Presto.Generator-522"><a href="#Presto.Generator-522"><span class="linenos">522</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 class="s2">"TO_UNIXTIME"</span><span class="p">,</span> <span class="n">coalesced</span><span class="p">)</span> +</span><span id="Presto.Generator-523"><a href="#Presto.Generator-523"><span class="linenos">523</span></a> +</span><span id="Presto.Generator-524"><a href="#Presto.Generator-524"><span class="linenos">524</span></a> <span class="k">def</span> <span class="nf">bracket_sql</span><span class="p">(</span><span class="bp">self</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">Bracket</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator-525"><a href="#Presto.Generator-525"><span class="linenos">525</span></a> <span class="k">if</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">"safe"</span><span class="p">):</span> +</span><span id="Presto.Generator-526"><a href="#Presto.Generator-526"><span class="linenos">526</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="Presto.Generator-527"><a href="#Presto.Generator-527"><span class="linenos">527</span></a> <span class="s2">"ELEMENT_AT"</span><span class="p">,</span> +</span><span id="Presto.Generator-528"><a href="#Presto.Generator-528"><span class="linenos">528</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="Presto.Generator-529"><a href="#Presto.Generator-529"><span class="linenos">529</span></a> <span class="n">seq_get</span><span class="p">(</span> +</span><span id="Presto.Generator-530"><a href="#Presto.Generator-530"><span class="linenos">530</span></a> <span class="n">apply_index_offset</span><span class="p">(</span> +</span><span id="Presto.Generator-531"><a href="#Presto.Generator-531"><span class="linenos">531</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="Presto.Generator-532"><a href="#Presto.Generator-532"><span class="linenos">532</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> +</span><span id="Presto.Generator-533"><a href="#Presto.Generator-533"><span class="linenos">533</span></a> <span class="mi">1</span> <span class="o">-</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">"offset"</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> +</span><span id="Presto.Generator-534"><a href="#Presto.Generator-534"><span class="linenos">534</span></a> <span class="p">),</span> +</span><span id="Presto.Generator-535"><a href="#Presto.Generator-535"><span class="linenos">535</span></a> <span class="mi">0</span><span class="p">,</span> +</span><span id="Presto.Generator-536"><a href="#Presto.Generator-536"><span class="linenos">536</span></a> <span class="p">),</span> +</span><span id="Presto.Generator-537"><a href="#Presto.Generator-537"><span class="linenos">537</span></a> <span class="p">)</span> +</span><span id="Presto.Generator-538"><a href="#Presto.Generator-538"><span class="linenos">538</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">bracket_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Presto.Generator-539"><a href="#Presto.Generator-539"><span class="linenos">539</span></a> +</span><span id="Presto.Generator-540"><a href="#Presto.Generator-540"><span class="linenos">540</span></a> <span class="k">def</span> <span class="nf">struct_sql</span><span class="p">(</span><span class="bp">self</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">Struct</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator-541"><a href="#Presto.Generator-541"><span class="linenos">541</span></a> <span class="kn">from</span> <span class="nn">sqlglot.optimizer.annotate_types</span> <span class="kn">import</span> <span class="n">annotate_types</span> +</span><span id="Presto.Generator-542"><a href="#Presto.Generator-542"><span class="linenos">542</span></a> +</span><span id="Presto.Generator-543"><a href="#Presto.Generator-543"><span class="linenos">543</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">annotate_types</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Presto.Generator-544"><a href="#Presto.Generator-544"><span class="linenos">544</span></a> <span class="n">values</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="Presto.Generator-545"><a href="#Presto.Generator-545"><span class="linenos">545</span></a> <span class="n">schema</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="Presto.Generator-546"><a href="#Presto.Generator-546"><span class="linenos">546</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Presto.Generator-547"><a href="#Presto.Generator-547"><span class="linenos">547</span></a> +</span><span id="Presto.Generator-548"><a href="#Presto.Generator-548"><span class="linenos">548</span></a> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="Presto.Generator-549"><a href="#Presto.Generator-549"><span class="linenos">549</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">PropertyEQ</span><span class="p">):</span> +</span><span id="Presto.Generator-550"><a href="#Presto.Generator-550"><span class="linenos">550</span></a> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">UNKNOWN</span><span class="p">):</span> +</span><span id="Presto.Generator-551"><a href="#Presto.Generator-551"><span class="linenos">551</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Presto.Generator-552"><a href="#Presto.Generator-552"><span class="linenos">552</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Presto.Generator-553"><a href="#Presto.Generator-553"><span class="linenos">553</span></a> <span class="n">schema</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="Presto.Generator-554"><a href="#Presto.Generator-554"><span class="linenos">554</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="s2">"expression"</span><span class="p">))</span> +</span><span id="Presto.Generator-555"><a href="#Presto.Generator-555"><span class="linenos">555</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Presto.Generator-556"><a href="#Presto.Generator-556"><span class="linenos">556</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">))</span> +</span><span id="Presto.Generator-557"><a href="#Presto.Generator-557"><span class="linenos">557</span></a> +</span><span id="Presto.Generator-558"><a href="#Presto.Generator-558"><span class="linenos">558</span></a> <span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">)</span> +</span><span id="Presto.Generator-559"><a href="#Presto.Generator-559"><span class="linenos">559</span></a> +</span><span id="Presto.Generator-560"><a href="#Presto.Generator-560"><span class="linenos">560</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">size</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span> <span class="o">!=</span> <span class="n">size</span><span class="p">:</span> +</span><span id="Presto.Generator-561"><a href="#Presto.Generator-561"><span class="linenos">561</span></a> <span class="k">if</span> <span class="n">unknown_type</span><span class="p">:</span> +</span><span id="Presto.Generator-562"><a href="#Presto.Generator-562"><span class="linenos">562</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span> +</span><span id="Presto.Generator-563"><a href="#Presto.Generator-563"><span class="linenos">563</span></a> <span class="s2">"Cannot convert untyped key-value definitions (try annotate_types)."</span> +</span><span id="Presto.Generator-564"><a href="#Presto.Generator-564"><span class="linenos">564</span></a> <span class="p">)</span> +</span><span id="Presto.Generator-565"><a href="#Presto.Generator-565"><span class="linenos">565</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 class="s2">"ROW"</span><span class="p">,</span> <span class="o">*</span><span class="n">values</span><span class="p">)</span> +</span><span id="Presto.Generator-566"><a href="#Presto.Generator-566"><span class="linenos">566</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"CAST(ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">values</span><span class="p">)</span><span class="si">}</span><span class="s2">) AS ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span><span class="si">}</span><span class="s2">))"</span> +</span><span id="Presto.Generator-567"><a href="#Presto.Generator-567"><span class="linenos">567</span></a> +</span><span id="Presto.Generator-568"><a href="#Presto.Generator-568"><span class="linenos">568</span></a> <span class="k">def</span> <span class="nf">interval_sql</span><span class="p">(</span><span class="bp">self</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">Interval</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator-569"><a href="#Presto.Generator-569"><span class="linenos">569</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"unit"</span><span class="p">)</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"WEEK"</span><span class="p">):</span> +</span><span id="Presto.Generator-570"><a href="#Presto.Generator-570"><span class="linenos">570</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"(</span><span class="si">{</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> * INTERVAL '7' DAY)"</span> +</span><span id="Presto.Generator-571"><a href="#Presto.Generator-571"><span class="linenos">571</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">interval_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Presto.Generator-572"><a href="#Presto.Generator-572"><span class="linenos">572</span></a> +</span><span id="Presto.Generator-573"><a href="#Presto.Generator-573"><span class="linenos">573</span></a> <span class="k">def</span> <span class="nf">transaction_sql</span><span class="p">(</span><span class="bp">self</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">Transaction</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator-574"><a href="#Presto.Generator-574"><span class="linenos">574</span></a> <span class="n">modes</span> <span class="o">=</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">"modes"</span><span class="p">)</span> +</span><span id="Presto.Generator-575"><a href="#Presto.Generator-575"><span class="linenos">575</span></a> <span class="n">modes</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" </span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">modes</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">modes</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="Presto.Generator-576"><a href="#Presto.Generator-576"><span class="linenos">576</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"START TRANSACTION</span><span class="si">{</span><span class="n">modes</span><span class="si">}</span><span class="s2">"</span> +</span><span id="Presto.Generator-577"><a href="#Presto.Generator-577"><span class="linenos">577</span></a> +</span><span id="Presto.Generator-578"><a href="#Presto.Generator-578"><span class="linenos">578</span></a> <span class="k">def</span> <span class="nf">generateseries_sql</span><span class="p">(</span><span class="bp">self</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">GenerateSeries</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator-579"><a href="#Presto.Generator-579"><span class="linenos">579</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"start"</span><span class="p">]</span> +</span><span id="Presto.Generator-580"><a href="#Presto.Generator-580"><span class="linenos">580</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"end"</span><span class="p">]</span> +</span><span id="Presto.Generator-581"><a href="#Presto.Generator-581"><span class="linenos">581</span></a> <span class="n">step</span> <span class="o">=</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">"step"</span><span class="p">)</span> +</span><span id="Presto.Generator-582"><a href="#Presto.Generator-582"><span class="linenos">582</span></a> +</span><span id="Presto.Generator-583"><a href="#Presto.Generator-583"><span class="linenos">583</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> +</span><span id="Presto.Generator-584"><a href="#Presto.Generator-584"><span class="linenos">584</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span> +</span><span id="Presto.Generator-585"><a href="#Presto.Generator-585"><span class="linenos">585</span></a> <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> +</span><span id="Presto.Generator-586"><a href="#Presto.Generator-586"><span class="linenos">586</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">end</span><span class="o">.</span><span class="n">to</span> +</span><span id="Presto.Generator-587"><a href="#Presto.Generator-587"><span class="linenos">587</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Presto.Generator-588"><a href="#Presto.Generator-588"><span class="linenos">588</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="Presto.Generator-589"><a href="#Presto.Generator-589"><span class="linenos">589</span></a> +</span><span id="Presto.Generator-590"><a href="#Presto.Generator-590"><span class="linenos">590</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">and</span> <span class="n">target_type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"timestamp"</span><span class="p">):</span> +</span><span id="Presto.Generator-591"><a href="#Presto.Generator-591"><span class="linenos">591</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">is</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span><span class="p">:</span> +</span><span id="Presto.Generator-592"><a href="#Presto.Generator-592"><span class="linenos">592</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> +</span><span id="Presto.Generator-593"><a href="#Presto.Generator-593"><span class="linenos">593</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Presto.Generator-594"><a href="#Presto.Generator-594"><span class="linenos">594</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> +</span><span id="Presto.Generator-595"><a href="#Presto.Generator-595"><span class="linenos">595</span></a> +</span><span id="Presto.Generator-596"><a href="#Presto.Generator-596"><span class="linenos">596</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 class="s2">"SEQUENCE"</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">step</span><span class="p">)</span> +</span><span id="Presto.Generator-597"><a href="#Presto.Generator-597"><span class="linenos">597</span></a> +</span><span id="Presto.Generator-598"><a href="#Presto.Generator-598"><span class="linenos">598</span></a> <span class="k">def</span> <span class="nf">offset_limit_modifiers</span><span class="p">(</span> +</span><span id="Presto.Generator-599"><a href="#Presto.Generator-599"><span class="linenos">599</span></a> <span class="bp">self</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">Expression</span><span class="p">,</span> <span class="n">fetch</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">limit</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">exp</span><span class="o">.</span><span class="n">Fetch</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Limit</span><span class="p">]</span> +</span><span id="Presto.Generator-600"><a href="#Presto.Generator-600"><span class="linenos">600</span></a> <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="Presto.Generator-601"><a href="#Presto.Generator-601"><span class="linenos">601</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="Presto.Generator-602"><a href="#Presto.Generator-602"><span class="linenos">602</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"offset"</span><span class="p">),</span> +</span><span id="Presto.Generator-603"><a href="#Presto.Generator-603"><span class="linenos">603</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">limit</span><span class="p">),</span> +</span><span id="Presto.Generator-604"><a href="#Presto.Generator-604"><span class="linenos">604</span></a> <span class="p">]</span> +</span><span id="Presto.Generator-605"><a href="#Presto.Generator-605"><span class="linenos">605</span></a> +</span><span id="Presto.Generator-606"><a href="#Presto.Generator-606"><span class="linenos">606</span></a> <span class="k">def</span> <span class="nf">create_sql</span><span class="p">(</span><span class="bp">self</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">Create</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator-607"><a href="#Presto.Generator-607"><span class="linenos">607</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Presto.Generator-608"><a href="#Presto.Generator-608"><span class="linenos">608</span></a><span class="sd"> Presto doesn't support CREATE VIEW with expressions (ex: `CREATE VIEW x (cola)` then `(cola)` is the expression),</span> +</span><span id="Presto.Generator-609"><a href="#Presto.Generator-609"><span class="linenos">609</span></a><span class="sd"> so we need to remove them</span> +</span><span id="Presto.Generator-610"><a href="#Presto.Generator-610"><span class="linenos">610</span></a><span class="sd"> """</span> +</span><span id="Presto.Generator-611"><a href="#Presto.Generator-611"><span class="linenos">611</span></a> <span class="n">kind</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"kind"</span><span class="p">]</span> +</span><span id="Presto.Generator-612"><a href="#Presto.Generator-612"><span class="linenos">612</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="Presto.Generator-613"><a href="#Presto.Generator-613"><span class="linenos">613</span></a> <span class="k">if</span> <span class="n">kind</span> <span class="o">==</span> <span class="s2">"VIEW"</span> <span class="ow">and</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="Presto.Generator-614"><a href="#Presto.Generator-614"><span class="linenos">614</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="Presto.Generator-615"><a href="#Presto.Generator-615"><span class="linenos">615</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">create_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -2497,7 +2684,7 @@ Default: True</li> <div class="attr variable"> <span class="name">TYPE_MAPPING</span> = <input id="Presto.Generator.TYPE_MAPPING-view-value" class="view-value-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> - <label class="view-value-button pdoc-button" for="Presto.Generator.TYPE_MAPPING-view-value"></label><span class="default_value">{<Type.NCHAR: 'NCHAR'>: 'CHAR', <Type.NVARCHAR: 'NVARCHAR'>: 'VARCHAR', <Type.MEDIUMTEXT: 'MEDIUMTEXT'>: 'TEXT', <Type.LONGTEXT: 'LONGTEXT'>: 'TEXT', <Type.TINYTEXT: 'TINYTEXT'>: 'TEXT', <Type.MEDIUMBLOB: 'MEDIUMBLOB'>: 'BLOB', <Type.LONGBLOB: 'LONGBLOB'>: 'BLOB', <Type.TINYBLOB: 'TINYBLOB'>: 'BLOB', <Type.INET: 'INET'>: 'INET', <Type.INT: 'INT'>: 'INTEGER', <Type.FLOAT: 'FLOAT'>: 'REAL', <Type.BINARY: 'BINARY'>: 'VARBINARY', <Type.TEXT: 'TEXT'>: 'VARCHAR', <Type.TIMETZ: 'TIMETZ'>: 'TIME', <Type.TIMESTAMPTZ: 'TIMESTAMPTZ'>: 'TIMESTAMP', <Type.STRUCT: 'STRUCT'>: 'ROW', <Type.DATETIME: 'DATETIME'>: 'TIMESTAMP', <Type.DATETIME64: 'DATETIME64'>: 'TIMESTAMP'}</span> + <label class="view-value-button pdoc-button" for="Presto.Generator.TYPE_MAPPING-view-value"></label><span class="default_value">{<Type.NCHAR: 'NCHAR'>: 'CHAR', <Type.NVARCHAR: 'NVARCHAR'>: 'VARCHAR', <Type.MEDIUMTEXT: 'MEDIUMTEXT'>: 'TEXT', <Type.LONGTEXT: 'LONGTEXT'>: 'TEXT', <Type.TINYTEXT: 'TINYTEXT'>: 'TEXT', <Type.MEDIUMBLOB: 'MEDIUMBLOB'>: 'BLOB', <Type.LONGBLOB: 'LONGBLOB'>: 'BLOB', <Type.TINYBLOB: 'TINYBLOB'>: 'BLOB', <Type.INET: 'INET'>: 'INET', <Type.ROWVERSION: 'ROWVERSION'>: 'VARBINARY', <Type.INT: 'INT'>: 'INTEGER', <Type.FLOAT: 'FLOAT'>: 'REAL', <Type.BINARY: 'BINARY'>: 'VARBINARY', <Type.TEXT: 'TEXT'>: 'VARCHAR', <Type.TIMETZ: 'TIMETZ'>: 'TIME', <Type.TIMESTAMPTZ: 'TIMESTAMPTZ'>: 'TIMESTAMP', <Type.STRUCT: 'STRUCT'>: 'ROW', <Type.DATETIME: 'DATETIME'>: 'TIMESTAMP', <Type.DATETIME64: 'DATETIME64'>: 'TIMESTAMP'}</span> </div> @@ -2519,6 +2706,19 @@ Default: True</li> </div> + <div id="Presto.Generator.RESERVED_KEYWORDS" class="classattr"> + <div class="attr variable"> + <span class="name">RESERVED_KEYWORDS</span> = +<input id="Presto.Generator.RESERVED_KEYWORDS-view-value" class="view-value-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> + <label class="view-value-button pdoc-button" for="Presto.Generator.RESERVED_KEYWORDS-view-value"></label><span class="default_value">{'where', 'null', 'outer', 'cross', 'execute', 'and', 'for', 'right', 'in', 'current_timestamp', 'group', 'select', 'by', 'case', 'between', 'extract', 'intersect', 'table', 'into', 'escape', 'end', 'true', 'delete', 'as', 'then', 'values', 'deallocate', 'else', 'left', 'order', 'drop', 'exists', 'when', 'constraint', 'with', 'is', 'not', 'natural', 'using', 'create', 'full', 'having', 'except', 'union', 'on', 'distinct', 'from', 'inner', 'false', 'cast', 'join', 'describe', 'insert', 'like', 'or', 'alter', 'current_time', 'prepare'}</span> + + + </div> + <a class="headerlink" href="#Presto.Generator.RESERVED_KEYWORDS"></a> + + + + </div> <div id="Presto.Generator.strtounix_sql" class="classattr"> <input id="Presto.Generator.strtounix_sql-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> <div class="attr function"> @@ -2530,21 +2730,21 @@ Default: True</li> </div> <a class="headerlink" href="#Presto.Generator.strtounix_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.strtounix_sql-447"><a href="#Presto.Generator.strtounix_sql-447"><span class="linenos">447</span></a> <span class="k">def</span> <span class="nf">strtounix_sql</span><span class="p">(</span><span class="bp">self</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">StrToUnix</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator.strtounix_sql-448"><a href="#Presto.Generator.strtounix_sql-448"><span class="linenos">448</span></a> <span class="c1"># Since `TO_UNIXTIME` requires a `TIMESTAMP`, we need to parse the argument into one.</span> -</span><span id="Presto.Generator.strtounix_sql-449"><a href="#Presto.Generator.strtounix_sql-449"><span class="linenos">449</span></a> <span class="c1"># To do this, we first try to `DATE_PARSE` it, but since this can fail when there's a</span> -</span><span id="Presto.Generator.strtounix_sql-450"><a href="#Presto.Generator.strtounix_sql-450"><span class="linenos">450</span></a> <span class="c1"># timezone involved, we wrap it in a `TRY` call and use `PARSE_DATETIME` as a fallback,</span> -</span><span id="Presto.Generator.strtounix_sql-451"><a href="#Presto.Generator.strtounix_sql-451"><span class="linenos">451</span></a> <span class="c1"># which seems to be using the same time mapping as Hive, as per:</span> -</span><span id="Presto.Generator.strtounix_sql-452"><a href="#Presto.Generator.strtounix_sql-452"><span class="linenos">452</span></a> <span class="c1"># https://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html</span> -</span><span id="Presto.Generator.strtounix_sql-453"><a href="#Presto.Generator.strtounix_sql-453"><span class="linenos">453</span></a> <span class="n">value_as_text</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</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">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TEXT</span><span class="p">)</span> -</span><span id="Presto.Generator.strtounix_sql-454"><a href="#Presto.Generator.strtounix_sql-454"><span class="linenos">454</span></a> <span class="n">parse_without_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DATE_PARSE"</span><span class="p">,</span> <span class="n">value_as_text</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">))</span> -</span><span id="Presto.Generator.strtounix_sql-455"><a href="#Presto.Generator.strtounix_sql-455"><span class="linenos">455</span></a> <span class="n">parse_with_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span> -</span><span id="Presto.Generator.strtounix_sql-456"><a href="#Presto.Generator.strtounix_sql-456"><span class="linenos">456</span></a> <span class="s2">"PARSE_DATETIME"</span><span class="p">,</span> -</span><span id="Presto.Generator.strtounix_sql-457"><a href="#Presto.Generator.strtounix_sql-457"><span class="linenos">457</span></a> <span class="n">value_as_text</span><span class="p">,</span> -</span><span id="Presto.Generator.strtounix_sql-458"><a href="#Presto.Generator.strtounix_sql-458"><span class="linenos">458</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_MAPPING</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_TRIE</span><span class="p">),</span> -</span><span id="Presto.Generator.strtounix_sql-459"><a href="#Presto.Generator.strtounix_sql-459"><span class="linenos">459</span></a> <span class="p">)</span> -</span><span id="Presto.Generator.strtounix_sql-460"><a href="#Presto.Generator.strtounix_sql-460"><span class="linenos">460</span></a> <span class="n">coalesced</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"COALESCE"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"TRY"</span><span class="p">,</span> <span class="n">parse_without_tz</span><span class="p">),</span> <span class="n">parse_with_tz</span><span class="p">)</span> -</span><span id="Presto.Generator.strtounix_sql-461"><a href="#Presto.Generator.strtounix_sql-461"><span class="linenos">461</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 class="s2">"TO_UNIXTIME"</span><span class="p">,</span> <span class="n">coalesced</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.strtounix_sql-508"><a href="#Presto.Generator.strtounix_sql-508"><span class="linenos">508</span></a> <span class="k">def</span> <span class="nf">strtounix_sql</span><span class="p">(</span><span class="bp">self</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">StrToUnix</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator.strtounix_sql-509"><a href="#Presto.Generator.strtounix_sql-509"><span class="linenos">509</span></a> <span class="c1"># Since `TO_UNIXTIME` requires a `TIMESTAMP`, we need to parse the argument into one.</span> +</span><span id="Presto.Generator.strtounix_sql-510"><a href="#Presto.Generator.strtounix_sql-510"><span class="linenos">510</span></a> <span class="c1"># To do this, we first try to `DATE_PARSE` it, but since this can fail when there's a</span> +</span><span id="Presto.Generator.strtounix_sql-511"><a href="#Presto.Generator.strtounix_sql-511"><span class="linenos">511</span></a> <span class="c1"># timezone involved, we wrap it in a `TRY` call and use `PARSE_DATETIME` as a fallback,</span> +</span><span id="Presto.Generator.strtounix_sql-512"><a href="#Presto.Generator.strtounix_sql-512"><span class="linenos">512</span></a> <span class="c1"># which seems to be using the same time mapping as Hive, as per:</span> +</span><span id="Presto.Generator.strtounix_sql-513"><a href="#Presto.Generator.strtounix_sql-513"><span class="linenos">513</span></a> <span class="c1"># https://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html</span> +</span><span id="Presto.Generator.strtounix_sql-514"><a href="#Presto.Generator.strtounix_sql-514"><span class="linenos">514</span></a> <span class="n">value_as_text</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</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">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TEXT</span><span class="p">)</span> +</span><span id="Presto.Generator.strtounix_sql-515"><a href="#Presto.Generator.strtounix_sql-515"><span class="linenos">515</span></a> <span class="n">parse_without_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DATE_PARSE"</span><span class="p">,</span> <span class="n">value_as_text</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">))</span> +</span><span id="Presto.Generator.strtounix_sql-516"><a href="#Presto.Generator.strtounix_sql-516"><span class="linenos">516</span></a> <span class="n">parse_with_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span> +</span><span id="Presto.Generator.strtounix_sql-517"><a href="#Presto.Generator.strtounix_sql-517"><span class="linenos">517</span></a> <span class="s2">"PARSE_DATETIME"</span><span class="p">,</span> +</span><span id="Presto.Generator.strtounix_sql-518"><a href="#Presto.Generator.strtounix_sql-518"><span class="linenos">518</span></a> <span class="n">value_as_text</span><span class="p">,</span> +</span><span id="Presto.Generator.strtounix_sql-519"><a href="#Presto.Generator.strtounix_sql-519"><span class="linenos">519</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_MAPPING</span><span class="p">,</span> <span class="n">Hive</span><span class="o">.</span><span class="n">INVERSE_TIME_TRIE</span><span class="p">),</span> +</span><span id="Presto.Generator.strtounix_sql-520"><a href="#Presto.Generator.strtounix_sql-520"><span class="linenos">520</span></a> <span class="p">)</span> +</span><span id="Presto.Generator.strtounix_sql-521"><a href="#Presto.Generator.strtounix_sql-521"><span class="linenos">521</span></a> <span class="n">coalesced</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"COALESCE"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"TRY"</span><span class="p">,</span> <span class="n">parse_without_tz</span><span class="p">),</span> <span class="n">parse_with_tz</span><span class="p">)</span> +</span><span id="Presto.Generator.strtounix_sql-522"><a href="#Presto.Generator.strtounix_sql-522"><span class="linenos">522</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 class="s2">"TO_UNIXTIME"</span><span class="p">,</span> <span class="n">coalesced</span><span class="p">)</span> </span></pre></div> @@ -2562,21 +2762,21 @@ Default: True</li> </div> <a class="headerlink" href="#Presto.Generator.bracket_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.bracket_sql-463"><a href="#Presto.Generator.bracket_sql-463"><span class="linenos">463</span></a> <span class="k">def</span> <span class="nf">bracket_sql</span><span class="p">(</span><span class="bp">self</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">Bracket</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator.bracket_sql-464"><a href="#Presto.Generator.bracket_sql-464"><span class="linenos">464</span></a> <span class="k">if</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">"safe"</span><span class="p">):</span> -</span><span id="Presto.Generator.bracket_sql-465"><a href="#Presto.Generator.bracket_sql-465"><span class="linenos">465</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="Presto.Generator.bracket_sql-466"><a href="#Presto.Generator.bracket_sql-466"><span class="linenos">466</span></a> <span class="s2">"ELEMENT_AT"</span><span class="p">,</span> -</span><span id="Presto.Generator.bracket_sql-467"><a href="#Presto.Generator.bracket_sql-467"><span class="linenos">467</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="Presto.Generator.bracket_sql-468"><a href="#Presto.Generator.bracket_sql-468"><span class="linenos">468</span></a> <span class="n">seq_get</span><span class="p">(</span> -</span><span id="Presto.Generator.bracket_sql-469"><a href="#Presto.Generator.bracket_sql-469"><span class="linenos">469</span></a> <span class="n">apply_index_offset</span><span class="p">(</span> -</span><span id="Presto.Generator.bracket_sql-470"><a href="#Presto.Generator.bracket_sql-470"><span class="linenos">470</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="Presto.Generator.bracket_sql-471"><a href="#Presto.Generator.bracket_sql-471"><span class="linenos">471</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> -</span><span id="Presto.Generator.bracket_sql-472"><a href="#Presto.Generator.bracket_sql-472"><span class="linenos">472</span></a> <span class="mi">1</span> <span class="o">-</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">"offset"</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> -</span><span id="Presto.Generator.bracket_sql-473"><a href="#Presto.Generator.bracket_sql-473"><span class="linenos">473</span></a> <span class="p">),</span> -</span><span id="Presto.Generator.bracket_sql-474"><a href="#Presto.Generator.bracket_sql-474"><span class="linenos">474</span></a> <span class="mi">0</span><span class="p">,</span> -</span><span id="Presto.Generator.bracket_sql-475"><a href="#Presto.Generator.bracket_sql-475"><span class="linenos">475</span></a> <span class="p">),</span> -</span><span id="Presto.Generator.bracket_sql-476"><a href="#Presto.Generator.bracket_sql-476"><span class="linenos">476</span></a> <span class="p">)</span> -</span><span id="Presto.Generator.bracket_sql-477"><a href="#Presto.Generator.bracket_sql-477"><span class="linenos">477</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">bracket_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.bracket_sql-524"><a href="#Presto.Generator.bracket_sql-524"><span class="linenos">524</span></a> <span class="k">def</span> <span class="nf">bracket_sql</span><span class="p">(</span><span class="bp">self</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">Bracket</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator.bracket_sql-525"><a href="#Presto.Generator.bracket_sql-525"><span class="linenos">525</span></a> <span class="k">if</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">"safe"</span><span class="p">):</span> +</span><span id="Presto.Generator.bracket_sql-526"><a href="#Presto.Generator.bracket_sql-526"><span class="linenos">526</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="Presto.Generator.bracket_sql-527"><a href="#Presto.Generator.bracket_sql-527"><span class="linenos">527</span></a> <span class="s2">"ELEMENT_AT"</span><span class="p">,</span> +</span><span id="Presto.Generator.bracket_sql-528"><a href="#Presto.Generator.bracket_sql-528"><span class="linenos">528</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="Presto.Generator.bracket_sql-529"><a href="#Presto.Generator.bracket_sql-529"><span class="linenos">529</span></a> <span class="n">seq_get</span><span class="p">(</span> +</span><span id="Presto.Generator.bracket_sql-530"><a href="#Presto.Generator.bracket_sql-530"><span class="linenos">530</span></a> <span class="n">apply_index_offset</span><span class="p">(</span> +</span><span id="Presto.Generator.bracket_sql-531"><a href="#Presto.Generator.bracket_sql-531"><span class="linenos">531</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="Presto.Generator.bracket_sql-532"><a href="#Presto.Generator.bracket_sql-532"><span class="linenos">532</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> +</span><span id="Presto.Generator.bracket_sql-533"><a href="#Presto.Generator.bracket_sql-533"><span class="linenos">533</span></a> <span class="mi">1</span> <span class="o">-</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">"offset"</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> +</span><span id="Presto.Generator.bracket_sql-534"><a href="#Presto.Generator.bracket_sql-534"><span class="linenos">534</span></a> <span class="p">),</span> +</span><span id="Presto.Generator.bracket_sql-535"><a href="#Presto.Generator.bracket_sql-535"><span class="linenos">535</span></a> <span class="mi">0</span><span class="p">,</span> +</span><span id="Presto.Generator.bracket_sql-536"><a href="#Presto.Generator.bracket_sql-536"><span class="linenos">536</span></a> <span class="p">),</span> +</span><span id="Presto.Generator.bracket_sql-537"><a href="#Presto.Generator.bracket_sql-537"><span class="linenos">537</span></a> <span class="p">)</span> +</span><span id="Presto.Generator.bracket_sql-538"><a href="#Presto.Generator.bracket_sql-538"><span class="linenos">538</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">bracket_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -2594,33 +2794,33 @@ Default: True</li> </div> <a class="headerlink" href="#Presto.Generator.struct_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.struct_sql-479"><a href="#Presto.Generator.struct_sql-479"><span class="linenos">479</span></a> <span class="k">def</span> <span class="nf">struct_sql</span><span class="p">(</span><span class="bp">self</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">Struct</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator.struct_sql-480"><a href="#Presto.Generator.struct_sql-480"><span class="linenos">480</span></a> <span class="kn">from</span> <span class="nn">sqlglot.optimizer.annotate_types</span> <span class="kn">import</span> <span class="n">annotate_types</span> -</span><span id="Presto.Generator.struct_sql-481"><a href="#Presto.Generator.struct_sql-481"><span class="linenos">481</span></a> -</span><span id="Presto.Generator.struct_sql-482"><a href="#Presto.Generator.struct_sql-482"><span class="linenos">482</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">annotate_types</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="Presto.Generator.struct_sql-483"><a href="#Presto.Generator.struct_sql-483"><span class="linenos">483</span></a> <span class="n">values</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="Presto.Generator.struct_sql-484"><a href="#Presto.Generator.struct_sql-484"><span class="linenos">484</span></a> <span class="n">schema</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="Presto.Generator.struct_sql-485"><a href="#Presto.Generator.struct_sql-485"><span class="linenos">485</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Presto.Generator.struct_sql-486"><a href="#Presto.Generator.struct_sql-486"><span class="linenos">486</span></a> -</span><span id="Presto.Generator.struct_sql-487"><a href="#Presto.Generator.struct_sql-487"><span class="linenos">487</span></a> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> -</span><span id="Presto.Generator.struct_sql-488"><a href="#Presto.Generator.struct_sql-488"><span class="linenos">488</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">PropertyEQ</span><span class="p">):</span> -</span><span id="Presto.Generator.struct_sql-489"><a href="#Presto.Generator.struct_sql-489"><span class="linenos">489</span></a> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">UNKNOWN</span><span class="p">):</span> -</span><span id="Presto.Generator.struct_sql-490"><a href="#Presto.Generator.struct_sql-490"><span class="linenos">490</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Presto.Generator.struct_sql-491"><a href="#Presto.Generator.struct_sql-491"><span class="linenos">491</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Presto.Generator.struct_sql-492"><a href="#Presto.Generator.struct_sql-492"><span class="linenos">492</span></a> <span class="n">schema</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="Presto.Generator.struct_sql-493"><a href="#Presto.Generator.struct_sql-493"><span class="linenos">493</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="s2">"expression"</span><span class="p">))</span> -</span><span id="Presto.Generator.struct_sql-494"><a href="#Presto.Generator.struct_sql-494"><span class="linenos">494</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Presto.Generator.struct_sql-495"><a href="#Presto.Generator.struct_sql-495"><span class="linenos">495</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">))</span> -</span><span id="Presto.Generator.struct_sql-496"><a href="#Presto.Generator.struct_sql-496"><span class="linenos">496</span></a> -</span><span id="Presto.Generator.struct_sql-497"><a href="#Presto.Generator.struct_sql-497"><span class="linenos">497</span></a> <span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">)</span> -</span><span id="Presto.Generator.struct_sql-498"><a href="#Presto.Generator.struct_sql-498"><span class="linenos">498</span></a> -</span><span id="Presto.Generator.struct_sql-499"><a href="#Presto.Generator.struct_sql-499"><span class="linenos">499</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">size</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span> <span class="o">!=</span> <span class="n">size</span><span class="p">:</span> -</span><span id="Presto.Generator.struct_sql-500"><a href="#Presto.Generator.struct_sql-500"><span class="linenos">500</span></a> <span class="k">if</span> <span class="n">unknown_type</span><span class="p">:</span> -</span><span id="Presto.Generator.struct_sql-501"><a href="#Presto.Generator.struct_sql-501"><span class="linenos">501</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span> -</span><span id="Presto.Generator.struct_sql-502"><a href="#Presto.Generator.struct_sql-502"><span class="linenos">502</span></a> <span class="s2">"Cannot convert untyped key-value definitions (try annotate_types)."</span> -</span><span id="Presto.Generator.struct_sql-503"><a href="#Presto.Generator.struct_sql-503"><span class="linenos">503</span></a> <span class="p">)</span> -</span><span id="Presto.Generator.struct_sql-504"><a href="#Presto.Generator.struct_sql-504"><span class="linenos">504</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 class="s2">"ROW"</span><span class="p">,</span> <span class="o">*</span><span class="n">values</span><span class="p">)</span> -</span><span id="Presto.Generator.struct_sql-505"><a href="#Presto.Generator.struct_sql-505"><span class="linenos">505</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"CAST(ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">values</span><span class="p">)</span><span class="si">}</span><span class="s2">) AS ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span><span class="si">}</span><span class="s2">))"</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.struct_sql-540"><a href="#Presto.Generator.struct_sql-540"><span class="linenos">540</span></a> <span class="k">def</span> <span class="nf">struct_sql</span><span class="p">(</span><span class="bp">self</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">Struct</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator.struct_sql-541"><a href="#Presto.Generator.struct_sql-541"><span class="linenos">541</span></a> <span class="kn">from</span> <span class="nn">sqlglot.optimizer.annotate_types</span> <span class="kn">import</span> <span class="n">annotate_types</span> +</span><span id="Presto.Generator.struct_sql-542"><a href="#Presto.Generator.struct_sql-542"><span class="linenos">542</span></a> +</span><span id="Presto.Generator.struct_sql-543"><a href="#Presto.Generator.struct_sql-543"><span class="linenos">543</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">annotate_types</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Presto.Generator.struct_sql-544"><a href="#Presto.Generator.struct_sql-544"><span class="linenos">544</span></a> <span class="n">values</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="Presto.Generator.struct_sql-545"><a href="#Presto.Generator.struct_sql-545"><span class="linenos">545</span></a> <span class="n">schema</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="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="Presto.Generator.struct_sql-546"><a href="#Presto.Generator.struct_sql-546"><span class="linenos">546</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Presto.Generator.struct_sql-547"><a href="#Presto.Generator.struct_sql-547"><span class="linenos">547</span></a> +</span><span id="Presto.Generator.struct_sql-548"><a href="#Presto.Generator.struct_sql-548"><span class="linenos">548</span></a> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="Presto.Generator.struct_sql-549"><a href="#Presto.Generator.struct_sql-549"><span class="linenos">549</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">PropertyEQ</span><span class="p">):</span> +</span><span id="Presto.Generator.struct_sql-550"><a href="#Presto.Generator.struct_sql-550"><span class="linenos">550</span></a> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">UNKNOWN</span><span class="p">):</span> +</span><span id="Presto.Generator.struct_sql-551"><a href="#Presto.Generator.struct_sql-551"><span class="linenos">551</span></a> <span class="n">unknown_type</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Presto.Generator.struct_sql-552"><a href="#Presto.Generator.struct_sql-552"><span class="linenos">552</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Presto.Generator.struct_sql-553"><a href="#Presto.Generator.struct_sql-553"><span class="linenos">553</span></a> <span class="n">schema</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">type</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="Presto.Generator.struct_sql-554"><a href="#Presto.Generator.struct_sql-554"><span class="linenos">554</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="s2">"expression"</span><span class="p">))</span> +</span><span id="Presto.Generator.struct_sql-555"><a href="#Presto.Generator.struct_sql-555"><span class="linenos">555</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Presto.Generator.struct_sql-556"><a href="#Presto.Generator.struct_sql-556"><span class="linenos">556</span></a> <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">))</span> +</span><span id="Presto.Generator.struct_sql-557"><a href="#Presto.Generator.struct_sql-557"><span class="linenos">557</span></a> +</span><span id="Presto.Generator.struct_sql-558"><a href="#Presto.Generator.struct_sql-558"><span class="linenos">558</span></a> <span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">)</span> +</span><span id="Presto.Generator.struct_sql-559"><a href="#Presto.Generator.struct_sql-559"><span class="linenos">559</span></a> +</span><span id="Presto.Generator.struct_sql-560"><a href="#Presto.Generator.struct_sql-560"><span class="linenos">560</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">size</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span> <span class="o">!=</span> <span class="n">size</span><span class="p">:</span> +</span><span id="Presto.Generator.struct_sql-561"><a href="#Presto.Generator.struct_sql-561"><span class="linenos">561</span></a> <span class="k">if</span> <span class="n">unknown_type</span><span class="p">:</span> +</span><span id="Presto.Generator.struct_sql-562"><a href="#Presto.Generator.struct_sql-562"><span class="linenos">562</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span> +</span><span id="Presto.Generator.struct_sql-563"><a href="#Presto.Generator.struct_sql-563"><span class="linenos">563</span></a> <span class="s2">"Cannot convert untyped key-value definitions (try annotate_types)."</span> +</span><span id="Presto.Generator.struct_sql-564"><a href="#Presto.Generator.struct_sql-564"><span class="linenos">564</span></a> <span class="p">)</span> +</span><span id="Presto.Generator.struct_sql-565"><a href="#Presto.Generator.struct_sql-565"><span class="linenos">565</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 class="s2">"ROW"</span><span class="p">,</span> <span class="o">*</span><span class="n">values</span><span class="p">)</span> +</span><span id="Presto.Generator.struct_sql-566"><a href="#Presto.Generator.struct_sql-566"><span class="linenos">566</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"CAST(ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">values</span><span class="p">)</span><span class="si">}</span><span class="s2">) AS ROW(</span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">schema</span><span class="p">)</span><span class="si">}</span><span class="s2">))"</span> </span></pre></div> @@ -2638,10 +2838,10 @@ Default: True</li> </div> <a class="headerlink" href="#Presto.Generator.interval_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.interval_sql-507"><a href="#Presto.Generator.interval_sql-507"><span class="linenos">507</span></a> <span class="k">def</span> <span class="nf">interval_sql</span><span class="p">(</span><span class="bp">self</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">Interval</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator.interval_sql-508"><a href="#Presto.Generator.interval_sql-508"><span class="linenos">508</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"unit"</span><span class="p">)</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"WEEK"</span><span class="p">):</span> -</span><span id="Presto.Generator.interval_sql-509"><a href="#Presto.Generator.interval_sql-509"><span class="linenos">509</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"(</span><span class="si">{</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> * INTERVAL '7' DAY)"</span> -</span><span id="Presto.Generator.interval_sql-510"><a href="#Presto.Generator.interval_sql-510"><span class="linenos">510</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">interval_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.interval_sql-568"><a href="#Presto.Generator.interval_sql-568"><span class="linenos">568</span></a> <span class="k">def</span> <span class="nf">interval_sql</span><span class="p">(</span><span class="bp">self</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">Interval</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator.interval_sql-569"><a href="#Presto.Generator.interval_sql-569"><span class="linenos">569</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"unit"</span><span class="p">)</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"WEEK"</span><span class="p">):</span> +</span><span id="Presto.Generator.interval_sql-570"><a href="#Presto.Generator.interval_sql-570"><span class="linenos">570</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"(</span><span class="si">{</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> * INTERVAL '7' DAY)"</span> +</span><span id="Presto.Generator.interval_sql-571"><a href="#Presto.Generator.interval_sql-571"><span class="linenos">571</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">interval_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -2659,10 +2859,10 @@ Default: True</li> </div> <a class="headerlink" href="#Presto.Generator.transaction_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.transaction_sql-512"><a href="#Presto.Generator.transaction_sql-512"><span class="linenos">512</span></a> <span class="k">def</span> <span class="nf">transaction_sql</span><span class="p">(</span><span class="bp">self</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">Transaction</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator.transaction_sql-513"><a href="#Presto.Generator.transaction_sql-513"><span class="linenos">513</span></a> <span class="n">modes</span> <span class="o">=</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">"modes"</span><span class="p">)</span> -</span><span id="Presto.Generator.transaction_sql-514"><a href="#Presto.Generator.transaction_sql-514"><span class="linenos">514</span></a> <span class="n">modes</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" </span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">modes</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">modes</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="Presto.Generator.transaction_sql-515"><a href="#Presto.Generator.transaction_sql-515"><span class="linenos">515</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"START TRANSACTION</span><span class="si">{</span><span class="n">modes</span><span class="si">}</span><span class="s2">"</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.transaction_sql-573"><a href="#Presto.Generator.transaction_sql-573"><span class="linenos">573</span></a> <span class="k">def</span> <span class="nf">transaction_sql</span><span class="p">(</span><span class="bp">self</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">Transaction</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator.transaction_sql-574"><a href="#Presto.Generator.transaction_sql-574"><span class="linenos">574</span></a> <span class="n">modes</span> <span class="o">=</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">"modes"</span><span class="p">)</span> +</span><span id="Presto.Generator.transaction_sql-575"><a href="#Presto.Generator.transaction_sql-575"><span class="linenos">575</span></a> <span class="n">modes</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" </span><span class="si">{</span><span class="s1">', '</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">modes</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">modes</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="Presto.Generator.transaction_sql-576"><a href="#Presto.Generator.transaction_sql-576"><span class="linenos">576</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"START TRANSACTION</span><span class="si">{</span><span class="n">modes</span><span class="si">}</span><span class="s2">"</span> </span></pre></div> @@ -2680,25 +2880,25 @@ Default: True</li> </div> <a class="headerlink" href="#Presto.Generator.generateseries_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.generateseries_sql-517"><a href="#Presto.Generator.generateseries_sql-517"><span class="linenos">517</span></a> <span class="k">def</span> <span class="nf">generateseries_sql</span><span class="p">(</span><span class="bp">self</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">GenerateSeries</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator.generateseries_sql-518"><a href="#Presto.Generator.generateseries_sql-518"><span class="linenos">518</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"start"</span><span class="p">]</span> -</span><span id="Presto.Generator.generateseries_sql-519"><a href="#Presto.Generator.generateseries_sql-519"><span class="linenos">519</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"end"</span><span class="p">]</span> -</span><span id="Presto.Generator.generateseries_sql-520"><a href="#Presto.Generator.generateseries_sql-520"><span class="linenos">520</span></a> <span class="n">step</span> <span class="o">=</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">"step"</span><span class="p">)</span> -</span><span id="Presto.Generator.generateseries_sql-521"><a href="#Presto.Generator.generateseries_sql-521"><span class="linenos">521</span></a> -</span><span id="Presto.Generator.generateseries_sql-522"><a href="#Presto.Generator.generateseries_sql-522"><span class="linenos">522</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> -</span><span id="Presto.Generator.generateseries_sql-523"><a href="#Presto.Generator.generateseries_sql-523"><span class="linenos">523</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span> -</span><span id="Presto.Generator.generateseries_sql-524"><a href="#Presto.Generator.generateseries_sql-524"><span class="linenos">524</span></a> <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> -</span><span id="Presto.Generator.generateseries_sql-525"><a href="#Presto.Generator.generateseries_sql-525"><span class="linenos">525</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">end</span><span class="o">.</span><span class="n">to</span> -</span><span id="Presto.Generator.generateseries_sql-526"><a href="#Presto.Generator.generateseries_sql-526"><span class="linenos">526</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Presto.Generator.generateseries_sql-527"><a href="#Presto.Generator.generateseries_sql-527"><span class="linenos">527</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="Presto.Generator.generateseries_sql-528"><a href="#Presto.Generator.generateseries_sql-528"><span class="linenos">528</span></a> -</span><span id="Presto.Generator.generateseries_sql-529"><a href="#Presto.Generator.generateseries_sql-529"><span class="linenos">529</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">and</span> <span class="n">target_type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"timestamp"</span><span class="p">):</span> -</span><span id="Presto.Generator.generateseries_sql-530"><a href="#Presto.Generator.generateseries_sql-530"><span class="linenos">530</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">is</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span><span class="p">:</span> -</span><span id="Presto.Generator.generateseries_sql-531"><a href="#Presto.Generator.generateseries_sql-531"><span class="linenos">531</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> -</span><span id="Presto.Generator.generateseries_sql-532"><a href="#Presto.Generator.generateseries_sql-532"><span class="linenos">532</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Presto.Generator.generateseries_sql-533"><a href="#Presto.Generator.generateseries_sql-533"><span class="linenos">533</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> -</span><span id="Presto.Generator.generateseries_sql-534"><a href="#Presto.Generator.generateseries_sql-534"><span class="linenos">534</span></a> -</span><span id="Presto.Generator.generateseries_sql-535"><a href="#Presto.Generator.generateseries_sql-535"><span class="linenos">535</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 class="s2">"SEQUENCE"</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">step</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.generateseries_sql-578"><a href="#Presto.Generator.generateseries_sql-578"><span class="linenos">578</span></a> <span class="k">def</span> <span class="nf">generateseries_sql</span><span class="p">(</span><span class="bp">self</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">GenerateSeries</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator.generateseries_sql-579"><a href="#Presto.Generator.generateseries_sql-579"><span class="linenos">579</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"start"</span><span class="p">]</span> +</span><span id="Presto.Generator.generateseries_sql-580"><a href="#Presto.Generator.generateseries_sql-580"><span class="linenos">580</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"end"</span><span class="p">]</span> +</span><span id="Presto.Generator.generateseries_sql-581"><a href="#Presto.Generator.generateseries_sql-581"><span class="linenos">581</span></a> <span class="n">step</span> <span class="o">=</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">"step"</span><span class="p">)</span> +</span><span id="Presto.Generator.generateseries_sql-582"><a href="#Presto.Generator.generateseries_sql-582"><span class="linenos">582</span></a> +</span><span id="Presto.Generator.generateseries_sql-583"><a href="#Presto.Generator.generateseries_sql-583"><span class="linenos">583</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> +</span><span id="Presto.Generator.generateseries_sql-584"><a href="#Presto.Generator.generateseries_sql-584"><span class="linenos">584</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span> +</span><span id="Presto.Generator.generateseries_sql-585"><a href="#Presto.Generator.generateseries_sql-585"><span class="linenos">585</span></a> <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">):</span> +</span><span id="Presto.Generator.generateseries_sql-586"><a href="#Presto.Generator.generateseries_sql-586"><span class="linenos">586</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="n">end</span><span class="o">.</span><span class="n">to</span> +</span><span id="Presto.Generator.generateseries_sql-587"><a href="#Presto.Generator.generateseries_sql-587"><span class="linenos">587</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Presto.Generator.generateseries_sql-588"><a href="#Presto.Generator.generateseries_sql-588"><span class="linenos">588</span></a> <span class="n">target_type</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="Presto.Generator.generateseries_sql-589"><a href="#Presto.Generator.generateseries_sql-589"><span class="linenos">589</span></a> +</span><span id="Presto.Generator.generateseries_sql-590"><a href="#Presto.Generator.generateseries_sql-590"><span class="linenos">590</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">and</span> <span class="n">target_type</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"timestamp"</span><span class="p">):</span> +</span><span id="Presto.Generator.generateseries_sql-591"><a href="#Presto.Generator.generateseries_sql-591"><span class="linenos">591</span></a> <span class="k">if</span> <span class="n">target_type</span> <span class="ow">is</span> <span class="n">start</span><span class="o">.</span><span class="n">to</span><span class="p">:</span> +</span><span id="Presto.Generator.generateseries_sql-592"><a href="#Presto.Generator.generateseries_sql-592"><span class="linenos">592</span></a> <span class="n">end</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">end</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> +</span><span id="Presto.Generator.generateseries_sql-593"><a href="#Presto.Generator.generateseries_sql-593"><span class="linenos">593</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Presto.Generator.generateseries_sql-594"><a href="#Presto.Generator.generateseries_sql-594"><span class="linenos">594</span></a> <span class="n">start</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">target_type</span><span class="p">)</span> +</span><span id="Presto.Generator.generateseries_sql-595"><a href="#Presto.Generator.generateseries_sql-595"><span class="linenos">595</span></a> +</span><span id="Presto.Generator.generateseries_sql-596"><a href="#Presto.Generator.generateseries_sql-596"><span class="linenos">596</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 class="s2">"SEQUENCE"</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">step</span><span class="p">)</span> </span></pre></div> @@ -2716,13 +2916,13 @@ Default: True</li> </div> <a class="headerlink" href="#Presto.Generator.offset_limit_modifiers"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.offset_limit_modifiers-537"><a href="#Presto.Generator.offset_limit_modifiers-537"><span class="linenos">537</span></a> <span class="k">def</span> <span class="nf">offset_limit_modifiers</span><span class="p">(</span> -</span><span id="Presto.Generator.offset_limit_modifiers-538"><a href="#Presto.Generator.offset_limit_modifiers-538"><span class="linenos">538</span></a> <span class="bp">self</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">Expression</span><span class="p">,</span> <span class="n">fetch</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">limit</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">exp</span><span class="o">.</span><span class="n">Fetch</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Limit</span><span class="p">]</span> -</span><span id="Presto.Generator.offset_limit_modifiers-539"><a href="#Presto.Generator.offset_limit_modifiers-539"><span class="linenos">539</span></a> <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="Presto.Generator.offset_limit_modifiers-540"><a href="#Presto.Generator.offset_limit_modifiers-540"><span class="linenos">540</span></a> <span class="k">return</span> <span class="p">[</span> -</span><span id="Presto.Generator.offset_limit_modifiers-541"><a href="#Presto.Generator.offset_limit_modifiers-541"><span class="linenos">541</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"offset"</span><span class="p">),</span> -</span><span id="Presto.Generator.offset_limit_modifiers-542"><a href="#Presto.Generator.offset_limit_modifiers-542"><span class="linenos">542</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">limit</span><span class="p">),</span> -</span><span id="Presto.Generator.offset_limit_modifiers-543"><a href="#Presto.Generator.offset_limit_modifiers-543"><span class="linenos">543</span></a> <span class="p">]</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.offset_limit_modifiers-598"><a href="#Presto.Generator.offset_limit_modifiers-598"><span class="linenos">598</span></a> <span class="k">def</span> <span class="nf">offset_limit_modifiers</span><span class="p">(</span> +</span><span id="Presto.Generator.offset_limit_modifiers-599"><a href="#Presto.Generator.offset_limit_modifiers-599"><span class="linenos">599</span></a> <span class="bp">self</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">Expression</span><span class="p">,</span> <span class="n">fetch</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">limit</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">exp</span><span class="o">.</span><span class="n">Fetch</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Limit</span><span class="p">]</span> +</span><span id="Presto.Generator.offset_limit_modifiers-600"><a href="#Presto.Generator.offset_limit_modifiers-600"><span class="linenos">600</span></a> <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="Presto.Generator.offset_limit_modifiers-601"><a href="#Presto.Generator.offset_limit_modifiers-601"><span class="linenos">601</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="Presto.Generator.offset_limit_modifiers-602"><a href="#Presto.Generator.offset_limit_modifiers-602"><span class="linenos">602</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"offset"</span><span class="p">),</span> +</span><span id="Presto.Generator.offset_limit_modifiers-603"><a href="#Presto.Generator.offset_limit_modifiers-603"><span class="linenos">603</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">limit</span><span class="p">),</span> +</span><span id="Presto.Generator.offset_limit_modifiers-604"><a href="#Presto.Generator.offset_limit_modifiers-604"><span class="linenos">604</span></a> <span class="p">]</span> </span></pre></div> @@ -2740,16 +2940,16 @@ Default: True</li> </div> <a class="headerlink" href="#Presto.Generator.create_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.create_sql-545"><a href="#Presto.Generator.create_sql-545"><span class="linenos">545</span></a> <span class="k">def</span> <span class="nf">create_sql</span><span class="p">(</span><span class="bp">self</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">Create</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Presto.Generator.create_sql-546"><a href="#Presto.Generator.create_sql-546"><span class="linenos">546</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Presto.Generator.create_sql-547"><a href="#Presto.Generator.create_sql-547"><span class="linenos">547</span></a><span class="sd"> Presto doesn't support CREATE VIEW with expressions (ex: `CREATE VIEW x (cola)` then `(cola)` is the expression),</span> -</span><span id="Presto.Generator.create_sql-548"><a href="#Presto.Generator.create_sql-548"><span class="linenos">548</span></a><span class="sd"> so we need to remove them</span> -</span><span id="Presto.Generator.create_sql-549"><a href="#Presto.Generator.create_sql-549"><span class="linenos">549</span></a><span class="sd"> """</span> -</span><span id="Presto.Generator.create_sql-550"><a href="#Presto.Generator.create_sql-550"><span class="linenos">550</span></a> <span class="n">kind</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"kind"</span><span class="p">]</span> -</span><span id="Presto.Generator.create_sql-551"><a href="#Presto.Generator.create_sql-551"><span class="linenos">551</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> -</span><span id="Presto.Generator.create_sql-552"><a href="#Presto.Generator.create_sql-552"><span class="linenos">552</span></a> <span class="k">if</span> <span class="n">kind</span> <span class="o">==</span> <span class="s2">"VIEW"</span> <span class="ow">and</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> -</span><span id="Presto.Generator.create_sql-553"><a href="#Presto.Generator.create_sql-553"><span class="linenos">553</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> -</span><span id="Presto.Generator.create_sql-554"><a href="#Presto.Generator.create_sql-554"><span class="linenos">554</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">create_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Presto.Generator.create_sql-606"><a href="#Presto.Generator.create_sql-606"><span class="linenos">606</span></a> <span class="k">def</span> <span class="nf">create_sql</span><span class="p">(</span><span class="bp">self</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">Create</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Presto.Generator.create_sql-607"><a href="#Presto.Generator.create_sql-607"><span class="linenos">607</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Presto.Generator.create_sql-608"><a href="#Presto.Generator.create_sql-608"><span class="linenos">608</span></a><span class="sd"> Presto doesn't support CREATE VIEW with expressions (ex: `CREATE VIEW x (cola)` then `(cola)` is the expression),</span> +</span><span id="Presto.Generator.create_sql-609"><a href="#Presto.Generator.create_sql-609"><span class="linenos">609</span></a><span class="sd"> so we need to remove them</span> +</span><span id="Presto.Generator.create_sql-610"><a href="#Presto.Generator.create_sql-610"><span class="linenos">610</span></a><span class="sd"> """</span> +</span><span id="Presto.Generator.create_sql-611"><a href="#Presto.Generator.create_sql-611"><span class="linenos">611</span></a> <span class="n">kind</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"kind"</span><span class="p">]</span> +</span><span id="Presto.Generator.create_sql-612"><a href="#Presto.Generator.create_sql-612"><span class="linenos">612</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="Presto.Generator.create_sql-613"><a href="#Presto.Generator.create_sql-613"><span class="linenos">613</span></a> <span class="k">if</span> <span class="n">kind</span> <span class="o">==</span> <span class="s2">"VIEW"</span> <span class="ow">and</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="Presto.Generator.create_sql-614"><a href="#Presto.Generator.create_sql-614"><span class="linenos">614</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="Presto.Generator.create_sql-615"><a href="#Presto.Generator.create_sql-615"><span class="linenos">615</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">create_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -2841,7 +3041,6 @@ so we need to remove them</p> <dd id="Presto.Generator.TOKEN_MAPPING" class="variable"><a href="../generator.html#Generator.TOKEN_MAPPING">TOKEN_MAPPING</a></dd> <dd id="Presto.Generator.PARAMETER_TOKEN" class="variable"><a href="../generator.html#Generator.PARAMETER_TOKEN">PARAMETER_TOKEN</a></dd> <dd id="Presto.Generator.NAMED_PLACEHOLDER_TOKEN" class="variable"><a href="../generator.html#Generator.NAMED_PLACEHOLDER_TOKEN">NAMED_PLACEHOLDER_TOKEN</a></dd> - <dd id="Presto.Generator.RESERVED_KEYWORDS" class="variable"><a href="../generator.html#Generator.RESERVED_KEYWORDS">RESERVED_KEYWORDS</a></dd> <dd id="Presto.Generator.WITH_SEPARATED_COMMENTS" class="variable"><a href="../generator.html#Generator.WITH_SEPARATED_COMMENTS">WITH_SEPARATED_COMMENTS</a></dd> <dd id="Presto.Generator.EXCLUDE_COMMENTS" class="variable"><a href="../generator.html#Generator.EXCLUDE_COMMENTS">EXCLUDE_COMMENTS</a></dd> <dd id="Presto.Generator.UNWRAPPED_INTERVAL_VALUES" class="variable"><a href="../generator.html#Generator.UNWRAPPED_INTERVAL_VALUES">UNWRAPPED_INTERVAL_VALUES</a></dd> @@ -2875,6 +3074,7 @@ so we need to remove them</p> <dd id="Presto.Generator.uncache_sql" class="function"><a href="../generator.html#Generator.uncache_sql">uncache_sql</a></dd> <dd id="Presto.Generator.cache_sql" class="function"><a href="../generator.html#Generator.cache_sql">cache_sql</a></dd> <dd id="Presto.Generator.characterset_sql" class="function"><a href="../generator.html#Generator.characterset_sql">characterset_sql</a></dd> + <dd id="Presto.Generator.column_parts" class="function"><a href="../generator.html#Generator.column_parts">column_parts</a></dd> <dd id="Presto.Generator.column_sql" class="function"><a href="../generator.html#Generator.column_sql">column_sql</a></dd> <dd id="Presto.Generator.columnposition_sql" class="function"><a href="../generator.html#Generator.columnposition_sql">columnposition_sql</a></dd> <dd id="Presto.Generator.columndef_sql" class="function"><a href="../generator.html#Generator.columndef_sql">columndef_sql</a></dd> @@ -3124,7 +3324,7 @@ so we need to remove them</p> <dd id="Presto.Generator.function_fallback_sql" class="function"><a href="../generator.html#Generator.function_fallback_sql">function_fallback_sql</a></dd> <dd id="Presto.Generator.func" class="function"><a href="../generator.html#Generator.func">func</a></dd> <dd id="Presto.Generator.format_args" class="function"><a href="../generator.html#Generator.format_args">format_args</a></dd> - <dd id="Presto.Generator.text_width" class="function"><a href="../generator.html#Generator.text_width">text_width</a></dd> + <dd id="Presto.Generator.too_wide" class="function"><a href="../generator.html#Generator.too_wide">too_wide</a></dd> <dd id="Presto.Generator.format_time" class="function"><a href="../generator.html#Generator.format_time">format_time</a></dd> <dd id="Presto.Generator.expressions" class="function"><a href="../generator.html#Generator.expressions">expressions</a></dd> <dd id="Presto.Generator.op_expressions" class="function"><a href="../generator.html#Generator.op_expressions">op_expressions</a></dd> |