diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-12-19 11:01:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-12-19 11:01:36 +0000 |
commit | 948a422be120c069e48c63a8770fec7204307897 (patch) | |
tree | 80bc02d5e6cd3527409386aa1d706272bea54e6c /docs/sqlglot/dialects/dialect.html | |
parent | Adding upstream version 20.1.0. (diff) | |
download | sqlglot-948a422be120c069e48c63a8770fec7204307897.tar.xz sqlglot-948a422be120c069e48c63a8770fec7204307897.zip |
Adding upstream version 20.3.0.upstream/20.3.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'docs/sqlglot/dialects/dialect.html')
-rw-r--r-- | docs/sqlglot/dialects/dialect.html | 2935 |
1 files changed, 1478 insertions, 1457 deletions
diff --git a/docs/sqlglot/dialects/dialect.html b/docs/sqlglot/dialects/dialect.html index f17ad21..7dd51be 100644 --- a/docs/sqlglot/dialects/dialect.html +++ b/docs/sqlglot/dialects/dialect.html @@ -3,7 +3,7 @@ <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> - <meta name="generator" content="pdoc 14.1.0"/> + <meta name="generator" content="pdoc 14.2.0"/> <title>sqlglot.dialects.dialect API documentation</title> <style>/*! * Bootstrap Reboot v5.0.0 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors * Copyright 2011-2021 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;background-color:#fff;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important}</style> @@ -175,6 +175,9 @@ <a class="variable" href="#Dialect.SAFE_DIVISION">SAFE_DIVISION</a> </li> <li> + <a class="variable" href="#Dialect.CONCAT_COALESCE">CONCAT_COALESCE</a> + </li> + <li> <a class="variable" href="#Dialect.DATE_FORMAT">DATE_FORMAT</a> </li> <li> @@ -670,745 +673,748 @@ </span><span id="L-177"><a href="#L-177"><span class="linenos">177</span></a> <span class="c1"># True means 1 / 0 returns null.</span> </span><span id="L-178"><a href="#L-178"><span class="linenos">178</span></a> <span class="n">SAFE_DIVISION</span> <span class="o">=</span> <span class="kc">False</span> </span><span id="L-179"><a href="#L-179"><span class="linenos">179</span></a> -</span><span id="L-180"><a href="#L-180"><span class="linenos">180</span></a> <span class="n">DATE_FORMAT</span> <span class="o">=</span> <span class="s2">"'%Y-%m-</span><span class="si">%d</span><span class="s2">'"</span> -</span><span id="L-181"><a href="#L-181"><span class="linenos">181</span></a> <span class="n">DATEINT_FORMAT</span> <span class="o">=</span> <span class="s2">"'%Y%m</span><span class="si">%d</span><span class="s2">'"</span> -</span><span id="L-182"><a href="#L-182"><span class="linenos">182</span></a> <span class="n">TIME_FORMAT</span> <span class="o">=</span> <span class="s2">"'%Y-%m-</span><span class="si">%d</span><span class="s2"> %H:%M:%S'"</span> -</span><span id="L-183"><a href="#L-183"><span class="linenos">183</span></a> -</span><span id="L-184"><a href="#L-184"><span class="linenos">184</span></a> <span class="c1"># Custom time mappings in which the key represents dialect time format</span> -</span><span id="L-185"><a href="#L-185"><span class="linenos">185</span></a> <span class="c1"># and the value represents a python time format</span> -</span><span id="L-186"><a href="#L-186"><span class="linenos">186</span></a> <span class="n">TIME_MAPPING</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="L-187"><a href="#L-187"><span class="linenos">187</span></a> -</span><span id="L-188"><a href="#L-188"><span class="linenos">188</span></a> <span class="c1"># https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#format_model_rules_date_time</span> -</span><span id="L-189"><a href="#L-189"><span class="linenos">189</span></a> <span class="c1"># https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Data-Type-Conversions/Character-to-DATE-Conversion/Forcing-a-FORMAT-on-CAST-for-Converting-Character-to-DATE</span> -</span><span id="L-190"><a href="#L-190"><span class="linenos">190</span></a> <span class="c1"># special syntax cast(x as date format 'yyyy') defaults to time_mapping</span> -</span><span id="L-191"><a href="#L-191"><span class="linenos">191</span></a> <span class="n">FORMAT_MAPPING</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="L-192"><a href="#L-192"><span class="linenos">192</span></a> -</span><span id="L-193"><a href="#L-193"><span class="linenos">193</span></a> <span class="c1"># Mapping of an unescaped escape sequence to the corresponding character</span> -</span><span id="L-194"><a href="#L-194"><span class="linenos">194</span></a> <span class="n">ESCAPE_SEQUENCES</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="L-180"><a href="#L-180"><span class="linenos">180</span></a> <span class="c1"># A NULL arg in CONCAT yields NULL by default, but in some dialects it yields an empty string</span> +</span><span id="L-181"><a href="#L-181"><span class="linenos">181</span></a> <span class="n">CONCAT_COALESCE</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-182"><a href="#L-182"><span class="linenos">182</span></a> +</span><span id="L-183"><a href="#L-183"><span class="linenos">183</span></a> <span class="n">DATE_FORMAT</span> <span class="o">=</span> <span class="s2">"'%Y-%m-</span><span class="si">%d</span><span class="s2">'"</span> +</span><span id="L-184"><a href="#L-184"><span class="linenos">184</span></a> <span class="n">DATEINT_FORMAT</span> <span class="o">=</span> <span class="s2">"'%Y%m</span><span class="si">%d</span><span class="s2">'"</span> +</span><span id="L-185"><a href="#L-185"><span class="linenos">185</span></a> <span class="n">TIME_FORMAT</span> <span class="o">=</span> <span class="s2">"'%Y-%m-</span><span class="si">%d</span><span class="s2"> %H:%M:%S'"</span> +</span><span id="L-186"><a href="#L-186"><span class="linenos">186</span></a> +</span><span id="L-187"><a href="#L-187"><span class="linenos">187</span></a> <span class="c1"># Custom time mappings in which the key represents dialect time format</span> +</span><span id="L-188"><a href="#L-188"><span class="linenos">188</span></a> <span class="c1"># and the value represents a python time format</span> +</span><span id="L-189"><a href="#L-189"><span class="linenos">189</span></a> <span class="n">TIME_MAPPING</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="L-190"><a href="#L-190"><span class="linenos">190</span></a> +</span><span id="L-191"><a href="#L-191"><span class="linenos">191</span></a> <span class="c1"># https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#format_model_rules_date_time</span> +</span><span id="L-192"><a href="#L-192"><span class="linenos">192</span></a> <span class="c1"># https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Data-Type-Conversions/Character-to-DATE-Conversion/Forcing-a-FORMAT-on-CAST-for-Converting-Character-to-DATE</span> +</span><span id="L-193"><a href="#L-193"><span class="linenos">193</span></a> <span class="c1"># special syntax cast(x as date format 'yyyy') defaults to time_mapping</span> +</span><span id="L-194"><a href="#L-194"><span class="linenos">194</span></a> <span class="n">FORMAT_MAPPING</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> </span><span id="L-195"><a href="#L-195"><span class="linenos">195</span></a> -</span><span id="L-196"><a href="#L-196"><span class="linenos">196</span></a> <span class="c1"># Columns that are auto-generated by the engine corresponding to this dialect</span> -</span><span id="L-197"><a href="#L-197"><span class="linenos">197</span></a> <span class="c1"># Such columns may be excluded from SELECT * queries, for example</span> -</span><span id="L-198"><a href="#L-198"><span class="linenos">198</span></a> <span class="n">PSEUDOCOLUMNS</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Set</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span> -</span><span id="L-199"><a href="#L-199"><span class="linenos">199</span></a> -</span><span id="L-200"><a href="#L-200"><span class="linenos">200</span></a> <span class="c1"># --- Autofilled ---</span> -</span><span id="L-201"><a href="#L-201"><span class="linenos">201</span></a> -</span><span id="L-202"><a href="#L-202"><span class="linenos">202</span></a> <span class="n">tokenizer_class</span> <span class="o">=</span> <span class="n">Tokenizer</span> -</span><span id="L-203"><a href="#L-203"><span class="linenos">203</span></a> <span class="n">parser_class</span> <span class="o">=</span> <span class="n">Parser</span> -</span><span id="L-204"><a href="#L-204"><span class="linenos">204</span></a> <span class="n">generator_class</span> <span class="o">=</span> <span class="n">Generator</span> -</span><span id="L-205"><a href="#L-205"><span class="linenos">205</span></a> -</span><span id="L-206"><a href="#L-206"><span class="linenos">206</span></a> <span class="c1"># A trie of the time_mapping keys</span> -</span><span id="L-207"><a href="#L-207"><span class="linenos">207</span></a> <span class="n">TIME_TRIE</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="L-208"><a href="#L-208"><span class="linenos">208</span></a> <span class="n">FORMAT_TRIE</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="L-209"><a href="#L-209"><span class="linenos">209</span></a> -</span><span id="L-210"><a href="#L-210"><span class="linenos">210</span></a> <span class="n">INVERSE_TIME_MAPPING</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="L-211"><a href="#L-211"><span class="linenos">211</span></a> <span class="n">INVERSE_TIME_TRIE</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="L-196"><a href="#L-196"><span class="linenos">196</span></a> <span class="c1"># Mapping of an unescaped escape sequence to the corresponding character</span> +</span><span id="L-197"><a href="#L-197"><span class="linenos">197</span></a> <span class="n">ESCAPE_SEQUENCES</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="L-198"><a href="#L-198"><span class="linenos">198</span></a> +</span><span id="L-199"><a href="#L-199"><span class="linenos">199</span></a> <span class="c1"># Columns that are auto-generated by the engine corresponding to this dialect</span> +</span><span id="L-200"><a href="#L-200"><span class="linenos">200</span></a> <span class="c1"># Such columns may be excluded from SELECT * queries, for example</span> +</span><span id="L-201"><a href="#L-201"><span class="linenos">201</span></a> <span class="n">PSEUDOCOLUMNS</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Set</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span> +</span><span id="L-202"><a href="#L-202"><span class="linenos">202</span></a> +</span><span id="L-203"><a href="#L-203"><span class="linenos">203</span></a> <span class="c1"># --- Autofilled ---</span> +</span><span id="L-204"><a href="#L-204"><span class="linenos">204</span></a> +</span><span id="L-205"><a href="#L-205"><span class="linenos">205</span></a> <span class="n">tokenizer_class</span> <span class="o">=</span> <span class="n">Tokenizer</span> +</span><span id="L-206"><a href="#L-206"><span class="linenos">206</span></a> <span class="n">parser_class</span> <span class="o">=</span> <span class="n">Parser</span> +</span><span id="L-207"><a href="#L-207"><span class="linenos">207</span></a> <span class="n">generator_class</span> <span class="o">=</span> <span class="n">Generator</span> +</span><span id="L-208"><a href="#L-208"><span class="linenos">208</span></a> +</span><span id="L-209"><a href="#L-209"><span class="linenos">209</span></a> <span class="c1"># A trie of the time_mapping keys</span> +</span><span id="L-210"><a href="#L-210"><span class="linenos">210</span></a> <span class="n">TIME_TRIE</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="L-211"><a href="#L-211"><span class="linenos">211</span></a> <span class="n">FORMAT_TRIE</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">=</span> <span class="p">{}</span> </span><span id="L-212"><a href="#L-212"><span class="linenos">212</span></a> -</span><span id="L-213"><a href="#L-213"><span class="linenos">213</span></a> <span class="n">INVERSE_ESCAPE_SEQUENCES</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="L-214"><a href="#L-214"><span class="linenos">214</span></a> -</span><span id="L-215"><a href="#L-215"><span class="linenos">215</span></a> <span class="c1"># Delimiters for quotes, identifiers and the corresponding escape characters</span> -</span><span id="L-216"><a href="#L-216"><span class="linenos">216</span></a> <span class="n">QUOTE_START</span> <span class="o">=</span> <span class="s2">"'"</span> -</span><span id="L-217"><a href="#L-217"><span class="linenos">217</span></a> <span class="n">QUOTE_END</span> <span class="o">=</span> <span class="s2">"'"</span> -</span><span id="L-218"><a href="#L-218"><span class="linenos">218</span></a> <span class="n">IDENTIFIER_START</span> <span class="o">=</span> <span class="s1">'"'</span> -</span><span id="L-219"><a href="#L-219"><span class="linenos">219</span></a> <span class="n">IDENTIFIER_END</span> <span class="o">=</span> <span class="s1">'"'</span> -</span><span id="L-220"><a href="#L-220"><span class="linenos">220</span></a> -</span><span id="L-221"><a href="#L-221"><span class="linenos">221</span></a> <span class="c1"># Delimiters for bit, hex and byte literals</span> -</span><span id="L-222"><a href="#L-222"><span class="linenos">222</span></a> <span class="n">BIT_START</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-223"><a href="#L-223"><span class="linenos">223</span></a> <span class="n">BIT_END</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-224"><a href="#L-224"><span class="linenos">224</span></a> <span class="n">HEX_START</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-225"><a href="#L-225"><span class="linenos">225</span></a> <span class="n">HEX_END</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-226"><a href="#L-226"><span class="linenos">226</span></a> <span class="n">BYTE_START</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-227"><a href="#L-227"><span class="linenos">227</span></a> <span class="n">BYTE_END</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-228"><a href="#L-228"><span class="linenos">228</span></a> -</span><span id="L-229"><a href="#L-229"><span class="linenos">229</span></a> <span class="nd">@classmethod</span> -</span><span id="L-230"><a href="#L-230"><span class="linenos">230</span></a> <span class="k">def</span> <span class="nf">get_or_raise</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">Dialect</span><span class="p">:</span> -</span><span id="L-231"><a href="#L-231"><span class="linenos">231</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-232"><a href="#L-232"><span class="linenos">232</span></a><span class="sd"> Look up a dialect in the global dialect registry and return it if it exists.</span> -</span><span id="L-233"><a href="#L-233"><span class="linenos">233</span></a> -</span><span id="L-234"><a href="#L-234"><span class="linenos">234</span></a><span class="sd"> Args:</span> -</span><span id="L-235"><a href="#L-235"><span class="linenos">235</span></a><span class="sd"> dialect: The target dialect. If this is a string, it can be optionally followed by</span> -</span><span id="L-236"><a href="#L-236"><span class="linenos">236</span></a><span class="sd"> additional key-value pairs that are separated by commas and are used to specify</span> -</span><span id="L-237"><a href="#L-237"><span class="linenos">237</span></a><span class="sd"> dialect settings, such as whether the dialect's identifiers are case-sensitive.</span> -</span><span id="L-238"><a href="#L-238"><span class="linenos">238</span></a> -</span><span id="L-239"><a href="#L-239"><span class="linenos">239</span></a><span class="sd"> Example:</span> -</span><span id="L-240"><a href="#L-240"><span class="linenos">240</span></a><span class="sd"> >>> dialect = dialect_class = get_or_raise("duckdb")</span> -</span><span id="L-241"><a href="#L-241"><span class="linenos">241</span></a><span class="sd"> >>> dialect = get_or_raise("mysql, normalization_strategy = case_sensitive")</span> -</span><span id="L-242"><a href="#L-242"><span class="linenos">242</span></a> -</span><span id="L-243"><a href="#L-243"><span class="linenos">243</span></a><span class="sd"> Returns:</span> -</span><span id="L-244"><a href="#L-244"><span class="linenos">244</span></a><span class="sd"> The corresponding Dialect instance.</span> -</span><span id="L-245"><a href="#L-245"><span class="linenos">245</span></a><span class="sd"> """</span> -</span><span id="L-246"><a href="#L-246"><span class="linenos">246</span></a> -</span><span id="L-247"><a href="#L-247"><span class="linenos">247</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">dialect</span><span class="p">:</span> -</span><span id="L-248"><a href="#L-248"><span class="linenos">248</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span> -</span><span id="L-249"><a href="#L-249"><span class="linenos">249</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="n">_Dialect</span><span class="p">):</span> -</span><span id="L-250"><a href="#L-250"><span class="linenos">250</span></a> <span class="k">return</span> <span class="n">dialect</span><span class="p">()</span> -</span><span id="L-251"><a href="#L-251"><span class="linenos">251</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="n">Dialect</span><span class="p">):</span> -</span><span id="L-252"><a href="#L-252"><span class="linenos">252</span></a> <span class="k">return</span> <span class="n">dialect</span> -</span><span id="L-253"><a href="#L-253"><span class="linenos">253</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> -</span><span id="L-254"><a href="#L-254"><span class="linenos">254</span></a> <span class="k">try</span><span class="p">:</span> -</span><span id="L-255"><a href="#L-255"><span class="linenos">255</span></a> <span class="n">dialect_name</span><span class="p">,</span> <span class="o">*</span><span class="n">kv_pairs</span> <span class="o">=</span> <span class="n">dialect</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">)</span> -</span><span id="L-256"><a href="#L-256"><span class="linenos">256</span></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="n">v</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="p">(</span><span class="n">kv</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">"="</span><span class="p">)</span> <span class="k">for</span> <span class="n">kv</span> <span class="ow">in</span> <span class="n">kv_pairs</span><span class="p">)}</span> -</span><span id="L-257"><a href="#L-257"><span class="linenos">257</span></a> <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> -</span><span id="L-258"><a href="#L-258"><span class="linenos">258</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> -</span><span id="L-259"><a href="#L-259"><span class="linenos">259</span></a> <span class="sa">f</span><span class="s2">"Invalid dialect format: '</span><span class="si">{</span><span class="n">dialect</span><span class="si">}</span><span class="s2">'. "</span> -</span><span id="L-260"><a href="#L-260"><span class="linenos">260</span></a> <span class="s2">"Please use the correct format: 'dialect [, k1 = v2 [, ...]]'."</span> -</span><span id="L-261"><a href="#L-261"><span class="linenos">261</span></a> <span class="p">)</span> -</span><span id="L-262"><a href="#L-262"><span class="linenos">262</span></a> -</span><span id="L-263"><a href="#L-263"><span class="linenos">263</span></a> <span class="n">result</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">dialect_name</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> -</span><span id="L-264"><a href="#L-264"><span class="linenos">264</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">result</span><span class="p">:</span> -</span><span id="L-265"><a href="#L-265"><span class="linenos">265</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unknown dialect '</span><span class="si">{</span><span class="n">dialect_name</span><span class="si">}</span><span class="s2">'."</span><span class="p">)</span> -</span><span id="L-266"><a href="#L-266"><span class="linenos">266</span></a> -</span><span id="L-267"><a href="#L-267"><span class="linenos">267</span></a> <span class="k">return</span> <span class="n">result</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> -</span><span id="L-268"><a href="#L-268"><span class="linenos">268</span></a> -</span><span id="L-269"><a href="#L-269"><span class="linenos">269</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid dialect type for '</span><span class="si">{</span><span class="n">dialect</span><span class="si">}</span><span class="s2">': '</span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span><span class="si">}</span><span class="s2">'."</span><span class="p">)</span> -</span><span id="L-270"><a href="#L-270"><span class="linenos">270</span></a> -</span><span id="L-271"><a href="#L-271"><span class="linenos">271</span></a> <span class="nd">@classmethod</span> -</span><span id="L-272"><a href="#L-272"><span class="linenos">272</span></a> <span class="k">def</span> <span class="nf">format_time</span><span class="p">(</span> -</span><span id="L-273"><a href="#L-273"><span class="linenos">273</span></a> <span class="bp">cls</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]</span> -</span><span id="L-274"><a href="#L-274"><span class="linenos">274</span></a> <span class="p">)</span> <span class="o">-></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">Expression</span><span class="p">]:</span> -</span><span id="L-275"><a href="#L-275"><span class="linenos">275</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> -</span><span id="L-276"><a href="#L-276"><span class="linenos">276</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span> -</span><span id="L-277"><a href="#L-277"><span class="linenos">277</span></a> <span class="c1"># the time formats are quoted</span> -</span><span id="L-278"><a href="#L-278"><span class="linenos">278</span></a> <span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_TRIE</span><span class="p">)</span> -</span><span id="L-279"><a href="#L-279"><span class="linenos">279</span></a> <span class="p">)</span> -</span><span id="L-280"><a href="#L-280"><span class="linenos">280</span></a> -</span><span id="L-281"><a href="#L-281"><span class="linenos">281</span></a> <span class="k">if</span> <span class="n">expression</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_string</span><span class="p">:</span> -</span><span id="L-282"><a href="#L-282"><span class="linenos">282</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="n">format_time</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="bp">cls</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_TRIE</span><span class="p">))</span> +</span><span id="L-213"><a href="#L-213"><span class="linenos">213</span></a> <span class="n">INVERSE_TIME_MAPPING</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="L-214"><a href="#L-214"><span class="linenos">214</span></a> <span class="n">INVERSE_TIME_TRIE</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="L-215"><a href="#L-215"><span class="linenos">215</span></a> +</span><span id="L-216"><a href="#L-216"><span class="linenos">216</span></a> <span class="n">INVERSE_ESCAPE_SEQUENCES</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="L-217"><a href="#L-217"><span class="linenos">217</span></a> +</span><span id="L-218"><a href="#L-218"><span class="linenos">218</span></a> <span class="c1"># Delimiters for quotes, identifiers and the corresponding escape characters</span> +</span><span id="L-219"><a href="#L-219"><span class="linenos">219</span></a> <span class="n">QUOTE_START</span> <span class="o">=</span> <span class="s2">"'"</span> +</span><span id="L-220"><a href="#L-220"><span class="linenos">220</span></a> <span class="n">QUOTE_END</span> <span class="o">=</span> <span class="s2">"'"</span> +</span><span id="L-221"><a href="#L-221"><span class="linenos">221</span></a> <span class="n">IDENTIFIER_START</span> <span class="o">=</span> <span class="s1">'"'</span> +</span><span id="L-222"><a href="#L-222"><span class="linenos">222</span></a> <span class="n">IDENTIFIER_END</span> <span class="o">=</span> <span class="s1">'"'</span> +</span><span id="L-223"><a href="#L-223"><span class="linenos">223</span></a> +</span><span id="L-224"><a href="#L-224"><span class="linenos">224</span></a> <span class="c1"># Delimiters for bit, hex and byte literals</span> +</span><span id="L-225"><a href="#L-225"><span class="linenos">225</span></a> <span class="n">BIT_START</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="L-226"><a href="#L-226"><span class="linenos">226</span></a> <span class="n">BIT_END</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="L-227"><a href="#L-227"><span class="linenos">227</span></a> <span class="n">HEX_START</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="L-228"><a href="#L-228"><span class="linenos">228</span></a> <span class="n">HEX_END</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="L-229"><a href="#L-229"><span class="linenos">229</span></a> <span class="n">BYTE_START</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="L-230"><a href="#L-230"><span class="linenos">230</span></a> <span class="n">BYTE_END</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="L-231"><a href="#L-231"><span class="linenos">231</span></a> +</span><span id="L-232"><a href="#L-232"><span class="linenos">232</span></a> <span class="nd">@classmethod</span> +</span><span id="L-233"><a href="#L-233"><span class="linenos">233</span></a> <span class="k">def</span> <span class="nf">get_or_raise</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">Dialect</span><span class="p">:</span> +</span><span id="L-234"><a href="#L-234"><span class="linenos">234</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-235"><a href="#L-235"><span class="linenos">235</span></a><span class="sd"> Look up a dialect in the global dialect registry and return it if it exists.</span> +</span><span id="L-236"><a href="#L-236"><span class="linenos">236</span></a> +</span><span id="L-237"><a href="#L-237"><span class="linenos">237</span></a><span class="sd"> Args:</span> +</span><span id="L-238"><a href="#L-238"><span class="linenos">238</span></a><span class="sd"> dialect: The target dialect. If this is a string, it can be optionally followed by</span> +</span><span id="L-239"><a href="#L-239"><span class="linenos">239</span></a><span class="sd"> additional key-value pairs that are separated by commas and are used to specify</span> +</span><span id="L-240"><a href="#L-240"><span class="linenos">240</span></a><span class="sd"> dialect settings, such as whether the dialect's identifiers are case-sensitive.</span> +</span><span id="L-241"><a href="#L-241"><span class="linenos">241</span></a> +</span><span id="L-242"><a href="#L-242"><span class="linenos">242</span></a><span class="sd"> Example:</span> +</span><span id="L-243"><a href="#L-243"><span class="linenos">243</span></a><span class="sd"> >>> dialect = dialect_class = get_or_raise("duckdb")</span> +</span><span id="L-244"><a href="#L-244"><span class="linenos">244</span></a><span class="sd"> >>> dialect = get_or_raise("mysql, normalization_strategy = case_sensitive")</span> +</span><span id="L-245"><a href="#L-245"><span class="linenos">245</span></a> +</span><span id="L-246"><a href="#L-246"><span class="linenos">246</span></a><span class="sd"> Returns:</span> +</span><span id="L-247"><a href="#L-247"><span class="linenos">247</span></a><span class="sd"> The corresponding Dialect instance.</span> +</span><span id="L-248"><a href="#L-248"><span class="linenos">248</span></a><span class="sd"> """</span> +</span><span id="L-249"><a href="#L-249"><span class="linenos">249</span></a> +</span><span id="L-250"><a href="#L-250"><span class="linenos">250</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">dialect</span><span class="p">:</span> +</span><span id="L-251"><a href="#L-251"><span class="linenos">251</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span> +</span><span id="L-252"><a href="#L-252"><span class="linenos">252</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="n">_Dialect</span><span class="p">):</span> +</span><span id="L-253"><a href="#L-253"><span class="linenos">253</span></a> <span class="k">return</span> <span class="n">dialect</span><span class="p">()</span> +</span><span id="L-254"><a href="#L-254"><span class="linenos">254</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="n">Dialect</span><span class="p">):</span> +</span><span id="L-255"><a href="#L-255"><span class="linenos">255</span></a> <span class="k">return</span> <span class="n">dialect</span> +</span><span id="L-256"><a href="#L-256"><span class="linenos">256</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="L-257"><a href="#L-257"><span class="linenos">257</span></a> <span class="k">try</span><span class="p">:</span> +</span><span id="L-258"><a href="#L-258"><span class="linenos">258</span></a> <span class="n">dialect_name</span><span class="p">,</span> <span class="o">*</span><span class="n">kv_pairs</span> <span class="o">=</span> <span class="n">dialect</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">)</span> +</span><span id="L-259"><a href="#L-259"><span class="linenos">259</span></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="n">v</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="p">(</span><span class="n">kv</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">"="</span><span class="p">)</span> <span class="k">for</span> <span class="n">kv</span> <span class="ow">in</span> <span class="n">kv_pairs</span><span class="p">)}</span> +</span><span id="L-260"><a href="#L-260"><span class="linenos">260</span></a> <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> +</span><span id="L-261"><a href="#L-261"><span class="linenos">261</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> +</span><span id="L-262"><a href="#L-262"><span class="linenos">262</span></a> <span class="sa">f</span><span class="s2">"Invalid dialect format: '</span><span class="si">{</span><span class="n">dialect</span><span class="si">}</span><span class="s2">'. "</span> +</span><span id="L-263"><a href="#L-263"><span class="linenos">263</span></a> <span class="s2">"Please use the correct format: 'dialect [, k1 = v2 [, ...]]'."</span> +</span><span id="L-264"><a href="#L-264"><span class="linenos">264</span></a> <span class="p">)</span> +</span><span id="L-265"><a href="#L-265"><span class="linenos">265</span></a> +</span><span id="L-266"><a href="#L-266"><span class="linenos">266</span></a> <span class="n">result</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">dialect_name</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> +</span><span id="L-267"><a href="#L-267"><span class="linenos">267</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">result</span><span class="p">:</span> +</span><span id="L-268"><a href="#L-268"><span class="linenos">268</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unknown dialect '</span><span class="si">{</span><span class="n">dialect_name</span><span class="si">}</span><span class="s2">'."</span><span class="p">)</span> +</span><span id="L-269"><a href="#L-269"><span class="linenos">269</span></a> +</span><span id="L-270"><a href="#L-270"><span class="linenos">270</span></a> <span class="k">return</span> <span class="n">result</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span><span id="L-271"><a href="#L-271"><span class="linenos">271</span></a> +</span><span id="L-272"><a href="#L-272"><span class="linenos">272</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid dialect type for '</span><span class="si">{</span><span class="n">dialect</span><span class="si">}</span><span class="s2">': '</span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span><span class="si">}</span><span class="s2">'."</span><span class="p">)</span> +</span><span id="L-273"><a href="#L-273"><span class="linenos">273</span></a> +</span><span id="L-274"><a href="#L-274"><span class="linenos">274</span></a> <span class="nd">@classmethod</span> +</span><span id="L-275"><a href="#L-275"><span class="linenos">275</span></a> <span class="k">def</span> <span class="nf">format_time</span><span class="p">(</span> +</span><span id="L-276"><a href="#L-276"><span class="linenos">276</span></a> <span class="bp">cls</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]</span> +</span><span id="L-277"><a href="#L-277"><span class="linenos">277</span></a> <span class="p">)</span> <span class="o">-></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">Expression</span><span class="p">]:</span> +</span><span id="L-278"><a href="#L-278"><span class="linenos">278</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="L-279"><a href="#L-279"><span class="linenos">279</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span> +</span><span id="L-280"><a href="#L-280"><span class="linenos">280</span></a> <span class="c1"># the time formats are quoted</span> +</span><span id="L-281"><a href="#L-281"><span class="linenos">281</span></a> <span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_TRIE</span><span class="p">)</span> +</span><span id="L-282"><a href="#L-282"><span class="linenos">282</span></a> <span class="p">)</span> </span><span id="L-283"><a href="#L-283"><span class="linenos">283</span></a> -</span><span id="L-284"><a href="#L-284"><span class="linenos">284</span></a> <span class="k">return</span> <span class="n">expression</span> -</span><span id="L-285"><a href="#L-285"><span class="linenos">285</span></a> -</span><span id="L-286"><a href="#L-286"><span class="linenos">286</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="L-287"><a href="#L-287"><span class="linenos">287</span></a> <span class="n">normalization_strategy</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"normalization_strategy"</span><span class="p">)</span> +</span><span id="L-284"><a href="#L-284"><span class="linenos">284</span></a> <span class="k">if</span> <span class="n">expression</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_string</span><span class="p">:</span> +</span><span id="L-285"><a href="#L-285"><span class="linenos">285</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="n">format_time</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="bp">cls</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_TRIE</span><span class="p">))</span> +</span><span id="L-286"><a href="#L-286"><span class="linenos">286</span></a> +</span><span id="L-287"><a href="#L-287"><span class="linenos">287</span></a> <span class="k">return</span> <span class="n">expression</span> </span><span id="L-288"><a href="#L-288"><span class="linenos">288</span></a> -</span><span id="L-289"><a href="#L-289"><span class="linenos">289</span></a> <span class="k">if</span> <span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> -</span><span id="L-290"><a href="#L-290"><span class="linenos">290</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">NORMALIZATION_STRATEGY</span> -</span><span id="L-291"><a href="#L-291"><span class="linenos">291</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="L-292"><a href="#L-292"><span class="linenos">292</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="o">=</span> <span class="n">NormalizationStrategy</span><span class="p">(</span><span class="n">normalization_strategy</span><span class="o">.</span><span class="n">upper</span><span class="p">())</span> -</span><span id="L-293"><a href="#L-293"><span class="linenos">293</span></a> -</span><span id="L-294"><a href="#L-294"><span class="linenos">294</span></a> <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> -</span><span id="L-295"><a href="#L-295"><span class="linenos">295</span></a> <span class="c1"># Does not currently take dialect state into account</span> -</span><span id="L-296"><a href="#L-296"><span class="linenos">296</span></a> <span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">==</span> <span class="n">other</span> -</span><span id="L-297"><a href="#L-297"><span class="linenos">297</span></a> -</span><span id="L-298"><a href="#L-298"><span class="linenos">298</span></a> <span class="k">def</span> <span class="fm">__hash__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">int</span><span class="p">:</span> -</span><span id="L-299"><a href="#L-299"><span class="linenos">299</span></a> <span class="c1"># Does not currently take dialect state into account</span> -</span><span id="L-300"><a href="#L-300"><span class="linenos">300</span></a> <span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span> -</span><span id="L-301"><a href="#L-301"><span class="linenos">301</span></a> -</span><span id="L-302"><a href="#L-302"><span class="linenos">302</span></a> <span class="k">def</span> <span class="nf">normalize_identifier</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">E</span><span class="p">)</span> <span class="o">-></span> <span class="n">E</span><span class="p">:</span> -</span><span id="L-303"><a href="#L-303"><span class="linenos">303</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-304"><a href="#L-304"><span class="linenos">304</span></a><span class="sd"> Transforms an identifier in a way that resembles how it'd be resolved by this dialect.</span> -</span><span id="L-305"><a href="#L-305"><span class="linenos">305</span></a> -</span><span id="L-306"><a href="#L-306"><span class="linenos">306</span></a><span class="sd"> For example, an identifier like FoO would be resolved as foo in Postgres, because it</span> -</span><span id="L-307"><a href="#L-307"><span class="linenos">307</span></a><span class="sd"> lowercases all unquoted identifiers. On the other hand, Snowflake uppercases them, so</span> -</span><span id="L-308"><a href="#L-308"><span class="linenos">308</span></a><span class="sd"> it would resolve it as FOO. If it was quoted, it'd need to be treated as case-sensitive,</span> -</span><span id="L-309"><a href="#L-309"><span class="linenos">309</span></a><span class="sd"> and so any normalization would be prohibited in order to avoid "breaking" the identifier.</span> -</span><span id="L-310"><a href="#L-310"><span class="linenos">310</span></a> -</span><span id="L-311"><a href="#L-311"><span class="linenos">311</span></a><span class="sd"> There are also dialects like Spark, which are case-insensitive even when quotes are</span> -</span><span id="L-312"><a href="#L-312"><span class="linenos">312</span></a><span class="sd"> present, and dialects like MySQL, whose resolution rules match those employed by the</span> -</span><span id="L-313"><a href="#L-313"><span class="linenos">313</span></a><span class="sd"> underlying operating system, for example they may always be case-sensitive in Linux.</span> -</span><span id="L-314"><a href="#L-314"><span class="linenos">314</span></a> -</span><span id="L-315"><a href="#L-315"><span class="linenos">315</span></a><span class="sd"> Finally, the normalization behavior of some engines can even be controlled through flags,</span> -</span><span id="L-316"><a href="#L-316"><span class="linenos">316</span></a><span class="sd"> like in Redshift's case, where users can explicitly set enable_case_sensitive_identifier.</span> +</span><span id="L-289"><a href="#L-289"><span class="linenos">289</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="L-290"><a href="#L-290"><span class="linenos">290</span></a> <span class="n">normalization_strategy</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"normalization_strategy"</span><span class="p">)</span> +</span><span id="L-291"><a href="#L-291"><span class="linenos">291</span></a> +</span><span id="L-292"><a href="#L-292"><span class="linenos">292</span></a> <span class="k">if</span> <span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="L-293"><a href="#L-293"><span class="linenos">293</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">NORMALIZATION_STRATEGY</span> +</span><span id="L-294"><a href="#L-294"><span class="linenos">294</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="L-295"><a href="#L-295"><span class="linenos">295</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="o">=</span> <span class="n">NormalizationStrategy</span><span class="p">(</span><span class="n">normalization_strategy</span><span class="o">.</span><span class="n">upper</span><span class="p">())</span> +</span><span id="L-296"><a href="#L-296"><span class="linenos">296</span></a> +</span><span id="L-297"><a href="#L-297"><span class="linenos">297</span></a> <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> +</span><span id="L-298"><a href="#L-298"><span class="linenos">298</span></a> <span class="c1"># Does not currently take dialect state into account</span> +</span><span id="L-299"><a href="#L-299"><span class="linenos">299</span></a> <span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">==</span> <span class="n">other</span> +</span><span id="L-300"><a href="#L-300"><span class="linenos">300</span></a> +</span><span id="L-301"><a href="#L-301"><span class="linenos">301</span></a> <span class="k">def</span> <span class="fm">__hash__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">int</span><span class="p">:</span> +</span><span id="L-302"><a href="#L-302"><span class="linenos">302</span></a> <span class="c1"># Does not currently take dialect state into account</span> +</span><span id="L-303"><a href="#L-303"><span class="linenos">303</span></a> <span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span> +</span><span id="L-304"><a href="#L-304"><span class="linenos">304</span></a> +</span><span id="L-305"><a href="#L-305"><span class="linenos">305</span></a> <span class="k">def</span> <span class="nf">normalize_identifier</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">E</span><span class="p">)</span> <span class="o">-></span> <span class="n">E</span><span class="p">:</span> +</span><span id="L-306"><a href="#L-306"><span class="linenos">306</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-307"><a href="#L-307"><span class="linenos">307</span></a><span class="sd"> Transforms an identifier in a way that resembles how it'd be resolved by this dialect.</span> +</span><span id="L-308"><a href="#L-308"><span class="linenos">308</span></a> +</span><span id="L-309"><a href="#L-309"><span class="linenos">309</span></a><span class="sd"> For example, an identifier like FoO would be resolved as foo in Postgres, because it</span> +</span><span id="L-310"><a href="#L-310"><span class="linenos">310</span></a><span class="sd"> lowercases all unquoted identifiers. On the other hand, Snowflake uppercases them, so</span> +</span><span id="L-311"><a href="#L-311"><span class="linenos">311</span></a><span class="sd"> it would resolve it as FOO. If it was quoted, it'd need to be treated as case-sensitive,</span> +</span><span id="L-312"><a href="#L-312"><span class="linenos">312</span></a><span class="sd"> and so any normalization would be prohibited in order to avoid "breaking" the identifier.</span> +</span><span id="L-313"><a href="#L-313"><span class="linenos">313</span></a> +</span><span id="L-314"><a href="#L-314"><span class="linenos">314</span></a><span class="sd"> There are also dialects like Spark, which are case-insensitive even when quotes are</span> +</span><span id="L-315"><a href="#L-315"><span class="linenos">315</span></a><span class="sd"> present, and dialects like MySQL, whose resolution rules match those employed by the</span> +</span><span id="L-316"><a href="#L-316"><span class="linenos">316</span></a><span class="sd"> underlying operating system, for example they may always be case-sensitive in Linux.</span> </span><span id="L-317"><a href="#L-317"><span class="linenos">317</span></a> -</span><span id="L-318"><a href="#L-318"><span class="linenos">318</span></a><span class="sd"> SQLGlot aims to understand and handle all of these different behaviors gracefully, so</span> -</span><span id="L-319"><a href="#L-319"><span class="linenos">319</span></a><span class="sd"> that it can analyze queries in the optimizer and successfully capture their semantics.</span> -</span><span id="L-320"><a href="#L-320"><span class="linenos">320</span></a><span class="sd"> """</span> -</span><span id="L-321"><a href="#L-321"><span class="linenos">321</span></a> <span class="k">if</span> <span class="p">(</span> -</span><span id="L-322"><a href="#L-322"><span class="linenos">322</span></a> <span class="nb">isinstance</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">Identifier</span><span class="p">)</span> -</span><span id="L-323"><a href="#L-323"><span class="linenos">323</span></a> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_SENSITIVE</span> -</span><span id="L-324"><a href="#L-324"><span class="linenos">324</span></a> <span class="ow">and</span> <span class="p">(</span> -</span><span id="L-325"><a href="#L-325"><span class="linenos">325</span></a> <span class="ow">not</span> <span class="n">expression</span><span class="o">.</span><span class="n">quoted</span> -</span><span id="L-326"><a href="#L-326"><span class="linenos">326</span></a> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_INSENSITIVE</span> -</span><span id="L-327"><a href="#L-327"><span class="linenos">327</span></a> <span class="p">)</span> -</span><span id="L-328"><a href="#L-328"><span class="linenos">328</span></a> <span class="p">):</span> -</span><span id="L-329"><a href="#L-329"><span class="linenos">329</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> -</span><span id="L-330"><a href="#L-330"><span class="linenos">330</span></a> <span class="s2">"this"</span><span class="p">,</span> -</span><span id="L-331"><a href="#L-331"><span class="linenos">331</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> -</span><span id="L-332"><a href="#L-332"><span class="linenos">332</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">UPPERCASE</span> -</span><span id="L-333"><a href="#L-333"><span class="linenos">333</span></a> <span class="k">else</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> -</span><span id="L-334"><a href="#L-334"><span class="linenos">334</span></a> <span class="p">)</span> -</span><span id="L-335"><a href="#L-335"><span class="linenos">335</span></a> -</span><span id="L-336"><a href="#L-336"><span class="linenos">336</span></a> <span class="k">return</span> <span class="n">expression</span> -</span><span id="L-337"><a href="#L-337"><span class="linenos">337</span></a> -</span><span id="L-338"><a href="#L-338"><span class="linenos">338</span></a> <span class="k">def</span> <span class="nf">case_sensitive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> -</span><span id="L-339"><a href="#L-339"><span class="linenos">339</span></a><span class="w"> </span><span class="sd">"""Checks if text contains any case sensitive characters, based on the dialect's rules."""</span> -</span><span id="L-340"><a href="#L-340"><span class="linenos">340</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_INSENSITIVE</span><span class="p">:</span> -</span><span id="L-341"><a href="#L-341"><span class="linenos">341</span></a> <span class="k">return</span> <span class="kc">False</span> -</span><span id="L-342"><a href="#L-342"><span class="linenos">342</span></a> -</span><span id="L-343"><a href="#L-343"><span class="linenos">343</span></a> <span class="n">unsafe</span> <span class="o">=</span> <span class="p">(</span> -</span><span id="L-344"><a href="#L-344"><span class="linenos">344</span></a> <span class="nb">str</span><span class="o">.</span><span class="n">islower</span> -</span><span id="L-345"><a href="#L-345"><span class="linenos">345</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">UPPERCASE</span> -</span><span id="L-346"><a href="#L-346"><span class="linenos">346</span></a> <span class="k">else</span> <span class="nb">str</span><span class="o">.</span><span class="n">isupper</span> -</span><span id="L-347"><a href="#L-347"><span class="linenos">347</span></a> <span class="p">)</span> -</span><span id="L-348"><a href="#L-348"><span class="linenos">348</span></a> <span class="k">return</span> <span class="nb">any</span><span class="p">(</span><span class="n">unsafe</span><span class="p">(</span><span class="n">char</span><span class="p">)</span> <span class="k">for</span> <span class="n">char</span> <span class="ow">in</span> <span class="n">text</span><span class="p">)</span> -</span><span id="L-349"><a href="#L-349"><span class="linenos">349</span></a> -</span><span id="L-350"><a href="#L-350"><span class="linenos">350</span></a> <span class="k">def</span> <span class="nf">can_identify</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">identify</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">bool</span> <span class="o">=</span> <span class="s2">"safe"</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> -</span><span id="L-351"><a href="#L-351"><span class="linenos">351</span></a><span class="w"> </span><span class="sd">"""Checks if text can be identified given an identify option.</span> +</span><span id="L-318"><a href="#L-318"><span class="linenos">318</span></a><span class="sd"> Finally, the normalization behavior of some engines can even be controlled through flags,</span> +</span><span id="L-319"><a href="#L-319"><span class="linenos">319</span></a><span class="sd"> like in Redshift's case, where users can explicitly set enable_case_sensitive_identifier.</span> +</span><span id="L-320"><a href="#L-320"><span class="linenos">320</span></a> +</span><span id="L-321"><a href="#L-321"><span class="linenos">321</span></a><span class="sd"> SQLGlot aims to understand and handle all of these different behaviors gracefully, so</span> +</span><span id="L-322"><a href="#L-322"><span class="linenos">322</span></a><span class="sd"> that it can analyze queries in the optimizer and successfully capture their semantics.</span> +</span><span id="L-323"><a href="#L-323"><span class="linenos">323</span></a><span class="sd"> """</span> +</span><span id="L-324"><a href="#L-324"><span class="linenos">324</span></a> <span class="k">if</span> <span class="p">(</span> +</span><span id="L-325"><a href="#L-325"><span class="linenos">325</span></a> <span class="nb">isinstance</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">Identifier</span><span class="p">)</span> +</span><span id="L-326"><a href="#L-326"><span class="linenos">326</span></a> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_SENSITIVE</span> +</span><span id="L-327"><a href="#L-327"><span class="linenos">327</span></a> <span class="ow">and</span> <span class="p">(</span> +</span><span id="L-328"><a href="#L-328"><span class="linenos">328</span></a> <span class="ow">not</span> <span class="n">expression</span><span class="o">.</span><span class="n">quoted</span> +</span><span id="L-329"><a href="#L-329"><span class="linenos">329</span></a> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_INSENSITIVE</span> +</span><span id="L-330"><a href="#L-330"><span class="linenos">330</span></a> <span class="p">)</span> +</span><span id="L-331"><a href="#L-331"><span class="linenos">331</span></a> <span class="p">):</span> +</span><span id="L-332"><a href="#L-332"><span class="linenos">332</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="L-333"><a href="#L-333"><span class="linenos">333</span></a> <span class="s2">"this"</span><span class="p">,</span> +</span><span id="L-334"><a href="#L-334"><span class="linenos">334</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> +</span><span id="L-335"><a href="#L-335"><span class="linenos">335</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">UPPERCASE</span> +</span><span id="L-336"><a href="#L-336"><span class="linenos">336</span></a> <span class="k">else</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> +</span><span id="L-337"><a href="#L-337"><span class="linenos">337</span></a> <span class="p">)</span> +</span><span id="L-338"><a href="#L-338"><span class="linenos">338</span></a> +</span><span id="L-339"><a href="#L-339"><span class="linenos">339</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="L-340"><a href="#L-340"><span class="linenos">340</span></a> +</span><span id="L-341"><a href="#L-341"><span class="linenos">341</span></a> <span class="k">def</span> <span class="nf">case_sensitive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> +</span><span id="L-342"><a href="#L-342"><span class="linenos">342</span></a><span class="w"> </span><span class="sd">"""Checks if text contains any case sensitive characters, based on the dialect's rules."""</span> +</span><span id="L-343"><a href="#L-343"><span class="linenos">343</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_INSENSITIVE</span><span class="p">:</span> +</span><span id="L-344"><a href="#L-344"><span class="linenos">344</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="L-345"><a href="#L-345"><span class="linenos">345</span></a> +</span><span id="L-346"><a href="#L-346"><span class="linenos">346</span></a> <span class="n">unsafe</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="L-347"><a href="#L-347"><span class="linenos">347</span></a> <span class="nb">str</span><span class="o">.</span><span class="n">islower</span> +</span><span id="L-348"><a href="#L-348"><span class="linenos">348</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">UPPERCASE</span> +</span><span id="L-349"><a href="#L-349"><span class="linenos">349</span></a> <span class="k">else</span> <span class="nb">str</span><span class="o">.</span><span class="n">isupper</span> +</span><span id="L-350"><a href="#L-350"><span class="linenos">350</span></a> <span class="p">)</span> +</span><span id="L-351"><a href="#L-351"><span class="linenos">351</span></a> <span class="k">return</span> <span class="nb">any</span><span class="p">(</span><span class="n">unsafe</span><span class="p">(</span><span class="n">char</span><span class="p">)</span> <span class="k">for</span> <span class="n">char</span> <span class="ow">in</span> <span class="n">text</span><span class="p">)</span> </span><span id="L-352"><a href="#L-352"><span class="linenos">352</span></a> -</span><span id="L-353"><a href="#L-353"><span class="linenos">353</span></a><span class="sd"> Args:</span> -</span><span id="L-354"><a href="#L-354"><span class="linenos">354</span></a><span class="sd"> text: The text to check.</span> -</span><span id="L-355"><a href="#L-355"><span class="linenos">355</span></a><span class="sd"> identify:</span> -</span><span id="L-356"><a href="#L-356"><span class="linenos">356</span></a><span class="sd"> "always" or `True`: Always returns true.</span> -</span><span id="L-357"><a href="#L-357"><span class="linenos">357</span></a><span class="sd"> "safe": True if the identifier is case-insensitive.</span> -</span><span id="L-358"><a href="#L-358"><span class="linenos">358</span></a> -</span><span id="L-359"><a href="#L-359"><span class="linenos">359</span></a><span class="sd"> Returns:</span> -</span><span id="L-360"><a href="#L-360"><span class="linenos">360</span></a><span class="sd"> Whether or not the given text can be identified.</span> -</span><span id="L-361"><a href="#L-361"><span class="linenos">361</span></a><span class="sd"> """</span> -</span><span id="L-362"><a href="#L-362"><span class="linenos">362</span></a> <span class="k">if</span> <span class="n">identify</span> <span class="ow">is</span> <span class="kc">True</span> <span class="ow">or</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"always"</span><span class="p">:</span> -</span><span id="L-363"><a href="#L-363"><span class="linenos">363</span></a> <span class="k">return</span> <span class="kc">True</span> -</span><span id="L-364"><a href="#L-364"><span class="linenos">364</span></a> -</span><span id="L-365"><a href="#L-365"><span class="linenos">365</span></a> <span class="k">if</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"safe"</span><span class="p">:</span> -</span><span id="L-366"><a href="#L-366"><span class="linenos">366</span></a> <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">case_sensitive</span><span class="p">(</span><span class="n">text</span><span class="p">)</span> +</span><span id="L-353"><a href="#L-353"><span class="linenos">353</span></a> <span class="k">def</span> <span class="nf">can_identify</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">identify</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">bool</span> <span class="o">=</span> <span class="s2">"safe"</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> +</span><span id="L-354"><a href="#L-354"><span class="linenos">354</span></a><span class="w"> </span><span class="sd">"""Checks if text can be identified given an identify option.</span> +</span><span id="L-355"><a href="#L-355"><span class="linenos">355</span></a> +</span><span id="L-356"><a href="#L-356"><span class="linenos">356</span></a><span class="sd"> Args:</span> +</span><span id="L-357"><a href="#L-357"><span class="linenos">357</span></a><span class="sd"> text: The text to check.</span> +</span><span id="L-358"><a href="#L-358"><span class="linenos">358</span></a><span class="sd"> identify:</span> +</span><span id="L-359"><a href="#L-359"><span class="linenos">359</span></a><span class="sd"> "always" or `True`: Always returns true.</span> +</span><span id="L-360"><a href="#L-360"><span class="linenos">360</span></a><span class="sd"> "safe": True if the identifier is case-insensitive.</span> +</span><span id="L-361"><a href="#L-361"><span class="linenos">361</span></a> +</span><span id="L-362"><a href="#L-362"><span class="linenos">362</span></a><span class="sd"> Returns:</span> +</span><span id="L-363"><a href="#L-363"><span class="linenos">363</span></a><span class="sd"> Whether or not the given text can be identified.</span> +</span><span id="L-364"><a href="#L-364"><span class="linenos">364</span></a><span class="sd"> """</span> +</span><span id="L-365"><a href="#L-365"><span class="linenos">365</span></a> <span class="k">if</span> <span class="n">identify</span> <span class="ow">is</span> <span class="kc">True</span> <span class="ow">or</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"always"</span><span class="p">:</span> +</span><span id="L-366"><a href="#L-366"><span class="linenos">366</span></a> <span class="k">return</span> <span class="kc">True</span> </span><span id="L-367"><a href="#L-367"><span class="linenos">367</span></a> -</span><span id="L-368"><a href="#L-368"><span class="linenos">368</span></a> <span class="k">return</span> <span class="kc">False</span> -</span><span id="L-369"><a href="#L-369"><span class="linenos">369</span></a> -</span><span id="L-370"><a href="#L-370"><span class="linenos">370</span></a> <span class="k">def</span> <span class="nf">quote_identifier</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">E</span><span class="p">,</span> <span class="n">identify</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span> <span class="o">-></span> <span class="n">E</span><span class="p">:</span> -</span><span id="L-371"><a href="#L-371"><span class="linenos">371</span></a> <span class="k">if</span> <span class="nb">isinstance</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">Identifier</span><span class="p">):</span> -</span><span id="L-372"><a href="#L-372"><span class="linenos">372</span></a> <span class="n">name</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> -</span><span id="L-373"><a href="#L-373"><span class="linenos">373</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> -</span><span id="L-374"><a href="#L-374"><span class="linenos">374</span></a> <span class="s2">"quoted"</span><span class="p">,</span> -</span><span id="L-375"><a href="#L-375"><span class="linenos">375</span></a> <span class="n">identify</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">case_sensitive</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">exp</span><span class="o">.</span><span class="n">SAFE_IDENTIFIER_RE</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">name</span><span class="p">),</span> -</span><span id="L-376"><a href="#L-376"><span class="linenos">376</span></a> <span class="p">)</span> -</span><span id="L-377"><a href="#L-377"><span class="linenos">377</span></a> -</span><span id="L-378"><a href="#L-378"><span class="linenos">378</span></a> <span class="k">return</span> <span class="n">expression</span> -</span><span id="L-379"><a href="#L-379"><span class="linenos">379</span></a> -</span><span id="L-380"><a href="#L-380"><span class="linenos">380</span></a> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="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">Expression</span><span class="p">]]:</span> -</span><span id="L-381"><a href="#L-381"><span class="linenos">381</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">),</span> <span class="n">sql</span><span class="p">)</span> +</span><span id="L-368"><a href="#L-368"><span class="linenos">368</span></a> <span class="k">if</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"safe"</span><span class="p">:</span> +</span><span id="L-369"><a href="#L-369"><span class="linenos">369</span></a> <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">case_sensitive</span><span class="p">(</span><span class="n">text</span><span class="p">)</span> +</span><span id="L-370"><a href="#L-370"><span class="linenos">370</span></a> +</span><span id="L-371"><a href="#L-371"><span class="linenos">371</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="L-372"><a href="#L-372"><span class="linenos">372</span></a> +</span><span id="L-373"><a href="#L-373"><span class="linenos">373</span></a> <span class="k">def</span> <span class="nf">quote_identifier</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">E</span><span class="p">,</span> <span class="n">identify</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span> <span class="o">-></span> <span class="n">E</span><span class="p">:</span> +</span><span id="L-374"><a href="#L-374"><span class="linenos">374</span></a> <span class="k">if</span> <span class="nb">isinstance</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">Identifier</span><span class="p">):</span> +</span><span id="L-375"><a href="#L-375"><span class="linenos">375</span></a> <span class="n">name</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="L-376"><a href="#L-376"><span class="linenos">376</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="L-377"><a href="#L-377"><span class="linenos">377</span></a> <span class="s2">"quoted"</span><span class="p">,</span> +</span><span id="L-378"><a href="#L-378"><span class="linenos">378</span></a> <span class="n">identify</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">case_sensitive</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">exp</span><span class="o">.</span><span class="n">SAFE_IDENTIFIER_RE</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">name</span><span class="p">),</span> +</span><span id="L-379"><a href="#L-379"><span class="linenos">379</span></a> <span class="p">)</span> +</span><span id="L-380"><a href="#L-380"><span class="linenos">380</span></a> +</span><span id="L-381"><a href="#L-381"><span class="linenos">381</span></a> <span class="k">return</span> <span class="n">expression</span> </span><span id="L-382"><a href="#L-382"><span class="linenos">382</span></a> -</span><span id="L-383"><a href="#L-383"><span class="linenos">383</span></a> <span class="k">def</span> <span class="nf">parse_into</span><span class="p">(</span> -</span><span id="L-384"><a href="#L-384"><span class="linenos">384</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">expression_type</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">IntoType</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span> -</span><span id="L-385"><a href="#L-385"><span class="linenos">385</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="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">Expression</span><span class="p">]]:</span> -</span><span id="L-386"><a href="#L-386"><span class="linenos">386</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">parse_into</span><span class="p">(</span><span class="n">expression_type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">),</span> <span class="n">sql</span><span class="p">)</span> -</span><span id="L-387"><a href="#L-387"><span class="linenos">387</span></a> -</span><span id="L-388"><a href="#L-388"><span class="linenos">388</span></a> <span class="k">def</span> <span class="nf">generate</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">Expression</span><span class="p">,</span> <span class="n">copy</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-389"><a href="#L-389"><span class="linenos">389</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="n">copy</span><span class="p">)</span> +</span><span id="L-383"><a href="#L-383"><span class="linenos">383</span></a> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="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">Expression</span><span class="p">]]:</span> +</span><span id="L-384"><a href="#L-384"><span class="linenos">384</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">),</span> <span class="n">sql</span><span class="p">)</span> +</span><span id="L-385"><a href="#L-385"><span class="linenos">385</span></a> +</span><span id="L-386"><a href="#L-386"><span class="linenos">386</span></a> <span class="k">def</span> <span class="nf">parse_into</span><span class="p">(</span> +</span><span id="L-387"><a href="#L-387"><span class="linenos">387</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">expression_type</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">IntoType</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span> +</span><span id="L-388"><a href="#L-388"><span class="linenos">388</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="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">Expression</span><span class="p">]]:</span> +</span><span id="L-389"><a href="#L-389"><span class="linenos">389</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">parse_into</span><span class="p">(</span><span class="n">expression_type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">),</span> <span class="n">sql</span><span class="p">)</span> </span><span id="L-390"><a href="#L-390"><span class="linenos">390</span></a> -</span><span id="L-391"><a href="#L-391"><span class="linenos">391</span></a> <span class="k">def</span> <span class="nf">transpile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> -</span><span id="L-392"><a href="#L-392"><span class="linenos">392</span></a> <span class="k">return</span> <span class="p">[</span> -</span><span id="L-393"><a href="#L-393"><span class="linenos">393</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="k">if</span> <span class="n">expression</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="L-394"><a href="#L-394"><span class="linenos">394</span></a> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> -</span><span id="L-395"><a href="#L-395"><span class="linenos">395</span></a> <span class="p">]</span> -</span><span id="L-396"><a href="#L-396"><span class="linenos">396</span></a> -</span><span id="L-397"><a href="#L-397"><span class="linenos">397</span></a> <span class="k">def</span> <span class="nf">tokenize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Token</span><span class="p">]:</span> -</span><span id="L-398"><a href="#L-398"><span class="linenos">398</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenizer</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> +</span><span id="L-391"><a href="#L-391"><span class="linenos">391</span></a> <span class="k">def</span> <span class="nf">generate</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">Expression</span><span class="p">,</span> <span class="n">copy</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-392"><a href="#L-392"><span class="linenos">392</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="n">copy</span><span class="p">)</span> +</span><span id="L-393"><a href="#L-393"><span class="linenos">393</span></a> +</span><span id="L-394"><a href="#L-394"><span class="linenos">394</span></a> <span class="k">def</span> <span class="nf">transpile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="L-395"><a href="#L-395"><span class="linenos">395</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="L-396"><a href="#L-396"><span class="linenos">396</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="k">if</span> <span class="n">expression</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="L-397"><a href="#L-397"><span class="linenos">397</span></a> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> +</span><span id="L-398"><a href="#L-398"><span class="linenos">398</span></a> <span class="p">]</span> </span><span id="L-399"><a href="#L-399"><span class="linenos">399</span></a> -</span><span id="L-400"><a href="#L-400"><span class="linenos">400</span></a> <span class="nd">@property</span> -</span><span id="L-401"><a href="#L-401"><span class="linenos">401</span></a> <span class="k">def</span> <span class="nf">tokenizer</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Tokenizer</span><span class="p">:</span> -</span><span id="L-402"><a href="#L-402"><span class="linenos">402</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">"_tokenizer"</span><span class="p">):</span> -</span><span id="L-403"><a href="#L-403"><span class="linenos">403</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_tokenizer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenizer_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span> -</span><span id="L-404"><a href="#L-404"><span class="linenos">404</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_tokenizer</span> -</span><span id="L-405"><a href="#L-405"><span class="linenos">405</span></a> -</span><span id="L-406"><a href="#L-406"><span class="linenos">406</span></a> <span class="k">def</span> <span class="nf">parser</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">Parser</span><span class="p">:</span> -</span><span id="L-407"><a href="#L-407"><span class="linenos">407</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> +</span><span id="L-400"><a href="#L-400"><span class="linenos">400</span></a> <span class="k">def</span> <span class="nf">tokenize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Token</span><span class="p">]:</span> +</span><span id="L-401"><a href="#L-401"><span class="linenos">401</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenizer</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> +</span><span id="L-402"><a href="#L-402"><span class="linenos">402</span></a> +</span><span id="L-403"><a href="#L-403"><span class="linenos">403</span></a> <span class="nd">@property</span> +</span><span id="L-404"><a href="#L-404"><span class="linenos">404</span></a> <span class="k">def</span> <span class="nf">tokenizer</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Tokenizer</span><span class="p">:</span> +</span><span id="L-405"><a href="#L-405"><span class="linenos">405</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">"_tokenizer"</span><span class="p">):</span> +</span><span id="L-406"><a href="#L-406"><span class="linenos">406</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_tokenizer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenizer_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span> +</span><span id="L-407"><a href="#L-407"><span class="linenos">407</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_tokenizer</span> </span><span id="L-408"><a href="#L-408"><span class="linenos">408</span></a> -</span><span id="L-409"><a href="#L-409"><span class="linenos">409</span></a> <span class="k">def</span> <span class="nf">generator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">Generator</span><span class="p">:</span> -</span><span id="L-410"><a href="#L-410"><span class="linenos">410</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> +</span><span id="L-409"><a href="#L-409"><span class="linenos">409</span></a> <span class="k">def</span> <span class="nf">parser</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">Parser</span><span class="p">:</span> +</span><span id="L-410"><a href="#L-410"><span class="linenos">410</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> </span><span id="L-411"><a href="#L-411"><span class="linenos">411</span></a> -</span><span id="L-412"><a href="#L-412"><span class="linenos">412</span></a> -</span><span id="L-413"><a href="#L-413"><span class="linenos">413</span></a><span class="n">DialectType</span> <span class="o">=</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Dialect</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">Dialect</span><span class="p">],</span> <span class="kc">None</span><span class="p">]</span> +</span><span id="L-412"><a href="#L-412"><span class="linenos">412</span></a> <span class="k">def</span> <span class="nf">generator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">Generator</span><span class="p">:</span> +</span><span id="L-413"><a href="#L-413"><span class="linenos">413</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> </span><span id="L-414"><a href="#L-414"><span class="linenos">414</span></a> </span><span id="L-415"><a href="#L-415"><span class="linenos">415</span></a> -</span><span id="L-416"><a href="#L-416"><span class="linenos">416</span></a><span class="k">def</span> <span class="nf">rename_func</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</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="nb">str</span><span class="p">]:</span> -</span><span id="L-417"><a href="#L-417"><span class="linenos">417</span></a> <span class="k">return</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">expression</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="n">name</span><span class="p">,</span> <span class="o">*</span><span class="n">flatten</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span> +</span><span id="L-416"><a href="#L-416"><span class="linenos">416</span></a><span class="n">DialectType</span> <span class="o">=</span> <span class="n">t</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Dialect</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">Dialect</span><span class="p">],</span> <span class="kc">None</span><span class="p">]</span> +</span><span id="L-417"><a href="#L-417"><span class="linenos">417</span></a> </span><span id="L-418"><a href="#L-418"><span class="linenos">418</span></a> -</span><span id="L-419"><a href="#L-419"><span class="linenos">419</span></a> -</span><span id="L-420"><a href="#L-420"><span class="linenos">420</span></a><span class="k">def</span> <span class="nf">approx_count_distinct_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-421"><a href="#L-421"><span class="linenos">421</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">"accuracy"</span><span class="p">):</span> -</span><span id="L-422"><a href="#L-422"><span class="linenos">422</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"APPROX_COUNT_DISTINCT does not support accuracy"</span><span class="p">)</span> -</span><span id="L-423"><a href="#L-423"><span class="linenos">423</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">"APPROX_COUNT_DISTINCT"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> -</span><span id="L-424"><a href="#L-424"><span class="linenos">424</span></a> -</span><span id="L-425"><a href="#L-425"><span class="linenos">425</span></a> -</span><span id="L-426"><a href="#L-426"><span class="linenos">426</span></a><span class="k">def</span> <span class="nf">if_sql</span><span class="p">(</span> -</span><span id="L-427"><a href="#L-427"><span class="linenos">427</span></a> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"IF"</span><span class="p">,</span> <span class="n">false_value</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">Expression</span> <span class="o">|</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-428"><a href="#L-428"><span class="linenos">428</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">If</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> -</span><span id="L-429"><a href="#L-429"><span class="linenos">429</span></a> <span class="k">def</span> <span class="nf">_if_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">If</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-430"><a href="#L-430"><span class="linenos">430</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-431"><a href="#L-431"><span class="linenos">431</span></a> <span class="n">name</span><span class="p">,</span> -</span><span id="L-432"><a href="#L-432"><span class="linenos">432</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="L-433"><a href="#L-433"><span class="linenos">433</span></a> <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">"true"</span><span class="p">),</span> -</span><span id="L-434"><a href="#L-434"><span class="linenos">434</span></a> <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">"false"</span><span class="p">)</span> <span class="ow">or</span> <span class="n">false_value</span><span class="p">,</span> -</span><span id="L-435"><a href="#L-435"><span class="linenos">435</span></a> <span class="p">)</span> -</span><span id="L-436"><a href="#L-436"><span class="linenos">436</span></a> -</span><span id="L-437"><a href="#L-437"><span class="linenos">437</span></a> <span class="k">return</span> <span class="n">_if_sql</span> -</span><span id="L-438"><a href="#L-438"><span class="linenos">438</span></a> +</span><span id="L-419"><a href="#L-419"><span class="linenos">419</span></a><span class="k">def</span> <span class="nf">rename_func</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</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="nb">str</span><span class="p">]:</span> +</span><span id="L-420"><a href="#L-420"><span class="linenos">420</span></a> <span class="k">return</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">expression</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="n">name</span><span class="p">,</span> <span class="o">*</span><span class="n">flatten</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span> +</span><span id="L-421"><a href="#L-421"><span class="linenos">421</span></a> +</span><span id="L-422"><a href="#L-422"><span class="linenos">422</span></a> +</span><span id="L-423"><a href="#L-423"><span class="linenos">423</span></a><span class="k">def</span> <span class="nf">approx_count_distinct_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-424"><a href="#L-424"><span class="linenos">424</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">"accuracy"</span><span class="p">):</span> +</span><span id="L-425"><a href="#L-425"><span class="linenos">425</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"APPROX_COUNT_DISTINCT does not support accuracy"</span><span class="p">)</span> +</span><span id="L-426"><a href="#L-426"><span class="linenos">426</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">"APPROX_COUNT_DISTINCT"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> +</span><span id="L-427"><a href="#L-427"><span class="linenos">427</span></a> +</span><span id="L-428"><a href="#L-428"><span class="linenos">428</span></a> +</span><span id="L-429"><a href="#L-429"><span class="linenos">429</span></a><span class="k">def</span> <span class="nf">if_sql</span><span class="p">(</span> +</span><span id="L-430"><a href="#L-430"><span class="linenos">430</span></a> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"IF"</span><span class="p">,</span> <span class="n">false_value</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">Expression</span> <span class="o">|</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="L-431"><a href="#L-431"><span class="linenos">431</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">If</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> +</span><span id="L-432"><a href="#L-432"><span class="linenos">432</span></a> <span class="k">def</span> <span class="nf">_if_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">If</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-433"><a href="#L-433"><span class="linenos">433</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-434"><a href="#L-434"><span class="linenos">434</span></a> <span class="n">name</span><span class="p">,</span> +</span><span id="L-435"><a href="#L-435"><span class="linenos">435</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="L-436"><a href="#L-436"><span class="linenos">436</span></a> <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">"true"</span><span class="p">),</span> +</span><span id="L-437"><a href="#L-437"><span class="linenos">437</span></a> <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">"false"</span><span class="p">)</span> <span class="ow">or</span> <span class="n">false_value</span><span class="p">,</span> +</span><span id="L-438"><a href="#L-438"><span class="linenos">438</span></a> <span class="p">)</span> </span><span id="L-439"><a href="#L-439"><span class="linenos">439</span></a> -</span><span id="L-440"><a href="#L-440"><span class="linenos">440</span></a><span class="k">def</span> <span class="nf">arrow_json_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtract</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONBExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-441"><a href="#L-441"><span class="linenos">441</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"->"</span><span class="p">)</span> +</span><span id="L-440"><a href="#L-440"><span class="linenos">440</span></a> <span class="k">return</span> <span class="n">_if_sql</span> +</span><span id="L-441"><a href="#L-441"><span class="linenos">441</span></a> </span><span id="L-442"><a href="#L-442"><span class="linenos">442</span></a> -</span><span id="L-443"><a href="#L-443"><span class="linenos">443</span></a> -</span><span id="L-444"><a href="#L-444"><span class="linenos">444</span></a><span class="k">def</span> <span class="nf">arrow_json_extract_scalar_sql</span><span class="p">(</span> -</span><span id="L-445"><a href="#L-445"><span class="linenos">445</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONBExtractScalar</span> -</span><span id="L-446"><a href="#L-446"><span class="linenos">446</span></a><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="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"->>"</span><span class="p">)</span> -</span><span id="L-448"><a href="#L-448"><span class="linenos">448</span></a> -</span><span id="L-449"><a href="#L-449"><span class="linenos">449</span></a> -</span><span id="L-450"><a href="#L-450"><span class="linenos">450</span></a><span class="k">def</span> <span class="nf">inline_array_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Array</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-451"><a href="#L-451"><span class="linenos">451</span></a> <span class="k">return</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">expressions</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span><span class="w"> </span><span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span><span class="si">}</span><span class="s2">]"</span> +</span><span id="L-443"><a href="#L-443"><span class="linenos">443</span></a><span class="k">def</span> <span class="nf">arrow_json_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtract</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONBExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-444"><a href="#L-444"><span class="linenos">444</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"->"</span><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><span id="L-447"><a href="#L-447"><span class="linenos">447</span></a><span class="k">def</span> <span class="nf">arrow_json_extract_scalar_sql</span><span class="p">(</span> +</span><span id="L-448"><a href="#L-448"><span class="linenos">448</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONBExtractScalar</span> +</span><span id="L-449"><a href="#L-449"><span class="linenos">449</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-450"><a href="#L-450"><span class="linenos">450</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"->>"</span><span class="p">)</span> +</span><span id="L-451"><a href="#L-451"><span class="linenos">451</span></a> </span><span id="L-452"><a href="#L-452"><span class="linenos">452</span></a> -</span><span id="L-453"><a href="#L-453"><span class="linenos">453</span></a> -</span><span id="L-454"><a href="#L-454"><span class="linenos">454</span></a><span class="k">def</span> <span class="nf">no_ilike_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ILike</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-455"><a href="#L-455"><span class="linenos">455</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">like_sql</span><span class="p">(</span> -</span><span id="L-456"><a href="#L-456"><span class="linenos">456</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Like</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Lower</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">),</span> <span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> -</span><span id="L-457"><a href="#L-457"><span class="linenos">457</span></a> <span class="p">)</span> -</span><span id="L-458"><a href="#L-458"><span class="linenos">458</span></a> -</span><span id="L-459"><a href="#L-459"><span class="linenos">459</span></a> -</span><span id="L-460"><a href="#L-460"><span class="linenos">460</span></a><span class="k">def</span> <span class="nf">no_paren_current_date_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">CurrentDate</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-461"><a href="#L-461"><span class="linenos">461</span></a> <span class="n">zone</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> -</span><span id="L-462"><a href="#L-462"><span class="linenos">462</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"CURRENT_DATE AT TIME ZONE </span><span class="si">{</span><span class="n">zone</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">zone</span> <span class="k">else</span> <span class="s2">"CURRENT_DATE"</span> -</span><span id="L-463"><a href="#L-463"><span class="linenos">463</span></a> -</span><span id="L-464"><a href="#L-464"><span class="linenos">464</span></a> -</span><span id="L-465"><a href="#L-465"><span class="linenos">465</span></a><span class="k">def</span> <span class="nf">no_recursive_cte_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">With</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-466"><a href="#L-466"><span class="linenos">466</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">"recursive"</span><span class="p">):</span> -</span><span id="L-467"><a href="#L-467"><span class="linenos">467</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Recursive CTEs are unsupported"</span><span class="p">)</span> -</span><span id="L-468"><a href="#L-468"><span class="linenos">468</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"recursive"</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-469"><a href="#L-469"><span class="linenos">469</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">with_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="L-470"><a href="#L-470"><span class="linenos">470</span></a> -</span><span id="L-471"><a href="#L-471"><span class="linenos">471</span></a> -</span><span id="L-472"><a href="#L-472"><span class="linenos">472</span></a><span class="k">def</span> <span class="nf">no_safe_divide_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">SafeDivide</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-473"><a href="#L-473"><span class="linenos">473</span></a> <span class="n">n</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> -</span><span id="L-474"><a href="#L-474"><span class="linenos">474</span></a> <span class="n">d</span> <span class="o">=</span> <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">"expression"</span><span class="p">)</span> -</span><span id="L-475"><a href="#L-475"><span class="linenos">475</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"IF(</span><span class="si">{</span><span class="n">d</span><span class="si">}</span><span class="s2"> <> 0, </span><span class="si">{</span><span class="n">n</span><span class="si">}</span><span class="s2"> / </span><span class="si">{</span><span class="n">d</span><span class="si">}</span><span class="s2">, NULL)"</span> -</span><span id="L-476"><a href="#L-476"><span class="linenos">476</span></a> -</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">no_tablesample_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TableSample</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="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"TABLESAMPLE unsupported"</span><span class="p">)</span> -</span><span id="L-480"><a href="#L-480"><span class="linenos">480</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> -</span><span id="L-481"><a href="#L-481"><span class="linenos">481</span></a> -</span><span id="L-482"><a href="#L-482"><span class="linenos">482</span></a> -</span><span id="L-483"><a href="#L-483"><span class="linenos">483</span></a><span class="k">def</span> <span class="nf">no_pivot_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-484"><a href="#L-484"><span class="linenos">484</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"PIVOT unsupported"</span><span class="p">)</span> -</span><span id="L-485"><a href="#L-485"><span class="linenos">485</span></a> <span class="k">return</span> <span class="s2">""</span> -</span><span id="L-486"><a href="#L-486"><span class="linenos">486</span></a> -</span><span id="L-487"><a href="#L-487"><span class="linenos">487</span></a> -</span><span id="L-488"><a href="#L-488"><span class="linenos">488</span></a><span class="k">def</span> <span class="nf">no_trycast_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TryCast</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-489"><a href="#L-489"><span class="linenos">489</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cast_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-453"><a href="#L-453"><span class="linenos">453</span></a><span class="k">def</span> <span class="nf">inline_array_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Array</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-454"><a href="#L-454"><span class="linenos">454</span></a> <span class="k">return</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">expressions</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span><span class="w"> </span><span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span><span class="si">}</span><span class="s2">]"</span> +</span><span id="L-455"><a href="#L-455"><span class="linenos">455</span></a> +</span><span id="L-456"><a href="#L-456"><span class="linenos">456</span></a> +</span><span id="L-457"><a href="#L-457"><span class="linenos">457</span></a><span class="k">def</span> <span class="nf">no_ilike_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ILike</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-458"><a href="#L-458"><span class="linenos">458</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">like_sql</span><span class="p">(</span> +</span><span id="L-459"><a href="#L-459"><span class="linenos">459</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Like</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Lower</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">),</span> <span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-460"><a href="#L-460"><span class="linenos">460</span></a> <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><span id="L-463"><a href="#L-463"><span class="linenos">463</span></a><span class="k">def</span> <span class="nf">no_paren_current_date_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">CurrentDate</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-464"><a href="#L-464"><span class="linenos">464</span></a> <span class="n">zone</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> +</span><span id="L-465"><a href="#L-465"><span class="linenos">465</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"CURRENT_DATE AT TIME ZONE </span><span class="si">{</span><span class="n">zone</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">zone</span> <span class="k">else</span> <span class="s2">"CURRENT_DATE"</span> +</span><span id="L-466"><a href="#L-466"><span class="linenos">466</span></a> +</span><span id="L-467"><a href="#L-467"><span class="linenos">467</span></a> +</span><span id="L-468"><a href="#L-468"><span class="linenos">468</span></a><span class="k">def</span> <span class="nf">no_recursive_cte_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">With</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-469"><a href="#L-469"><span class="linenos">469</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">"recursive"</span><span class="p">):</span> +</span><span id="L-470"><a href="#L-470"><span class="linenos">470</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Recursive CTEs are unsupported"</span><span class="p">)</span> +</span><span id="L-471"><a href="#L-471"><span class="linenos">471</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"recursive"</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-472"><a href="#L-472"><span class="linenos">472</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">with_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-473"><a href="#L-473"><span class="linenos">473</span></a> +</span><span id="L-474"><a href="#L-474"><span class="linenos">474</span></a> +</span><span id="L-475"><a href="#L-475"><span class="linenos">475</span></a><span class="k">def</span> <span class="nf">no_safe_divide_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">SafeDivide</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-476"><a href="#L-476"><span class="linenos">476</span></a> <span class="n">n</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> +</span><span id="L-477"><a href="#L-477"><span class="linenos">477</span></a> <span class="n">d</span> <span class="o">=</span> <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">"expression"</span><span class="p">)</span> +</span><span id="L-478"><a href="#L-478"><span class="linenos">478</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"IF(</span><span class="si">{</span><span class="n">d</span><span class="si">}</span><span class="s2"> <> 0, </span><span class="si">{</span><span class="n">n</span><span class="si">}</span><span class="s2"> / </span><span class="si">{</span><span class="n">d</span><span class="si">}</span><span class="s2">, NULL)"</span> +</span><span id="L-479"><a href="#L-479"><span class="linenos">479</span></a> +</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="k">def</span> <span class="nf">no_tablesample_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TableSample</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-482"><a href="#L-482"><span class="linenos">482</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"TABLESAMPLE unsupported"</span><span class="p">)</span> +</span><span id="L-483"><a href="#L-483"><span class="linenos">483</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> +</span><span id="L-484"><a href="#L-484"><span class="linenos">484</span></a> +</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">def</span> <span class="nf">no_pivot_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-487"><a href="#L-487"><span class="linenos">487</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"PIVOT unsupported"</span><span class="p">)</span> +</span><span id="L-488"><a href="#L-488"><span class="linenos">488</span></a> <span class="k">return</span> <span class="s2">""</span> +</span><span id="L-489"><a href="#L-489"><span class="linenos">489</span></a> </span><span id="L-490"><a href="#L-490"><span class="linenos">490</span></a> -</span><span id="L-491"><a href="#L-491"><span class="linenos">491</span></a> -</span><span id="L-492"><a href="#L-492"><span class="linenos">492</span></a><span class="k">def</span> <span class="nf">no_properties_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Properties</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-493"><a href="#L-493"><span class="linenos">493</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Properties unsupported"</span><span class="p">)</span> -</span><span id="L-494"><a href="#L-494"><span class="linenos">494</span></a> <span class="k">return</span> <span class="s2">""</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><span id="L-497"><a href="#L-497"><span class="linenos">497</span></a><span class="k">def</span> <span class="nf">no_comment_column_constraint_sql</span><span class="p">(</span> -</span><span id="L-498"><a href="#L-498"><span class="linenos">498</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">CommentColumnConstraint</span> -</span><span id="L-499"><a href="#L-499"><span class="linenos">499</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</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 class="s2">"CommentColumnConstraint unsupported"</span><span class="p">)</span> -</span><span id="L-501"><a href="#L-501"><span class="linenos">501</span></a> <span class="k">return</span> <span class="s2">""</span> -</span><span id="L-502"><a href="#L-502"><span class="linenos">502</span></a> -</span><span id="L-503"><a href="#L-503"><span class="linenos">503</span></a> -</span><span id="L-504"><a href="#L-504"><span class="linenos">504</span></a><span class="k">def</span> <span class="nf">no_map_from_entries_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">MapFromEntries</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-505"><a href="#L-505"><span class="linenos">505</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"MAP_FROM_ENTRIES unsupported"</span><span class="p">)</span> -</span><span id="L-506"><a href="#L-506"><span class="linenos">506</span></a> <span class="k">return</span> <span class="s2">""</span> -</span><span id="L-507"><a href="#L-507"><span class="linenos">507</span></a> -</span><span id="L-508"><a href="#L-508"><span class="linenos">508</span></a> -</span><span id="L-509"><a href="#L-509"><span class="linenos">509</span></a><span class="k">def</span> <span class="nf">str_position_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrPosition</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-510"><a href="#L-510"><span class="linenos">510</span></a> <span class="n">this</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> -</span><span id="L-511"><a href="#L-511"><span class="linenos">511</span></a> <span class="n">substr</span> <span class="o">=</span> <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">"substr"</span><span class="p">)</span> -</span><span id="L-512"><a href="#L-512"><span class="linenos">512</span></a> <span class="n">position</span> <span class="o">=</span> <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">"position"</span><span class="p">)</span> -</span><span id="L-513"><a href="#L-513"><span class="linenos">513</span></a> <span class="k">if</span> <span class="n">position</span><span class="p">:</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">"STRPOS(SUBSTR(</span><span class="si">{</span><span class="n">this</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">position</span><span class="si">}</span><span class="s2">), </span><span class="si">{</span><span class="n">substr</span><span class="si">}</span><span class="s2">) + </span><span class="si">{</span><span class="n">position</span><span class="si">}</span><span class="s2"> - 1"</span> -</span><span id="L-515"><a href="#L-515"><span class="linenos">515</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"STRPOS(</span><span class="si">{</span><span class="n">this</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">substr</span><span class="si">}</span><span class="s2">)"</span> -</span><span id="L-516"><a href="#L-516"><span class="linenos">516</span></a> -</span><span id="L-517"><a href="#L-517"><span class="linenos">517</span></a> -</span><span id="L-518"><a href="#L-518"><span class="linenos">518</span></a><span class="k">def</span> <span class="nf">struct_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">StructExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-519"><a href="#L-519"><span class="linenos">519</span></a> <span class="k">return</span> <span class="p">(</span> -</span><span id="L-520"><a href="#L-520"><span class="linenos">520</span></a> <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">expression</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">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">name</span><span class="p">))</span><span class="si">}</span><span class="s2">"</span> -</span><span id="L-521"><a href="#L-521"><span class="linenos">521</span></a> <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><span id="L-524"><a href="#L-524"><span class="linenos">524</span></a><span class="k">def</span> <span class="nf">var_map_sql</span><span class="p">(</span> -</span><span id="L-525"><a href="#L-525"><span class="linenos">525</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Map</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">VarMap</span><span class="p">,</span> <span class="n">map_func_name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"MAP"</span> -</span><span id="L-526"><a href="#L-526"><span class="linenos">526</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-527"><a href="#L-527"><span class="linenos">527</span></a> <span class="n">keys</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">"keys"</span><span class="p">]</span> -</span><span id="L-528"><a href="#L-528"><span class="linenos">528</span></a> <span class="n">values</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">"values"</span><span class="p">]</span> -</span><span id="L-529"><a href="#L-529"><span class="linenos">529</span></a> -</span><span id="L-530"><a href="#L-530"><span class="linenos">530</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">keys</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Array</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Array</span><span class="p">):</span> -</span><span id="L-531"><a href="#L-531"><span class="linenos">531</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Cannot convert array columns into map."</span><span class="p">)</span> -</span><span id="L-532"><a href="#L-532"><span class="linenos">532</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="n">map_func_name</span><span class="p">,</span> <span class="n">keys</span><span class="p">,</span> <span class="n">values</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="n">args</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="L-535"><a href="#L-535"><span class="linenos">535</span></a> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">keys</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> <span class="n">values</span><span class="o">.</span><span class="n">expressions</span><span class="p">):</span> -</span><span id="L-536"><a href="#L-536"><span class="linenos">536</span></a> <span class="n">args</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">key</span><span class="p">))</span> -</span><span id="L-537"><a href="#L-537"><span class="linenos">537</span></a> <span class="n">args</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">value</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">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="n">map_func_name</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span> -</span><span id="L-540"><a href="#L-540"><span class="linenos">540</span></a> +</span><span id="L-491"><a href="#L-491"><span class="linenos">491</span></a><span class="k">def</span> <span class="nf">no_trycast_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TryCast</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-492"><a href="#L-492"><span class="linenos">492</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cast_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-493"><a href="#L-493"><span class="linenos">493</span></a> +</span><span id="L-494"><a href="#L-494"><span class="linenos">494</span></a> +</span><span id="L-495"><a href="#L-495"><span class="linenos">495</span></a><span class="k">def</span> <span class="nf">no_properties_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Properties</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-496"><a href="#L-496"><span class="linenos">496</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Properties unsupported"</span><span class="p">)</span> +</span><span id="L-497"><a href="#L-497"><span class="linenos">497</span></a> <span class="k">return</span> <span class="s2">""</span> +</span><span id="L-498"><a href="#L-498"><span class="linenos">498</span></a> +</span><span id="L-499"><a href="#L-499"><span class="linenos">499</span></a> +</span><span id="L-500"><a href="#L-500"><span class="linenos">500</span></a><span class="k">def</span> <span class="nf">no_comment_column_constraint_sql</span><span class="p">(</span> +</span><span id="L-501"><a href="#L-501"><span class="linenos">501</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">CommentColumnConstraint</span> +</span><span id="L-502"><a href="#L-502"><span class="linenos">502</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-503"><a href="#L-503"><span class="linenos">503</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"CommentColumnConstraint unsupported"</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="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><span id="L-507"><a href="#L-507"><span class="linenos">507</span></a><span class="k">def</span> <span class="nf">no_map_from_entries_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">MapFromEntries</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="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"MAP_FROM_ENTRIES unsupported"</span><span class="p">)</span> +</span><span id="L-509"><a href="#L-509"><span class="linenos">509</span></a> <span class="k">return</span> <span class="s2">""</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><span id="L-512"><a href="#L-512"><span class="linenos">512</span></a><span class="k">def</span> <span class="nf">str_position_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrPosition</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-513"><a href="#L-513"><span class="linenos">513</span></a> <span class="n">this</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> +</span><span id="L-514"><a href="#L-514"><span class="linenos">514</span></a> <span class="n">substr</span> <span class="o">=</span> <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">"substr"</span><span class="p">)</span> +</span><span id="L-515"><a href="#L-515"><span class="linenos">515</span></a> <span class="n">position</span> <span class="o">=</span> <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">"position"</span><span class="p">)</span> +</span><span id="L-516"><a href="#L-516"><span class="linenos">516</span></a> <span class="k">if</span> <span class="n">position</span><span class="p">:</span> +</span><span id="L-517"><a href="#L-517"><span class="linenos">517</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"STRPOS(SUBSTR(</span><span class="si">{</span><span class="n">this</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">position</span><span class="si">}</span><span class="s2">), </span><span class="si">{</span><span class="n">substr</span><span class="si">}</span><span class="s2">) + </span><span class="si">{</span><span class="n">position</span><span class="si">}</span><span class="s2"> - 1"</span> +</span><span id="L-518"><a href="#L-518"><span class="linenos">518</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"STRPOS(</span><span class="si">{</span><span class="n">this</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">substr</span><span class="si">}</span><span class="s2">)"</span> +</span><span id="L-519"><a href="#L-519"><span class="linenos">519</span></a> +</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">def</span> <span class="nf">struct_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">StructExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-522"><a href="#L-522"><span class="linenos">522</span></a> <span class="k">return</span> <span class="p">(</span> +</span><span id="L-523"><a href="#L-523"><span class="linenos">523</span></a> <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">expression</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">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">name</span><span class="p">))</span><span class="si">}</span><span class="s2">"</span> +</span><span id="L-524"><a href="#L-524"><span class="linenos">524</span></a> <span class="p">)</span> +</span><span id="L-525"><a href="#L-525"><span class="linenos">525</span></a> +</span><span id="L-526"><a href="#L-526"><span class="linenos">526</span></a> +</span><span id="L-527"><a href="#L-527"><span class="linenos">527</span></a><span class="k">def</span> <span class="nf">var_map_sql</span><span class="p">(</span> +</span><span id="L-528"><a href="#L-528"><span class="linenos">528</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Map</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">VarMap</span><span class="p">,</span> <span class="n">map_func_name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"MAP"</span> +</span><span id="L-529"><a href="#L-529"><span class="linenos">529</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-530"><a href="#L-530"><span class="linenos">530</span></a> <span class="n">keys</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">"keys"</span><span class="p">]</span> +</span><span id="L-531"><a href="#L-531"><span class="linenos">531</span></a> <span class="n">values</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">"values"</span><span class="p">]</span> +</span><span id="L-532"><a href="#L-532"><span class="linenos">532</span></a> +</span><span id="L-533"><a href="#L-533"><span class="linenos">533</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">keys</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Array</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Array</span><span class="p">):</span> +</span><span id="L-534"><a href="#L-534"><span class="linenos">534</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Cannot convert array columns into map."</span><span class="p">)</span> +</span><span id="L-535"><a href="#L-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="n">map_func_name</span><span class="p">,</span> <span class="n">keys</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span> +</span><span id="L-536"><a href="#L-536"><span class="linenos">536</span></a> +</span><span id="L-537"><a href="#L-537"><span class="linenos">537</span></a> <span class="n">args</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="L-538"><a href="#L-538"><span class="linenos">538</span></a> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">keys</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> <span class="n">values</span><span class="o">.</span><span class="n">expressions</span><span class="p">):</span> +</span><span id="L-539"><a href="#L-539"><span class="linenos">539</span></a> <span class="n">args</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">key</span><span class="p">))</span> +</span><span id="L-540"><a href="#L-540"><span class="linenos">540</span></a> <span class="n">args</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">value</span><span class="p">))</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="k">def</span> <span class="nf">format_time_lambda</span><span class="p">(</span> -</span><span id="L-543"><a href="#L-543"><span class="linenos">543</span></a> <span class="n">exp_class</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">E</span><span class="p">],</span> <span class="n">dialect</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">default</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span> <span class="o">|</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-544"><a href="#L-544"><span class="linenos">544</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">E</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">"""Helper used for time expressions.</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="sd"> Args:</span> -</span><span id="L-548"><a href="#L-548"><span class="linenos">548</span></a><span class="sd"> exp_class: the expression class to instantiate.</span> -</span><span id="L-549"><a href="#L-549"><span class="linenos">549</span></a><span class="sd"> dialect: target sql dialect.</span> -</span><span id="L-550"><a href="#L-550"><span class="linenos">550</span></a><span class="sd"> default: the default format, True being time.</span> -</span><span id="L-551"><a href="#L-551"><span class="linenos">551</span></a> -</span><span id="L-552"><a href="#L-552"><span class="linenos">552</span></a><span class="sd"> Returns:</span> -</span><span id="L-553"><a href="#L-553"><span class="linenos">553</span></a><span class="sd"> A callable that can be used to return the appropriately formatted time expression.</span> -</span><span id="L-554"><a href="#L-554"><span class="linenos">554</span></a><span class="sd"> """</span> -</span><span id="L-555"><a href="#L-555"><span class="linenos">555</span></a> -</span><span id="L-556"><a href="#L-556"><span class="linenos">556</span></a> <span class="k">def</span> <span class="nf">_format_time</span><span class="p">(</span><span class="n">args</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">):</span> -</span><span id="L-557"><a href="#L-557"><span class="linenos">557</span></a> <span class="k">return</span> <span class="n">exp_class</span><span class="p">(</span> -</span><span id="L-558"><a href="#L-558"><span class="linenos">558</span></a> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> -</span><span id="L-559"><a href="#L-559"><span class="linenos">559</span></a> <span class="nb">format</span><span class="o">=</span><span class="n">Dialect</span><span class="p">[</span><span class="n">dialect</span><span class="p">]</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span> -</span><span id="L-560"><a href="#L-560"><span class="linenos">560</span></a> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> -</span><span id="L-561"><a href="#L-561"><span class="linenos">561</span></a> <span class="ow">or</span> <span class="p">(</span><span class="n">Dialect</span><span class="p">[</span><span class="n">dialect</span><span class="p">]</span><span class="o">.</span><span class="n">TIME_FORMAT</span> <span class="k">if</span> <span class="n">default</span> <span class="ow">is</span> <span class="kc">True</span> <span class="k">else</span> <span class="n">default</span> <span class="ow">or</span> <span class="kc">None</span><span class="p">)</span> -</span><span id="L-562"><a href="#L-562"><span class="linenos">562</span></a> <span class="p">),</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><span id="L-565"><a href="#L-565"><span class="linenos">565</span></a> <span class="k">return</span> <span class="n">_format_time</span> -</span><span id="L-566"><a href="#L-566"><span class="linenos">566</span></a> +</span><span id="L-542"><a href="#L-542"><span class="linenos">542</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="n">map_func_name</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><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><span id="L-545"><a href="#L-545"><span class="linenos">545</span></a><span class="k">def</span> <span class="nf">format_time_lambda</span><span class="p">(</span> +</span><span id="L-546"><a href="#L-546"><span class="linenos">546</span></a> <span class="n">exp_class</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">E</span><span class="p">],</span> <span class="n">dialect</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">default</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span> <span class="o">|</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="L-547"><a href="#L-547"><span class="linenos">547</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">E</span><span class="p">]:</span> +</span><span id="L-548"><a href="#L-548"><span class="linenos">548</span></a><span class="w"> </span><span class="sd">"""Helper used for time expressions.</span> +</span><span id="L-549"><a href="#L-549"><span class="linenos">549</span></a> +</span><span id="L-550"><a href="#L-550"><span class="linenos">550</span></a><span class="sd"> Args:</span> +</span><span id="L-551"><a href="#L-551"><span class="linenos">551</span></a><span class="sd"> exp_class: the expression class to instantiate.</span> +</span><span id="L-552"><a href="#L-552"><span class="linenos">552</span></a><span class="sd"> dialect: target sql dialect.</span> +</span><span id="L-553"><a href="#L-553"><span class="linenos">553</span></a><span class="sd"> default: the default format, True being time.</span> +</span><span id="L-554"><a href="#L-554"><span class="linenos">554</span></a> +</span><span id="L-555"><a href="#L-555"><span class="linenos">555</span></a><span class="sd"> Returns:</span> +</span><span id="L-556"><a href="#L-556"><span class="linenos">556</span></a><span class="sd"> A callable that can be used to return the appropriately formatted time expression.</span> +</span><span id="L-557"><a href="#L-557"><span class="linenos">557</span></a><span class="sd"> """</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">def</span> <span class="nf">_format_time</span><span class="p">(</span><span class="n">args</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">):</span> +</span><span id="L-560"><a href="#L-560"><span class="linenos">560</span></a> <span class="k">return</span> <span class="n">exp_class</span><span class="p">(</span> +</span><span id="L-561"><a href="#L-561"><span class="linenos">561</span></a> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> +</span><span id="L-562"><a href="#L-562"><span class="linenos">562</span></a> <span class="nb">format</span><span class="o">=</span><span class="n">Dialect</span><span class="p">[</span><span class="n">dialect</span><span class="p">]</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span> +</span><span id="L-563"><a href="#L-563"><span class="linenos">563</span></a> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> +</span><span id="L-564"><a href="#L-564"><span class="linenos">564</span></a> <span class="ow">or</span> <span class="p">(</span><span class="n">Dialect</span><span class="p">[</span><span class="n">dialect</span><span class="p">]</span><span class="o">.</span><span class="n">TIME_FORMAT</span> <span class="k">if</span> <span class="n">default</span> <span class="ow">is</span> <span class="kc">True</span> <span class="k">else</span> <span class="n">default</span> <span class="ow">or</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="L-565"><a href="#L-565"><span class="linenos">565</span></a> <span class="p">),</span> +</span><span id="L-566"><a href="#L-566"><span class="linenos">566</span></a> <span class="p">)</span> </span><span id="L-567"><a href="#L-567"><span class="linenos">567</span></a> -</span><span id="L-568"><a href="#L-568"><span class="linenos">568</span></a><span class="k">def</span> <span class="nf">time_format</span><span class="p">(</span> -</span><span id="L-569"><a href="#L-569"><span class="linenos">569</span></a> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> -</span><span id="L-570"><a href="#L-570"><span class="linenos">570</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToStr</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrToUnix</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]]:</span> -</span><span id="L-571"><a href="#L-571"><span class="linenos">571</span></a> <span class="k">def</span> <span class="nf">_time_format</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToStr</span> <span class="o">|</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="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> -</span><span id="L-572"><a href="#L-572"><span class="linenos">572</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-573"><a href="#L-573"><span class="linenos">573</span></a><span class="sd"> Returns the time format for a given expression, unless it's equivalent</span> -</span><span id="L-574"><a href="#L-574"><span class="linenos">574</span></a><span class="sd"> to the default time format of the dialect of interest.</span> -</span><span id="L-575"><a href="#L-575"><span class="linenos">575</span></a><span class="sd"> """</span> -</span><span id="L-576"><a href="#L-576"><span class="linenos">576</span></a> <span class="n">time_format</span> <span class="o">=</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-577"><a href="#L-577"><span class="linenos">577</span></a> <span class="k">return</span> <span class="n">time_format</span> <span class="k">if</span> <span class="n">time_format</span> <span class="o">!=</span> <span class="n">Dialect</span><span class="o">.</span><span class="n">get_or_raise</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span><span class="o">.</span><span class="n">TIME_FORMAT</span> <span class="k">else</span> <span class="kc">None</span> -</span><span id="L-578"><a href="#L-578"><span class="linenos">578</span></a> -</span><span id="L-579"><a href="#L-579"><span class="linenos">579</span></a> <span class="k">return</span> <span class="n">_time_format</span> -</span><span id="L-580"><a href="#L-580"><span class="linenos">580</span></a> +</span><span id="L-568"><a href="#L-568"><span class="linenos">568</span></a> <span class="k">return</span> <span class="n">_format_time</span> +</span><span id="L-569"><a href="#L-569"><span class="linenos">569</span></a> +</span><span id="L-570"><a href="#L-570"><span class="linenos">570</span></a> +</span><span id="L-571"><a href="#L-571"><span class="linenos">571</span></a><span class="k">def</span> <span class="nf">time_format</span><span class="p">(</span> +</span><span id="L-572"><a href="#L-572"><span class="linenos">572</span></a> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="L-573"><a href="#L-573"><span class="linenos">573</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToStr</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrToUnix</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]]:</span> +</span><span id="L-574"><a href="#L-574"><span class="linenos">574</span></a> <span class="k">def</span> <span class="nf">_time_format</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToStr</span> <span class="o">|</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="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="L-575"><a href="#L-575"><span class="linenos">575</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-576"><a href="#L-576"><span class="linenos">576</span></a><span class="sd"> Returns the time format for a given expression, unless it's equivalent</span> +</span><span id="L-577"><a href="#L-577"><span class="linenos">577</span></a><span class="sd"> to the default time format of the dialect of interest.</span> +</span><span id="L-578"><a href="#L-578"><span class="linenos">578</span></a><span class="sd"> """</span> +</span><span id="L-579"><a href="#L-579"><span class="linenos">579</span></a> <span class="n">time_format</span> <span class="o">=</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-580"><a href="#L-580"><span class="linenos">580</span></a> <span class="k">return</span> <span class="n">time_format</span> <span class="k">if</span> <span class="n">time_format</span> <span class="o">!=</span> <span class="n">Dialect</span><span class="o">.</span><span class="n">get_or_raise</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span><span class="o">.</span><span class="n">TIME_FORMAT</span> <span class="k">else</span> <span class="kc">None</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">def</span> <span class="nf">create_with_partitions_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Create</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-583"><a href="#L-583"><span class="linenos">583</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-584"><a href="#L-584"><span class="linenos">584</span></a><span class="sd"> In Hive and Spark, the PARTITIONED BY property acts as an extension of a table's schema. When the</span> -</span><span id="L-585"><a href="#L-585"><span class="linenos">585</span></a><span class="sd"> PARTITIONED BY value is an array of column names, they are transformed into a schema. The corresponding</span> -</span><span id="L-586"><a href="#L-586"><span class="linenos">586</span></a><span class="sd"> columns are removed from the create statement.</span> -</span><span id="L-587"><a href="#L-587"><span class="linenos">587</span></a><span class="sd"> """</span> -</span><span id="L-588"><a href="#L-588"><span class="linenos">588</span></a> <span class="n">has_schema</span> <span class="o">=</span> <span class="nb">isinstance</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">Schema</span><span class="p">)</span> -</span><span id="L-589"><a href="#L-589"><span class="linenos">589</span></a> <span class="n">is_partitionable</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">"kind"</span><span class="p">)</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">"TABLE"</span><span class="p">,</span> <span class="s2">"VIEW"</span><span class="p">)</span> -</span><span id="L-590"><a href="#L-590"><span class="linenos">590</span></a> -</span><span id="L-591"><a href="#L-591"><span class="linenos">591</span></a> <span class="k">if</span> <span class="n">has_schema</span> <span class="ow">and</span> <span class="n">is_partitionable</span><span class="p">:</span> -</span><span id="L-592"><a href="#L-592"><span class="linenos">592</span></a> <span class="n">prop</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">PartitionedByProperty</span><span class="p">)</span> -</span><span id="L-593"><a href="#L-593"><span class="linenos">593</span></a> <span class="k">if</span> <span class="n">prop</span> <span class="ow">and</span> <span class="n">prop</span><span class="o">.</span><span class="n">this</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">prop</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">Schema</span><span class="p">):</span> -</span><span id="L-594"><a href="#L-594"><span class="linenos">594</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-595"><a href="#L-595"><span class="linenos">595</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="p">{</span><span class="n">v</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">prop</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">}</span> -</span><span id="L-596"><a href="#L-596"><span class="linenos">596</span></a> <span class="n">partitions</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span> <span class="k">if</span> <span class="n">col</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="n">columns</span><span class="p">]</span> -</span><span id="L-597"><a href="#L-597"><span class="linenos">597</span></a> <span class="n">schema</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="p">[</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span> <span class="k">if</span> <span class="n">e</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">partitions</span><span class="p">])</span> -</span><span id="L-598"><a href="#L-598"><span class="linenos">598</span></a> <span class="n">prop</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">PartitionedByProperty</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Schema</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">partitions</span><span class="p">)))</span> -</span><span id="L-599"><a href="#L-599"><span class="linenos">599</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">schema</span><span class="p">)</span> -</span><span id="L-600"><a href="#L-600"><span class="linenos">600</span></a> -</span><span id="L-601"><a href="#L-601"><span class="linenos">601</span></a> <span class="k">return</span> <span class="bp">self</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-602"><a href="#L-602"><span class="linenos">602</span></a> +</span><span id="L-582"><a href="#L-582"><span class="linenos">582</span></a> <span class="k">return</span> <span class="n">_time_format</span> +</span><span id="L-583"><a href="#L-583"><span class="linenos">583</span></a> +</span><span id="L-584"><a href="#L-584"><span class="linenos">584</span></a> +</span><span id="L-585"><a href="#L-585"><span class="linenos">585</span></a><span class="k">def</span> <span class="nf">create_with_partitions_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Create</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-586"><a href="#L-586"><span class="linenos">586</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-587"><a href="#L-587"><span class="linenos">587</span></a><span class="sd"> In Hive and Spark, the PARTITIONED BY property acts as an extension of a table's schema. When the</span> +</span><span id="L-588"><a href="#L-588"><span class="linenos">588</span></a><span class="sd"> PARTITIONED BY value is an array of column names, they are transformed into a schema. The corresponding</span> +</span><span id="L-589"><a href="#L-589"><span class="linenos">589</span></a><span class="sd"> columns are removed from the create statement.</span> +</span><span id="L-590"><a href="#L-590"><span class="linenos">590</span></a><span class="sd"> """</span> +</span><span id="L-591"><a href="#L-591"><span class="linenos">591</span></a> <span class="n">has_schema</span> <span class="o">=</span> <span class="nb">isinstance</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">Schema</span><span class="p">)</span> +</span><span id="L-592"><a href="#L-592"><span class="linenos">592</span></a> <span class="n">is_partitionable</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">"kind"</span><span class="p">)</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">"TABLE"</span><span class="p">,</span> <span class="s2">"VIEW"</span><span class="p">)</span> +</span><span id="L-593"><a href="#L-593"><span class="linenos">593</span></a> +</span><span id="L-594"><a href="#L-594"><span class="linenos">594</span></a> <span class="k">if</span> <span class="n">has_schema</span> <span class="ow">and</span> <span class="n">is_partitionable</span><span class="p">:</span> +</span><span id="L-595"><a href="#L-595"><span class="linenos">595</span></a> <span class="n">prop</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">PartitionedByProperty</span><span class="p">)</span> +</span><span id="L-596"><a href="#L-596"><span class="linenos">596</span></a> <span class="k">if</span> <span class="n">prop</span> <span class="ow">and</span> <span class="n">prop</span><span class="o">.</span><span class="n">this</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">prop</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">Schema</span><span class="p">):</span> +</span><span id="L-597"><a href="#L-597"><span class="linenos">597</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-598"><a href="#L-598"><span class="linenos">598</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="p">{</span><span class="n">v</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">prop</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">}</span> +</span><span id="L-599"><a href="#L-599"><span class="linenos">599</span></a> <span class="n">partitions</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span> <span class="k">if</span> <span class="n">col</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="n">columns</span><span class="p">]</span> +</span><span id="L-600"><a href="#L-600"><span class="linenos">600</span></a> <span class="n">schema</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="p">[</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span> <span class="k">if</span> <span class="n">e</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">partitions</span><span class="p">])</span> +</span><span id="L-601"><a href="#L-601"><span class="linenos">601</span></a> <span class="n">prop</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">PartitionedByProperty</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Schema</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">partitions</span><span class="p">)))</span> +</span><span id="L-602"><a href="#L-602"><span class="linenos">602</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">schema</span><span class="p">)</span> </span><span id="L-603"><a href="#L-603"><span class="linenos">603</span></a> -</span><span id="L-604"><a href="#L-604"><span class="linenos">604</span></a><span class="k">def</span> <span class="nf">parse_date_delta</span><span class="p">(</span> -</span><span id="L-605"><a href="#L-605"><span class="linenos">605</span></a> <span class="n">exp_class</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">E</span><span class="p">],</span> <span class="n">unit_mapping</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-606"><a href="#L-606"><span class="linenos">606</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">E</span><span class="p">]:</span> -</span><span id="L-607"><a href="#L-607"><span class="linenos">607</span></a> <span class="k">def</span> <span class="nf">inner_func</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">E</span><span class="p">:</span> -</span><span id="L-608"><a href="#L-608"><span class="linenos">608</span></a> <span class="n">unit_based</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span> -</span><span id="L-609"><a href="#L-609"><span class="linenos">609</span></a> <span class="n">this</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">if</span> <span class="n">unit_based</span> <span class="k">else</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> -</span><span id="L-610"><a href="#L-610"><span class="linenos">610</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">if</span> <span class="n">unit_based</span> <span class="k">else</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="s2">"DAY"</span><span class="p">)</span> -</span><span id="L-611"><a href="#L-611"><span class="linenos">611</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">unit_mapping</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">unit</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> <span class="n">unit</span><span class="o">.</span><span class="n">name</span><span class="p">))</span> <span class="k">if</span> <span class="n">unit_mapping</span> <span class="k">else</span> <span class="n">unit</span> -</span><span id="L-612"><a href="#L-612"><span class="linenos">612</span></a> <span class="k">return</span> <span class="n">exp_class</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">)</span> -</span><span id="L-613"><a href="#L-613"><span class="linenos">613</span></a> -</span><span id="L-614"><a href="#L-614"><span class="linenos">614</span></a> <span class="k">return</span> <span class="n">inner_func</span> -</span><span id="L-615"><a href="#L-615"><span class="linenos">615</span></a> +</span><span id="L-604"><a href="#L-604"><span class="linenos">604</span></a> <span class="k">return</span> <span class="bp">self</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-605"><a href="#L-605"><span class="linenos">605</span></a> +</span><span id="L-606"><a href="#L-606"><span class="linenos">606</span></a> +</span><span id="L-607"><a href="#L-607"><span class="linenos">607</span></a><span class="k">def</span> <span class="nf">parse_date_delta</span><span class="p">(</span> +</span><span id="L-608"><a href="#L-608"><span class="linenos">608</span></a> <span class="n">exp_class</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">E</span><span class="p">],</span> <span class="n">unit_mapping</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="L-609"><a href="#L-609"><span class="linenos">609</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">E</span><span class="p">]:</span> +</span><span id="L-610"><a href="#L-610"><span class="linenos">610</span></a> <span class="k">def</span> <span class="nf">inner_func</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">E</span><span class="p">:</span> +</span><span id="L-611"><a href="#L-611"><span class="linenos">611</span></a> <span class="n">unit_based</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span> +</span><span id="L-612"><a href="#L-612"><span class="linenos">612</span></a> <span class="n">this</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">if</span> <span class="n">unit_based</span> <span class="k">else</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> +</span><span id="L-613"><a href="#L-613"><span class="linenos">613</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">if</span> <span class="n">unit_based</span> <span class="k">else</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="s2">"DAY"</span><span class="p">)</span> +</span><span id="L-614"><a href="#L-614"><span class="linenos">614</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">unit_mapping</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">unit</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> <span class="n">unit</span><span class="o">.</span><span class="n">name</span><span class="p">))</span> <span class="k">if</span> <span class="n">unit_mapping</span> <span class="k">else</span> <span class="n">unit</span> +</span><span id="L-615"><a href="#L-615"><span class="linenos">615</span></a> <span class="k">return</span> <span class="n">exp_class</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">)</span> </span><span id="L-616"><a href="#L-616"><span class="linenos">616</span></a> -</span><span id="L-617"><a href="#L-617"><span class="linenos">617</span></a><span class="k">def</span> <span class="nf">parse_date_delta_with_interval</span><span class="p">(</span> -</span><span id="L-618"><a href="#L-618"><span class="linenos">618</span></a> <span class="n">expression_class</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">E</span><span class="p">],</span> -</span><span id="L-619"><a href="#L-619"><span class="linenos">619</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">E</span><span class="p">]]:</span> -</span><span id="L-620"><a href="#L-620"><span class="linenos">620</span></a> <span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">E</span><span class="p">]:</span> -</span><span id="L-621"><a href="#L-621"><span class="linenos">621</span></a> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o"><</span> <span class="mi">2</span><span class="p">:</span> -</span><span id="L-622"><a href="#L-622"><span class="linenos">622</span></a> <span class="k">return</span> <span class="kc">None</span> -</span><span id="L-623"><a href="#L-623"><span class="linenos">623</span></a> -</span><span id="L-624"><a href="#L-624"><span class="linenos">624</span></a> <span class="n">interval</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> -</span><span id="L-625"><a href="#L-625"><span class="linenos">625</span></a> -</span><span id="L-626"><a href="#L-626"><span class="linenos">626</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">interval</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Interval</span><span class="p">):</span> -</span><span id="L-627"><a href="#L-627"><span class="linenos">627</span></a> <span class="k">raise</span> <span class="n">ParseError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"INTERVAL expression expected but got '</span><span class="si">{</span><span class="n">interval</span><span class="si">}</span><span class="s2">'"</span><span class="p">)</span> +</span><span id="L-617"><a href="#L-617"><span class="linenos">617</span></a> <span class="k">return</span> <span class="n">inner_func</span> +</span><span id="L-618"><a href="#L-618"><span class="linenos">618</span></a> +</span><span id="L-619"><a href="#L-619"><span class="linenos">619</span></a> +</span><span id="L-620"><a href="#L-620"><span class="linenos">620</span></a><span class="k">def</span> <span class="nf">parse_date_delta_with_interval</span><span class="p">(</span> +</span><span id="L-621"><a href="#L-621"><span class="linenos">621</span></a> <span class="n">expression_class</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">E</span><span class="p">],</span> +</span><span id="L-622"><a href="#L-622"><span class="linenos">622</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">E</span><span class="p">]]:</span> +</span><span id="L-623"><a href="#L-623"><span class="linenos">623</span></a> <span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">E</span><span class="p">]:</span> +</span><span id="L-624"><a href="#L-624"><span class="linenos">624</span></a> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o"><</span> <span class="mi">2</span><span class="p">:</span> +</span><span id="L-625"><a href="#L-625"><span class="linenos">625</span></a> <span class="k">return</span> <span class="kc">None</span> +</span><span id="L-626"><a href="#L-626"><span class="linenos">626</span></a> +</span><span id="L-627"><a href="#L-627"><span class="linenos">627</span></a> <span class="n">interval</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> </span><span id="L-628"><a href="#L-628"><span class="linenos">628</span></a> -</span><span id="L-629"><a href="#L-629"><span class="linenos">629</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">interval</span><span class="o">.</span><span class="n">this</span> -</span><span id="L-630"><a href="#L-630"><span class="linenos">630</span></a> <span class="k">if</span> <span class="n">expression</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_string</span><span class="p">:</span> -</span><span id="L-631"><a href="#L-631"><span class="linenos">631</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">number</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> -</span><span id="L-632"><a href="#L-632"><span class="linenos">632</span></a> -</span><span id="L-633"><a href="#L-633"><span class="linenos">633</span></a> <span class="k">return</span> <span class="n">expression_class</span><span class="p">(</span> -</span><span id="L-634"><a href="#L-634"><span class="linenos">634</span></a> <span class="n">this</span><span class="o">=</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="n">interval</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"unit"</span><span class="p">))</span> -</span><span id="L-635"><a href="#L-635"><span class="linenos">635</span></a> <span class="p">)</span> -</span><span id="L-636"><a href="#L-636"><span class="linenos">636</span></a> -</span><span id="L-637"><a href="#L-637"><span class="linenos">637</span></a> <span class="k">return</span> <span class="n">func</span> -</span><span id="L-638"><a href="#L-638"><span class="linenos">638</span></a> +</span><span id="L-629"><a href="#L-629"><span class="linenos">629</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">interval</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Interval</span><span class="p">):</span> +</span><span id="L-630"><a href="#L-630"><span class="linenos">630</span></a> <span class="k">raise</span> <span class="n">ParseError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"INTERVAL expression expected but got '</span><span class="si">{</span><span class="n">interval</span><span class="si">}</span><span class="s2">'"</span><span class="p">)</span> +</span><span id="L-631"><a href="#L-631"><span class="linenos">631</span></a> +</span><span id="L-632"><a href="#L-632"><span class="linenos">632</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">interval</span><span class="o">.</span><span class="n">this</span> +</span><span id="L-633"><a href="#L-633"><span class="linenos">633</span></a> <span class="k">if</span> <span class="n">expression</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_string</span><span class="p">:</span> +</span><span id="L-634"><a href="#L-634"><span class="linenos">634</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">number</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> +</span><span id="L-635"><a href="#L-635"><span class="linenos">635</span></a> +</span><span id="L-636"><a href="#L-636"><span class="linenos">636</span></a> <span class="k">return</span> <span class="n">expression_class</span><span class="p">(</span> +</span><span id="L-637"><a href="#L-637"><span class="linenos">637</span></a> <span class="n">this</span><span class="o">=</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="n">interval</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"unit"</span><span class="p">))</span> +</span><span id="L-638"><a href="#L-638"><span class="linenos">638</span></a> <span class="p">)</span> </span><span id="L-639"><a href="#L-639"><span class="linenos">639</span></a> -</span><span id="L-640"><a href="#L-640"><span class="linenos">640</span></a><span class="k">def</span> <span class="nf">date_trunc_to_time</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">DateTrunc</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">:</span> -</span><span id="L-641"><a href="#L-641"><span class="linenos">641</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> -</span><span id="L-642"><a href="#L-642"><span class="linenos">642</span></a> <span class="n">this</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> -</span><span id="L-643"><a href="#L-643"><span class="linenos">643</span></a> -</span><span id="L-644"><a href="#L-644"><span class="linenos">644</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">this</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">)</span> <span class="ow">and</span> <span class="n">this</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"date"</span><span class="p">):</span> -</span><span id="L-645"><a href="#L-645"><span class="linenos">645</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">DateTrunc</span><span class="p">(</span><span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">)</span> -</span><span id="L-646"><a href="#L-646"><span class="linenos">646</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">)</span> -</span><span id="L-647"><a href="#L-647"><span class="linenos">647</span></a> -</span><span id="L-648"><a href="#L-648"><span class="linenos">648</span></a> -</span><span id="L-649"><a href="#L-649"><span class="linenos">649</span></a><span class="k">def</span> <span class="nf">date_add_interval_sql</span><span class="p">(</span> -</span><span id="L-650"><a href="#L-650"><span class="linenos">650</span></a> <span class="n">data_type</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">kind</span><span class="p">:</span> <span class="nb">str</span> -</span><span id="L-651"><a href="#L-651"><span class="linenos">651</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</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="nb">str</span><span class="p">]:</span> -</span><span id="L-652"><a href="#L-652"><span class="linenos">652</span></a> <span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-653"><a href="#L-653"><span class="linenos">653</span></a> <span class="n">this</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> -</span><span id="L-654"><a href="#L-654"><span class="linenos">654</span></a> <span class="n">unit</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">"unit"</span><span class="p">)</span> -</span><span id="L-655"><a href="#L-655"><span class="linenos">655</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">unit</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="k">if</span> <span class="n">unit</span> <span class="k">else</span> <span class="s2">"DAY"</span><span class="p">)</span> -</span><span id="L-656"><a href="#L-656"><span class="linenos">656</span></a> <span class="n">interval</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Interval</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">)</span> -</span><span id="L-657"><a href="#L-657"><span class="linenos">657</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">data_type</span><span class="si">}</span><span class="s2">_</span><span class="si">{</span><span class="n">kind</span><span class="si">}</span><span class="s2">(</span><span class="si">{</span><span class="n">this</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">interval</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span> -</span><span id="L-658"><a href="#L-658"><span class="linenos">658</span></a> -</span><span id="L-659"><a href="#L-659"><span class="linenos">659</span></a> <span class="k">return</span> <span class="n">func</span> -</span><span id="L-660"><a href="#L-660"><span class="linenos">660</span></a> +</span><span id="L-640"><a href="#L-640"><span class="linenos">640</span></a> <span class="k">return</span> <span class="n">func</span> +</span><span id="L-641"><a href="#L-641"><span class="linenos">641</span></a> +</span><span id="L-642"><a href="#L-642"><span class="linenos">642</span></a> +</span><span id="L-643"><a href="#L-643"><span class="linenos">643</span></a><span class="k">def</span> <span class="nf">date_trunc_to_time</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">DateTrunc</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">:</span> +</span><span id="L-644"><a href="#L-644"><span class="linenos">644</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> +</span><span id="L-645"><a href="#L-645"><span class="linenos">645</span></a> <span class="n">this</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> +</span><span id="L-646"><a href="#L-646"><span class="linenos">646</span></a> +</span><span id="L-647"><a href="#L-647"><span class="linenos">647</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">this</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">)</span> <span class="ow">and</span> <span class="n">this</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"date"</span><span class="p">):</span> +</span><span id="L-648"><a href="#L-648"><span class="linenos">648</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">DateTrunc</span><span class="p">(</span><span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">)</span> +</span><span id="L-649"><a href="#L-649"><span class="linenos">649</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">)</span> +</span><span id="L-650"><a href="#L-650"><span class="linenos">650</span></a> +</span><span id="L-651"><a href="#L-651"><span class="linenos">651</span></a> +</span><span id="L-652"><a href="#L-652"><span class="linenos">652</span></a><span class="k">def</span> <span class="nf">date_add_interval_sql</span><span class="p">(</span> +</span><span id="L-653"><a href="#L-653"><span class="linenos">653</span></a> <span class="n">data_type</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">kind</span><span class="p">:</span> <span class="nb">str</span> +</span><span id="L-654"><a href="#L-654"><span class="linenos">654</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</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="nb">str</span><span class="p">]:</span> +</span><span id="L-655"><a href="#L-655"><span class="linenos">655</span></a> <span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-656"><a href="#L-656"><span class="linenos">656</span></a> <span class="n">this</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> +</span><span id="L-657"><a href="#L-657"><span class="linenos">657</span></a> <span class="n">unit</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">"unit"</span><span class="p">)</span> +</span><span id="L-658"><a href="#L-658"><span class="linenos">658</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">unit</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="k">if</span> <span class="n">unit</span> <span class="k">else</span> <span class="s2">"DAY"</span><span class="p">)</span> +</span><span id="L-659"><a href="#L-659"><span class="linenos">659</span></a> <span class="n">interval</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Interval</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">)</span> +</span><span id="L-660"><a href="#L-660"><span class="linenos">660</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">data_type</span><span class="si">}</span><span class="s2">_</span><span class="si">{</span><span class="n">kind</span><span class="si">}</span><span class="s2">(</span><span class="si">{</span><span class="n">this</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">interval</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span> </span><span id="L-661"><a href="#L-661"><span class="linenos">661</span></a> -</span><span id="L-662"><a href="#L-662"><span class="linenos">662</span></a><span class="k">def</span> <span class="nf">timestamptrunc_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-663"><a href="#L-663"><span class="linenos">663</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-664"><a href="#L-664"><span class="linenos">664</span></a> <span class="s2">"DATE_TRUNC"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</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="ow">or</span> <span class="s2">"day"</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> -</span><span id="L-665"><a href="#L-665"><span class="linenos">665</span></a> <span class="p">)</span> -</span><span id="L-666"><a href="#L-666"><span class="linenos">666</span></a> -</span><span id="L-667"><a href="#L-667"><span class="linenos">667</span></a> -</span><span id="L-668"><a href="#L-668"><span class="linenos">668</span></a><span class="k">def</span> <span class="nf">no_timestamp_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Timestamp</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-669"><a href="#L-669"><span class="linenos">669</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">:</span> -</span><span id="L-670"><a href="#L-670"><span class="linenos">670</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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">to</span><span class="o">=</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">TIMESTAMP</span><span class="p">))</span> -</span><span id="L-671"><a href="#L-671"><span class="linenos">671</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"expression"</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">in</span> <span class="n">TIMEZONES</span><span class="p">:</span> -</span><span id="L-672"><a href="#L-672"><span class="linenos">672</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> -</span><span id="L-673"><a href="#L-673"><span class="linenos">673</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">AtTimeZone</span><span class="p">(</span> -</span><span id="L-674"><a href="#L-674"><span class="linenos">674</span></a> <span class="n">this</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">to</span><span class="o">=</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">TIMESTAMP</span><span class="p">),</span> -</span><span id="L-675"><a href="#L-675"><span class="linenos">675</span></a> <span class="n">zone</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> -</span><span id="L-676"><a href="#L-676"><span class="linenos">676</span></a> <span class="p">)</span> -</span><span id="L-677"><a href="#L-677"><span class="linenos">677</span></a> <span class="p">)</span> -</span><span id="L-678"><a href="#L-678"><span class="linenos">678</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">function_fallback_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="L-679"><a href="#L-679"><span class="linenos">679</span></a> -</span><span id="L-680"><a href="#L-680"><span class="linenos">680</span></a> -</span><span id="L-681"><a href="#L-681"><span class="linenos">681</span></a><span class="k">def</span> <span class="nf">locate_to_strposition</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">:</span> -</span><span id="L-682"><a href="#L-682"><span class="linenos">682</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrPosition</span><span class="p">(</span> -</span><span id="L-683"><a href="#L-683"><span class="linenos">683</span></a> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">substr</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">position</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> -</span><span id="L-684"><a href="#L-684"><span class="linenos">684</span></a> <span class="p">)</span> -</span><span id="L-685"><a href="#L-685"><span class="linenos">685</span></a> -</span><span id="L-686"><a href="#L-686"><span class="linenos">686</span></a> -</span><span id="L-687"><a href="#L-687"><span class="linenos">687</span></a><span class="k">def</span> <span class="nf">strposition_to_locate_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrPosition</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-688"><a href="#L-688"><span class="linenos">688</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-689"><a href="#L-689"><span class="linenos">689</span></a> <span class="s2">"LOCATE"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"substr"</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"position"</span><span class="p">)</span> -</span><span id="L-690"><a href="#L-690"><span class="linenos">690</span></a> <span class="p">)</span> -</span><span id="L-691"><a href="#L-691"><span class="linenos">691</span></a> -</span><span id="L-692"><a href="#L-692"><span class="linenos">692</span></a> -</span><span id="L-693"><a href="#L-693"><span class="linenos">693</span></a><span class="k">def</span> <span class="nf">left_to_substring_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Left</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-694"><a href="#L-694"><span class="linenos">694</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> -</span><span id="L-695"><a href="#L-695"><span class="linenos">695</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Substring</span><span class="p">(</span> -</span><span id="L-696"><a href="#L-696"><span class="linenos">696</span></a> <span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">number</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">length</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span> -</span><span id="L-697"><a href="#L-697"><span class="linenos">697</span></a> <span class="p">)</span> -</span><span id="L-698"><a href="#L-698"><span class="linenos">698</span></a> <span class="p">)</span> -</span><span id="L-699"><a href="#L-699"><span class="linenos">699</span></a> -</span><span id="L-700"><a href="#L-700"><span class="linenos">700</span></a> -</span><span id="L-701"><a href="#L-701"><span class="linenos">701</span></a><span class="k">def</span> <span class="nf">right_to_substring_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Left</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-702"><a href="#L-702"><span class="linenos">702</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> -</span><span id="L-703"><a href="#L-703"><span class="linenos">703</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Substring</span><span class="p">(</span> -</span><span id="L-704"><a href="#L-704"><span class="linenos">704</span></a> <span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="L-705"><a href="#L-705"><span class="linenos">705</span></a> <span class="n">start</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Length</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> <span class="o">-</span> <span class="n">exp</span><span class="o">.</span><span class="n">paren</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span> <span class="o">-</span> <span class="mi">1</span><span class="p">),</span> -</span><span id="L-706"><a href="#L-706"><span class="linenos">706</span></a> <span class="p">)</span> -</span><span id="L-707"><a href="#L-707"><span class="linenos">707</span></a> <span class="p">)</span> -</span><span id="L-708"><a href="#L-708"><span class="linenos">708</span></a> -</span><span id="L-709"><a href="#L-709"><span class="linenos">709</span></a> -</span><span id="L-710"><a href="#L-710"><span class="linenos">710</span></a><span class="k">def</span> <span class="nf">timestrtotime_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimeStrToTime</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-711"><a href="#L-711"><span class="linenos">711</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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="s2">"timestamp"</span><span class="p">))</span> +</span><span id="L-662"><a href="#L-662"><span class="linenos">662</span></a> <span class="k">return</span> <span class="n">func</span> +</span><span id="L-663"><a href="#L-663"><span class="linenos">663</span></a> +</span><span id="L-664"><a href="#L-664"><span class="linenos">664</span></a> +</span><span id="L-665"><a href="#L-665"><span class="linenos">665</span></a><span class="k">def</span> <span class="nf">timestamptrunc_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-666"><a href="#L-666"><span class="linenos">666</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-667"><a href="#L-667"><span class="linenos">667</span></a> <span class="s2">"DATE_TRUNC"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</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="ow">or</span> <span class="s2">"day"</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="L-668"><a href="#L-668"><span class="linenos">668</span></a> <span class="p">)</span> +</span><span id="L-669"><a href="#L-669"><span class="linenos">669</span></a> +</span><span id="L-670"><a href="#L-670"><span class="linenos">670</span></a> +</span><span id="L-671"><a href="#L-671"><span class="linenos">671</span></a><span class="k">def</span> <span class="nf">no_timestamp_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Timestamp</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-672"><a href="#L-672"><span class="linenos">672</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">:</span> +</span><span id="L-673"><a href="#L-673"><span class="linenos">673</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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">to</span><span class="o">=</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">TIMESTAMP</span><span class="p">))</span> +</span><span id="L-674"><a href="#L-674"><span class="linenos">674</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"expression"</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">in</span> <span class="n">TIMEZONES</span><span class="p">:</span> +</span><span id="L-675"><a href="#L-675"><span class="linenos">675</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> +</span><span id="L-676"><a href="#L-676"><span class="linenos">676</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">AtTimeZone</span><span class="p">(</span> +</span><span id="L-677"><a href="#L-677"><span class="linenos">677</span></a> <span class="n">this</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">to</span><span class="o">=</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">TIMESTAMP</span><span class="p">),</span> +</span><span id="L-678"><a href="#L-678"><span class="linenos">678</span></a> <span class="n">zone</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> +</span><span id="L-679"><a href="#L-679"><span class="linenos">679</span></a> <span class="p">)</span> +</span><span id="L-680"><a href="#L-680"><span class="linenos">680</span></a> <span class="p">)</span> +</span><span id="L-681"><a href="#L-681"><span class="linenos">681</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">function_fallback_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-682"><a href="#L-682"><span class="linenos">682</span></a> +</span><span id="L-683"><a href="#L-683"><span class="linenos">683</span></a> +</span><span id="L-684"><a href="#L-684"><span class="linenos">684</span></a><span class="k">def</span> <span class="nf">locate_to_strposition</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">:</span> +</span><span id="L-685"><a href="#L-685"><span class="linenos">685</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrPosition</span><span class="p">(</span> +</span><span id="L-686"><a href="#L-686"><span class="linenos">686</span></a> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">substr</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">position</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> +</span><span id="L-687"><a href="#L-687"><span class="linenos">687</span></a> <span class="p">)</span> +</span><span id="L-688"><a href="#L-688"><span class="linenos">688</span></a> +</span><span id="L-689"><a href="#L-689"><span class="linenos">689</span></a> +</span><span id="L-690"><a href="#L-690"><span class="linenos">690</span></a><span class="k">def</span> <span class="nf">strposition_to_locate_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrPosition</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-691"><a href="#L-691"><span class="linenos">691</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-692"><a href="#L-692"><span class="linenos">692</span></a> <span class="s2">"LOCATE"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"substr"</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"position"</span><span class="p">)</span> +</span><span id="L-693"><a href="#L-693"><span class="linenos">693</span></a> <span class="p">)</span> +</span><span id="L-694"><a href="#L-694"><span class="linenos">694</span></a> +</span><span id="L-695"><a href="#L-695"><span class="linenos">695</span></a> +</span><span id="L-696"><a href="#L-696"><span class="linenos">696</span></a><span class="k">def</span> <span class="nf">left_to_substring_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Left</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-697"><a href="#L-697"><span class="linenos">697</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> +</span><span id="L-698"><a href="#L-698"><span class="linenos">698</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Substring</span><span class="p">(</span> +</span><span id="L-699"><a href="#L-699"><span class="linenos">699</span></a> <span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">number</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">length</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span> +</span><span id="L-700"><a href="#L-700"><span class="linenos">700</span></a> <span class="p">)</span> +</span><span id="L-701"><a href="#L-701"><span class="linenos">701</span></a> <span class="p">)</span> +</span><span id="L-702"><a href="#L-702"><span class="linenos">702</span></a> +</span><span id="L-703"><a href="#L-703"><span class="linenos">703</span></a> +</span><span id="L-704"><a href="#L-704"><span class="linenos">704</span></a><span class="k">def</span> <span class="nf">right_to_substring_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Left</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-705"><a href="#L-705"><span class="linenos">705</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> +</span><span id="L-706"><a href="#L-706"><span class="linenos">706</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Substring</span><span class="p">(</span> +</span><span id="L-707"><a href="#L-707"><span class="linenos">707</span></a> <span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="L-708"><a href="#L-708"><span class="linenos">708</span></a> <span class="n">start</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Length</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> <span class="o">-</span> <span class="n">exp</span><span class="o">.</span><span class="n">paren</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span> <span class="o">-</span> <span class="mi">1</span><span class="p">),</span> +</span><span id="L-709"><a href="#L-709"><span class="linenos">709</span></a> <span class="p">)</span> +</span><span id="L-710"><a href="#L-710"><span class="linenos">710</span></a> <span class="p">)</span> +</span><span id="L-711"><a href="#L-711"><span class="linenos">711</span></a> </span><span id="L-712"><a href="#L-712"><span class="linenos">712</span></a> -</span><span id="L-713"><a href="#L-713"><span class="linenos">713</span></a> -</span><span id="L-714"><a href="#L-714"><span class="linenos">714</span></a><span class="k">def</span> <span class="nf">datestrtodate_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DateStrToDate</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-715"><a href="#L-715"><span class="linenos">715</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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="s2">"date"</span><span class="p">))</span> +</span><span id="L-713"><a href="#L-713"><span class="linenos">713</span></a><span class="k">def</span> <span class="nf">timestrtotime_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimeStrToTime</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-714"><a href="#L-714"><span class="linenos">714</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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="s2">"timestamp"</span><span class="p">))</span> +</span><span id="L-715"><a href="#L-715"><span class="linenos">715</span></a> </span><span id="L-716"><a href="#L-716"><span class="linenos">716</span></a> -</span><span id="L-717"><a href="#L-717"><span class="linenos">717</span></a> -</span><span id="L-718"><a href="#L-718"><span class="linenos">718</span></a><span class="c1"># Used for Presto and Duckdb which use functions that don't support charset, and assume utf-8</span> -</span><span id="L-719"><a href="#L-719"><span class="linenos">719</span></a><span class="k">def</span> <span class="nf">encode_decode_sql</span><span class="p">(</span> -</span><span id="L-720"><a href="#L-720"><span class="linenos">720</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">replace</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="L-721"><a href="#L-721"><span class="linenos">721</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-722"><a href="#L-722"><span class="linenos">722</span></a> <span class="n">charset</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">"charset"</span><span class="p">)</span> -</span><span id="L-723"><a href="#L-723"><span class="linenos">723</span></a> <span class="k">if</span> <span class="n">charset</span> <span class="ow">and</span> <span class="n">charset</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">!=</span> <span class="s2">"utf-8"</span><span class="p">:</span> -</span><span id="L-724"><a href="#L-724"><span class="linenos">724</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Expected utf-8 character set, got </span><span class="si">{</span><span class="n">charset</span><span class="si">}</span><span class="s2">."</span><span class="p">)</span> -</span><span id="L-725"><a href="#L-725"><span class="linenos">725</span></a> -</span><span id="L-726"><a href="#L-726"><span class="linenos">726</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="n">name</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"replace"</span><span class="p">)</span> <span class="k">if</span> <span class="n">replace</span> <span class="k">else</span> <span class="kc">None</span><span class="p">)</span> -</span><span id="L-727"><a href="#L-727"><span class="linenos">727</span></a> +</span><span id="L-717"><a href="#L-717"><span class="linenos">717</span></a><span class="k">def</span> <span class="nf">datestrtodate_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DateStrToDate</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-718"><a href="#L-718"><span class="linenos">718</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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="s2">"date"</span><span class="p">))</span> +</span><span id="L-719"><a href="#L-719"><span class="linenos">719</span></a> +</span><span id="L-720"><a href="#L-720"><span class="linenos">720</span></a> +</span><span id="L-721"><a href="#L-721"><span class="linenos">721</span></a><span class="c1"># Used for Presto and Duckdb which use functions that don't support charset, and assume utf-8</span> +</span><span id="L-722"><a href="#L-722"><span class="linenos">722</span></a><span class="k">def</span> <span class="nf">encode_decode_sql</span><span class="p">(</span> +</span><span id="L-723"><a href="#L-723"><span class="linenos">723</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">replace</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="L-724"><a href="#L-724"><span class="linenos">724</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-725"><a href="#L-725"><span class="linenos">725</span></a> <span class="n">charset</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">"charset"</span><span class="p">)</span> +</span><span id="L-726"><a href="#L-726"><span class="linenos">726</span></a> <span class="k">if</span> <span class="n">charset</span> <span class="ow">and</span> <span class="n">charset</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">!=</span> <span class="s2">"utf-8"</span><span class="p">:</span> +</span><span id="L-727"><a href="#L-727"><span class="linenos">727</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Expected utf-8 character set, got </span><span class="si">{</span><span class="n">charset</span><span class="si">}</span><span class="s2">."</span><span class="p">)</span> </span><span id="L-728"><a href="#L-728"><span class="linenos">728</span></a> -</span><span id="L-729"><a href="#L-729"><span class="linenos">729</span></a><span class="k">def</span> <span class="nf">min_or_least</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Min</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-730"><a href="#L-730"><span class="linenos">730</span></a> <span class="n">name</span> <span class="o">=</span> <span class="s2">"LEAST"</span> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> <span class="k">else</span> <span class="s2">"MIN"</span> -</span><span id="L-731"><a href="#L-731"><span class="linenos">731</span></a> <span class="k">return</span> <span class="n">rename_func</span><span class="p">(</span><span class="n">name</span><span class="p">)(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">)</span> -</span><span id="L-732"><a href="#L-732"><span class="linenos">732</span></a> -</span><span id="L-733"><a href="#L-733"><span class="linenos">733</span></a> -</span><span id="L-734"><a href="#L-734"><span class="linenos">734</span></a><span class="k">def</span> <span class="nf">max_or_greatest</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Max</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-735"><a href="#L-735"><span class="linenos">735</span></a> <span class="n">name</span> <span class="o">=</span> <span class="s2">"GREATEST"</span> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> <span class="k">else</span> <span class="s2">"MAX"</span> -</span><span id="L-736"><a href="#L-736"><span class="linenos">736</span></a> <span class="k">return</span> <span class="n">rename_func</span><span class="p">(</span><span class="n">name</span><span class="p">)(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">)</span> -</span><span id="L-737"><a href="#L-737"><span class="linenos">737</span></a> -</span><span id="L-738"><a href="#L-738"><span class="linenos">738</span></a> -</span><span id="L-739"><a href="#L-739"><span class="linenos">739</span></a><span class="k">def</span> <span class="nf">count_if_to_sum</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">CountIf</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-740"><a href="#L-740"><span class="linenos">740</span></a> <span class="n">cond</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="L-729"><a href="#L-729"><span class="linenos">729</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="n">name</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"replace"</span><span class="p">)</span> <span class="k">if</span> <span class="n">replace</span> <span class="k">else</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="L-730"><a href="#L-730"><span class="linenos">730</span></a> +</span><span id="L-731"><a href="#L-731"><span class="linenos">731</span></a> +</span><span id="L-732"><a href="#L-732"><span class="linenos">732</span></a><span class="k">def</span> <span class="nf">min_or_least</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Min</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-733"><a href="#L-733"><span class="linenos">733</span></a> <span class="n">name</span> <span class="o">=</span> <span class="s2">"LEAST"</span> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> <span class="k">else</span> <span class="s2">"MIN"</span> +</span><span id="L-734"><a href="#L-734"><span class="linenos">734</span></a> <span class="k">return</span> <span class="n">rename_func</span><span class="p">(</span><span class="n">name</span><span class="p">)(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">)</span> +</span><span id="L-735"><a href="#L-735"><span class="linenos">735</span></a> +</span><span id="L-736"><a href="#L-736"><span class="linenos">736</span></a> +</span><span id="L-737"><a href="#L-737"><span class="linenos">737</span></a><span class="k">def</span> <span class="nf">max_or_greatest</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Max</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-738"><a href="#L-738"><span class="linenos">738</span></a> <span class="n">name</span> <span class="o">=</span> <span class="s2">"GREATEST"</span> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> <span class="k">else</span> <span class="s2">"MAX"</span> +</span><span id="L-739"><a href="#L-739"><span class="linenos">739</span></a> <span class="k">return</span> <span class="n">rename_func</span><span class="p">(</span><span class="n">name</span><span class="p">)(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">)</span> +</span><span id="L-740"><a href="#L-740"><span class="linenos">740</span></a> </span><span id="L-741"><a href="#L-741"><span class="linenos">741</span></a> -</span><span id="L-742"><a href="#L-742"><span class="linenos">742</span></a> <span class="k">if</span> <span class="nb">isinstance</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">Distinct</span><span class="p">):</span> -</span><span id="L-743"><a href="#L-743"><span class="linenos">743</span></a> <span class="n">cond</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> -</span><span id="L-744"><a href="#L-744"><span class="linenos">744</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"DISTINCT is not supported when converting COUNT_IF to SUM"</span><span class="p">)</span> -</span><span id="L-745"><a href="#L-745"><span class="linenos">745</span></a> -</span><span id="L-746"><a href="#L-746"><span class="linenos">746</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">"sum"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"if"</span><span class="p">,</span> <span class="n">cond</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> -</span><span id="L-747"><a href="#L-747"><span class="linenos">747</span></a> +</span><span id="L-742"><a href="#L-742"><span class="linenos">742</span></a><span class="k">def</span> <span class="nf">count_if_to_sum</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">CountIf</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-743"><a href="#L-743"><span class="linenos">743</span></a> <span class="n">cond</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="L-744"><a href="#L-744"><span class="linenos">744</span></a> +</span><span id="L-745"><a href="#L-745"><span class="linenos">745</span></a> <span class="k">if</span> <span class="nb">isinstance</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">Distinct</span><span class="p">):</span> +</span><span id="L-746"><a href="#L-746"><span class="linenos">746</span></a> <span class="n">cond</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> +</span><span id="L-747"><a href="#L-747"><span class="linenos">747</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"DISTINCT is not supported when converting COUNT_IF to SUM"</span><span class="p">)</span> </span><span id="L-748"><a href="#L-748"><span class="linenos">748</span></a> -</span><span id="L-749"><a href="#L-749"><span class="linenos">749</span></a><span class="k">def</span> <span class="nf">trim_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Trim</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-750"><a href="#L-750"><span class="linenos">750</span></a> <span class="n">target</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> -</span><span id="L-751"><a href="#L-751"><span class="linenos">751</span></a> <span class="n">trim_type</span> <span class="o">=</span> <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">"position"</span><span class="p">)</span> -</span><span id="L-752"><a href="#L-752"><span class="linenos">752</span></a> <span class="n">remove_chars</span> <span class="o">=</span> <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">"expression"</span><span class="p">)</span> -</span><span id="L-753"><a href="#L-753"><span class="linenos">753</span></a> <span class="n">collation</span> <span class="o">=</span> <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">"collation"</span><span class="p">)</span> -</span><span id="L-754"><a href="#L-754"><span class="linenos">754</span></a> -</span><span id="L-755"><a href="#L-755"><span class="linenos">755</span></a> <span class="c1"># Use TRIM/LTRIM/RTRIM syntax if the expression isn't database-specific</span> -</span><span id="L-756"><a href="#L-756"><span class="linenos">756</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">remove_chars</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">collation</span><span class="p">:</span> -</span><span id="L-757"><a href="#L-757"><span class="linenos">757</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">trim_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="L-758"><a href="#L-758"><span class="linenos">758</span></a> -</span><span id="L-759"><a href="#L-759"><span class="linenos">759</span></a> <span class="n">trim_type</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">trim_type</span><span class="si">}</span><span class="s2"> "</span> <span class="k">if</span> <span class="n">trim_type</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="L-760"><a href="#L-760"><span class="linenos">760</span></a> <span class="n">remove_chars</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">remove_chars</span><span class="si">}</span><span class="s2"> "</span> <span class="k">if</span> <span class="n">remove_chars</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="L-761"><a href="#L-761"><span class="linenos">761</span></a> <span class="n">from_part</span> <span class="o">=</span> <span class="s2">"FROM "</span> <span class="k">if</span> <span class="n">trim_type</span> <span class="ow">or</span> <span class="n">remove_chars</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="L-762"><a href="#L-762"><span class="linenos">762</span></a> <span class="n">collation</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" COLLATE </span><span class="si">{</span><span class="n">collation</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">collation</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="L-763"><a href="#L-763"><span class="linenos">763</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"TRIM(</span><span class="si">{</span><span class="n">trim_type</span><span class="si">}{</span><span class="n">remove_chars</span><span class="si">}{</span><span class="n">from_part</span><span class="si">}{</span><span class="n">target</span><span class="si">}{</span><span class="n">collation</span><span class="si">}</span><span class="s2">)"</span> -</span><span id="L-764"><a href="#L-764"><span class="linenos">764</span></a> -</span><span id="L-765"><a href="#L-765"><span class="linenos">765</span></a> -</span><span id="L-766"><a href="#L-766"><span class="linenos">766</span></a><span class="k">def</span> <span class="nf">str_to_time_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-767"><a href="#L-767"><span class="linenos">767</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">"STRPTIME"</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="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-749"><a href="#L-749"><span class="linenos">749</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">"sum"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"if"</span><span class="p">,</span> <span class="n">cond</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> +</span><span id="L-750"><a href="#L-750"><span class="linenos">750</span></a> +</span><span id="L-751"><a href="#L-751"><span class="linenos">751</span></a> +</span><span id="L-752"><a href="#L-752"><span class="linenos">752</span></a><span class="k">def</span> <span class="nf">trim_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Trim</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-753"><a href="#L-753"><span class="linenos">753</span></a> <span class="n">target</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> +</span><span id="L-754"><a href="#L-754"><span class="linenos">754</span></a> <span class="n">trim_type</span> <span class="o">=</span> <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">"position"</span><span class="p">)</span> +</span><span id="L-755"><a href="#L-755"><span class="linenos">755</span></a> <span class="n">remove_chars</span> <span class="o">=</span> <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">"expression"</span><span class="p">)</span> +</span><span id="L-756"><a href="#L-756"><span class="linenos">756</span></a> <span class="n">collation</span> <span class="o">=</span> <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">"collation"</span><span class="p">)</span> +</span><span id="L-757"><a href="#L-757"><span class="linenos">757</span></a> +</span><span id="L-758"><a href="#L-758"><span class="linenos">758</span></a> <span class="c1"># Use TRIM/LTRIM/RTRIM syntax if the expression isn't database-specific</span> +</span><span id="L-759"><a href="#L-759"><span class="linenos">759</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">remove_chars</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">collation</span><span class="p">:</span> +</span><span id="L-760"><a href="#L-760"><span class="linenos">760</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">trim_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-761"><a href="#L-761"><span class="linenos">761</span></a> +</span><span id="L-762"><a href="#L-762"><span class="linenos">762</span></a> <span class="n">trim_type</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">trim_type</span><span class="si">}</span><span class="s2"> "</span> <span class="k">if</span> <span class="n">trim_type</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="L-763"><a href="#L-763"><span class="linenos">763</span></a> <span class="n">remove_chars</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">remove_chars</span><span class="si">}</span><span class="s2"> "</span> <span class="k">if</span> <span class="n">remove_chars</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="L-764"><a href="#L-764"><span class="linenos">764</span></a> <span class="n">from_part</span> <span class="o">=</span> <span class="s2">"FROM "</span> <span class="k">if</span> <span class="n">trim_type</span> <span class="ow">or</span> <span class="n">remove_chars</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="L-765"><a href="#L-765"><span class="linenos">765</span></a> <span class="n">collation</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" COLLATE </span><span class="si">{</span><span class="n">collation</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">collation</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="L-766"><a href="#L-766"><span class="linenos">766</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"TRIM(</span><span class="si">{</span><span class="n">trim_type</span><span class="si">}{</span><span class="n">remove_chars</span><span class="si">}{</span><span class="n">from_part</span><span class="si">}{</span><span class="n">target</span><span class="si">}{</span><span class="n">collation</span><span class="si">}</span><span class="s2">)"</span> +</span><span id="L-767"><a href="#L-767"><span class="linenos">767</span></a> </span><span id="L-768"><a href="#L-768"><span class="linenos">768</span></a> -</span><span id="L-769"><a href="#L-769"><span class="linenos">769</span></a> -</span><span id="L-770"><a href="#L-770"><span class="linenos">770</span></a><span class="k">def</span> <span class="nf">ts_or_ds_to_date_sql</span><span class="p">(</span><span class="n">dialect</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">:</span> -</span><span id="L-771"><a href="#L-771"><span class="linenos">771</span></a> <span class="k">def</span> <span class="nf">_ts_or_ds_to_date_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsToDate</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-772"><a href="#L-772"><span class="linenos">772</span></a> <span class="n">_dialect</span> <span class="o">=</span> <span class="n">Dialect</span><span class="o">.</span><span class="n">get_or_raise</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span> -</span><span id="L-773"><a href="#L-773"><span class="linenos">773</span></a> <span class="n">time_format</span> <span class="o">=</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-774"><a href="#L-774"><span class="linenos">774</span></a> <span class="k">if</span> <span class="n">time_format</span> <span class="ow">and</span> <span class="n">time_format</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="n">_dialect</span><span class="o">.</span><span class="n">TIME_FORMAT</span><span class="p">,</span> <span class="n">_dialect</span><span class="o">.</span><span class="n">DATE_FORMAT</span><span class="p">):</span> -</span><span id="L-775"><a href="#L-775"><span class="linenos">775</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> -</span><span id="L-776"><a href="#L-776"><span class="linenos">776</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span> -</span><span id="L-777"><a href="#L-777"><span class="linenos">777</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">StrToTime</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="nb">format</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">"format"</span><span class="p">]),</span> -</span><span id="L-778"><a href="#L-778"><span class="linenos">778</span></a> <span class="s2">"date"</span><span class="p">,</span> -</span><span id="L-779"><a href="#L-779"><span class="linenos">779</span></a> <span class="p">)</span> -</span><span id="L-780"><a href="#L-780"><span class="linenos">780</span></a> <span class="p">)</span> -</span><span id="L-781"><a href="#L-781"><span class="linenos">781</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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="s2">"date"</span><span class="p">))</span> -</span><span id="L-782"><a href="#L-782"><span class="linenos">782</span></a> -</span><span id="L-783"><a href="#L-783"><span class="linenos">783</span></a> <span class="k">return</span> <span class="n">_ts_or_ds_to_date_sql</span> -</span><span id="L-784"><a href="#L-784"><span class="linenos">784</span></a> +</span><span id="L-769"><a href="#L-769"><span class="linenos">769</span></a><span class="k">def</span> <span class="nf">str_to_time_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-770"><a href="#L-770"><span class="linenos">770</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">"STRPTIME"</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="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-771"><a href="#L-771"><span class="linenos">771</span></a> +</span><span id="L-772"><a href="#L-772"><span class="linenos">772</span></a> +</span><span id="L-773"><a href="#L-773"><span class="linenos">773</span></a><span class="k">def</span> <span class="nf">ts_or_ds_to_date_sql</span><span class="p">(</span><span class="n">dialect</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">:</span> +</span><span id="L-774"><a href="#L-774"><span class="linenos">774</span></a> <span class="k">def</span> <span class="nf">_ts_or_ds_to_date_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsToDate</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-775"><a href="#L-775"><span class="linenos">775</span></a> <span class="n">_dialect</span> <span class="o">=</span> <span class="n">Dialect</span><span class="o">.</span><span class="n">get_or_raise</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span> +</span><span id="L-776"><a href="#L-776"><span class="linenos">776</span></a> <span class="n">time_format</span> <span class="o">=</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-777"><a href="#L-777"><span class="linenos">777</span></a> <span class="k">if</span> <span class="n">time_format</span> <span class="ow">and</span> <span class="n">time_format</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="n">_dialect</span><span class="o">.</span><span class="n">TIME_FORMAT</span><span class="p">,</span> <span class="n">_dialect</span><span class="o">.</span><span class="n">DATE_FORMAT</span><span class="p">):</span> +</span><span id="L-778"><a href="#L-778"><span class="linenos">778</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> +</span><span id="L-779"><a href="#L-779"><span class="linenos">779</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span> +</span><span id="L-780"><a href="#L-780"><span class="linenos">780</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">StrToTime</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="nb">format</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">"format"</span><span class="p">]),</span> +</span><span id="L-781"><a href="#L-781"><span class="linenos">781</span></a> <span class="s2">"date"</span><span class="p">,</span> +</span><span id="L-782"><a href="#L-782"><span class="linenos">782</span></a> <span class="p">)</span> +</span><span id="L-783"><a href="#L-783"><span class="linenos">783</span></a> <span class="p">)</span> +</span><span id="L-784"><a href="#L-784"><span class="linenos">784</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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="s2">"date"</span><span class="p">))</span> </span><span id="L-785"><a href="#L-785"><span class="linenos">785</span></a> -</span><span id="L-786"><a href="#L-786"><span class="linenos">786</span></a><span class="k">def</span> <span class="nf">concat_to_dpipe_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Concat</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-787"><a href="#L-787"><span class="linenos">787</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DPipe</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">y</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-786"><a href="#L-786"><span class="linenos">786</span></a> <span class="k">return</span> <span class="n">_ts_or_ds_to_date_sql</span> +</span><span id="L-787"><a href="#L-787"><span class="linenos">787</span></a> </span><span id="L-788"><a href="#L-788"><span class="linenos">788</span></a> -</span><span id="L-789"><a href="#L-789"><span class="linenos">789</span></a> -</span><span id="L-790"><a href="#L-790"><span class="linenos">790</span></a><span class="k">def</span> <span class="nf">concat_ws_to_dpipe_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ConcatWs</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-791"><a href="#L-791"><span class="linenos">791</span></a> <span class="n">delim</span><span class="p">,</span> <span class="o">*</span><span class="n">rest_args</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> -</span><span id="L-792"><a href="#L-792"><span class="linenos">792</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> -</span><span id="L-793"><a href="#L-793"><span class="linenos">793</span></a> <span class="n">reduce</span><span class="p">(</span> -</span><span id="L-794"><a href="#L-794"><span class="linenos">794</span></a> <span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DPipe</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">DPipe</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">delim</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">y</span><span class="p">)),</span> -</span><span id="L-795"><a href="#L-795"><span class="linenos">795</span></a> <span class="n">rest_args</span><span class="p">,</span> -</span><span id="L-796"><a href="#L-796"><span class="linenos">796</span></a> <span class="p">)</span> -</span><span id="L-797"><a href="#L-797"><span class="linenos">797</span></a> <span class="p">)</span> -</span><span id="L-798"><a href="#L-798"><span class="linenos">798</span></a> -</span><span id="L-799"><a href="#L-799"><span class="linenos">799</span></a> -</span><span id="L-800"><a href="#L-800"><span class="linenos">800</span></a><span class="k">def</span> <span class="nf">regexp_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">RegexpExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-801"><a href="#L-801"><span class="linenos">801</span></a> <span class="n">bad_args</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="p">(</span><span class="s2">"position"</span><span class="p">,</span> <span class="s2">"occurrence"</span><span class="p">,</span> <span class="s2">"parameters"</span><span class="p">)))</span> -</span><span id="L-802"><a href="#L-802"><span class="linenos">802</span></a> <span class="k">if</span> <span class="n">bad_args</span><span class="p">:</span> -</span><span id="L-803"><a href="#L-803"><span class="linenos">803</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"REGEXP_EXTRACT does not support the following arg(s): </span><span class="si">{</span><span class="n">bad_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="L-804"><a href="#L-804"><span class="linenos">804</span></a> -</span><span id="L-805"><a href="#L-805"><span class="linenos">805</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-806"><a href="#L-806"><span class="linenos">806</span></a> <span class="s2">"REGEXP_EXTRACT"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"group"</span><span class="p">)</span> -</span><span id="L-807"><a href="#L-807"><span class="linenos">807</span></a> <span class="p">)</span> -</span><span id="L-808"><a href="#L-808"><span class="linenos">808</span></a> -</span><span id="L-809"><a href="#L-809"><span class="linenos">809</span></a> -</span><span id="L-810"><a href="#L-810"><span class="linenos">810</span></a><span class="k">def</span> <span class="nf">regexp_replace_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">RegexpReplace</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-811"><a href="#L-811"><span class="linenos">811</span></a> <span class="n">bad_args</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span> -</span><span id="L-812"><a href="#L-812"><span class="linenos">812</span></a> <span class="nb">filter</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="p">(</span><span class="s2">"position"</span><span class="p">,</span> <span class="s2">"occurrence"</span><span class="p">,</span> <span class="s2">"parameters"</span><span class="p">,</span> <span class="s2">"modifiers"</span><span class="p">))</span> -</span><span id="L-813"><a href="#L-813"><span class="linenos">813</span></a> <span class="p">)</span> -</span><span id="L-814"><a href="#L-814"><span class="linenos">814</span></a> <span class="k">if</span> <span class="n">bad_args</span><span class="p">:</span> -</span><span id="L-815"><a href="#L-815"><span class="linenos">815</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"REGEXP_REPLACE does not support the following arg(s): </span><span class="si">{</span><span class="n">bad_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="L-816"><a href="#L-816"><span class="linenos">816</span></a> -</span><span id="L-817"><a href="#L-817"><span class="linenos">817</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-818"><a href="#L-818"><span class="linenos">818</span></a> <span class="s2">"REGEXP_REPLACE"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"replacement"</span><span class="p">]</span> -</span><span id="L-819"><a href="#L-819"><span class="linenos">819</span></a> <span class="p">)</span> -</span><span id="L-820"><a href="#L-820"><span class="linenos">820</span></a> -</span><span id="L-821"><a href="#L-821"><span class="linenos">821</span></a> -</span><span id="L-822"><a href="#L-822"><span class="linenos">822</span></a><span class="k">def</span> <span class="nf">pivot_column_names</span><span class="p">(</span><span class="n">aggregations</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">],</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> -</span><span id="L-823"><a href="#L-823"><span class="linenos">823</span></a> <span class="n">names</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="L-824"><a href="#L-824"><span class="linenos">824</span></a> <span class="k">for</span> <span class="n">agg</span> <span class="ow">in</span> <span class="n">aggregations</span><span class="p">:</span> -</span><span id="L-825"><a href="#L-825"><span class="linenos">825</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">agg</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Alias</span><span class="p">):</span> -</span><span id="L-826"><a href="#L-826"><span class="linenos">826</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg</span><span class="o">.</span><span class="n">alias</span><span class="p">)</span> -</span><span id="L-827"><a href="#L-827"><span class="linenos">827</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="L-828"><a href="#L-828"><span class="linenos">828</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-829"><a href="#L-829"><span class="linenos">829</span></a><span class="sd"> This case corresponds to aggregations without aliases being used as suffixes</span> -</span><span id="L-830"><a href="#L-830"><span class="linenos">830</span></a><span class="sd"> (e.g. col_avg(foo)). We need to unquote identifiers because they're going to</span> -</span><span id="L-831"><a href="#L-831"><span class="linenos">831</span></a><span class="sd"> be quoted in the base parser's `_parse_pivot` method, due to `to_identifier`.</span> -</span><span id="L-832"><a href="#L-832"><span class="linenos">832</span></a><span class="sd"> Otherwise, we'd end up with `col_avg(`foo`)` (notice the double quotes).</span> -</span><span id="L-833"><a href="#L-833"><span class="linenos">833</span></a><span class="sd"> """</span> -</span><span id="L-834"><a href="#L-834"><span class="linenos">834</span></a> <span class="n">agg_all_unquoted</span> <span class="o">=</span> <span class="n">agg</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span> -</span><span id="L-835"><a href="#L-835"><span class="linenos">835</span></a> <span class="k">lambda</span> <span class="n">node</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">quoted</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> -</span><span id="L-836"><a href="#L-836"><span class="linenos">836</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">)</span> -</span><span id="L-837"><a href="#L-837"><span class="linenos">837</span></a> <span class="k">else</span> <span class="n">node</span> -</span><span id="L-838"><a href="#L-838"><span class="linenos">838</span></a> <span class="p">)</span> -</span><span id="L-839"><a href="#L-839"><span class="linenos">839</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg_all_unquoted</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span> <span class="n">normalize_functions</span><span class="o">=</span><span class="s2">"lower"</span><span class="p">))</span> -</span><span id="L-840"><a href="#L-840"><span class="linenos">840</span></a> -</span><span id="L-841"><a href="#L-841"><span class="linenos">841</span></a> <span class="k">return</span> <span class="n">names</span> -</span><span id="L-842"><a href="#L-842"><span class="linenos">842</span></a> +</span><span id="L-789"><a href="#L-789"><span class="linenos">789</span></a><span class="k">def</span> <span class="nf">concat_to_dpipe_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Concat</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-790"><a href="#L-790"><span class="linenos">790</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DPipe</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">y</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-791"><a href="#L-791"><span class="linenos">791</span></a> +</span><span id="L-792"><a href="#L-792"><span class="linenos">792</span></a> +</span><span id="L-793"><a href="#L-793"><span class="linenos">793</span></a><span class="k">def</span> <span class="nf">concat_ws_to_dpipe_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ConcatWs</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-794"><a href="#L-794"><span class="linenos">794</span></a> <span class="n">delim</span><span class="p">,</span> <span class="o">*</span><span class="n">rest_args</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="L-795"><a href="#L-795"><span class="linenos">795</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> +</span><span id="L-796"><a href="#L-796"><span class="linenos">796</span></a> <span class="n">reduce</span><span class="p">(</span> +</span><span id="L-797"><a href="#L-797"><span class="linenos">797</span></a> <span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DPipe</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">DPipe</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">delim</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">y</span><span class="p">)),</span> +</span><span id="L-798"><a href="#L-798"><span class="linenos">798</span></a> <span class="n">rest_args</span><span class="p">,</span> +</span><span id="L-799"><a href="#L-799"><span class="linenos">799</span></a> <span class="p">)</span> +</span><span id="L-800"><a href="#L-800"><span class="linenos">800</span></a> <span class="p">)</span> +</span><span id="L-801"><a href="#L-801"><span class="linenos">801</span></a> +</span><span id="L-802"><a href="#L-802"><span class="linenos">802</span></a> +</span><span id="L-803"><a href="#L-803"><span class="linenos">803</span></a><span class="k">def</span> <span class="nf">regexp_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">RegexpExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-804"><a href="#L-804"><span class="linenos">804</span></a> <span class="n">bad_args</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="p">(</span><span class="s2">"position"</span><span class="p">,</span> <span class="s2">"occurrence"</span><span class="p">,</span> <span class="s2">"parameters"</span><span class="p">)))</span> +</span><span id="L-805"><a href="#L-805"><span class="linenos">805</span></a> <span class="k">if</span> <span class="n">bad_args</span><span class="p">:</span> +</span><span id="L-806"><a href="#L-806"><span class="linenos">806</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"REGEXP_EXTRACT does not support the following arg(s): </span><span class="si">{</span><span class="n">bad_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="L-807"><a href="#L-807"><span class="linenos">807</span></a> +</span><span id="L-808"><a href="#L-808"><span class="linenos">808</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-809"><a href="#L-809"><span class="linenos">809</span></a> <span class="s2">"REGEXP_EXTRACT"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"group"</span><span class="p">)</span> +</span><span id="L-810"><a href="#L-810"><span class="linenos">810</span></a> <span class="p">)</span> +</span><span id="L-811"><a href="#L-811"><span class="linenos">811</span></a> +</span><span id="L-812"><a href="#L-812"><span class="linenos">812</span></a> +</span><span id="L-813"><a href="#L-813"><span class="linenos">813</span></a><span class="k">def</span> <span class="nf">regexp_replace_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">RegexpReplace</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-814"><a href="#L-814"><span class="linenos">814</span></a> <span class="n">bad_args</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span> +</span><span id="L-815"><a href="#L-815"><span class="linenos">815</span></a> <span class="nb">filter</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="p">(</span><span class="s2">"position"</span><span class="p">,</span> <span class="s2">"occurrence"</span><span class="p">,</span> <span class="s2">"parameters"</span><span class="p">,</span> <span class="s2">"modifiers"</span><span class="p">))</span> +</span><span id="L-816"><a href="#L-816"><span class="linenos">816</span></a> <span class="p">)</span> +</span><span id="L-817"><a href="#L-817"><span class="linenos">817</span></a> <span class="k">if</span> <span class="n">bad_args</span><span class="p">:</span> +</span><span id="L-818"><a href="#L-818"><span class="linenos">818</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"REGEXP_REPLACE does not support the following arg(s): </span><span class="si">{</span><span class="n">bad_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="L-819"><a href="#L-819"><span class="linenos">819</span></a> +</span><span id="L-820"><a href="#L-820"><span class="linenos">820</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-821"><a href="#L-821"><span class="linenos">821</span></a> <span class="s2">"REGEXP_REPLACE"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"replacement"</span><span class="p">]</span> +</span><span id="L-822"><a href="#L-822"><span class="linenos">822</span></a> <span class="p">)</span> +</span><span id="L-823"><a href="#L-823"><span class="linenos">823</span></a> +</span><span id="L-824"><a href="#L-824"><span class="linenos">824</span></a> +</span><span id="L-825"><a href="#L-825"><span class="linenos">825</span></a><span class="k">def</span> <span class="nf">pivot_column_names</span><span class="p">(</span><span class="n">aggregations</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">],</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="L-826"><a href="#L-826"><span class="linenos">826</span></a> <span class="n">names</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="L-827"><a href="#L-827"><span class="linenos">827</span></a> <span class="k">for</span> <span class="n">agg</span> <span class="ow">in</span> <span class="n">aggregations</span><span class="p">:</span> +</span><span id="L-828"><a href="#L-828"><span class="linenos">828</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">agg</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Alias</span><span class="p">):</span> +</span><span id="L-829"><a href="#L-829"><span class="linenos">829</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg</span><span class="o">.</span><span class="n">alias</span><span class="p">)</span> +</span><span id="L-830"><a href="#L-830"><span class="linenos">830</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="L-831"><a href="#L-831"><span class="linenos">831</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-832"><a href="#L-832"><span class="linenos">832</span></a><span class="sd"> This case corresponds to aggregations without aliases being used as suffixes</span> +</span><span id="L-833"><a href="#L-833"><span class="linenos">833</span></a><span class="sd"> (e.g. col_avg(foo)). We need to unquote identifiers because they're going to</span> +</span><span id="L-834"><a href="#L-834"><span class="linenos">834</span></a><span class="sd"> be quoted in the base parser's `_parse_pivot` method, due to `to_identifier`.</span> +</span><span id="L-835"><a href="#L-835"><span class="linenos">835</span></a><span class="sd"> Otherwise, we'd end up with `col_avg(`foo`)` (notice the double quotes).</span> +</span><span id="L-836"><a href="#L-836"><span class="linenos">836</span></a><span class="sd"> """</span> +</span><span id="L-837"><a href="#L-837"><span class="linenos">837</span></a> <span class="n">agg_all_unquoted</span> <span class="o">=</span> <span class="n">agg</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span> +</span><span id="L-838"><a href="#L-838"><span class="linenos">838</span></a> <span class="k">lambda</span> <span class="n">node</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">quoted</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span><span id="L-839"><a href="#L-839"><span class="linenos">839</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">)</span> +</span><span id="L-840"><a href="#L-840"><span class="linenos">840</span></a> <span class="k">else</span> <span class="n">node</span> +</span><span id="L-841"><a href="#L-841"><span class="linenos">841</span></a> <span class="p">)</span> +</span><span id="L-842"><a href="#L-842"><span class="linenos">842</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg_all_unquoted</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span> <span class="n">normalize_functions</span><span class="o">=</span><span class="s2">"lower"</span><span class="p">))</span> </span><span id="L-843"><a href="#L-843"><span class="linenos">843</span></a> -</span><span id="L-844"><a href="#L-844"><span class="linenos">844</span></a><span class="k">def</span> <span class="nf">binary_from_function</span><span class="p">(</span><span class="n">expr_type</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">B</span><span class="p">])</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">B</span><span class="p">]:</span> -</span><span id="L-845"><a href="#L-845"><span class="linenos">845</span></a> <span class="k">return</span> <span class="k">lambda</span> <span class="n">args</span><span class="p">:</span> <span class="n">expr_type</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">expression</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span> +</span><span id="L-844"><a href="#L-844"><span class="linenos">844</span></a> <span class="k">return</span> <span class="n">names</span> +</span><span id="L-845"><a href="#L-845"><span class="linenos">845</span></a> </span><span id="L-846"><a href="#L-846"><span class="linenos">846</span></a> -</span><span id="L-847"><a href="#L-847"><span class="linenos">847</span></a> -</span><span id="L-848"><a href="#L-848"><span class="linenos">848</span></a><span class="c1"># Used to represent DATE_TRUNC in Doris, Postgres and Starrocks dialects</span> -</span><span id="L-849"><a href="#L-849"><span class="linenos">849</span></a><span class="k">def</span> <span class="nf">parse_timestamp_trunc</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">:</span> -</span><span id="L-850"><a href="#L-850"><span class="linenos">850</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">unit</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> -</span><span id="L-851"><a href="#L-851"><span class="linenos">851</span></a> -</span><span id="L-852"><a href="#L-852"><span class="linenos">852</span></a> -</span><span id="L-853"><a href="#L-853"><span class="linenos">853</span></a><span class="k">def</span> <span class="nf">any_value_to_max_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">AnyValue</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-854"><a href="#L-854"><span class="linenos">854</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">"MAX"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> +</span><span id="L-847"><a href="#L-847"><span class="linenos">847</span></a><span class="k">def</span> <span class="nf">binary_from_function</span><span class="p">(</span><span class="n">expr_type</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">B</span><span class="p">])</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">B</span><span class="p">]:</span> +</span><span id="L-848"><a href="#L-848"><span class="linenos">848</span></a> <span class="k">return</span> <span class="k">lambda</span> <span class="n">args</span><span class="p">:</span> <span class="n">expr_type</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">expression</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span> +</span><span id="L-849"><a href="#L-849"><span class="linenos">849</span></a> +</span><span id="L-850"><a href="#L-850"><span class="linenos">850</span></a> +</span><span id="L-851"><a href="#L-851"><span class="linenos">851</span></a><span class="c1"># Used to represent DATE_TRUNC in Doris, Postgres and Starrocks dialects</span> +</span><span id="L-852"><a href="#L-852"><span class="linenos">852</span></a><span class="k">def</span> <span class="nf">parse_timestamp_trunc</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">:</span> +</span><span id="L-853"><a href="#L-853"><span class="linenos">853</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">unit</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> +</span><span id="L-854"><a href="#L-854"><span class="linenos">854</span></a> </span><span id="L-855"><a href="#L-855"><span class="linenos">855</span></a> -</span><span id="L-856"><a href="#L-856"><span class="linenos">856</span></a> -</span><span id="L-857"><a href="#L-857"><span class="linenos">857</span></a><span class="k">def</span> <span class="nf">bool_xor_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Xor</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-858"><a href="#L-858"><span class="linenos">858</span></a> <span class="n">a</span> <span class="o">=</span> <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="o">.</span><span class="n">left</span><span class="p">)</span> -</span><span id="L-859"><a href="#L-859"><span class="linenos">859</span></a> <span class="n">b</span> <span class="o">=</span> <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="o">.</span><span class="n">right</span><span class="p">)</span> -</span><span id="L-860"><a href="#L-860"><span class="linenos">860</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"(</span><span class="si">{</span><span class="n">a</span><span class="si">}</span><span class="s2"> AND (NOT </span><span class="si">{</span><span class="n">b</span><span class="si">}</span><span class="s2">)) OR ((NOT </span><span class="si">{</span><span class="n">a</span><span class="si">}</span><span class="s2">) AND </span><span class="si">{</span><span class="n">b</span><span class="si">}</span><span class="s2">)"</span> -</span><span id="L-861"><a href="#L-861"><span class="linenos">861</span></a> -</span><span id="L-862"><a href="#L-862"><span class="linenos">862</span></a> -</span><span id="L-863"><a href="#L-863"><span class="linenos">863</span></a><span class="c1"># Used to generate JSON_OBJECT with a comma in BigQuery and MySQL instead of colon</span> -</span><span id="L-864"><a href="#L-864"><span class="linenos">864</span></a><span class="k">def</span> <span class="nf">json_keyvalue_comma_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONKeyValue</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-865"><a href="#L-865"><span class="linenos">865</span></a> <span class="k">return</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">expression</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">expression</span><span class="p">,</span><span class="w"> </span><span class="s1">'expression'</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> -</span><span id="L-866"><a href="#L-866"><span class="linenos">866</span></a> -</span><span id="L-867"><a href="#L-867"><span class="linenos">867</span></a> -</span><span id="L-868"><a href="#L-868"><span class="linenos">868</span></a><span class="k">def</span> <span class="nf">is_parse_json</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="o">-></span> <span class="nb">bool</span><span class="p">:</span> -</span><span id="L-869"><a href="#L-869"><span class="linenos">869</span></a> <span class="k">return</span> <span class="nb">isinstance</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">ParseJSON</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span> -</span><span id="L-870"><a href="#L-870"><span class="linenos">870</span></a> <span class="nb">isinstance</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">Cast</span><span class="p">)</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"json"</span><span class="p">)</span> -</span><span id="L-871"><a href="#L-871"><span class="linenos">871</span></a> <span class="p">)</span> -</span><span id="L-872"><a href="#L-872"><span class="linenos">872</span></a> -</span><span id="L-873"><a href="#L-873"><span class="linenos">873</span></a> -</span><span id="L-874"><a href="#L-874"><span class="linenos">874</span></a><span class="k">def</span> <span class="nf">isnull_to_is_null</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">:</span> -</span><span id="L-875"><a href="#L-875"><span class="linenos">875</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Paren</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Is</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">null</span><span class="p">()))</span> +</span><span id="L-856"><a href="#L-856"><span class="linenos">856</span></a><span class="k">def</span> <span class="nf">any_value_to_max_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">AnyValue</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-857"><a href="#L-857"><span class="linenos">857</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">"MAX"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> +</span><span id="L-858"><a href="#L-858"><span class="linenos">858</span></a> +</span><span id="L-859"><a href="#L-859"><span class="linenos">859</span></a> +</span><span id="L-860"><a href="#L-860"><span class="linenos">860</span></a><span class="k">def</span> <span class="nf">bool_xor_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Xor</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-861"><a href="#L-861"><span class="linenos">861</span></a> <span class="n">a</span> <span class="o">=</span> <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="o">.</span><span class="n">left</span><span class="p">)</span> +</span><span id="L-862"><a href="#L-862"><span class="linenos">862</span></a> <span class="n">b</span> <span class="o">=</span> <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="o">.</span><span class="n">right</span><span class="p">)</span> +</span><span id="L-863"><a href="#L-863"><span class="linenos">863</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"(</span><span class="si">{</span><span class="n">a</span><span class="si">}</span><span class="s2"> AND (NOT </span><span class="si">{</span><span class="n">b</span><span class="si">}</span><span class="s2">)) OR ((NOT </span><span class="si">{</span><span class="n">a</span><span class="si">}</span><span class="s2">) AND </span><span class="si">{</span><span class="n">b</span><span class="si">}</span><span class="s2">)"</span> +</span><span id="L-864"><a href="#L-864"><span class="linenos">864</span></a> +</span><span id="L-865"><a href="#L-865"><span class="linenos">865</span></a> +</span><span id="L-866"><a href="#L-866"><span class="linenos">866</span></a><span class="c1"># Used to generate JSON_OBJECT with a comma in BigQuery and MySQL instead of colon</span> +</span><span id="L-867"><a href="#L-867"><span class="linenos">867</span></a><span class="k">def</span> <span class="nf">json_keyvalue_comma_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONKeyValue</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-868"><a href="#L-868"><span class="linenos">868</span></a> <span class="k">return</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">expression</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">expression</span><span class="p">,</span><span class="w"> </span><span class="s1">'expression'</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> +</span><span id="L-869"><a href="#L-869"><span class="linenos">869</span></a> +</span><span id="L-870"><a href="#L-870"><span class="linenos">870</span></a> +</span><span id="L-871"><a href="#L-871"><span class="linenos">871</span></a><span class="k">def</span> <span class="nf">is_parse_json</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="o">-></span> <span class="nb">bool</span><span class="p">:</span> +</span><span id="L-872"><a href="#L-872"><span class="linenos">872</span></a> <span class="k">return</span> <span class="nb">isinstance</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">ParseJSON</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span> +</span><span id="L-873"><a href="#L-873"><span class="linenos">873</span></a> <span class="nb">isinstance</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">Cast</span><span class="p">)</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"json"</span><span class="p">)</span> +</span><span id="L-874"><a href="#L-874"><span class="linenos">874</span></a> <span class="p">)</span> +</span><span id="L-875"><a href="#L-875"><span class="linenos">875</span></a> </span><span id="L-876"><a href="#L-876"><span class="linenos">876</span></a> -</span><span id="L-877"><a href="#L-877"><span class="linenos">877</span></a> -</span><span id="L-878"><a href="#L-878"><span class="linenos">878</span></a><span class="k">def</span> <span class="nf">generatedasidentitycolumnconstraint_sql</span><span class="p">(</span> -</span><span id="L-879"><a href="#L-879"><span class="linenos">879</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">GeneratedAsIdentityColumnConstraint</span> -</span><span id="L-880"><a href="#L-880"><span class="linenos">880</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-881"><a href="#L-881"><span class="linenos">881</span></a> <span class="n">start</span> <span class="o">=</span> <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">"start"</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">"1"</span> -</span><span id="L-882"><a href="#L-882"><span class="linenos">882</span></a> <span class="n">increment</span> <span class="o">=</span> <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">"increment"</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">"1"</span> -</span><span id="L-883"><a href="#L-883"><span class="linenos">883</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"IDENTITY(</span><span class="si">{</span><span class="n">start</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">increment</span><span class="si">}</span><span class="s2">)"</span> -</span><span id="L-884"><a href="#L-884"><span class="linenos">884</span></a> -</span><span id="L-885"><a href="#L-885"><span class="linenos">885</span></a> -</span><span id="L-886"><a href="#L-886"><span class="linenos">886</span></a><span class="k">def</span> <span class="nf">arg_max_or_min_no_count</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMax</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMin</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> -</span><span id="L-887"><a href="#L-887"><span class="linenos">887</span></a> <span class="k">def</span> <span class="nf">_arg_max_or_min_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMax</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMin</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-888"><a href="#L-888"><span class="linenos">888</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">"count"</span><span class="p">):</span> -</span><span id="L-889"><a href="#L-889"><span class="linenos">889</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Only two arguments are supported in function </span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">."</span><span class="p">)</span> -</span><span id="L-890"><a href="#L-890"><span class="linenos">890</span></a> -</span><span id="L-891"><a href="#L-891"><span class="linenos">891</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="n">name</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> -</span><span id="L-892"><a href="#L-892"><span class="linenos">892</span></a> -</span><span id="L-893"><a href="#L-893"><span class="linenos">893</span></a> <span class="k">return</span> <span class="n">_arg_max_or_min_sql</span> -</span><span id="L-894"><a href="#L-894"><span class="linenos">894</span></a> +</span><span id="L-877"><a href="#L-877"><span class="linenos">877</span></a><span class="k">def</span> <span class="nf">isnull_to_is_null</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">:</span> +</span><span id="L-878"><a href="#L-878"><span class="linenos">878</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Paren</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Is</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">null</span><span class="p">()))</span> +</span><span id="L-879"><a href="#L-879"><span class="linenos">879</span></a> +</span><span id="L-880"><a href="#L-880"><span class="linenos">880</span></a> +</span><span id="L-881"><a href="#L-881"><span class="linenos">881</span></a><span class="k">def</span> <span class="nf">generatedasidentitycolumnconstraint_sql</span><span class="p">(</span> +</span><span id="L-882"><a href="#L-882"><span class="linenos">882</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">GeneratedAsIdentityColumnConstraint</span> +</span><span id="L-883"><a href="#L-883"><span class="linenos">883</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-884"><a href="#L-884"><span class="linenos">884</span></a> <span class="n">start</span> <span class="o">=</span> <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">"start"</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">"1"</span> +</span><span id="L-885"><a href="#L-885"><span class="linenos">885</span></a> <span class="n">increment</span> <span class="o">=</span> <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">"increment"</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">"1"</span> +</span><span id="L-886"><a href="#L-886"><span class="linenos">886</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"IDENTITY(</span><span class="si">{</span><span class="n">start</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">increment</span><span class="si">}</span><span class="s2">)"</span> +</span><span id="L-887"><a href="#L-887"><span class="linenos">887</span></a> +</span><span id="L-888"><a href="#L-888"><span class="linenos">888</span></a> +</span><span id="L-889"><a href="#L-889"><span class="linenos">889</span></a><span class="k">def</span> <span class="nf">arg_max_or_min_no_count</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMax</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMin</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> +</span><span id="L-890"><a href="#L-890"><span class="linenos">890</span></a> <span class="k">def</span> <span class="nf">_arg_max_or_min_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMax</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMin</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-891"><a href="#L-891"><span class="linenos">891</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">"count"</span><span class="p">):</span> +</span><span id="L-892"><a href="#L-892"><span class="linenos">892</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Only two arguments are supported in function </span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">."</span><span class="p">)</span> +</span><span id="L-893"><a href="#L-893"><span class="linenos">893</span></a> +</span><span id="L-894"><a href="#L-894"><span class="linenos">894</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="n">name</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> </span><span id="L-895"><a href="#L-895"><span class="linenos">895</span></a> -</span><span id="L-896"><a href="#L-896"><span class="linenos">896</span></a><span class="k">def</span> <span class="nf">ts_or_ds_add_cast</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">TsOrDsAdd</span><span class="p">)</span> <span class="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsAdd</span><span class="p">:</span> -</span><span id="L-897"><a href="#L-897"><span class="linenos">897</span></a> <span class="n">this</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="L-896"><a href="#L-896"><span class="linenos">896</span></a> <span class="k">return</span> <span class="n">_arg_max_or_min_sql</span> +</span><span id="L-897"><a href="#L-897"><span class="linenos">897</span></a> </span><span id="L-898"><a href="#L-898"><span class="linenos">898</span></a> -</span><span id="L-899"><a href="#L-899"><span class="linenos">899</span></a> <span class="n">return_type</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">return_type</span> -</span><span id="L-900"><a href="#L-900"><span class="linenos">900</span></a> <span class="k">if</span> <span class="n">return_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">DATE</span><span class="p">):</span> -</span><span id="L-901"><a href="#L-901"><span class="linenos">901</span></a> <span class="c1"># If we need to cast to a DATE, we cast to TIMESTAMP first to make sure we</span> -</span><span id="L-902"><a href="#L-902"><span class="linenos">902</span></a> <span class="c1"># can truncate timestamp strings, because some dialects can't cast them to DATE</span> -</span><span id="L-903"><a href="#L-903"><span class="linenos">903</span></a> <span class="n">this</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">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">TIMESTAMP</span><span class="p">)</span> -</span><span id="L-904"><a href="#L-904"><span class="linenos">904</span></a> -</span><span id="L-905"><a href="#L-905"><span class="linenos">905</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">this</span><span class="p">,</span> <span class="n">return_type</span><span class="p">))</span> -</span><span id="L-906"><a href="#L-906"><span class="linenos">906</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="L-899"><a href="#L-899"><span class="linenos">899</span></a><span class="k">def</span> <span class="nf">ts_or_ds_add_cast</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">TsOrDsAdd</span><span class="p">)</span> <span class="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsAdd</span><span class="p">:</span> +</span><span id="L-900"><a href="#L-900"><span class="linenos">900</span></a> <span class="n">this</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="L-901"><a href="#L-901"><span class="linenos">901</span></a> +</span><span id="L-902"><a href="#L-902"><span class="linenos">902</span></a> <span class="n">return_type</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">return_type</span> +</span><span id="L-903"><a href="#L-903"><span class="linenos">903</span></a> <span class="k">if</span> <span class="n">return_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">DATE</span><span class="p">):</span> +</span><span id="L-904"><a href="#L-904"><span class="linenos">904</span></a> <span class="c1"># If we need to cast to a DATE, we cast to TIMESTAMP first to make sure we</span> +</span><span id="L-905"><a href="#L-905"><span class="linenos">905</span></a> <span class="c1"># can truncate timestamp strings, because some dialects can't cast them to DATE</span> +</span><span id="L-906"><a href="#L-906"><span class="linenos">906</span></a> <span class="n">this</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">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">TIMESTAMP</span><span class="p">)</span> </span><span id="L-907"><a href="#L-907"><span class="linenos">907</span></a> -</span><span id="L-908"><a href="#L-908"><span class="linenos">908</span></a> -</span><span id="L-909"><a href="#L-909"><span class="linenos">909</span></a><span class="k">def</span> <span class="nf">date_delta_sql</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">cast</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">DATE_ADD_OR_DIFF</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> -</span><span id="L-910"><a href="#L-910"><span class="linenos">910</span></a> <span class="k">def</span> <span class="nf">_delta_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">DATE_ADD_OR_DIFF</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-911"><a href="#L-911"><span class="linenos">911</span></a> <span class="k">if</span> <span class="n">cast</span> <span class="ow">and</span> <span class="nb">isinstance</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">TsOrDsAdd</span><span class="p">):</span> -</span><span id="L-912"><a href="#L-912"><span class="linenos">912</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">ts_or_ds_add_cast</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="L-913"><a href="#L-913"><span class="linenos">913</span></a> -</span><span id="L-914"><a href="#L-914"><span class="linenos">914</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-915"><a href="#L-915"><span class="linenos">915</span></a> <span class="n">name</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</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="ow">or</span> <span class="s2">"day"</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> -</span><span id="L-916"><a href="#L-916"><span class="linenos">916</span></a> <span class="p">)</span> -</span><span id="L-917"><a href="#L-917"><span class="linenos">917</span></a> -</span><span id="L-918"><a href="#L-918"><span class="linenos">918</span></a> <span class="k">return</span> <span class="n">_delta_sql</span> +</span><span id="L-908"><a href="#L-908"><span class="linenos">908</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">this</span><span class="p">,</span> <span class="n">return_type</span><span class="p">))</span> +</span><span id="L-909"><a href="#L-909"><span class="linenos">909</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="L-910"><a href="#L-910"><span class="linenos">910</span></a> +</span><span id="L-911"><a href="#L-911"><span class="linenos">911</span></a> +</span><span id="L-912"><a href="#L-912"><span class="linenos">912</span></a><span class="k">def</span> <span class="nf">date_delta_sql</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">cast</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">DATE_ADD_OR_DIFF</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> +</span><span id="L-913"><a href="#L-913"><span class="linenos">913</span></a> <span class="k">def</span> <span class="nf">_delta_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">DATE_ADD_OR_DIFF</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-914"><a href="#L-914"><span class="linenos">914</span></a> <span class="k">if</span> <span class="n">cast</span> <span class="ow">and</span> <span class="nb">isinstance</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">TsOrDsAdd</span><span class="p">):</span> +</span><span id="L-915"><a href="#L-915"><span class="linenos">915</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">ts_or_ds_add_cast</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-916"><a href="#L-916"><span class="linenos">916</span></a> +</span><span id="L-917"><a href="#L-917"><span class="linenos">917</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-918"><a href="#L-918"><span class="linenos">918</span></a> <span class="n">name</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</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="ow">or</span> <span class="s2">"day"</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="L-919"><a href="#L-919"><span class="linenos">919</span></a> <span class="p">)</span> +</span><span id="L-920"><a href="#L-920"><span class="linenos">920</span></a> +</span><span id="L-921"><a href="#L-921"><span class="linenos">921</span></a> <span class="k">return</span> <span class="n">_delta_sql</span> </span></pre></div> @@ -1998,237 +2004,240 @@ </span><span id="Dialect-178"><a href="#Dialect-178"><span class="linenos">178</span></a> <span class="c1"># True means 1 / 0 returns null.</span> </span><span id="Dialect-179"><a href="#Dialect-179"><span class="linenos">179</span></a> <span class="n">SAFE_DIVISION</span> <span class="o">=</span> <span class="kc">False</span> </span><span id="Dialect-180"><a href="#Dialect-180"><span class="linenos">180</span></a> -</span><span id="Dialect-181"><a href="#Dialect-181"><span class="linenos">181</span></a> <span class="n">DATE_FORMAT</span> <span class="o">=</span> <span class="s2">"'%Y-%m-</span><span class="si">%d</span><span class="s2">'"</span> -</span><span id="Dialect-182"><a href="#Dialect-182"><span class="linenos">182</span></a> <span class="n">DATEINT_FORMAT</span> <span class="o">=</span> <span class="s2">"'%Y%m</span><span class="si">%d</span><span class="s2">'"</span> -</span><span id="Dialect-183"><a href="#Dialect-183"><span class="linenos">183</span></a> <span class="n">TIME_FORMAT</span> <span class="o">=</span> <span class="s2">"'%Y-%m-</span><span class="si">%d</span><span class="s2"> %H:%M:%S'"</span> -</span><span id="Dialect-184"><a href="#Dialect-184"><span class="linenos">184</span></a> -</span><span id="Dialect-185"><a href="#Dialect-185"><span class="linenos">185</span></a> <span class="c1"># Custom time mappings in which the key represents dialect time format</span> -</span><span id="Dialect-186"><a href="#Dialect-186"><span class="linenos">186</span></a> <span class="c1"># and the value represents a python time format</span> -</span><span id="Dialect-187"><a href="#Dialect-187"><span class="linenos">187</span></a> <span class="n">TIME_MAPPING</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="Dialect-188"><a href="#Dialect-188"><span class="linenos">188</span></a> -</span><span id="Dialect-189"><a href="#Dialect-189"><span class="linenos">189</span></a> <span class="c1"># https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#format_model_rules_date_time</span> -</span><span id="Dialect-190"><a href="#Dialect-190"><span class="linenos">190</span></a> <span class="c1"># https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Data-Type-Conversions/Character-to-DATE-Conversion/Forcing-a-FORMAT-on-CAST-for-Converting-Character-to-DATE</span> -</span><span id="Dialect-191"><a href="#Dialect-191"><span class="linenos">191</span></a> <span class="c1"># special syntax cast(x as date format 'yyyy') defaults to time_mapping</span> -</span><span id="Dialect-192"><a href="#Dialect-192"><span class="linenos">192</span></a> <span class="n">FORMAT_MAPPING</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="Dialect-193"><a href="#Dialect-193"><span class="linenos">193</span></a> -</span><span id="Dialect-194"><a href="#Dialect-194"><span class="linenos">194</span></a> <span class="c1"># Mapping of an unescaped escape sequence to the corresponding character</span> -</span><span id="Dialect-195"><a href="#Dialect-195"><span class="linenos">195</span></a> <span class="n">ESCAPE_SEQUENCES</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="Dialect-181"><a href="#Dialect-181"><span class="linenos">181</span></a> <span class="c1"># A NULL arg in CONCAT yields NULL by default, but in some dialects it yields an empty string</span> +</span><span id="Dialect-182"><a href="#Dialect-182"><span class="linenos">182</span></a> <span class="n">CONCAT_COALESCE</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Dialect-183"><a href="#Dialect-183"><span class="linenos">183</span></a> +</span><span id="Dialect-184"><a href="#Dialect-184"><span class="linenos">184</span></a> <span class="n">DATE_FORMAT</span> <span class="o">=</span> <span class="s2">"'%Y-%m-</span><span class="si">%d</span><span class="s2">'"</span> +</span><span id="Dialect-185"><a href="#Dialect-185"><span class="linenos">185</span></a> <span class="n">DATEINT_FORMAT</span> <span class="o">=</span> <span class="s2">"'%Y%m</span><span class="si">%d</span><span class="s2">'"</span> +</span><span id="Dialect-186"><a href="#Dialect-186"><span class="linenos">186</span></a> <span class="n">TIME_FORMAT</span> <span class="o">=</span> <span class="s2">"'%Y-%m-</span><span class="si">%d</span><span class="s2"> %H:%M:%S'"</span> +</span><span id="Dialect-187"><a href="#Dialect-187"><span class="linenos">187</span></a> +</span><span id="Dialect-188"><a href="#Dialect-188"><span class="linenos">188</span></a> <span class="c1"># Custom time mappings in which the key represents dialect time format</span> +</span><span id="Dialect-189"><a href="#Dialect-189"><span class="linenos">189</span></a> <span class="c1"># and the value represents a python time format</span> +</span><span id="Dialect-190"><a href="#Dialect-190"><span class="linenos">190</span></a> <span class="n">TIME_MAPPING</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="Dialect-191"><a href="#Dialect-191"><span class="linenos">191</span></a> +</span><span id="Dialect-192"><a href="#Dialect-192"><span class="linenos">192</span></a> <span class="c1"># https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#format_model_rules_date_time</span> +</span><span id="Dialect-193"><a href="#Dialect-193"><span class="linenos">193</span></a> <span class="c1"># https://docs.teradata.com/r/Teradata-Database-SQL-Functions-Operators-Expressions-and-Predicates/March-2017/Data-Type-Conversions/Character-to-DATE-Conversion/Forcing-a-FORMAT-on-CAST-for-Converting-Character-to-DATE</span> +</span><span id="Dialect-194"><a href="#Dialect-194"><span class="linenos">194</span></a> <span class="c1"># special syntax cast(x as date format 'yyyy') defaults to time_mapping</span> +</span><span id="Dialect-195"><a href="#Dialect-195"><span class="linenos">195</span></a> <span class="n">FORMAT_MAPPING</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> </span><span id="Dialect-196"><a href="#Dialect-196"><span class="linenos">196</span></a> -</span><span id="Dialect-197"><a href="#Dialect-197"><span class="linenos">197</span></a> <span class="c1"># Columns that are auto-generated by the engine corresponding to this dialect</span> -</span><span id="Dialect-198"><a href="#Dialect-198"><span class="linenos">198</span></a> <span class="c1"># Such columns may be excluded from SELECT * queries, for example</span> -</span><span id="Dialect-199"><a href="#Dialect-199"><span class="linenos">199</span></a> <span class="n">PSEUDOCOLUMNS</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Set</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span> -</span><span id="Dialect-200"><a href="#Dialect-200"><span class="linenos">200</span></a> -</span><span id="Dialect-201"><a href="#Dialect-201"><span class="linenos">201</span></a> <span class="c1"># --- Autofilled ---</span> -</span><span id="Dialect-202"><a href="#Dialect-202"><span class="linenos">202</span></a> -</span><span id="Dialect-203"><a href="#Dialect-203"><span class="linenos">203</span></a> <span class="n">tokenizer_class</span> <span class="o">=</span> <span class="n">Tokenizer</span> -</span><span id="Dialect-204"><a href="#Dialect-204"><span class="linenos">204</span></a> <span class="n">parser_class</span> <span class="o">=</span> <span class="n">Parser</span> -</span><span id="Dialect-205"><a href="#Dialect-205"><span class="linenos">205</span></a> <span class="n">generator_class</span> <span class="o">=</span> <span class="n">Generator</span> -</span><span id="Dialect-206"><a href="#Dialect-206"><span class="linenos">206</span></a> -</span><span id="Dialect-207"><a href="#Dialect-207"><span class="linenos">207</span></a> <span class="c1"># A trie of the time_mapping keys</span> -</span><span id="Dialect-208"><a href="#Dialect-208"><span class="linenos">208</span></a> <span class="n">TIME_TRIE</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="Dialect-209"><a href="#Dialect-209"><span class="linenos">209</span></a> <span class="n">FORMAT_TRIE</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="Dialect-210"><a href="#Dialect-210"><span class="linenos">210</span></a> -</span><span id="Dialect-211"><a href="#Dialect-211"><span class="linenos">211</span></a> <span class="n">INVERSE_TIME_MAPPING</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="Dialect-212"><a href="#Dialect-212"><span class="linenos">212</span></a> <span class="n">INVERSE_TIME_TRIE</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="Dialect-197"><a href="#Dialect-197"><span class="linenos">197</span></a> <span class="c1"># Mapping of an unescaped escape sequence to the corresponding character</span> +</span><span id="Dialect-198"><a href="#Dialect-198"><span class="linenos">198</span></a> <span class="n">ESCAPE_SEQUENCES</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="Dialect-199"><a href="#Dialect-199"><span class="linenos">199</span></a> +</span><span id="Dialect-200"><a href="#Dialect-200"><span class="linenos">200</span></a> <span class="c1"># Columns that are auto-generated by the engine corresponding to this dialect</span> +</span><span id="Dialect-201"><a href="#Dialect-201"><span class="linenos">201</span></a> <span class="c1"># Such columns may be excluded from SELECT * queries, for example</span> +</span><span id="Dialect-202"><a href="#Dialect-202"><span class="linenos">202</span></a> <span class="n">PSEUDOCOLUMNS</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Set</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span> +</span><span id="Dialect-203"><a href="#Dialect-203"><span class="linenos">203</span></a> +</span><span id="Dialect-204"><a href="#Dialect-204"><span class="linenos">204</span></a> <span class="c1"># --- Autofilled ---</span> +</span><span id="Dialect-205"><a href="#Dialect-205"><span class="linenos">205</span></a> +</span><span id="Dialect-206"><a href="#Dialect-206"><span class="linenos">206</span></a> <span class="n">tokenizer_class</span> <span class="o">=</span> <span class="n">Tokenizer</span> +</span><span id="Dialect-207"><a href="#Dialect-207"><span class="linenos">207</span></a> <span class="n">parser_class</span> <span class="o">=</span> <span class="n">Parser</span> +</span><span id="Dialect-208"><a href="#Dialect-208"><span class="linenos">208</span></a> <span class="n">generator_class</span> <span class="o">=</span> <span class="n">Generator</span> +</span><span id="Dialect-209"><a href="#Dialect-209"><span class="linenos">209</span></a> +</span><span id="Dialect-210"><a href="#Dialect-210"><span class="linenos">210</span></a> <span class="c1"># A trie of the time_mapping keys</span> +</span><span id="Dialect-211"><a href="#Dialect-211"><span class="linenos">211</span></a> <span class="n">TIME_TRIE</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="Dialect-212"><a href="#Dialect-212"><span class="linenos">212</span></a> <span class="n">FORMAT_TRIE</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">=</span> <span class="p">{}</span> </span><span id="Dialect-213"><a href="#Dialect-213"><span class="linenos">213</span></a> -</span><span id="Dialect-214"><a href="#Dialect-214"><span class="linenos">214</span></a> <span class="n">INVERSE_ESCAPE_SEQUENCES</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="Dialect-215"><a href="#Dialect-215"><span class="linenos">215</span></a> -</span><span id="Dialect-216"><a href="#Dialect-216"><span class="linenos">216</span></a> <span class="c1"># Delimiters for quotes, identifiers and the corresponding escape characters</span> -</span><span id="Dialect-217"><a href="#Dialect-217"><span class="linenos">217</span></a> <span class="n">QUOTE_START</span> <span class="o">=</span> <span class="s2">"'"</span> -</span><span id="Dialect-218"><a href="#Dialect-218"><span class="linenos">218</span></a> <span class="n">QUOTE_END</span> <span class="o">=</span> <span class="s2">"'"</span> -</span><span id="Dialect-219"><a href="#Dialect-219"><span class="linenos">219</span></a> <span class="n">IDENTIFIER_START</span> <span class="o">=</span> <span class="s1">'"'</span> -</span><span id="Dialect-220"><a href="#Dialect-220"><span class="linenos">220</span></a> <span class="n">IDENTIFIER_END</span> <span class="o">=</span> <span class="s1">'"'</span> -</span><span id="Dialect-221"><a href="#Dialect-221"><span class="linenos">221</span></a> -</span><span id="Dialect-222"><a href="#Dialect-222"><span class="linenos">222</span></a> <span class="c1"># Delimiters for bit, hex and byte literals</span> -</span><span id="Dialect-223"><a href="#Dialect-223"><span class="linenos">223</span></a> <span class="n">BIT_START</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="Dialect-224"><a href="#Dialect-224"><span class="linenos">224</span></a> <span class="n">BIT_END</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="Dialect-225"><a href="#Dialect-225"><span class="linenos">225</span></a> <span class="n">HEX_START</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="Dialect-226"><a href="#Dialect-226"><span class="linenos">226</span></a> <span class="n">HEX_END</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="Dialect-227"><a href="#Dialect-227"><span class="linenos">227</span></a> <span class="n">BYTE_START</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="Dialect-228"><a href="#Dialect-228"><span class="linenos">228</span></a> <span class="n">BYTE_END</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="Dialect-229"><a href="#Dialect-229"><span class="linenos">229</span></a> -</span><span id="Dialect-230"><a href="#Dialect-230"><span class="linenos">230</span></a> <span class="nd">@classmethod</span> -</span><span id="Dialect-231"><a href="#Dialect-231"><span class="linenos">231</span></a> <span class="k">def</span> <span class="nf">get_or_raise</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">Dialect</span><span class="p">:</span> -</span><span id="Dialect-232"><a href="#Dialect-232"><span class="linenos">232</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect-233"><a href="#Dialect-233"><span class="linenos">233</span></a><span class="sd"> Look up a dialect in the global dialect registry and return it if it exists.</span> -</span><span id="Dialect-234"><a href="#Dialect-234"><span class="linenos">234</span></a> -</span><span id="Dialect-235"><a href="#Dialect-235"><span class="linenos">235</span></a><span class="sd"> Args:</span> -</span><span id="Dialect-236"><a href="#Dialect-236"><span class="linenos">236</span></a><span class="sd"> dialect: The target dialect. If this is a string, it can be optionally followed by</span> -</span><span id="Dialect-237"><a href="#Dialect-237"><span class="linenos">237</span></a><span class="sd"> additional key-value pairs that are separated by commas and are used to specify</span> -</span><span id="Dialect-238"><a href="#Dialect-238"><span class="linenos">238</span></a><span class="sd"> dialect settings, such as whether the dialect's identifiers are case-sensitive.</span> -</span><span id="Dialect-239"><a href="#Dialect-239"><span class="linenos">239</span></a> -</span><span id="Dialect-240"><a href="#Dialect-240"><span class="linenos">240</span></a><span class="sd"> Example:</span> -</span><span id="Dialect-241"><a href="#Dialect-241"><span class="linenos">241</span></a><span class="sd"> >>> dialect = dialect_class = get_or_raise("duckdb")</span> -</span><span id="Dialect-242"><a href="#Dialect-242"><span class="linenos">242</span></a><span class="sd"> >>> dialect = get_or_raise("mysql, normalization_strategy = case_sensitive")</span> -</span><span id="Dialect-243"><a href="#Dialect-243"><span class="linenos">243</span></a> -</span><span id="Dialect-244"><a href="#Dialect-244"><span class="linenos">244</span></a><span class="sd"> Returns:</span> -</span><span id="Dialect-245"><a href="#Dialect-245"><span class="linenos">245</span></a><span class="sd"> The corresponding Dialect instance.</span> -</span><span id="Dialect-246"><a href="#Dialect-246"><span class="linenos">246</span></a><span class="sd"> """</span> -</span><span id="Dialect-247"><a href="#Dialect-247"><span class="linenos">247</span></a> -</span><span id="Dialect-248"><a href="#Dialect-248"><span class="linenos">248</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">dialect</span><span class="p">:</span> -</span><span id="Dialect-249"><a href="#Dialect-249"><span class="linenos">249</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span> -</span><span id="Dialect-250"><a href="#Dialect-250"><span class="linenos">250</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="n">_Dialect</span><span class="p">):</span> -</span><span id="Dialect-251"><a href="#Dialect-251"><span class="linenos">251</span></a> <span class="k">return</span> <span class="n">dialect</span><span class="p">()</span> -</span><span id="Dialect-252"><a href="#Dialect-252"><span class="linenos">252</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="n">Dialect</span><span class="p">):</span> -</span><span id="Dialect-253"><a href="#Dialect-253"><span class="linenos">253</span></a> <span class="k">return</span> <span class="n">dialect</span> -</span><span id="Dialect-254"><a href="#Dialect-254"><span class="linenos">254</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> -</span><span id="Dialect-255"><a href="#Dialect-255"><span class="linenos">255</span></a> <span class="k">try</span><span class="p">:</span> -</span><span id="Dialect-256"><a href="#Dialect-256"><span class="linenos">256</span></a> <span class="n">dialect_name</span><span class="p">,</span> <span class="o">*</span><span class="n">kv_pairs</span> <span class="o">=</span> <span class="n">dialect</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">)</span> -</span><span id="Dialect-257"><a href="#Dialect-257"><span class="linenos">257</span></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="n">v</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="p">(</span><span class="n">kv</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">"="</span><span class="p">)</span> <span class="k">for</span> <span class="n">kv</span> <span class="ow">in</span> <span class="n">kv_pairs</span><span class="p">)}</span> -</span><span id="Dialect-258"><a href="#Dialect-258"><span class="linenos">258</span></a> <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> -</span><span id="Dialect-259"><a href="#Dialect-259"><span class="linenos">259</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> -</span><span id="Dialect-260"><a href="#Dialect-260"><span class="linenos">260</span></a> <span class="sa">f</span><span class="s2">"Invalid dialect format: '</span><span class="si">{</span><span class="n">dialect</span><span class="si">}</span><span class="s2">'. "</span> -</span><span id="Dialect-261"><a href="#Dialect-261"><span class="linenos">261</span></a> <span class="s2">"Please use the correct format: 'dialect [, k1 = v2 [, ...]]'."</span> -</span><span id="Dialect-262"><a href="#Dialect-262"><span class="linenos">262</span></a> <span class="p">)</span> -</span><span id="Dialect-263"><a href="#Dialect-263"><span class="linenos">263</span></a> -</span><span id="Dialect-264"><a href="#Dialect-264"><span class="linenos">264</span></a> <span class="n">result</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">dialect_name</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> -</span><span id="Dialect-265"><a href="#Dialect-265"><span class="linenos">265</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">result</span><span class="p">:</span> -</span><span id="Dialect-266"><a href="#Dialect-266"><span class="linenos">266</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unknown dialect '</span><span class="si">{</span><span class="n">dialect_name</span><span class="si">}</span><span class="s2">'."</span><span class="p">)</span> -</span><span id="Dialect-267"><a href="#Dialect-267"><span class="linenos">267</span></a> -</span><span id="Dialect-268"><a href="#Dialect-268"><span class="linenos">268</span></a> <span class="k">return</span> <span class="n">result</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> -</span><span id="Dialect-269"><a href="#Dialect-269"><span class="linenos">269</span></a> -</span><span id="Dialect-270"><a href="#Dialect-270"><span class="linenos">270</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid dialect type for '</span><span class="si">{</span><span class="n">dialect</span><span class="si">}</span><span class="s2">': '</span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span><span class="si">}</span><span class="s2">'."</span><span class="p">)</span> -</span><span id="Dialect-271"><a href="#Dialect-271"><span class="linenos">271</span></a> -</span><span id="Dialect-272"><a href="#Dialect-272"><span class="linenos">272</span></a> <span class="nd">@classmethod</span> -</span><span id="Dialect-273"><a href="#Dialect-273"><span class="linenos">273</span></a> <span class="k">def</span> <span class="nf">format_time</span><span class="p">(</span> -</span><span id="Dialect-274"><a href="#Dialect-274"><span class="linenos">274</span></a> <span class="bp">cls</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]</span> -</span><span id="Dialect-275"><a href="#Dialect-275"><span class="linenos">275</span></a> <span class="p">)</span> <span class="o">-></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">Expression</span><span class="p">]:</span> -</span><span id="Dialect-276"><a href="#Dialect-276"><span class="linenos">276</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> -</span><span id="Dialect-277"><a href="#Dialect-277"><span class="linenos">277</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span> -</span><span id="Dialect-278"><a href="#Dialect-278"><span class="linenos">278</span></a> <span class="c1"># the time formats are quoted</span> -</span><span id="Dialect-279"><a href="#Dialect-279"><span class="linenos">279</span></a> <span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_TRIE</span><span class="p">)</span> -</span><span id="Dialect-280"><a href="#Dialect-280"><span class="linenos">280</span></a> <span class="p">)</span> -</span><span id="Dialect-281"><a href="#Dialect-281"><span class="linenos">281</span></a> -</span><span id="Dialect-282"><a href="#Dialect-282"><span class="linenos">282</span></a> <span class="k">if</span> <span class="n">expression</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_string</span><span class="p">:</span> -</span><span id="Dialect-283"><a href="#Dialect-283"><span class="linenos">283</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="n">format_time</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="bp">cls</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_TRIE</span><span class="p">))</span> +</span><span id="Dialect-214"><a href="#Dialect-214"><span class="linenos">214</span></a> <span class="n">INVERSE_TIME_MAPPING</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="Dialect-215"><a href="#Dialect-215"><span class="linenos">215</span></a> <span class="n">INVERSE_TIME_TRIE</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="Dialect-216"><a href="#Dialect-216"><span class="linenos">216</span></a> +</span><span id="Dialect-217"><a href="#Dialect-217"><span class="linenos">217</span></a> <span class="n">INVERSE_ESCAPE_SEQUENCES</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="Dialect-218"><a href="#Dialect-218"><span class="linenos">218</span></a> +</span><span id="Dialect-219"><a href="#Dialect-219"><span class="linenos">219</span></a> <span class="c1"># Delimiters for quotes, identifiers and the corresponding escape characters</span> +</span><span id="Dialect-220"><a href="#Dialect-220"><span class="linenos">220</span></a> <span class="n">QUOTE_START</span> <span class="o">=</span> <span class="s2">"'"</span> +</span><span id="Dialect-221"><a href="#Dialect-221"><span class="linenos">221</span></a> <span class="n">QUOTE_END</span> <span class="o">=</span> <span class="s2">"'"</span> +</span><span id="Dialect-222"><a href="#Dialect-222"><span class="linenos">222</span></a> <span class="n">IDENTIFIER_START</span> <span class="o">=</span> <span class="s1">'"'</span> +</span><span id="Dialect-223"><a href="#Dialect-223"><span class="linenos">223</span></a> <span class="n">IDENTIFIER_END</span> <span class="o">=</span> <span class="s1">'"'</span> +</span><span id="Dialect-224"><a href="#Dialect-224"><span class="linenos">224</span></a> +</span><span id="Dialect-225"><a href="#Dialect-225"><span class="linenos">225</span></a> <span class="c1"># Delimiters for bit, hex and byte literals</span> +</span><span id="Dialect-226"><a href="#Dialect-226"><span class="linenos">226</span></a> <span class="n">BIT_START</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="Dialect-227"><a href="#Dialect-227"><span class="linenos">227</span></a> <span class="n">BIT_END</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="Dialect-228"><a href="#Dialect-228"><span class="linenos">228</span></a> <span class="n">HEX_START</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="Dialect-229"><a href="#Dialect-229"><span class="linenos">229</span></a> <span class="n">HEX_END</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="Dialect-230"><a href="#Dialect-230"><span class="linenos">230</span></a> <span class="n">BYTE_START</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="Dialect-231"><a href="#Dialect-231"><span class="linenos">231</span></a> <span class="n">BYTE_END</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="Dialect-232"><a href="#Dialect-232"><span class="linenos">232</span></a> +</span><span id="Dialect-233"><a href="#Dialect-233"><span class="linenos">233</span></a> <span class="nd">@classmethod</span> +</span><span id="Dialect-234"><a href="#Dialect-234"><span class="linenos">234</span></a> <span class="k">def</span> <span class="nf">get_or_raise</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">Dialect</span><span class="p">:</span> +</span><span id="Dialect-235"><a href="#Dialect-235"><span class="linenos">235</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect-236"><a href="#Dialect-236"><span class="linenos">236</span></a><span class="sd"> Look up a dialect in the global dialect registry and return it if it exists.</span> +</span><span id="Dialect-237"><a href="#Dialect-237"><span class="linenos">237</span></a> +</span><span id="Dialect-238"><a href="#Dialect-238"><span class="linenos">238</span></a><span class="sd"> Args:</span> +</span><span id="Dialect-239"><a href="#Dialect-239"><span class="linenos">239</span></a><span class="sd"> dialect: The target dialect. If this is a string, it can be optionally followed by</span> +</span><span id="Dialect-240"><a href="#Dialect-240"><span class="linenos">240</span></a><span class="sd"> additional key-value pairs that are separated by commas and are used to specify</span> +</span><span id="Dialect-241"><a href="#Dialect-241"><span class="linenos">241</span></a><span class="sd"> dialect settings, such as whether the dialect's identifiers are case-sensitive.</span> +</span><span id="Dialect-242"><a href="#Dialect-242"><span class="linenos">242</span></a> +</span><span id="Dialect-243"><a href="#Dialect-243"><span class="linenos">243</span></a><span class="sd"> Example:</span> +</span><span id="Dialect-244"><a href="#Dialect-244"><span class="linenos">244</span></a><span class="sd"> >>> dialect = dialect_class = get_or_raise("duckdb")</span> +</span><span id="Dialect-245"><a href="#Dialect-245"><span class="linenos">245</span></a><span class="sd"> >>> dialect = get_or_raise("mysql, normalization_strategy = case_sensitive")</span> +</span><span id="Dialect-246"><a href="#Dialect-246"><span class="linenos">246</span></a> +</span><span id="Dialect-247"><a href="#Dialect-247"><span class="linenos">247</span></a><span class="sd"> Returns:</span> +</span><span id="Dialect-248"><a href="#Dialect-248"><span class="linenos">248</span></a><span class="sd"> The corresponding Dialect instance.</span> +</span><span id="Dialect-249"><a href="#Dialect-249"><span class="linenos">249</span></a><span class="sd"> """</span> +</span><span id="Dialect-250"><a href="#Dialect-250"><span class="linenos">250</span></a> +</span><span id="Dialect-251"><a href="#Dialect-251"><span class="linenos">251</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">dialect</span><span class="p">:</span> +</span><span id="Dialect-252"><a href="#Dialect-252"><span class="linenos">252</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span> +</span><span id="Dialect-253"><a href="#Dialect-253"><span class="linenos">253</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="n">_Dialect</span><span class="p">):</span> +</span><span id="Dialect-254"><a href="#Dialect-254"><span class="linenos">254</span></a> <span class="k">return</span> <span class="n">dialect</span><span class="p">()</span> +</span><span id="Dialect-255"><a href="#Dialect-255"><span class="linenos">255</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="n">Dialect</span><span class="p">):</span> +</span><span id="Dialect-256"><a href="#Dialect-256"><span class="linenos">256</span></a> <span class="k">return</span> <span class="n">dialect</span> +</span><span id="Dialect-257"><a href="#Dialect-257"><span class="linenos">257</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="Dialect-258"><a href="#Dialect-258"><span class="linenos">258</span></a> <span class="k">try</span><span class="p">:</span> +</span><span id="Dialect-259"><a href="#Dialect-259"><span class="linenos">259</span></a> <span class="n">dialect_name</span><span class="p">,</span> <span class="o">*</span><span class="n">kv_pairs</span> <span class="o">=</span> <span class="n">dialect</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">)</span> +</span><span id="Dialect-260"><a href="#Dialect-260"><span class="linenos">260</span></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="n">v</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="p">(</span><span class="n">kv</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">"="</span><span class="p">)</span> <span class="k">for</span> <span class="n">kv</span> <span class="ow">in</span> <span class="n">kv_pairs</span><span class="p">)}</span> +</span><span id="Dialect-261"><a href="#Dialect-261"><span class="linenos">261</span></a> <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> +</span><span id="Dialect-262"><a href="#Dialect-262"><span class="linenos">262</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> +</span><span id="Dialect-263"><a href="#Dialect-263"><span class="linenos">263</span></a> <span class="sa">f</span><span class="s2">"Invalid dialect format: '</span><span class="si">{</span><span class="n">dialect</span><span class="si">}</span><span class="s2">'. "</span> +</span><span id="Dialect-264"><a href="#Dialect-264"><span class="linenos">264</span></a> <span class="s2">"Please use the correct format: 'dialect [, k1 = v2 [, ...]]'."</span> +</span><span id="Dialect-265"><a href="#Dialect-265"><span class="linenos">265</span></a> <span class="p">)</span> +</span><span id="Dialect-266"><a href="#Dialect-266"><span class="linenos">266</span></a> +</span><span id="Dialect-267"><a href="#Dialect-267"><span class="linenos">267</span></a> <span class="n">result</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">dialect_name</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> +</span><span id="Dialect-268"><a href="#Dialect-268"><span class="linenos">268</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">result</span><span class="p">:</span> +</span><span id="Dialect-269"><a href="#Dialect-269"><span class="linenos">269</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unknown dialect '</span><span class="si">{</span><span class="n">dialect_name</span><span class="si">}</span><span class="s2">'."</span><span class="p">)</span> +</span><span id="Dialect-270"><a href="#Dialect-270"><span class="linenos">270</span></a> +</span><span id="Dialect-271"><a href="#Dialect-271"><span class="linenos">271</span></a> <span class="k">return</span> <span class="n">result</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span><span id="Dialect-272"><a href="#Dialect-272"><span class="linenos">272</span></a> +</span><span id="Dialect-273"><a href="#Dialect-273"><span class="linenos">273</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid dialect type for '</span><span class="si">{</span><span class="n">dialect</span><span class="si">}</span><span class="s2">': '</span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span><span class="si">}</span><span class="s2">'."</span><span class="p">)</span> +</span><span id="Dialect-274"><a href="#Dialect-274"><span class="linenos">274</span></a> +</span><span id="Dialect-275"><a href="#Dialect-275"><span class="linenos">275</span></a> <span class="nd">@classmethod</span> +</span><span id="Dialect-276"><a href="#Dialect-276"><span class="linenos">276</span></a> <span class="k">def</span> <span class="nf">format_time</span><span class="p">(</span> +</span><span id="Dialect-277"><a href="#Dialect-277"><span class="linenos">277</span></a> <span class="bp">cls</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]</span> +</span><span id="Dialect-278"><a href="#Dialect-278"><span class="linenos">278</span></a> <span class="p">)</span> <span class="o">-></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">Expression</span><span class="p">]:</span> +</span><span id="Dialect-279"><a href="#Dialect-279"><span class="linenos">279</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="Dialect-280"><a href="#Dialect-280"><span class="linenos">280</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span> +</span><span id="Dialect-281"><a href="#Dialect-281"><span class="linenos">281</span></a> <span class="c1"># the time formats are quoted</span> +</span><span id="Dialect-282"><a href="#Dialect-282"><span class="linenos">282</span></a> <span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_TRIE</span><span class="p">)</span> +</span><span id="Dialect-283"><a href="#Dialect-283"><span class="linenos">283</span></a> <span class="p">)</span> </span><span id="Dialect-284"><a href="#Dialect-284"><span class="linenos">284</span></a> -</span><span id="Dialect-285"><a href="#Dialect-285"><span class="linenos">285</span></a> <span class="k">return</span> <span class="n">expression</span> -</span><span id="Dialect-286"><a href="#Dialect-286"><span class="linenos">286</span></a> -</span><span id="Dialect-287"><a href="#Dialect-287"><span class="linenos">287</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Dialect-288"><a href="#Dialect-288"><span class="linenos">288</span></a> <span class="n">normalization_strategy</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"normalization_strategy"</span><span class="p">)</span> +</span><span id="Dialect-285"><a href="#Dialect-285"><span class="linenos">285</span></a> <span class="k">if</span> <span class="n">expression</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_string</span><span class="p">:</span> +</span><span id="Dialect-286"><a href="#Dialect-286"><span class="linenos">286</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="n">format_time</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="bp">cls</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_TRIE</span><span class="p">))</span> +</span><span id="Dialect-287"><a href="#Dialect-287"><span class="linenos">287</span></a> +</span><span id="Dialect-288"><a href="#Dialect-288"><span class="linenos">288</span></a> <span class="k">return</span> <span class="n">expression</span> </span><span id="Dialect-289"><a href="#Dialect-289"><span class="linenos">289</span></a> -</span><span id="Dialect-290"><a href="#Dialect-290"><span class="linenos">290</span></a> <span class="k">if</span> <span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Dialect-291"><a href="#Dialect-291"><span class="linenos">291</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">NORMALIZATION_STRATEGY</span> -</span><span id="Dialect-292"><a href="#Dialect-292"><span class="linenos">292</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Dialect-293"><a href="#Dialect-293"><span class="linenos">293</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="o">=</span> <span class="n">NormalizationStrategy</span><span class="p">(</span><span class="n">normalization_strategy</span><span class="o">.</span><span class="n">upper</span><span class="p">())</span> -</span><span id="Dialect-294"><a href="#Dialect-294"><span class="linenos">294</span></a> -</span><span id="Dialect-295"><a href="#Dialect-295"><span class="linenos">295</span></a> <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> -</span><span id="Dialect-296"><a href="#Dialect-296"><span class="linenos">296</span></a> <span class="c1"># Does not currently take dialect state into account</span> -</span><span id="Dialect-297"><a href="#Dialect-297"><span class="linenos">297</span></a> <span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">==</span> <span class="n">other</span> -</span><span id="Dialect-298"><a href="#Dialect-298"><span class="linenos">298</span></a> -</span><span id="Dialect-299"><a href="#Dialect-299"><span class="linenos">299</span></a> <span class="k">def</span> <span class="fm">__hash__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">int</span><span class="p">:</span> -</span><span id="Dialect-300"><a href="#Dialect-300"><span class="linenos">300</span></a> <span class="c1"># Does not currently take dialect state into account</span> -</span><span id="Dialect-301"><a href="#Dialect-301"><span class="linenos">301</span></a> <span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span> -</span><span id="Dialect-302"><a href="#Dialect-302"><span class="linenos">302</span></a> -</span><span id="Dialect-303"><a href="#Dialect-303"><span class="linenos">303</span></a> <span class="k">def</span> <span class="nf">normalize_identifier</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">E</span><span class="p">)</span> <span class="o">-></span> <span class="n">E</span><span class="p">:</span> -</span><span id="Dialect-304"><a href="#Dialect-304"><span class="linenos">304</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect-305"><a href="#Dialect-305"><span class="linenos">305</span></a><span class="sd"> Transforms an identifier in a way that resembles how it'd be resolved by this dialect.</span> -</span><span id="Dialect-306"><a href="#Dialect-306"><span class="linenos">306</span></a> -</span><span id="Dialect-307"><a href="#Dialect-307"><span class="linenos">307</span></a><span class="sd"> For example, an identifier like FoO would be resolved as foo in Postgres, because it</span> -</span><span id="Dialect-308"><a href="#Dialect-308"><span class="linenos">308</span></a><span class="sd"> lowercases all unquoted identifiers. On the other hand, Snowflake uppercases them, so</span> -</span><span id="Dialect-309"><a href="#Dialect-309"><span class="linenos">309</span></a><span class="sd"> it would resolve it as FOO. If it was quoted, it'd need to be treated as case-sensitive,</span> -</span><span id="Dialect-310"><a href="#Dialect-310"><span class="linenos">310</span></a><span class="sd"> and so any normalization would be prohibited in order to avoid "breaking" the identifier.</span> -</span><span id="Dialect-311"><a href="#Dialect-311"><span class="linenos">311</span></a> -</span><span id="Dialect-312"><a href="#Dialect-312"><span class="linenos">312</span></a><span class="sd"> There are also dialects like Spark, which are case-insensitive even when quotes are</span> -</span><span id="Dialect-313"><a href="#Dialect-313"><span class="linenos">313</span></a><span class="sd"> present, and dialects like MySQL, whose resolution rules match those employed by the</span> -</span><span id="Dialect-314"><a href="#Dialect-314"><span class="linenos">314</span></a><span class="sd"> underlying operating system, for example they may always be case-sensitive in Linux.</span> -</span><span id="Dialect-315"><a href="#Dialect-315"><span class="linenos">315</span></a> -</span><span id="Dialect-316"><a href="#Dialect-316"><span class="linenos">316</span></a><span class="sd"> Finally, the normalization behavior of some engines can even be controlled through flags,</span> -</span><span id="Dialect-317"><a href="#Dialect-317"><span class="linenos">317</span></a><span class="sd"> like in Redshift's case, where users can explicitly set enable_case_sensitive_identifier.</span> +</span><span id="Dialect-290"><a href="#Dialect-290"><span class="linenos">290</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Dialect-291"><a href="#Dialect-291"><span class="linenos">291</span></a> <span class="n">normalization_strategy</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"normalization_strategy"</span><span class="p">)</span> +</span><span id="Dialect-292"><a href="#Dialect-292"><span class="linenos">292</span></a> +</span><span id="Dialect-293"><a href="#Dialect-293"><span class="linenos">293</span></a> <span class="k">if</span> <span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Dialect-294"><a href="#Dialect-294"><span class="linenos">294</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">NORMALIZATION_STRATEGY</span> +</span><span id="Dialect-295"><a href="#Dialect-295"><span class="linenos">295</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Dialect-296"><a href="#Dialect-296"><span class="linenos">296</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="o">=</span> <span class="n">NormalizationStrategy</span><span class="p">(</span><span class="n">normalization_strategy</span><span class="o">.</span><span class="n">upper</span><span class="p">())</span> +</span><span id="Dialect-297"><a href="#Dialect-297"><span class="linenos">297</span></a> +</span><span id="Dialect-298"><a href="#Dialect-298"><span class="linenos">298</span></a> <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Any</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> +</span><span id="Dialect-299"><a href="#Dialect-299"><span class="linenos">299</span></a> <span class="c1"># Does not currently take dialect state into account</span> +</span><span id="Dialect-300"><a href="#Dialect-300"><span class="linenos">300</span></a> <span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">==</span> <span class="n">other</span> +</span><span id="Dialect-301"><a href="#Dialect-301"><span class="linenos">301</span></a> +</span><span id="Dialect-302"><a href="#Dialect-302"><span class="linenos">302</span></a> <span class="k">def</span> <span class="fm">__hash__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">int</span><span class="p">:</span> +</span><span id="Dialect-303"><a href="#Dialect-303"><span class="linenos">303</span></a> <span class="c1"># Does not currently take dialect state into account</span> +</span><span id="Dialect-304"><a href="#Dialect-304"><span class="linenos">304</span></a> <span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span> +</span><span id="Dialect-305"><a href="#Dialect-305"><span class="linenos">305</span></a> +</span><span id="Dialect-306"><a href="#Dialect-306"><span class="linenos">306</span></a> <span class="k">def</span> <span class="nf">normalize_identifier</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">E</span><span class="p">)</span> <span class="o">-></span> <span class="n">E</span><span class="p">:</span> +</span><span id="Dialect-307"><a href="#Dialect-307"><span class="linenos">307</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect-308"><a href="#Dialect-308"><span class="linenos">308</span></a><span class="sd"> Transforms an identifier in a way that resembles how it'd be resolved by this dialect.</span> +</span><span id="Dialect-309"><a href="#Dialect-309"><span class="linenos">309</span></a> +</span><span id="Dialect-310"><a href="#Dialect-310"><span class="linenos">310</span></a><span class="sd"> For example, an identifier like FoO would be resolved as foo in Postgres, because it</span> +</span><span id="Dialect-311"><a href="#Dialect-311"><span class="linenos">311</span></a><span class="sd"> lowercases all unquoted identifiers. On the other hand, Snowflake uppercases them, so</span> +</span><span id="Dialect-312"><a href="#Dialect-312"><span class="linenos">312</span></a><span class="sd"> it would resolve it as FOO. If it was quoted, it'd need to be treated as case-sensitive,</span> +</span><span id="Dialect-313"><a href="#Dialect-313"><span class="linenos">313</span></a><span class="sd"> and so any normalization would be prohibited in order to avoid "breaking" the identifier.</span> +</span><span id="Dialect-314"><a href="#Dialect-314"><span class="linenos">314</span></a> +</span><span id="Dialect-315"><a href="#Dialect-315"><span class="linenos">315</span></a><span class="sd"> There are also dialects like Spark, which are case-insensitive even when quotes are</span> +</span><span id="Dialect-316"><a href="#Dialect-316"><span class="linenos">316</span></a><span class="sd"> present, and dialects like MySQL, whose resolution rules match those employed by the</span> +</span><span id="Dialect-317"><a href="#Dialect-317"><span class="linenos">317</span></a><span class="sd"> underlying operating system, for example they may always be case-sensitive in Linux.</span> </span><span id="Dialect-318"><a href="#Dialect-318"><span class="linenos">318</span></a> -</span><span id="Dialect-319"><a href="#Dialect-319"><span class="linenos">319</span></a><span class="sd"> SQLGlot aims to understand and handle all of these different behaviors gracefully, so</span> -</span><span id="Dialect-320"><a href="#Dialect-320"><span class="linenos">320</span></a><span class="sd"> that it can analyze queries in the optimizer and successfully capture their semantics.</span> -</span><span id="Dialect-321"><a href="#Dialect-321"><span class="linenos">321</span></a><span class="sd"> """</span> -</span><span id="Dialect-322"><a href="#Dialect-322"><span class="linenos">322</span></a> <span class="k">if</span> <span class="p">(</span> -</span><span id="Dialect-323"><a href="#Dialect-323"><span class="linenos">323</span></a> <span class="nb">isinstance</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">Identifier</span><span class="p">)</span> -</span><span id="Dialect-324"><a href="#Dialect-324"><span class="linenos">324</span></a> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_SENSITIVE</span> -</span><span id="Dialect-325"><a href="#Dialect-325"><span class="linenos">325</span></a> <span class="ow">and</span> <span class="p">(</span> -</span><span id="Dialect-326"><a href="#Dialect-326"><span class="linenos">326</span></a> <span class="ow">not</span> <span class="n">expression</span><span class="o">.</span><span class="n">quoted</span> -</span><span id="Dialect-327"><a href="#Dialect-327"><span class="linenos">327</span></a> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_INSENSITIVE</span> -</span><span id="Dialect-328"><a href="#Dialect-328"><span class="linenos">328</span></a> <span class="p">)</span> -</span><span id="Dialect-329"><a href="#Dialect-329"><span class="linenos">329</span></a> <span class="p">):</span> -</span><span id="Dialect-330"><a href="#Dialect-330"><span class="linenos">330</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> -</span><span id="Dialect-331"><a href="#Dialect-331"><span class="linenos">331</span></a> <span class="s2">"this"</span><span class="p">,</span> -</span><span id="Dialect-332"><a href="#Dialect-332"><span class="linenos">332</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> -</span><span id="Dialect-333"><a href="#Dialect-333"><span class="linenos">333</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">UPPERCASE</span> -</span><span id="Dialect-334"><a href="#Dialect-334"><span class="linenos">334</span></a> <span class="k">else</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> -</span><span id="Dialect-335"><a href="#Dialect-335"><span class="linenos">335</span></a> <span class="p">)</span> -</span><span id="Dialect-336"><a href="#Dialect-336"><span class="linenos">336</span></a> -</span><span id="Dialect-337"><a href="#Dialect-337"><span class="linenos">337</span></a> <span class="k">return</span> <span class="n">expression</span> -</span><span id="Dialect-338"><a href="#Dialect-338"><span class="linenos">338</span></a> -</span><span id="Dialect-339"><a href="#Dialect-339"><span class="linenos">339</span></a> <span class="k">def</span> <span class="nf">case_sensitive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> -</span><span id="Dialect-340"><a href="#Dialect-340"><span class="linenos">340</span></a><span class="w"> </span><span class="sd">"""Checks if text contains any case sensitive characters, based on the dialect's rules."""</span> -</span><span id="Dialect-341"><a href="#Dialect-341"><span class="linenos">341</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_INSENSITIVE</span><span class="p">:</span> -</span><span id="Dialect-342"><a href="#Dialect-342"><span class="linenos">342</span></a> <span class="k">return</span> <span class="kc">False</span> -</span><span id="Dialect-343"><a href="#Dialect-343"><span class="linenos">343</span></a> -</span><span id="Dialect-344"><a href="#Dialect-344"><span class="linenos">344</span></a> <span class="n">unsafe</span> <span class="o">=</span> <span class="p">(</span> -</span><span id="Dialect-345"><a href="#Dialect-345"><span class="linenos">345</span></a> <span class="nb">str</span><span class="o">.</span><span class="n">islower</span> -</span><span id="Dialect-346"><a href="#Dialect-346"><span class="linenos">346</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">UPPERCASE</span> -</span><span id="Dialect-347"><a href="#Dialect-347"><span class="linenos">347</span></a> <span class="k">else</span> <span class="nb">str</span><span class="o">.</span><span class="n">isupper</span> -</span><span id="Dialect-348"><a href="#Dialect-348"><span class="linenos">348</span></a> <span class="p">)</span> -</span><span id="Dialect-349"><a href="#Dialect-349"><span class="linenos">349</span></a> <span class="k">return</span> <span class="nb">any</span><span class="p">(</span><span class="n">unsafe</span><span class="p">(</span><span class="n">char</span><span class="p">)</span> <span class="k">for</span> <span class="n">char</span> <span class="ow">in</span> <span class="n">text</span><span class="p">)</span> -</span><span id="Dialect-350"><a href="#Dialect-350"><span class="linenos">350</span></a> -</span><span id="Dialect-351"><a href="#Dialect-351"><span class="linenos">351</span></a> <span class="k">def</span> <span class="nf">can_identify</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">identify</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">bool</span> <span class="o">=</span> <span class="s2">"safe"</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> -</span><span id="Dialect-352"><a href="#Dialect-352"><span class="linenos">352</span></a><span class="w"> </span><span class="sd">"""Checks if text can be identified given an identify option.</span> +</span><span id="Dialect-319"><a href="#Dialect-319"><span class="linenos">319</span></a><span class="sd"> Finally, the normalization behavior of some engines can even be controlled through flags,</span> +</span><span id="Dialect-320"><a href="#Dialect-320"><span class="linenos">320</span></a><span class="sd"> like in Redshift's case, where users can explicitly set enable_case_sensitive_identifier.</span> +</span><span id="Dialect-321"><a href="#Dialect-321"><span class="linenos">321</span></a> +</span><span id="Dialect-322"><a href="#Dialect-322"><span class="linenos">322</span></a><span class="sd"> SQLGlot aims to understand and handle all of these different behaviors gracefully, so</span> +</span><span id="Dialect-323"><a href="#Dialect-323"><span class="linenos">323</span></a><span class="sd"> that it can analyze queries in the optimizer and successfully capture their semantics.</span> +</span><span id="Dialect-324"><a href="#Dialect-324"><span class="linenos">324</span></a><span class="sd"> """</span> +</span><span id="Dialect-325"><a href="#Dialect-325"><span class="linenos">325</span></a> <span class="k">if</span> <span class="p">(</span> +</span><span id="Dialect-326"><a href="#Dialect-326"><span class="linenos">326</span></a> <span class="nb">isinstance</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">Identifier</span><span class="p">)</span> +</span><span id="Dialect-327"><a href="#Dialect-327"><span class="linenos">327</span></a> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_SENSITIVE</span> +</span><span id="Dialect-328"><a href="#Dialect-328"><span class="linenos">328</span></a> <span class="ow">and</span> <span class="p">(</span> +</span><span id="Dialect-329"><a href="#Dialect-329"><span class="linenos">329</span></a> <span class="ow">not</span> <span class="n">expression</span><span class="o">.</span><span class="n">quoted</span> +</span><span id="Dialect-330"><a href="#Dialect-330"><span class="linenos">330</span></a> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_INSENSITIVE</span> +</span><span id="Dialect-331"><a href="#Dialect-331"><span class="linenos">331</span></a> <span class="p">)</span> +</span><span id="Dialect-332"><a href="#Dialect-332"><span class="linenos">332</span></a> <span class="p">):</span> +</span><span id="Dialect-333"><a href="#Dialect-333"><span class="linenos">333</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="Dialect-334"><a href="#Dialect-334"><span class="linenos">334</span></a> <span class="s2">"this"</span><span class="p">,</span> +</span><span id="Dialect-335"><a href="#Dialect-335"><span class="linenos">335</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> +</span><span id="Dialect-336"><a href="#Dialect-336"><span class="linenos">336</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">UPPERCASE</span> +</span><span id="Dialect-337"><a href="#Dialect-337"><span class="linenos">337</span></a> <span class="k">else</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> +</span><span id="Dialect-338"><a href="#Dialect-338"><span class="linenos">338</span></a> <span class="p">)</span> +</span><span id="Dialect-339"><a href="#Dialect-339"><span class="linenos">339</span></a> +</span><span id="Dialect-340"><a href="#Dialect-340"><span class="linenos">340</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="Dialect-341"><a href="#Dialect-341"><span class="linenos">341</span></a> +</span><span id="Dialect-342"><a href="#Dialect-342"><span class="linenos">342</span></a> <span class="k">def</span> <span class="nf">case_sensitive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> +</span><span id="Dialect-343"><a href="#Dialect-343"><span class="linenos">343</span></a><span class="w"> </span><span class="sd">"""Checks if text contains any case sensitive characters, based on the dialect's rules."""</span> +</span><span id="Dialect-344"><a href="#Dialect-344"><span class="linenos">344</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_INSENSITIVE</span><span class="p">:</span> +</span><span id="Dialect-345"><a href="#Dialect-345"><span class="linenos">345</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="Dialect-346"><a href="#Dialect-346"><span class="linenos">346</span></a> +</span><span id="Dialect-347"><a href="#Dialect-347"><span class="linenos">347</span></a> <span class="n">unsafe</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="Dialect-348"><a href="#Dialect-348"><span class="linenos">348</span></a> <span class="nb">str</span><span class="o">.</span><span class="n">islower</span> +</span><span id="Dialect-349"><a href="#Dialect-349"><span class="linenos">349</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">UPPERCASE</span> +</span><span id="Dialect-350"><a href="#Dialect-350"><span class="linenos">350</span></a> <span class="k">else</span> <span class="nb">str</span><span class="o">.</span><span class="n">isupper</span> +</span><span id="Dialect-351"><a href="#Dialect-351"><span class="linenos">351</span></a> <span class="p">)</span> +</span><span id="Dialect-352"><a href="#Dialect-352"><span class="linenos">352</span></a> <span class="k">return</span> <span class="nb">any</span><span class="p">(</span><span class="n">unsafe</span><span class="p">(</span><span class="n">char</span><span class="p">)</span> <span class="k">for</span> <span class="n">char</span> <span class="ow">in</span> <span class="n">text</span><span class="p">)</span> </span><span id="Dialect-353"><a href="#Dialect-353"><span class="linenos">353</span></a> -</span><span id="Dialect-354"><a href="#Dialect-354"><span class="linenos">354</span></a><span class="sd"> Args:</span> -</span><span id="Dialect-355"><a href="#Dialect-355"><span class="linenos">355</span></a><span class="sd"> text: The text to check.</span> -</span><span id="Dialect-356"><a href="#Dialect-356"><span class="linenos">356</span></a><span class="sd"> identify:</span> -</span><span id="Dialect-357"><a href="#Dialect-357"><span class="linenos">357</span></a><span class="sd"> "always" or `True`: Always returns true.</span> -</span><span id="Dialect-358"><a href="#Dialect-358"><span class="linenos">358</span></a><span class="sd"> "safe": True if the identifier is case-insensitive.</span> -</span><span id="Dialect-359"><a href="#Dialect-359"><span class="linenos">359</span></a> -</span><span id="Dialect-360"><a href="#Dialect-360"><span class="linenos">360</span></a><span class="sd"> Returns:</span> -</span><span id="Dialect-361"><a href="#Dialect-361"><span class="linenos">361</span></a><span class="sd"> Whether or not the given text can be identified.</span> -</span><span id="Dialect-362"><a href="#Dialect-362"><span class="linenos">362</span></a><span class="sd"> """</span> -</span><span id="Dialect-363"><a href="#Dialect-363"><span class="linenos">363</span></a> <span class="k">if</span> <span class="n">identify</span> <span class="ow">is</span> <span class="kc">True</span> <span class="ow">or</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"always"</span><span class="p">:</span> -</span><span id="Dialect-364"><a href="#Dialect-364"><span class="linenos">364</span></a> <span class="k">return</span> <span class="kc">True</span> -</span><span id="Dialect-365"><a href="#Dialect-365"><span class="linenos">365</span></a> -</span><span id="Dialect-366"><a href="#Dialect-366"><span class="linenos">366</span></a> <span class="k">if</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"safe"</span><span class="p">:</span> -</span><span id="Dialect-367"><a href="#Dialect-367"><span class="linenos">367</span></a> <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">case_sensitive</span><span class="p">(</span><span class="n">text</span><span class="p">)</span> +</span><span id="Dialect-354"><a href="#Dialect-354"><span class="linenos">354</span></a> <span class="k">def</span> <span class="nf">can_identify</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">identify</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">bool</span> <span class="o">=</span> <span class="s2">"safe"</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> +</span><span id="Dialect-355"><a href="#Dialect-355"><span class="linenos">355</span></a><span class="w"> </span><span class="sd">"""Checks if text can be identified given an identify option.</span> +</span><span id="Dialect-356"><a href="#Dialect-356"><span class="linenos">356</span></a> +</span><span id="Dialect-357"><a href="#Dialect-357"><span class="linenos">357</span></a><span class="sd"> Args:</span> +</span><span id="Dialect-358"><a href="#Dialect-358"><span class="linenos">358</span></a><span class="sd"> text: The text to check.</span> +</span><span id="Dialect-359"><a href="#Dialect-359"><span class="linenos">359</span></a><span class="sd"> identify:</span> +</span><span id="Dialect-360"><a href="#Dialect-360"><span class="linenos">360</span></a><span class="sd"> "always" or `True`: Always returns true.</span> +</span><span id="Dialect-361"><a href="#Dialect-361"><span class="linenos">361</span></a><span class="sd"> "safe": True if the identifier is case-insensitive.</span> +</span><span id="Dialect-362"><a href="#Dialect-362"><span class="linenos">362</span></a> +</span><span id="Dialect-363"><a href="#Dialect-363"><span class="linenos">363</span></a><span class="sd"> Returns:</span> +</span><span id="Dialect-364"><a href="#Dialect-364"><span class="linenos">364</span></a><span class="sd"> Whether or not the given text can be identified.</span> +</span><span id="Dialect-365"><a href="#Dialect-365"><span class="linenos">365</span></a><span class="sd"> """</span> +</span><span id="Dialect-366"><a href="#Dialect-366"><span class="linenos">366</span></a> <span class="k">if</span> <span class="n">identify</span> <span class="ow">is</span> <span class="kc">True</span> <span class="ow">or</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"always"</span><span class="p">:</span> +</span><span id="Dialect-367"><a href="#Dialect-367"><span class="linenos">367</span></a> <span class="k">return</span> <span class="kc">True</span> </span><span id="Dialect-368"><a href="#Dialect-368"><span class="linenos">368</span></a> -</span><span id="Dialect-369"><a href="#Dialect-369"><span class="linenos">369</span></a> <span class="k">return</span> <span class="kc">False</span> -</span><span id="Dialect-370"><a href="#Dialect-370"><span class="linenos">370</span></a> -</span><span id="Dialect-371"><a href="#Dialect-371"><span class="linenos">371</span></a> <span class="k">def</span> <span class="nf">quote_identifier</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">E</span><span class="p">,</span> <span class="n">identify</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span> <span class="o">-></span> <span class="n">E</span><span class="p">:</span> -</span><span id="Dialect-372"><a href="#Dialect-372"><span class="linenos">372</span></a> <span class="k">if</span> <span class="nb">isinstance</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">Identifier</span><span class="p">):</span> -</span><span id="Dialect-373"><a href="#Dialect-373"><span class="linenos">373</span></a> <span class="n">name</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> -</span><span id="Dialect-374"><a href="#Dialect-374"><span class="linenos">374</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> -</span><span id="Dialect-375"><a href="#Dialect-375"><span class="linenos">375</span></a> <span class="s2">"quoted"</span><span class="p">,</span> -</span><span id="Dialect-376"><a href="#Dialect-376"><span class="linenos">376</span></a> <span class="n">identify</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">case_sensitive</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">exp</span><span class="o">.</span><span class="n">SAFE_IDENTIFIER_RE</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">name</span><span class="p">),</span> -</span><span id="Dialect-377"><a href="#Dialect-377"><span class="linenos">377</span></a> <span class="p">)</span> -</span><span id="Dialect-378"><a href="#Dialect-378"><span class="linenos">378</span></a> -</span><span id="Dialect-379"><a href="#Dialect-379"><span class="linenos">379</span></a> <span class="k">return</span> <span class="n">expression</span> -</span><span id="Dialect-380"><a href="#Dialect-380"><span class="linenos">380</span></a> -</span><span id="Dialect-381"><a href="#Dialect-381"><span class="linenos">381</span></a> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="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">Expression</span><span class="p">]]:</span> -</span><span id="Dialect-382"><a href="#Dialect-382"><span class="linenos">382</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">),</span> <span class="n">sql</span><span class="p">)</span> +</span><span id="Dialect-369"><a href="#Dialect-369"><span class="linenos">369</span></a> <span class="k">if</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"safe"</span><span class="p">:</span> +</span><span id="Dialect-370"><a href="#Dialect-370"><span class="linenos">370</span></a> <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">case_sensitive</span><span class="p">(</span><span class="n">text</span><span class="p">)</span> +</span><span id="Dialect-371"><a href="#Dialect-371"><span class="linenos">371</span></a> +</span><span id="Dialect-372"><a href="#Dialect-372"><span class="linenos">372</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="Dialect-373"><a href="#Dialect-373"><span class="linenos">373</span></a> +</span><span id="Dialect-374"><a href="#Dialect-374"><span class="linenos">374</span></a> <span class="k">def</span> <span class="nf">quote_identifier</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">E</span><span class="p">,</span> <span class="n">identify</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span> <span class="o">-></span> <span class="n">E</span><span class="p">:</span> +</span><span id="Dialect-375"><a href="#Dialect-375"><span class="linenos">375</span></a> <span class="k">if</span> <span class="nb">isinstance</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">Identifier</span><span class="p">):</span> +</span><span id="Dialect-376"><a href="#Dialect-376"><span class="linenos">376</span></a> <span class="n">name</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="Dialect-377"><a href="#Dialect-377"><span class="linenos">377</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="Dialect-378"><a href="#Dialect-378"><span class="linenos">378</span></a> <span class="s2">"quoted"</span><span class="p">,</span> +</span><span id="Dialect-379"><a href="#Dialect-379"><span class="linenos">379</span></a> <span class="n">identify</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">case_sensitive</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">exp</span><span class="o">.</span><span class="n">SAFE_IDENTIFIER_RE</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">name</span><span class="p">),</span> +</span><span id="Dialect-380"><a href="#Dialect-380"><span class="linenos">380</span></a> <span class="p">)</span> +</span><span id="Dialect-381"><a href="#Dialect-381"><span class="linenos">381</span></a> +</span><span id="Dialect-382"><a href="#Dialect-382"><span class="linenos">382</span></a> <span class="k">return</span> <span class="n">expression</span> </span><span id="Dialect-383"><a href="#Dialect-383"><span class="linenos">383</span></a> -</span><span id="Dialect-384"><a href="#Dialect-384"><span class="linenos">384</span></a> <span class="k">def</span> <span class="nf">parse_into</span><span class="p">(</span> -</span><span id="Dialect-385"><a href="#Dialect-385"><span class="linenos">385</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">expression_type</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">IntoType</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span> -</span><span id="Dialect-386"><a href="#Dialect-386"><span class="linenos">386</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="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">Expression</span><span class="p">]]:</span> -</span><span id="Dialect-387"><a href="#Dialect-387"><span class="linenos">387</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">parse_into</span><span class="p">(</span><span class="n">expression_type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">),</span> <span class="n">sql</span><span class="p">)</span> -</span><span id="Dialect-388"><a href="#Dialect-388"><span class="linenos">388</span></a> -</span><span id="Dialect-389"><a href="#Dialect-389"><span class="linenos">389</span></a> <span class="k">def</span> <span class="nf">generate</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">Expression</span><span class="p">,</span> <span class="n">copy</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Dialect-390"><a href="#Dialect-390"><span class="linenos">390</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="n">copy</span><span class="p">)</span> +</span><span id="Dialect-384"><a href="#Dialect-384"><span class="linenos">384</span></a> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="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">Expression</span><span class="p">]]:</span> +</span><span id="Dialect-385"><a href="#Dialect-385"><span class="linenos">385</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">),</span> <span class="n">sql</span><span class="p">)</span> +</span><span id="Dialect-386"><a href="#Dialect-386"><span class="linenos">386</span></a> +</span><span id="Dialect-387"><a href="#Dialect-387"><span class="linenos">387</span></a> <span class="k">def</span> <span class="nf">parse_into</span><span class="p">(</span> +</span><span id="Dialect-388"><a href="#Dialect-388"><span class="linenos">388</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">expression_type</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">IntoType</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span> +</span><span id="Dialect-389"><a href="#Dialect-389"><span class="linenos">389</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="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">Expression</span><span class="p">]]:</span> +</span><span id="Dialect-390"><a href="#Dialect-390"><span class="linenos">390</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">parse_into</span><span class="p">(</span><span class="n">expression_type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">),</span> <span class="n">sql</span><span class="p">)</span> </span><span id="Dialect-391"><a href="#Dialect-391"><span class="linenos">391</span></a> -</span><span id="Dialect-392"><a href="#Dialect-392"><span class="linenos">392</span></a> <span class="k">def</span> <span class="nf">transpile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> -</span><span id="Dialect-393"><a href="#Dialect-393"><span class="linenos">393</span></a> <span class="k">return</span> <span class="p">[</span> -</span><span id="Dialect-394"><a href="#Dialect-394"><span class="linenos">394</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="k">if</span> <span class="n">expression</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="Dialect-395"><a href="#Dialect-395"><span class="linenos">395</span></a> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> -</span><span id="Dialect-396"><a href="#Dialect-396"><span class="linenos">396</span></a> <span class="p">]</span> -</span><span id="Dialect-397"><a href="#Dialect-397"><span class="linenos">397</span></a> -</span><span id="Dialect-398"><a href="#Dialect-398"><span class="linenos">398</span></a> <span class="k">def</span> <span class="nf">tokenize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Token</span><span class="p">]:</span> -</span><span id="Dialect-399"><a href="#Dialect-399"><span class="linenos">399</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenizer</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> +</span><span id="Dialect-392"><a href="#Dialect-392"><span class="linenos">392</span></a> <span class="k">def</span> <span class="nf">generate</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">Expression</span><span class="p">,</span> <span class="n">copy</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Dialect-393"><a href="#Dialect-393"><span class="linenos">393</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="n">copy</span><span class="p">)</span> +</span><span id="Dialect-394"><a href="#Dialect-394"><span class="linenos">394</span></a> +</span><span id="Dialect-395"><a href="#Dialect-395"><span class="linenos">395</span></a> <span class="k">def</span> <span class="nf">transpile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="Dialect-396"><a href="#Dialect-396"><span class="linenos">396</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="Dialect-397"><a href="#Dialect-397"><span class="linenos">397</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="k">if</span> <span class="n">expression</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="Dialect-398"><a href="#Dialect-398"><span class="linenos">398</span></a> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> +</span><span id="Dialect-399"><a href="#Dialect-399"><span class="linenos">399</span></a> <span class="p">]</span> </span><span id="Dialect-400"><a href="#Dialect-400"><span class="linenos">400</span></a> -</span><span id="Dialect-401"><a href="#Dialect-401"><span class="linenos">401</span></a> <span class="nd">@property</span> -</span><span id="Dialect-402"><a href="#Dialect-402"><span class="linenos">402</span></a> <span class="k">def</span> <span class="nf">tokenizer</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Tokenizer</span><span class="p">:</span> -</span><span id="Dialect-403"><a href="#Dialect-403"><span class="linenos">403</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">"_tokenizer"</span><span class="p">):</span> -</span><span id="Dialect-404"><a href="#Dialect-404"><span class="linenos">404</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_tokenizer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenizer_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span> -</span><span id="Dialect-405"><a href="#Dialect-405"><span class="linenos">405</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_tokenizer</span> -</span><span id="Dialect-406"><a href="#Dialect-406"><span class="linenos">406</span></a> -</span><span id="Dialect-407"><a href="#Dialect-407"><span class="linenos">407</span></a> <span class="k">def</span> <span class="nf">parser</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">Parser</span><span class="p">:</span> -</span><span id="Dialect-408"><a href="#Dialect-408"><span class="linenos">408</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> +</span><span id="Dialect-401"><a href="#Dialect-401"><span class="linenos">401</span></a> <span class="k">def</span> <span class="nf">tokenize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Token</span><span class="p">]:</span> +</span><span id="Dialect-402"><a href="#Dialect-402"><span class="linenos">402</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenizer</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> +</span><span id="Dialect-403"><a href="#Dialect-403"><span class="linenos">403</span></a> +</span><span id="Dialect-404"><a href="#Dialect-404"><span class="linenos">404</span></a> <span class="nd">@property</span> +</span><span id="Dialect-405"><a href="#Dialect-405"><span class="linenos">405</span></a> <span class="k">def</span> <span class="nf">tokenizer</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Tokenizer</span><span class="p">:</span> +</span><span id="Dialect-406"><a href="#Dialect-406"><span class="linenos">406</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">"_tokenizer"</span><span class="p">):</span> +</span><span id="Dialect-407"><a href="#Dialect-407"><span class="linenos">407</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_tokenizer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenizer_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span> +</span><span id="Dialect-408"><a href="#Dialect-408"><span class="linenos">408</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_tokenizer</span> </span><span id="Dialect-409"><a href="#Dialect-409"><span class="linenos">409</span></a> -</span><span id="Dialect-410"><a href="#Dialect-410"><span class="linenos">410</span></a> <span class="k">def</span> <span class="nf">generator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">Generator</span><span class="p">:</span> -</span><span id="Dialect-411"><a href="#Dialect-411"><span class="linenos">411</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> +</span><span id="Dialect-410"><a href="#Dialect-410"><span class="linenos">410</span></a> <span class="k">def</span> <span class="nf">parser</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">Parser</span><span class="p">:</span> +</span><span id="Dialect-411"><a href="#Dialect-411"><span class="linenos">411</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> +</span><span id="Dialect-412"><a href="#Dialect-412"><span class="linenos">412</span></a> +</span><span id="Dialect-413"><a href="#Dialect-413"><span class="linenos">413</span></a> <span class="k">def</span> <span class="nf">generator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">Generator</span><span class="p">:</span> +</span><span id="Dialect-414"><a href="#Dialect-414"><span class="linenos">414</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> </span></pre></div> @@ -2244,13 +2253,13 @@ </div> <a class="headerlink" href="#Dialect.__init__"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.__init__-287"><a href="#Dialect.__init__-287"><span class="linenos">287</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Dialect.__init__-288"><a href="#Dialect.__init__-288"><span class="linenos">288</span></a> <span class="n">normalization_strategy</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"normalization_strategy"</span><span class="p">)</span> -</span><span id="Dialect.__init__-289"><a href="#Dialect.__init__-289"><span class="linenos">289</span></a> -</span><span id="Dialect.__init__-290"><a href="#Dialect.__init__-290"><span class="linenos">290</span></a> <span class="k">if</span> <span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Dialect.__init__-291"><a href="#Dialect.__init__-291"><span class="linenos">291</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">NORMALIZATION_STRATEGY</span> -</span><span id="Dialect.__init__-292"><a href="#Dialect.__init__-292"><span class="linenos">292</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Dialect.__init__-293"><a href="#Dialect.__init__-293"><span class="linenos">293</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="o">=</span> <span class="n">NormalizationStrategy</span><span class="p">(</span><span class="n">normalization_strategy</span><span class="o">.</span><span class="n">upper</span><span class="p">())</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.__init__-290"><a href="#Dialect.__init__-290"><span class="linenos">290</span></a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Dialect.__init__-291"><a href="#Dialect.__init__-291"><span class="linenos">291</span></a> <span class="n">normalization_strategy</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"normalization_strategy"</span><span class="p">)</span> +</span><span id="Dialect.__init__-292"><a href="#Dialect.__init__-292"><span class="linenos">292</span></a> +</span><span id="Dialect.__init__-293"><a href="#Dialect.__init__-293"><span class="linenos">293</span></a> <span class="k">if</span> <span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Dialect.__init__-294"><a href="#Dialect.__init__-294"><span class="linenos">294</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">NORMALIZATION_STRATEGY</span> +</span><span id="Dialect.__init__-295"><a href="#Dialect.__init__-295"><span class="linenos">295</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Dialect.__init__-296"><a href="#Dialect.__init__-296"><span class="linenos">296</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="o">=</span> <span class="n">NormalizationStrategy</span><span class="p">(</span><span class="n">normalization_strategy</span><span class="o">.</span><span class="n">upper</span><span class="p">())</span> </span></pre></div> @@ -2425,6 +2434,18 @@ </div> + <div id="Dialect.CONCAT_COALESCE" class="classattr"> + <div class="attr variable"> + <span class="name">CONCAT_COALESCE</span> = +<span class="default_value">False</span> + + + </div> + <a class="headerlink" href="#Dialect.CONCAT_COALESCE"></a> + + + + </div> <div id="Dialect.DATE_FORMAT" class="classattr"> <div class="attr variable"> <span class="name">DATE_FORMAT</span> = @@ -2737,47 +2758,47 @@ </div> <a class="headerlink" href="#Dialect.get_or_raise"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.get_or_raise-230"><a href="#Dialect.get_or_raise-230"><span class="linenos">230</span></a> <span class="nd">@classmethod</span> -</span><span id="Dialect.get_or_raise-231"><a href="#Dialect.get_or_raise-231"><span class="linenos">231</span></a> <span class="k">def</span> <span class="nf">get_or_raise</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">Dialect</span><span class="p">:</span> -</span><span id="Dialect.get_or_raise-232"><a href="#Dialect.get_or_raise-232"><span class="linenos">232</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect.get_or_raise-233"><a href="#Dialect.get_or_raise-233"><span class="linenos">233</span></a><span class="sd"> Look up a dialect in the global dialect registry and return it if it exists.</span> -</span><span id="Dialect.get_or_raise-234"><a href="#Dialect.get_or_raise-234"><span class="linenos">234</span></a> -</span><span id="Dialect.get_or_raise-235"><a href="#Dialect.get_or_raise-235"><span class="linenos">235</span></a><span class="sd"> Args:</span> -</span><span id="Dialect.get_or_raise-236"><a href="#Dialect.get_or_raise-236"><span class="linenos">236</span></a><span class="sd"> dialect: The target dialect. If this is a string, it can be optionally followed by</span> -</span><span id="Dialect.get_or_raise-237"><a href="#Dialect.get_or_raise-237"><span class="linenos">237</span></a><span class="sd"> additional key-value pairs that are separated by commas and are used to specify</span> -</span><span id="Dialect.get_or_raise-238"><a href="#Dialect.get_or_raise-238"><span class="linenos">238</span></a><span class="sd"> dialect settings, such as whether the dialect's identifiers are case-sensitive.</span> -</span><span id="Dialect.get_or_raise-239"><a href="#Dialect.get_or_raise-239"><span class="linenos">239</span></a> -</span><span id="Dialect.get_or_raise-240"><a href="#Dialect.get_or_raise-240"><span class="linenos">240</span></a><span class="sd"> Example:</span> -</span><span id="Dialect.get_or_raise-241"><a href="#Dialect.get_or_raise-241"><span class="linenos">241</span></a><span class="sd"> >>> dialect = dialect_class = get_or_raise("duckdb")</span> -</span><span id="Dialect.get_or_raise-242"><a href="#Dialect.get_or_raise-242"><span class="linenos">242</span></a><span class="sd"> >>> dialect = get_or_raise("mysql, normalization_strategy = case_sensitive")</span> -</span><span id="Dialect.get_or_raise-243"><a href="#Dialect.get_or_raise-243"><span class="linenos">243</span></a> -</span><span id="Dialect.get_or_raise-244"><a href="#Dialect.get_or_raise-244"><span class="linenos">244</span></a><span class="sd"> Returns:</span> -</span><span id="Dialect.get_or_raise-245"><a href="#Dialect.get_or_raise-245"><span class="linenos">245</span></a><span class="sd"> The corresponding Dialect instance.</span> -</span><span id="Dialect.get_or_raise-246"><a href="#Dialect.get_or_raise-246"><span class="linenos">246</span></a><span class="sd"> """</span> -</span><span id="Dialect.get_or_raise-247"><a href="#Dialect.get_or_raise-247"><span class="linenos">247</span></a> -</span><span id="Dialect.get_or_raise-248"><a href="#Dialect.get_or_raise-248"><span class="linenos">248</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">dialect</span><span class="p">:</span> -</span><span id="Dialect.get_or_raise-249"><a href="#Dialect.get_or_raise-249"><span class="linenos">249</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span> -</span><span id="Dialect.get_or_raise-250"><a href="#Dialect.get_or_raise-250"><span class="linenos">250</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="n">_Dialect</span><span class="p">):</span> -</span><span id="Dialect.get_or_raise-251"><a href="#Dialect.get_or_raise-251"><span class="linenos">251</span></a> <span class="k">return</span> <span class="n">dialect</span><span class="p">()</span> -</span><span id="Dialect.get_or_raise-252"><a href="#Dialect.get_or_raise-252"><span class="linenos">252</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="n">Dialect</span><span class="p">):</span> -</span><span id="Dialect.get_or_raise-253"><a href="#Dialect.get_or_raise-253"><span class="linenos">253</span></a> <span class="k">return</span> <span class="n">dialect</span> -</span><span id="Dialect.get_or_raise-254"><a href="#Dialect.get_or_raise-254"><span class="linenos">254</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> -</span><span id="Dialect.get_or_raise-255"><a href="#Dialect.get_or_raise-255"><span class="linenos">255</span></a> <span class="k">try</span><span class="p">:</span> -</span><span id="Dialect.get_or_raise-256"><a href="#Dialect.get_or_raise-256"><span class="linenos">256</span></a> <span class="n">dialect_name</span><span class="p">,</span> <span class="o">*</span><span class="n">kv_pairs</span> <span class="o">=</span> <span class="n">dialect</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">)</span> -</span><span id="Dialect.get_or_raise-257"><a href="#Dialect.get_or_raise-257"><span class="linenos">257</span></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="n">v</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="p">(</span><span class="n">kv</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">"="</span><span class="p">)</span> <span class="k">for</span> <span class="n">kv</span> <span class="ow">in</span> <span class="n">kv_pairs</span><span class="p">)}</span> -</span><span id="Dialect.get_or_raise-258"><a href="#Dialect.get_or_raise-258"><span class="linenos">258</span></a> <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> -</span><span id="Dialect.get_or_raise-259"><a href="#Dialect.get_or_raise-259"><span class="linenos">259</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> -</span><span id="Dialect.get_or_raise-260"><a href="#Dialect.get_or_raise-260"><span class="linenos">260</span></a> <span class="sa">f</span><span class="s2">"Invalid dialect format: '</span><span class="si">{</span><span class="n">dialect</span><span class="si">}</span><span class="s2">'. "</span> -</span><span id="Dialect.get_or_raise-261"><a href="#Dialect.get_or_raise-261"><span class="linenos">261</span></a> <span class="s2">"Please use the correct format: 'dialect [, k1 = v2 [, ...]]'."</span> -</span><span id="Dialect.get_or_raise-262"><a href="#Dialect.get_or_raise-262"><span class="linenos">262</span></a> <span class="p">)</span> -</span><span id="Dialect.get_or_raise-263"><a href="#Dialect.get_or_raise-263"><span class="linenos">263</span></a> -</span><span id="Dialect.get_or_raise-264"><a href="#Dialect.get_or_raise-264"><span class="linenos">264</span></a> <span class="n">result</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">dialect_name</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> -</span><span id="Dialect.get_or_raise-265"><a href="#Dialect.get_or_raise-265"><span class="linenos">265</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">result</span><span class="p">:</span> -</span><span id="Dialect.get_or_raise-266"><a href="#Dialect.get_or_raise-266"><span class="linenos">266</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unknown dialect '</span><span class="si">{</span><span class="n">dialect_name</span><span class="si">}</span><span class="s2">'."</span><span class="p">)</span> -</span><span id="Dialect.get_or_raise-267"><a href="#Dialect.get_or_raise-267"><span class="linenos">267</span></a> -</span><span id="Dialect.get_or_raise-268"><a href="#Dialect.get_or_raise-268"><span class="linenos">268</span></a> <span class="k">return</span> <span class="n">result</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> -</span><span id="Dialect.get_or_raise-269"><a href="#Dialect.get_or_raise-269"><span class="linenos">269</span></a> -</span><span id="Dialect.get_or_raise-270"><a href="#Dialect.get_or_raise-270"><span class="linenos">270</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid dialect type for '</span><span class="si">{</span><span class="n">dialect</span><span class="si">}</span><span class="s2">': '</span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span><span class="si">}</span><span class="s2">'."</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.get_or_raise-233"><a href="#Dialect.get_or_raise-233"><span class="linenos">233</span></a> <span class="nd">@classmethod</span> +</span><span id="Dialect.get_or_raise-234"><a href="#Dialect.get_or_raise-234"><span class="linenos">234</span></a> <span class="k">def</span> <span class="nf">get_or_raise</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">Dialect</span><span class="p">:</span> +</span><span id="Dialect.get_or_raise-235"><a href="#Dialect.get_or_raise-235"><span class="linenos">235</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect.get_or_raise-236"><a href="#Dialect.get_or_raise-236"><span class="linenos">236</span></a><span class="sd"> Look up a dialect in the global dialect registry and return it if it exists.</span> +</span><span id="Dialect.get_or_raise-237"><a href="#Dialect.get_or_raise-237"><span class="linenos">237</span></a> +</span><span id="Dialect.get_or_raise-238"><a href="#Dialect.get_or_raise-238"><span class="linenos">238</span></a><span class="sd"> Args:</span> +</span><span id="Dialect.get_or_raise-239"><a href="#Dialect.get_or_raise-239"><span class="linenos">239</span></a><span class="sd"> dialect: The target dialect. If this is a string, it can be optionally followed by</span> +</span><span id="Dialect.get_or_raise-240"><a href="#Dialect.get_or_raise-240"><span class="linenos">240</span></a><span class="sd"> additional key-value pairs that are separated by commas and are used to specify</span> +</span><span id="Dialect.get_or_raise-241"><a href="#Dialect.get_or_raise-241"><span class="linenos">241</span></a><span class="sd"> dialect settings, such as whether the dialect's identifiers are case-sensitive.</span> +</span><span id="Dialect.get_or_raise-242"><a href="#Dialect.get_or_raise-242"><span class="linenos">242</span></a> +</span><span id="Dialect.get_or_raise-243"><a href="#Dialect.get_or_raise-243"><span class="linenos">243</span></a><span class="sd"> Example:</span> +</span><span id="Dialect.get_or_raise-244"><a href="#Dialect.get_or_raise-244"><span class="linenos">244</span></a><span class="sd"> >>> dialect = dialect_class = get_or_raise("duckdb")</span> +</span><span id="Dialect.get_or_raise-245"><a href="#Dialect.get_or_raise-245"><span class="linenos">245</span></a><span class="sd"> >>> dialect = get_or_raise("mysql, normalization_strategy = case_sensitive")</span> +</span><span id="Dialect.get_or_raise-246"><a href="#Dialect.get_or_raise-246"><span class="linenos">246</span></a> +</span><span id="Dialect.get_or_raise-247"><a href="#Dialect.get_or_raise-247"><span class="linenos">247</span></a><span class="sd"> Returns:</span> +</span><span id="Dialect.get_or_raise-248"><a href="#Dialect.get_or_raise-248"><span class="linenos">248</span></a><span class="sd"> The corresponding Dialect instance.</span> +</span><span id="Dialect.get_or_raise-249"><a href="#Dialect.get_or_raise-249"><span class="linenos">249</span></a><span class="sd"> """</span> +</span><span id="Dialect.get_or_raise-250"><a href="#Dialect.get_or_raise-250"><span class="linenos">250</span></a> +</span><span id="Dialect.get_or_raise-251"><a href="#Dialect.get_or_raise-251"><span class="linenos">251</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">dialect</span><span class="p">:</span> +</span><span id="Dialect.get_or_raise-252"><a href="#Dialect.get_or_raise-252"><span class="linenos">252</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span> +</span><span id="Dialect.get_or_raise-253"><a href="#Dialect.get_or_raise-253"><span class="linenos">253</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="n">_Dialect</span><span class="p">):</span> +</span><span id="Dialect.get_or_raise-254"><a href="#Dialect.get_or_raise-254"><span class="linenos">254</span></a> <span class="k">return</span> <span class="n">dialect</span><span class="p">()</span> +</span><span id="Dialect.get_or_raise-255"><a href="#Dialect.get_or_raise-255"><span class="linenos">255</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="n">Dialect</span><span class="p">):</span> +</span><span id="Dialect.get_or_raise-256"><a href="#Dialect.get_or_raise-256"><span class="linenos">256</span></a> <span class="k">return</span> <span class="n">dialect</span> +</span><span id="Dialect.get_or_raise-257"><a href="#Dialect.get_or_raise-257"><span class="linenos">257</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dialect</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="Dialect.get_or_raise-258"><a href="#Dialect.get_or_raise-258"><span class="linenos">258</span></a> <span class="k">try</span><span class="p">:</span> +</span><span id="Dialect.get_or_raise-259"><a href="#Dialect.get_or_raise-259"><span class="linenos">259</span></a> <span class="n">dialect_name</span><span class="p">,</span> <span class="o">*</span><span class="n">kv_pairs</span> <span class="o">=</span> <span class="n">dialect</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">)</span> +</span><span id="Dialect.get_or_raise-260"><a href="#Dialect.get_or_raise-260"><span class="linenos">260</span></a> <span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> <span class="n">v</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="p">(</span><span class="n">kv</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">"="</span><span class="p">)</span> <span class="k">for</span> <span class="n">kv</span> <span class="ow">in</span> <span class="n">kv_pairs</span><span class="p">)}</span> +</span><span id="Dialect.get_or_raise-261"><a href="#Dialect.get_or_raise-261"><span class="linenos">261</span></a> <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> +</span><span id="Dialect.get_or_raise-262"><a href="#Dialect.get_or_raise-262"><span class="linenos">262</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> +</span><span id="Dialect.get_or_raise-263"><a href="#Dialect.get_or_raise-263"><span class="linenos">263</span></a> <span class="sa">f</span><span class="s2">"Invalid dialect format: '</span><span class="si">{</span><span class="n">dialect</span><span class="si">}</span><span class="s2">'. "</span> +</span><span id="Dialect.get_or_raise-264"><a href="#Dialect.get_or_raise-264"><span class="linenos">264</span></a> <span class="s2">"Please use the correct format: 'dialect [, k1 = v2 [, ...]]'."</span> +</span><span id="Dialect.get_or_raise-265"><a href="#Dialect.get_or_raise-265"><span class="linenos">265</span></a> <span class="p">)</span> +</span><span id="Dialect.get_or_raise-266"><a href="#Dialect.get_or_raise-266"><span class="linenos">266</span></a> +</span><span id="Dialect.get_or_raise-267"><a href="#Dialect.get_or_raise-267"><span class="linenos">267</span></a> <span class="n">result</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">dialect_name</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> +</span><span id="Dialect.get_or_raise-268"><a href="#Dialect.get_or_raise-268"><span class="linenos">268</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">result</span><span class="p">:</span> +</span><span id="Dialect.get_or_raise-269"><a href="#Dialect.get_or_raise-269"><span class="linenos">269</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unknown dialect '</span><span class="si">{</span><span class="n">dialect_name</span><span class="si">}</span><span class="s2">'."</span><span class="p">)</span> +</span><span id="Dialect.get_or_raise-270"><a href="#Dialect.get_or_raise-270"><span class="linenos">270</span></a> +</span><span id="Dialect.get_or_raise-271"><a href="#Dialect.get_or_raise-271"><span class="linenos">271</span></a> <span class="k">return</span> <span class="n">result</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> +</span><span id="Dialect.get_or_raise-272"><a href="#Dialect.get_or_raise-272"><span class="linenos">272</span></a> +</span><span id="Dialect.get_or_raise-273"><a href="#Dialect.get_or_raise-273"><span class="linenos">273</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid dialect type for '</span><span class="si">{</span><span class="n">dialect</span><span class="si">}</span><span class="s2">': '</span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span><span class="si">}</span><span class="s2">'."</span><span class="p">)</span> </span></pre></div> @@ -2822,20 +2843,20 @@ dialect settings, such as whether the dialect's identifiers are case-sensitive.< </div> <a class="headerlink" href="#Dialect.format_time"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.format_time-272"><a href="#Dialect.format_time-272"><span class="linenos">272</span></a> <span class="nd">@classmethod</span> -</span><span id="Dialect.format_time-273"><a href="#Dialect.format_time-273"><span class="linenos">273</span></a> <span class="k">def</span> <span class="nf">format_time</span><span class="p">(</span> -</span><span id="Dialect.format_time-274"><a href="#Dialect.format_time-274"><span class="linenos">274</span></a> <span class="bp">cls</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]</span> -</span><span id="Dialect.format_time-275"><a href="#Dialect.format_time-275"><span class="linenos">275</span></a> <span class="p">)</span> <span class="o">-></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">Expression</span><span class="p">]:</span> -</span><span id="Dialect.format_time-276"><a href="#Dialect.format_time-276"><span class="linenos">276</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> -</span><span id="Dialect.format_time-277"><a href="#Dialect.format_time-277"><span class="linenos">277</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span> -</span><span id="Dialect.format_time-278"><a href="#Dialect.format_time-278"><span class="linenos">278</span></a> <span class="c1"># the time formats are quoted</span> -</span><span id="Dialect.format_time-279"><a href="#Dialect.format_time-279"><span class="linenos">279</span></a> <span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_TRIE</span><span class="p">)</span> -</span><span id="Dialect.format_time-280"><a href="#Dialect.format_time-280"><span class="linenos">280</span></a> <span class="p">)</span> -</span><span id="Dialect.format_time-281"><a href="#Dialect.format_time-281"><span class="linenos">281</span></a> -</span><span id="Dialect.format_time-282"><a href="#Dialect.format_time-282"><span class="linenos">282</span></a> <span class="k">if</span> <span class="n">expression</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_string</span><span class="p">:</span> -</span><span id="Dialect.format_time-283"><a href="#Dialect.format_time-283"><span class="linenos">283</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="n">format_time</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="bp">cls</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_TRIE</span><span class="p">))</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.format_time-275"><a href="#Dialect.format_time-275"><span class="linenos">275</span></a> <span class="nd">@classmethod</span> +</span><span id="Dialect.format_time-276"><a href="#Dialect.format_time-276"><span class="linenos">276</span></a> <span class="k">def</span> <span class="nf">format_time</span><span class="p">(</span> +</span><span id="Dialect.format_time-277"><a href="#Dialect.format_time-277"><span class="linenos">277</span></a> <span class="bp">cls</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]</span> +</span><span id="Dialect.format_time-278"><a href="#Dialect.format_time-278"><span class="linenos">278</span></a> <span class="p">)</span> <span class="o">-></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">Expression</span><span class="p">]:</span> +</span><span id="Dialect.format_time-279"><a href="#Dialect.format_time-279"><span class="linenos">279</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="Dialect.format_time-280"><a href="#Dialect.format_time-280"><span class="linenos">280</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span> +</span><span id="Dialect.format_time-281"><a href="#Dialect.format_time-281"><span class="linenos">281</span></a> <span class="c1"># the time formats are quoted</span> +</span><span id="Dialect.format_time-282"><a href="#Dialect.format_time-282"><span class="linenos">282</span></a> <span class="n">format_time</span><span class="p">(</span><span class="n">expression</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_TRIE</span><span class="p">)</span> +</span><span id="Dialect.format_time-283"><a href="#Dialect.format_time-283"><span class="linenos">283</span></a> <span class="p">)</span> </span><span id="Dialect.format_time-284"><a href="#Dialect.format_time-284"><span class="linenos">284</span></a> -</span><span id="Dialect.format_time-285"><a href="#Dialect.format_time-285"><span class="linenos">285</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="Dialect.format_time-285"><a href="#Dialect.format_time-285"><span class="linenos">285</span></a> <span class="k">if</span> <span class="n">expression</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_string</span><span class="p">:</span> +</span><span id="Dialect.format_time-286"><a href="#Dialect.format_time-286"><span class="linenos">286</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="n">format_time</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="bp">cls</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">TIME_TRIE</span><span class="p">))</span> +</span><span id="Dialect.format_time-287"><a href="#Dialect.format_time-287"><span class="linenos">287</span></a> +</span><span id="Dialect.format_time-288"><a href="#Dialect.format_time-288"><span class="linenos">288</span></a> <span class="k">return</span> <span class="n">expression</span> </span></pre></div> @@ -2853,41 +2874,41 @@ dialect settings, such as whether the dialect's identifiers are case-sensitive.< </div> <a class="headerlink" href="#Dialect.normalize_identifier"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.normalize_identifier-303"><a href="#Dialect.normalize_identifier-303"><span class="linenos">303</span></a> <span class="k">def</span> <span class="nf">normalize_identifier</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">E</span><span class="p">)</span> <span class="o">-></span> <span class="n">E</span><span class="p">:</span> -</span><span id="Dialect.normalize_identifier-304"><a href="#Dialect.normalize_identifier-304"><span class="linenos">304</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect.normalize_identifier-305"><a href="#Dialect.normalize_identifier-305"><span class="linenos">305</span></a><span class="sd"> Transforms an identifier in a way that resembles how it'd be resolved by this dialect.</span> -</span><span id="Dialect.normalize_identifier-306"><a href="#Dialect.normalize_identifier-306"><span class="linenos">306</span></a> -</span><span id="Dialect.normalize_identifier-307"><a href="#Dialect.normalize_identifier-307"><span class="linenos">307</span></a><span class="sd"> For example, an identifier like FoO would be resolved as foo in Postgres, because it</span> -</span><span id="Dialect.normalize_identifier-308"><a href="#Dialect.normalize_identifier-308"><span class="linenos">308</span></a><span class="sd"> lowercases all unquoted identifiers. On the other hand, Snowflake uppercases them, so</span> -</span><span id="Dialect.normalize_identifier-309"><a href="#Dialect.normalize_identifier-309"><span class="linenos">309</span></a><span class="sd"> it would resolve it as FOO. If it was quoted, it'd need to be treated as case-sensitive,</span> -</span><span id="Dialect.normalize_identifier-310"><a href="#Dialect.normalize_identifier-310"><span class="linenos">310</span></a><span class="sd"> and so any normalization would be prohibited in order to avoid "breaking" the identifier.</span> -</span><span id="Dialect.normalize_identifier-311"><a href="#Dialect.normalize_identifier-311"><span class="linenos">311</span></a> -</span><span id="Dialect.normalize_identifier-312"><a href="#Dialect.normalize_identifier-312"><span class="linenos">312</span></a><span class="sd"> There are also dialects like Spark, which are case-insensitive even when quotes are</span> -</span><span id="Dialect.normalize_identifier-313"><a href="#Dialect.normalize_identifier-313"><span class="linenos">313</span></a><span class="sd"> present, and dialects like MySQL, whose resolution rules match those employed by the</span> -</span><span id="Dialect.normalize_identifier-314"><a href="#Dialect.normalize_identifier-314"><span class="linenos">314</span></a><span class="sd"> underlying operating system, for example they may always be case-sensitive in Linux.</span> -</span><span id="Dialect.normalize_identifier-315"><a href="#Dialect.normalize_identifier-315"><span class="linenos">315</span></a> -</span><span id="Dialect.normalize_identifier-316"><a href="#Dialect.normalize_identifier-316"><span class="linenos">316</span></a><span class="sd"> Finally, the normalization behavior of some engines can even be controlled through flags,</span> -</span><span id="Dialect.normalize_identifier-317"><a href="#Dialect.normalize_identifier-317"><span class="linenos">317</span></a><span class="sd"> like in Redshift's case, where users can explicitly set enable_case_sensitive_identifier.</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.normalize_identifier-306"><a href="#Dialect.normalize_identifier-306"><span class="linenos">306</span></a> <span class="k">def</span> <span class="nf">normalize_identifier</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">E</span><span class="p">)</span> <span class="o">-></span> <span class="n">E</span><span class="p">:</span> +</span><span id="Dialect.normalize_identifier-307"><a href="#Dialect.normalize_identifier-307"><span class="linenos">307</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect.normalize_identifier-308"><a href="#Dialect.normalize_identifier-308"><span class="linenos">308</span></a><span class="sd"> Transforms an identifier in a way that resembles how it'd be resolved by this dialect.</span> +</span><span id="Dialect.normalize_identifier-309"><a href="#Dialect.normalize_identifier-309"><span class="linenos">309</span></a> +</span><span id="Dialect.normalize_identifier-310"><a href="#Dialect.normalize_identifier-310"><span class="linenos">310</span></a><span class="sd"> For example, an identifier like FoO would be resolved as foo in Postgres, because it</span> +</span><span id="Dialect.normalize_identifier-311"><a href="#Dialect.normalize_identifier-311"><span class="linenos">311</span></a><span class="sd"> lowercases all unquoted identifiers. On the other hand, Snowflake uppercases them, so</span> +</span><span id="Dialect.normalize_identifier-312"><a href="#Dialect.normalize_identifier-312"><span class="linenos">312</span></a><span class="sd"> it would resolve it as FOO. If it was quoted, it'd need to be treated as case-sensitive,</span> +</span><span id="Dialect.normalize_identifier-313"><a href="#Dialect.normalize_identifier-313"><span class="linenos">313</span></a><span class="sd"> and so any normalization would be prohibited in order to avoid "breaking" the identifier.</span> +</span><span id="Dialect.normalize_identifier-314"><a href="#Dialect.normalize_identifier-314"><span class="linenos">314</span></a> +</span><span id="Dialect.normalize_identifier-315"><a href="#Dialect.normalize_identifier-315"><span class="linenos">315</span></a><span class="sd"> There are also dialects like Spark, which are case-insensitive even when quotes are</span> +</span><span id="Dialect.normalize_identifier-316"><a href="#Dialect.normalize_identifier-316"><span class="linenos">316</span></a><span class="sd"> present, and dialects like MySQL, whose resolution rules match those employed by the</span> +</span><span id="Dialect.normalize_identifier-317"><a href="#Dialect.normalize_identifier-317"><span class="linenos">317</span></a><span class="sd"> underlying operating system, for example they may always be case-sensitive in Linux.</span> </span><span id="Dialect.normalize_identifier-318"><a href="#Dialect.normalize_identifier-318"><span class="linenos">318</span></a> -</span><span id="Dialect.normalize_identifier-319"><a href="#Dialect.normalize_identifier-319"><span class="linenos">319</span></a><span class="sd"> SQLGlot aims to understand and handle all of these different behaviors gracefully, so</span> -</span><span id="Dialect.normalize_identifier-320"><a href="#Dialect.normalize_identifier-320"><span class="linenos">320</span></a><span class="sd"> that it can analyze queries in the optimizer and successfully capture their semantics.</span> -</span><span id="Dialect.normalize_identifier-321"><a href="#Dialect.normalize_identifier-321"><span class="linenos">321</span></a><span class="sd"> """</span> -</span><span id="Dialect.normalize_identifier-322"><a href="#Dialect.normalize_identifier-322"><span class="linenos">322</span></a> <span class="k">if</span> <span class="p">(</span> -</span><span id="Dialect.normalize_identifier-323"><a href="#Dialect.normalize_identifier-323"><span class="linenos">323</span></a> <span class="nb">isinstance</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">Identifier</span><span class="p">)</span> -</span><span id="Dialect.normalize_identifier-324"><a href="#Dialect.normalize_identifier-324"><span class="linenos">324</span></a> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_SENSITIVE</span> -</span><span id="Dialect.normalize_identifier-325"><a href="#Dialect.normalize_identifier-325"><span class="linenos">325</span></a> <span class="ow">and</span> <span class="p">(</span> -</span><span id="Dialect.normalize_identifier-326"><a href="#Dialect.normalize_identifier-326"><span class="linenos">326</span></a> <span class="ow">not</span> <span class="n">expression</span><span class="o">.</span><span class="n">quoted</span> -</span><span id="Dialect.normalize_identifier-327"><a href="#Dialect.normalize_identifier-327"><span class="linenos">327</span></a> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_INSENSITIVE</span> -</span><span id="Dialect.normalize_identifier-328"><a href="#Dialect.normalize_identifier-328"><span class="linenos">328</span></a> <span class="p">)</span> -</span><span id="Dialect.normalize_identifier-329"><a href="#Dialect.normalize_identifier-329"><span class="linenos">329</span></a> <span class="p">):</span> -</span><span id="Dialect.normalize_identifier-330"><a href="#Dialect.normalize_identifier-330"><span class="linenos">330</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> -</span><span id="Dialect.normalize_identifier-331"><a href="#Dialect.normalize_identifier-331"><span class="linenos">331</span></a> <span class="s2">"this"</span><span class="p">,</span> -</span><span id="Dialect.normalize_identifier-332"><a href="#Dialect.normalize_identifier-332"><span class="linenos">332</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> -</span><span id="Dialect.normalize_identifier-333"><a href="#Dialect.normalize_identifier-333"><span class="linenos">333</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">UPPERCASE</span> -</span><span id="Dialect.normalize_identifier-334"><a href="#Dialect.normalize_identifier-334"><span class="linenos">334</span></a> <span class="k">else</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> -</span><span id="Dialect.normalize_identifier-335"><a href="#Dialect.normalize_identifier-335"><span class="linenos">335</span></a> <span class="p">)</span> -</span><span id="Dialect.normalize_identifier-336"><a href="#Dialect.normalize_identifier-336"><span class="linenos">336</span></a> -</span><span id="Dialect.normalize_identifier-337"><a href="#Dialect.normalize_identifier-337"><span class="linenos">337</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="Dialect.normalize_identifier-319"><a href="#Dialect.normalize_identifier-319"><span class="linenos">319</span></a><span class="sd"> Finally, the normalization behavior of some engines can even be controlled through flags,</span> +</span><span id="Dialect.normalize_identifier-320"><a href="#Dialect.normalize_identifier-320"><span class="linenos">320</span></a><span class="sd"> like in Redshift's case, where users can explicitly set enable_case_sensitive_identifier.</span> +</span><span id="Dialect.normalize_identifier-321"><a href="#Dialect.normalize_identifier-321"><span class="linenos">321</span></a> +</span><span id="Dialect.normalize_identifier-322"><a href="#Dialect.normalize_identifier-322"><span class="linenos">322</span></a><span class="sd"> SQLGlot aims to understand and handle all of these different behaviors gracefully, so</span> +</span><span id="Dialect.normalize_identifier-323"><a href="#Dialect.normalize_identifier-323"><span class="linenos">323</span></a><span class="sd"> that it can analyze queries in the optimizer and successfully capture their semantics.</span> +</span><span id="Dialect.normalize_identifier-324"><a href="#Dialect.normalize_identifier-324"><span class="linenos">324</span></a><span class="sd"> """</span> +</span><span id="Dialect.normalize_identifier-325"><a href="#Dialect.normalize_identifier-325"><span class="linenos">325</span></a> <span class="k">if</span> <span class="p">(</span> +</span><span id="Dialect.normalize_identifier-326"><a href="#Dialect.normalize_identifier-326"><span class="linenos">326</span></a> <span class="nb">isinstance</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">Identifier</span><span class="p">)</span> +</span><span id="Dialect.normalize_identifier-327"><a href="#Dialect.normalize_identifier-327"><span class="linenos">327</span></a> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_SENSITIVE</span> +</span><span id="Dialect.normalize_identifier-328"><a href="#Dialect.normalize_identifier-328"><span class="linenos">328</span></a> <span class="ow">and</span> <span class="p">(</span> +</span><span id="Dialect.normalize_identifier-329"><a href="#Dialect.normalize_identifier-329"><span class="linenos">329</span></a> <span class="ow">not</span> <span class="n">expression</span><span class="o">.</span><span class="n">quoted</span> +</span><span id="Dialect.normalize_identifier-330"><a href="#Dialect.normalize_identifier-330"><span class="linenos">330</span></a> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_INSENSITIVE</span> +</span><span id="Dialect.normalize_identifier-331"><a href="#Dialect.normalize_identifier-331"><span class="linenos">331</span></a> <span class="p">)</span> +</span><span id="Dialect.normalize_identifier-332"><a href="#Dialect.normalize_identifier-332"><span class="linenos">332</span></a> <span class="p">):</span> +</span><span id="Dialect.normalize_identifier-333"><a href="#Dialect.normalize_identifier-333"><span class="linenos">333</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="Dialect.normalize_identifier-334"><a href="#Dialect.normalize_identifier-334"><span class="linenos">334</span></a> <span class="s2">"this"</span><span class="p">,</span> +</span><span id="Dialect.normalize_identifier-335"><a href="#Dialect.normalize_identifier-335"><span class="linenos">335</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> +</span><span id="Dialect.normalize_identifier-336"><a href="#Dialect.normalize_identifier-336"><span class="linenos">336</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">UPPERCASE</span> +</span><span id="Dialect.normalize_identifier-337"><a href="#Dialect.normalize_identifier-337"><span class="linenos">337</span></a> <span class="k">else</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> +</span><span id="Dialect.normalize_identifier-338"><a href="#Dialect.normalize_identifier-338"><span class="linenos">338</span></a> <span class="p">)</span> +</span><span id="Dialect.normalize_identifier-339"><a href="#Dialect.normalize_identifier-339"><span class="linenos">339</span></a> +</span><span id="Dialect.normalize_identifier-340"><a href="#Dialect.normalize_identifier-340"><span class="linenos">340</span></a> <span class="k">return</span> <span class="n">expression</span> </span></pre></div> @@ -2922,17 +2943,17 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#Dialect.case_sensitive"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.case_sensitive-339"><a href="#Dialect.case_sensitive-339"><span class="linenos">339</span></a> <span class="k">def</span> <span class="nf">case_sensitive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> -</span><span id="Dialect.case_sensitive-340"><a href="#Dialect.case_sensitive-340"><span class="linenos">340</span></a><span class="w"> </span><span class="sd">"""Checks if text contains any case sensitive characters, based on the dialect's rules."""</span> -</span><span id="Dialect.case_sensitive-341"><a href="#Dialect.case_sensitive-341"><span class="linenos">341</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_INSENSITIVE</span><span class="p">:</span> -</span><span id="Dialect.case_sensitive-342"><a href="#Dialect.case_sensitive-342"><span class="linenos">342</span></a> <span class="k">return</span> <span class="kc">False</span> -</span><span id="Dialect.case_sensitive-343"><a href="#Dialect.case_sensitive-343"><span class="linenos">343</span></a> -</span><span id="Dialect.case_sensitive-344"><a href="#Dialect.case_sensitive-344"><span class="linenos">344</span></a> <span class="n">unsafe</span> <span class="o">=</span> <span class="p">(</span> -</span><span id="Dialect.case_sensitive-345"><a href="#Dialect.case_sensitive-345"><span class="linenos">345</span></a> <span class="nb">str</span><span class="o">.</span><span class="n">islower</span> -</span><span id="Dialect.case_sensitive-346"><a href="#Dialect.case_sensitive-346"><span class="linenos">346</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">UPPERCASE</span> -</span><span id="Dialect.case_sensitive-347"><a href="#Dialect.case_sensitive-347"><span class="linenos">347</span></a> <span class="k">else</span> <span class="nb">str</span><span class="o">.</span><span class="n">isupper</span> -</span><span id="Dialect.case_sensitive-348"><a href="#Dialect.case_sensitive-348"><span class="linenos">348</span></a> <span class="p">)</span> -</span><span id="Dialect.case_sensitive-349"><a href="#Dialect.case_sensitive-349"><span class="linenos">349</span></a> <span class="k">return</span> <span class="nb">any</span><span class="p">(</span><span class="n">unsafe</span><span class="p">(</span><span class="n">char</span><span class="p">)</span> <span class="k">for</span> <span class="n">char</span> <span class="ow">in</span> <span class="n">text</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.case_sensitive-342"><a href="#Dialect.case_sensitive-342"><span class="linenos">342</span></a> <span class="k">def</span> <span class="nf">case_sensitive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> +</span><span id="Dialect.case_sensitive-343"><a href="#Dialect.case_sensitive-343"><span class="linenos">343</span></a><span class="w"> </span><span class="sd">"""Checks if text contains any case sensitive characters, based on the dialect's rules."""</span> +</span><span id="Dialect.case_sensitive-344"><a href="#Dialect.case_sensitive-344"><span class="linenos">344</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_INSENSITIVE</span><span class="p">:</span> +</span><span id="Dialect.case_sensitive-345"><a href="#Dialect.case_sensitive-345"><span class="linenos">345</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="Dialect.case_sensitive-346"><a href="#Dialect.case_sensitive-346"><span class="linenos">346</span></a> +</span><span id="Dialect.case_sensitive-347"><a href="#Dialect.case_sensitive-347"><span class="linenos">347</span></a> <span class="n">unsafe</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="Dialect.case_sensitive-348"><a href="#Dialect.case_sensitive-348"><span class="linenos">348</span></a> <span class="nb">str</span><span class="o">.</span><span class="n">islower</span> +</span><span id="Dialect.case_sensitive-349"><a href="#Dialect.case_sensitive-349"><span class="linenos">349</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">UPPERCASE</span> +</span><span id="Dialect.case_sensitive-350"><a href="#Dialect.case_sensitive-350"><span class="linenos">350</span></a> <span class="k">else</span> <span class="nb">str</span><span class="o">.</span><span class="n">isupper</span> +</span><span id="Dialect.case_sensitive-351"><a href="#Dialect.case_sensitive-351"><span class="linenos">351</span></a> <span class="p">)</span> +</span><span id="Dialect.case_sensitive-352"><a href="#Dialect.case_sensitive-352"><span class="linenos">352</span></a> <span class="k">return</span> <span class="nb">any</span><span class="p">(</span><span class="n">unsafe</span><span class="p">(</span><span class="n">char</span><span class="p">)</span> <span class="k">for</span> <span class="n">char</span> <span class="ow">in</span> <span class="n">text</span><span class="p">)</span> </span></pre></div> @@ -2952,25 +2973,25 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#Dialect.can_identify"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.can_identify-351"><a href="#Dialect.can_identify-351"><span class="linenos">351</span></a> <span class="k">def</span> <span class="nf">can_identify</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">identify</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">bool</span> <span class="o">=</span> <span class="s2">"safe"</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> -</span><span id="Dialect.can_identify-352"><a href="#Dialect.can_identify-352"><span class="linenos">352</span></a><span class="w"> </span><span class="sd">"""Checks if text can be identified given an identify option.</span> -</span><span id="Dialect.can_identify-353"><a href="#Dialect.can_identify-353"><span class="linenos">353</span></a> -</span><span id="Dialect.can_identify-354"><a href="#Dialect.can_identify-354"><span class="linenos">354</span></a><span class="sd"> Args:</span> -</span><span id="Dialect.can_identify-355"><a href="#Dialect.can_identify-355"><span class="linenos">355</span></a><span class="sd"> text: The text to check.</span> -</span><span id="Dialect.can_identify-356"><a href="#Dialect.can_identify-356"><span class="linenos">356</span></a><span class="sd"> identify:</span> -</span><span id="Dialect.can_identify-357"><a href="#Dialect.can_identify-357"><span class="linenos">357</span></a><span class="sd"> "always" or `True`: Always returns true.</span> -</span><span id="Dialect.can_identify-358"><a href="#Dialect.can_identify-358"><span class="linenos">358</span></a><span class="sd"> "safe": True if the identifier is case-insensitive.</span> -</span><span id="Dialect.can_identify-359"><a href="#Dialect.can_identify-359"><span class="linenos">359</span></a> -</span><span id="Dialect.can_identify-360"><a href="#Dialect.can_identify-360"><span class="linenos">360</span></a><span class="sd"> Returns:</span> -</span><span id="Dialect.can_identify-361"><a href="#Dialect.can_identify-361"><span class="linenos">361</span></a><span class="sd"> Whether or not the given text can be identified.</span> -</span><span id="Dialect.can_identify-362"><a href="#Dialect.can_identify-362"><span class="linenos">362</span></a><span class="sd"> """</span> -</span><span id="Dialect.can_identify-363"><a href="#Dialect.can_identify-363"><span class="linenos">363</span></a> <span class="k">if</span> <span class="n">identify</span> <span class="ow">is</span> <span class="kc">True</span> <span class="ow">or</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"always"</span><span class="p">:</span> -</span><span id="Dialect.can_identify-364"><a href="#Dialect.can_identify-364"><span class="linenos">364</span></a> <span class="k">return</span> <span class="kc">True</span> -</span><span id="Dialect.can_identify-365"><a href="#Dialect.can_identify-365"><span class="linenos">365</span></a> -</span><span id="Dialect.can_identify-366"><a href="#Dialect.can_identify-366"><span class="linenos">366</span></a> <span class="k">if</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"safe"</span><span class="p">:</span> -</span><span id="Dialect.can_identify-367"><a href="#Dialect.can_identify-367"><span class="linenos">367</span></a> <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">case_sensitive</span><span class="p">(</span><span class="n">text</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.can_identify-354"><a href="#Dialect.can_identify-354"><span class="linenos">354</span></a> <span class="k">def</span> <span class="nf">can_identify</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">identify</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">bool</span> <span class="o">=</span> <span class="s2">"safe"</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> +</span><span id="Dialect.can_identify-355"><a href="#Dialect.can_identify-355"><span class="linenos">355</span></a><span class="w"> </span><span class="sd">"""Checks if text can be identified given an identify option.</span> +</span><span id="Dialect.can_identify-356"><a href="#Dialect.can_identify-356"><span class="linenos">356</span></a> +</span><span id="Dialect.can_identify-357"><a href="#Dialect.can_identify-357"><span class="linenos">357</span></a><span class="sd"> Args:</span> +</span><span id="Dialect.can_identify-358"><a href="#Dialect.can_identify-358"><span class="linenos">358</span></a><span class="sd"> text: The text to check.</span> +</span><span id="Dialect.can_identify-359"><a href="#Dialect.can_identify-359"><span class="linenos">359</span></a><span class="sd"> identify:</span> +</span><span id="Dialect.can_identify-360"><a href="#Dialect.can_identify-360"><span class="linenos">360</span></a><span class="sd"> "always" or `True`: Always returns true.</span> +</span><span id="Dialect.can_identify-361"><a href="#Dialect.can_identify-361"><span class="linenos">361</span></a><span class="sd"> "safe": True if the identifier is case-insensitive.</span> +</span><span id="Dialect.can_identify-362"><a href="#Dialect.can_identify-362"><span class="linenos">362</span></a> +</span><span id="Dialect.can_identify-363"><a href="#Dialect.can_identify-363"><span class="linenos">363</span></a><span class="sd"> Returns:</span> +</span><span id="Dialect.can_identify-364"><a href="#Dialect.can_identify-364"><span class="linenos">364</span></a><span class="sd"> Whether or not the given text can be identified.</span> +</span><span id="Dialect.can_identify-365"><a href="#Dialect.can_identify-365"><span class="linenos">365</span></a><span class="sd"> """</span> +</span><span id="Dialect.can_identify-366"><a href="#Dialect.can_identify-366"><span class="linenos">366</span></a> <span class="k">if</span> <span class="n">identify</span> <span class="ow">is</span> <span class="kc">True</span> <span class="ow">or</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"always"</span><span class="p">:</span> +</span><span id="Dialect.can_identify-367"><a href="#Dialect.can_identify-367"><span class="linenos">367</span></a> <span class="k">return</span> <span class="kc">True</span> </span><span id="Dialect.can_identify-368"><a href="#Dialect.can_identify-368"><span class="linenos">368</span></a> -</span><span id="Dialect.can_identify-369"><a href="#Dialect.can_identify-369"><span class="linenos">369</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="Dialect.can_identify-369"><a href="#Dialect.can_identify-369"><span class="linenos">369</span></a> <span class="k">if</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"safe"</span><span class="p">:</span> +</span><span id="Dialect.can_identify-370"><a href="#Dialect.can_identify-370"><span class="linenos">370</span></a> <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">case_sensitive</span><span class="p">(</span><span class="n">text</span><span class="p">)</span> +</span><span id="Dialect.can_identify-371"><a href="#Dialect.can_identify-371"><span class="linenos">371</span></a> +</span><span id="Dialect.can_identify-372"><a href="#Dialect.can_identify-372"><span class="linenos">372</span></a> <span class="k">return</span> <span class="kc">False</span> </span></pre></div> @@ -3004,15 +3025,15 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#Dialect.quote_identifier"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.quote_identifier-371"><a href="#Dialect.quote_identifier-371"><span class="linenos">371</span></a> <span class="k">def</span> <span class="nf">quote_identifier</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">E</span><span class="p">,</span> <span class="n">identify</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span> <span class="o">-></span> <span class="n">E</span><span class="p">:</span> -</span><span id="Dialect.quote_identifier-372"><a href="#Dialect.quote_identifier-372"><span class="linenos">372</span></a> <span class="k">if</span> <span class="nb">isinstance</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">Identifier</span><span class="p">):</span> -</span><span id="Dialect.quote_identifier-373"><a href="#Dialect.quote_identifier-373"><span class="linenos">373</span></a> <span class="n">name</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> -</span><span id="Dialect.quote_identifier-374"><a href="#Dialect.quote_identifier-374"><span class="linenos">374</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> -</span><span id="Dialect.quote_identifier-375"><a href="#Dialect.quote_identifier-375"><span class="linenos">375</span></a> <span class="s2">"quoted"</span><span class="p">,</span> -</span><span id="Dialect.quote_identifier-376"><a href="#Dialect.quote_identifier-376"><span class="linenos">376</span></a> <span class="n">identify</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">case_sensitive</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">exp</span><span class="o">.</span><span class="n">SAFE_IDENTIFIER_RE</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">name</span><span class="p">),</span> -</span><span id="Dialect.quote_identifier-377"><a href="#Dialect.quote_identifier-377"><span class="linenos">377</span></a> <span class="p">)</span> -</span><span id="Dialect.quote_identifier-378"><a href="#Dialect.quote_identifier-378"><span class="linenos">378</span></a> -</span><span id="Dialect.quote_identifier-379"><a href="#Dialect.quote_identifier-379"><span class="linenos">379</span></a> <span class="k">return</span> <span class="n">expression</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.quote_identifier-374"><a href="#Dialect.quote_identifier-374"><span class="linenos">374</span></a> <span class="k">def</span> <span class="nf">quote_identifier</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">E</span><span class="p">,</span> <span class="n">identify</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span> <span class="o">-></span> <span class="n">E</span><span class="p">:</span> +</span><span id="Dialect.quote_identifier-375"><a href="#Dialect.quote_identifier-375"><span class="linenos">375</span></a> <span class="k">if</span> <span class="nb">isinstance</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">Identifier</span><span class="p">):</span> +</span><span id="Dialect.quote_identifier-376"><a href="#Dialect.quote_identifier-376"><span class="linenos">376</span></a> <span class="n">name</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="Dialect.quote_identifier-377"><a href="#Dialect.quote_identifier-377"><span class="linenos">377</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="Dialect.quote_identifier-378"><a href="#Dialect.quote_identifier-378"><span class="linenos">378</span></a> <span class="s2">"quoted"</span><span class="p">,</span> +</span><span id="Dialect.quote_identifier-379"><a href="#Dialect.quote_identifier-379"><span class="linenos">379</span></a> <span class="n">identify</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">case_sensitive</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">exp</span><span class="o">.</span><span class="n">SAFE_IDENTIFIER_RE</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">name</span><span class="p">),</span> +</span><span id="Dialect.quote_identifier-380"><a href="#Dialect.quote_identifier-380"><span class="linenos">380</span></a> <span class="p">)</span> +</span><span id="Dialect.quote_identifier-381"><a href="#Dialect.quote_identifier-381"><span class="linenos">381</span></a> +</span><span id="Dialect.quote_identifier-382"><a href="#Dialect.quote_identifier-382"><span class="linenos">382</span></a> <span class="k">return</span> <span class="n">expression</span> </span></pre></div> @@ -3030,8 +3051,8 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#Dialect.parse"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.parse-381"><a href="#Dialect.parse-381"><span class="linenos">381</span></a> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="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">Expression</span><span class="p">]]:</span> -</span><span id="Dialect.parse-382"><a href="#Dialect.parse-382"><span class="linenos">382</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">),</span> <span class="n">sql</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.parse-384"><a href="#Dialect.parse-384"><span class="linenos">384</span></a> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="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">Expression</span><span class="p">]]:</span> +</span><span id="Dialect.parse-385"><a href="#Dialect.parse-385"><span class="linenos">385</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">),</span> <span class="n">sql</span><span class="p">)</span> </span></pre></div> @@ -3049,10 +3070,10 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#Dialect.parse_into"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.parse_into-384"><a href="#Dialect.parse_into-384"><span class="linenos">384</span></a> <span class="k">def</span> <span class="nf">parse_into</span><span class="p">(</span> -</span><span id="Dialect.parse_into-385"><a href="#Dialect.parse_into-385"><span class="linenos">385</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">expression_type</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">IntoType</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span> -</span><span id="Dialect.parse_into-386"><a href="#Dialect.parse_into-386"><span class="linenos">386</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="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">Expression</span><span class="p">]]:</span> -</span><span id="Dialect.parse_into-387"><a href="#Dialect.parse_into-387"><span class="linenos">387</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">parse_into</span><span class="p">(</span><span class="n">expression_type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">),</span> <span class="n">sql</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.parse_into-387"><a href="#Dialect.parse_into-387"><span class="linenos">387</span></a> <span class="k">def</span> <span class="nf">parse_into</span><span class="p">(</span> +</span><span id="Dialect.parse_into-388"><a href="#Dialect.parse_into-388"><span class="linenos">388</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">expression_type</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">IntoType</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span> +</span><span id="Dialect.parse_into-389"><a href="#Dialect.parse_into-389"><span class="linenos">389</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="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">Expression</span><span class="p">]]:</span> +</span><span id="Dialect.parse_into-390"><a href="#Dialect.parse_into-390"><span class="linenos">390</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">parse_into</span><span class="p">(</span><span class="n">expression_type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">),</span> <span class="n">sql</span><span class="p">)</span> </span></pre></div> @@ -3070,8 +3091,8 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#Dialect.generate"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.generate-389"><a href="#Dialect.generate-389"><span class="linenos">389</span></a> <span class="k">def</span> <span class="nf">generate</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">Expression</span><span class="p">,</span> <span class="n">copy</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Dialect.generate-390"><a href="#Dialect.generate-390"><span class="linenos">390</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="n">copy</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.generate-392"><a href="#Dialect.generate-392"><span class="linenos">392</span></a> <span class="k">def</span> <span class="nf">generate</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">Expression</span><span class="p">,</span> <span class="n">copy</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Dialect.generate-393"><a href="#Dialect.generate-393"><span class="linenos">393</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator</span><span class="p">(</span><span class="o">**</span><span class="n">opts</span><span class="p">)</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="n">copy</span><span class="p">)</span> </span></pre></div> @@ -3089,11 +3110,11 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#Dialect.transpile"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.transpile-392"><a href="#Dialect.transpile-392"><span class="linenos">392</span></a> <span class="k">def</span> <span class="nf">transpile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> -</span><span id="Dialect.transpile-393"><a href="#Dialect.transpile-393"><span class="linenos">393</span></a> <span class="k">return</span> <span class="p">[</span> -</span><span id="Dialect.transpile-394"><a href="#Dialect.transpile-394"><span class="linenos">394</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="k">if</span> <span class="n">expression</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="Dialect.transpile-395"><a href="#Dialect.transpile-395"><span class="linenos">395</span></a> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> -</span><span id="Dialect.transpile-396"><a href="#Dialect.transpile-396"><span class="linenos">396</span></a> <span class="p">]</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.transpile-395"><a href="#Dialect.transpile-395"><span class="linenos">395</span></a> <span class="k">def</span> <span class="nf">transpile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="Dialect.transpile-396"><a href="#Dialect.transpile-396"><span class="linenos">396</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="Dialect.transpile-397"><a href="#Dialect.transpile-397"><span class="linenos">397</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">copy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="k">if</span> <span class="n">expression</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="Dialect.transpile-398"><a href="#Dialect.transpile-398"><span class="linenos">398</span></a> <span class="k">for</span> <span class="n">expression</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> +</span><span id="Dialect.transpile-399"><a href="#Dialect.transpile-399"><span class="linenos">399</span></a> <span class="p">]</span> </span></pre></div> @@ -3111,8 +3132,8 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#Dialect.tokenize"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.tokenize-398"><a href="#Dialect.tokenize-398"><span class="linenos">398</span></a> <span class="k">def</span> <span class="nf">tokenize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Token</span><span class="p">]:</span> -</span><span id="Dialect.tokenize-399"><a href="#Dialect.tokenize-399"><span class="linenos">399</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenizer</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.tokenize-401"><a href="#Dialect.tokenize-401"><span class="linenos">401</span></a> <span class="k">def</span> <span class="nf">tokenize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Token</span><span class="p">]:</span> +</span><span id="Dialect.tokenize-402"><a href="#Dialect.tokenize-402"><span class="linenos">402</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">tokenizer</span><span class="o">.</span><span class="n">tokenize</span><span class="p">(</span><span class="n">sql</span><span class="p">)</span> </span></pre></div> @@ -3141,8 +3162,8 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#Dialect.parser"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.parser-407"><a href="#Dialect.parser-407"><span class="linenos">407</span></a> <span class="k">def</span> <span class="nf">parser</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">Parser</span><span class="p">:</span> -</span><span id="Dialect.parser-408"><a href="#Dialect.parser-408"><span class="linenos">408</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.parser-410"><a href="#Dialect.parser-410"><span class="linenos">410</span></a> <span class="k">def</span> <span class="nf">parser</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">Parser</span><span class="p">:</span> +</span><span id="Dialect.parser-411"><a href="#Dialect.parser-411"><span class="linenos">411</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> </span></pre></div> @@ -3160,8 +3181,8 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#Dialect.generator"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.generator-410"><a href="#Dialect.generator-410"><span class="linenos">410</span></a> <span class="k">def</span> <span class="nf">generator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">Generator</span><span class="p">:</span> -</span><span id="Dialect.generator-411"><a href="#Dialect.generator-411"><span class="linenos">411</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.generator-413"><a href="#Dialect.generator-413"><span class="linenos">413</span></a> <span class="k">def</span> <span class="nf">generator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> <span class="o">-></span> <span class="n">Generator</span><span class="p">:</span> +</span><span id="Dialect.generator-414"><a href="#Dialect.generator-414"><span class="linenos">414</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">generator_class</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">opts</span><span class="p">)</span> </span></pre></div> @@ -3193,8 +3214,8 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#rename_func"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="rename_func-417"><a href="#rename_func-417"><span class="linenos">417</span></a><span class="k">def</span> <span class="nf">rename_func</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</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="nb">str</span><span class="p">]:</span> -</span><span id="rename_func-418"><a href="#rename_func-418"><span class="linenos">418</span></a> <span class="k">return</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">expression</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="n">name</span><span class="p">,</span> <span class="o">*</span><span class="n">flatten</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="rename_func-420"><a href="#rename_func-420"><span class="linenos">420</span></a><span class="k">def</span> <span class="nf">rename_func</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</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="nb">str</span><span class="p">]:</span> +</span><span id="rename_func-421"><a href="#rename_func-421"><span class="linenos">421</span></a> <span class="k">return</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">expression</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="n">name</span><span class="p">,</span> <span class="o">*</span><span class="n">flatten</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span> </span></pre></div> @@ -3212,10 +3233,10 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#approx_count_distinct_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="approx_count_distinct_sql-421"><a href="#approx_count_distinct_sql-421"><span class="linenos">421</span></a><span class="k">def</span> <span class="nf">approx_count_distinct_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="approx_count_distinct_sql-422"><a href="#approx_count_distinct_sql-422"><span class="linenos">422</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">"accuracy"</span><span class="p">):</span> -</span><span id="approx_count_distinct_sql-423"><a href="#approx_count_distinct_sql-423"><span class="linenos">423</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"APPROX_COUNT_DISTINCT does not support accuracy"</span><span class="p">)</span> -</span><span id="approx_count_distinct_sql-424"><a href="#approx_count_distinct_sql-424"><span class="linenos">424</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">"APPROX_COUNT_DISTINCT"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="approx_count_distinct_sql-424"><a href="#approx_count_distinct_sql-424"><span class="linenos">424</span></a><span class="k">def</span> <span class="nf">approx_count_distinct_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="approx_count_distinct_sql-425"><a href="#approx_count_distinct_sql-425"><span class="linenos">425</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">"accuracy"</span><span class="p">):</span> +</span><span id="approx_count_distinct_sql-426"><a href="#approx_count_distinct_sql-426"><span class="linenos">426</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"APPROX_COUNT_DISTINCT does not support accuracy"</span><span class="p">)</span> +</span><span id="approx_count_distinct_sql-427"><a href="#approx_count_distinct_sql-427"><span class="linenos">427</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">"APPROX_COUNT_DISTINCT"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> </span></pre></div> @@ -3233,18 +3254,18 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#if_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="if_sql-427"><a href="#if_sql-427"><span class="linenos">427</span></a><span class="k">def</span> <span class="nf">if_sql</span><span class="p">(</span> -</span><span id="if_sql-428"><a href="#if_sql-428"><span class="linenos">428</span></a> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"IF"</span><span class="p">,</span> <span class="n">false_value</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">Expression</span> <span class="o">|</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="if_sql-429"><a href="#if_sql-429"><span class="linenos">429</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">If</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> -</span><span id="if_sql-430"><a href="#if_sql-430"><span class="linenos">430</span></a> <span class="k">def</span> <span class="nf">_if_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">If</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="if_sql-431"><a href="#if_sql-431"><span class="linenos">431</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="if_sql-432"><a href="#if_sql-432"><span class="linenos">432</span></a> <span class="n">name</span><span class="p">,</span> -</span><span id="if_sql-433"><a href="#if_sql-433"><span class="linenos">433</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="if_sql-434"><a href="#if_sql-434"><span class="linenos">434</span></a> <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">"true"</span><span class="p">),</span> -</span><span id="if_sql-435"><a href="#if_sql-435"><span class="linenos">435</span></a> <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">"false"</span><span class="p">)</span> <span class="ow">or</span> <span class="n">false_value</span><span class="p">,</span> -</span><span id="if_sql-436"><a href="#if_sql-436"><span class="linenos">436</span></a> <span class="p">)</span> -</span><span id="if_sql-437"><a href="#if_sql-437"><span class="linenos">437</span></a> -</span><span id="if_sql-438"><a href="#if_sql-438"><span class="linenos">438</span></a> <span class="k">return</span> <span class="n">_if_sql</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="if_sql-430"><a href="#if_sql-430"><span class="linenos">430</span></a><span class="k">def</span> <span class="nf">if_sql</span><span class="p">(</span> +</span><span id="if_sql-431"><a href="#if_sql-431"><span class="linenos">431</span></a> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"IF"</span><span class="p">,</span> <span class="n">false_value</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">Expression</span> <span class="o">|</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="if_sql-432"><a href="#if_sql-432"><span class="linenos">432</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">If</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> +</span><span id="if_sql-433"><a href="#if_sql-433"><span class="linenos">433</span></a> <span class="k">def</span> <span class="nf">_if_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">If</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="if_sql-434"><a href="#if_sql-434"><span class="linenos">434</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="if_sql-435"><a href="#if_sql-435"><span class="linenos">435</span></a> <span class="n">name</span><span class="p">,</span> +</span><span id="if_sql-436"><a href="#if_sql-436"><span class="linenos">436</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="if_sql-437"><a href="#if_sql-437"><span class="linenos">437</span></a> <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">"true"</span><span class="p">),</span> +</span><span id="if_sql-438"><a href="#if_sql-438"><span class="linenos">438</span></a> <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">"false"</span><span class="p">)</span> <span class="ow">or</span> <span class="n">false_value</span><span class="p">,</span> +</span><span id="if_sql-439"><a href="#if_sql-439"><span class="linenos">439</span></a> <span class="p">)</span> +</span><span id="if_sql-440"><a href="#if_sql-440"><span class="linenos">440</span></a> +</span><span id="if_sql-441"><a href="#if_sql-441"><span class="linenos">441</span></a> <span class="k">return</span> <span class="n">_if_sql</span> </span></pre></div> @@ -3262,8 +3283,8 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#arrow_json_extract_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="arrow_json_extract_sql-441"><a href="#arrow_json_extract_sql-441"><span class="linenos">441</span></a><span class="k">def</span> <span class="nf">arrow_json_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtract</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONBExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="arrow_json_extract_sql-442"><a href="#arrow_json_extract_sql-442"><span class="linenos">442</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"->"</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="arrow_json_extract_sql-444"><a href="#arrow_json_extract_sql-444"><span class="linenos">444</span></a><span class="k">def</span> <span class="nf">arrow_json_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtract</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONBExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="arrow_json_extract_sql-445"><a href="#arrow_json_extract_sql-445"><span class="linenos">445</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"->"</span><span class="p">)</span> </span></pre></div> @@ -3281,10 +3302,10 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#arrow_json_extract_scalar_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="arrow_json_extract_scalar_sql-445"><a href="#arrow_json_extract_scalar_sql-445"><span class="linenos">445</span></a><span class="k">def</span> <span class="nf">arrow_json_extract_scalar_sql</span><span class="p">(</span> -</span><span id="arrow_json_extract_scalar_sql-446"><a href="#arrow_json_extract_scalar_sql-446"><span class="linenos">446</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONBExtractScalar</span> -</span><span id="arrow_json_extract_scalar_sql-447"><a href="#arrow_json_extract_scalar_sql-447"><span class="linenos">447</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="arrow_json_extract_scalar_sql-448"><a href="#arrow_json_extract_scalar_sql-448"><span class="linenos">448</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"->>"</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="arrow_json_extract_scalar_sql-448"><a href="#arrow_json_extract_scalar_sql-448"><span class="linenos">448</span></a><span class="k">def</span> <span class="nf">arrow_json_extract_scalar_sql</span><span class="p">(</span> +</span><span id="arrow_json_extract_scalar_sql-449"><a href="#arrow_json_extract_scalar_sql-449"><span class="linenos">449</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONBExtractScalar</span> +</span><span id="arrow_json_extract_scalar_sql-450"><a href="#arrow_json_extract_scalar_sql-450"><span class="linenos">450</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="arrow_json_extract_scalar_sql-451"><a href="#arrow_json_extract_scalar_sql-451"><span class="linenos">451</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">binary</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"->>"</span><span class="p">)</span> </span></pre></div> @@ -3302,8 +3323,8 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#inline_array_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="inline_array_sql-451"><a href="#inline_array_sql-451"><span class="linenos">451</span></a><span class="k">def</span> <span class="nf">inline_array_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Array</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="inline_array_sql-452"><a href="#inline_array_sql-452"><span class="linenos">452</span></a> <span class="k">return</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">expressions</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span><span class="w"> </span><span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span><span class="si">}</span><span class="s2">]"</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="inline_array_sql-454"><a href="#inline_array_sql-454"><span class="linenos">454</span></a><span class="k">def</span> <span class="nf">inline_array_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Array</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="inline_array_sql-455"><a href="#inline_array_sql-455"><span class="linenos">455</span></a> <span class="k">return</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">expressions</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span><span class="w"> </span><span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span><span class="si">}</span><span class="s2">]"</span> </span></pre></div> @@ -3321,10 +3342,10 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#no_ilike_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="no_ilike_sql-455"><a href="#no_ilike_sql-455"><span class="linenos">455</span></a><span class="k">def</span> <span class="nf">no_ilike_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ILike</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="no_ilike_sql-456"><a href="#no_ilike_sql-456"><span class="linenos">456</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">like_sql</span><span class="p">(</span> -</span><span id="no_ilike_sql-457"><a href="#no_ilike_sql-457"><span class="linenos">457</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Like</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Lower</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">),</span> <span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> -</span><span id="no_ilike_sql-458"><a href="#no_ilike_sql-458"><span class="linenos">458</span></a> <span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="no_ilike_sql-458"><a href="#no_ilike_sql-458"><span class="linenos">458</span></a><span class="k">def</span> <span class="nf">no_ilike_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ILike</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="no_ilike_sql-459"><a href="#no_ilike_sql-459"><span class="linenos">459</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">like_sql</span><span class="p">(</span> +</span><span id="no_ilike_sql-460"><a href="#no_ilike_sql-460"><span class="linenos">460</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Like</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Lower</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">),</span> <span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="no_ilike_sql-461"><a href="#no_ilike_sql-461"><span class="linenos">461</span></a> <span class="p">)</span> </span></pre></div> @@ -3342,9 +3363,9 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#no_paren_current_date_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="no_paren_current_date_sql-461"><a href="#no_paren_current_date_sql-461"><span class="linenos">461</span></a><span class="k">def</span> <span class="nf">no_paren_current_date_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">CurrentDate</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="no_paren_current_date_sql-462"><a href="#no_paren_current_date_sql-462"><span class="linenos">462</span></a> <span class="n">zone</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> -</span><span id="no_paren_current_date_sql-463"><a href="#no_paren_current_date_sql-463"><span class="linenos">463</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"CURRENT_DATE AT TIME ZONE </span><span class="si">{</span><span class="n">zone</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">zone</span> <span class="k">else</span> <span class="s2">"CURRENT_DATE"</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="no_paren_current_date_sql-464"><a href="#no_paren_current_date_sql-464"><span class="linenos">464</span></a><span class="k">def</span> <span class="nf">no_paren_current_date_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">CurrentDate</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="no_paren_current_date_sql-465"><a href="#no_paren_current_date_sql-465"><span class="linenos">465</span></a> <span class="n">zone</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> +</span><span id="no_paren_current_date_sql-466"><a href="#no_paren_current_date_sql-466"><span class="linenos">466</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"CURRENT_DATE AT TIME ZONE </span><span class="si">{</span><span class="n">zone</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">zone</span> <span class="k">else</span> <span class="s2">"CURRENT_DATE"</span> </span></pre></div> @@ -3362,11 +3383,11 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#no_recursive_cte_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="no_recursive_cte_sql-466"><a href="#no_recursive_cte_sql-466"><span class="linenos">466</span></a><span class="k">def</span> <span class="nf">no_recursive_cte_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">With</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="no_recursive_cte_sql-467"><a href="#no_recursive_cte_sql-467"><span class="linenos">467</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">"recursive"</span><span class="p">):</span> -</span><span id="no_recursive_cte_sql-468"><a href="#no_recursive_cte_sql-468"><span class="linenos">468</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Recursive CTEs are unsupported"</span><span class="p">)</span> -</span><span id="no_recursive_cte_sql-469"><a href="#no_recursive_cte_sql-469"><span class="linenos">469</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"recursive"</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="no_recursive_cte_sql-470"><a href="#no_recursive_cte_sql-470"><span class="linenos">470</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">with_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="no_recursive_cte_sql-469"><a href="#no_recursive_cte_sql-469"><span class="linenos">469</span></a><span class="k">def</span> <span class="nf">no_recursive_cte_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">With</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="no_recursive_cte_sql-470"><a href="#no_recursive_cte_sql-470"><span class="linenos">470</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">"recursive"</span><span class="p">):</span> +</span><span id="no_recursive_cte_sql-471"><a href="#no_recursive_cte_sql-471"><span class="linenos">471</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Recursive CTEs are unsupported"</span><span class="p">)</span> +</span><span id="no_recursive_cte_sql-472"><a href="#no_recursive_cte_sql-472"><span class="linenos">472</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"recursive"</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="no_recursive_cte_sql-473"><a href="#no_recursive_cte_sql-473"><span class="linenos">473</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">with_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -3384,10 +3405,10 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#no_safe_divide_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="no_safe_divide_sql-473"><a href="#no_safe_divide_sql-473"><span class="linenos">473</span></a><span class="k">def</span> <span class="nf">no_safe_divide_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">SafeDivide</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="no_safe_divide_sql-474"><a href="#no_safe_divide_sql-474"><span class="linenos">474</span></a> <span class="n">n</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> -</span><span id="no_safe_divide_sql-475"><a href="#no_safe_divide_sql-475"><span class="linenos">475</span></a> <span class="n">d</span> <span class="o">=</span> <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">"expression"</span><span class="p">)</span> -</span><span id="no_safe_divide_sql-476"><a href="#no_safe_divide_sql-476"><span class="linenos">476</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"IF(</span><span class="si">{</span><span class="n">d</span><span class="si">}</span><span class="s2"> <> 0, </span><span class="si">{</span><span class="n">n</span><span class="si">}</span><span class="s2"> / </span><span class="si">{</span><span class="n">d</span><span class="si">}</span><span class="s2">, NULL)"</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="no_safe_divide_sql-476"><a href="#no_safe_divide_sql-476"><span class="linenos">476</span></a><span class="k">def</span> <span class="nf">no_safe_divide_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">SafeDivide</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="no_safe_divide_sql-477"><a href="#no_safe_divide_sql-477"><span class="linenos">477</span></a> <span class="n">n</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> +</span><span id="no_safe_divide_sql-478"><a href="#no_safe_divide_sql-478"><span class="linenos">478</span></a> <span class="n">d</span> <span class="o">=</span> <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">"expression"</span><span class="p">)</span> +</span><span id="no_safe_divide_sql-479"><a href="#no_safe_divide_sql-479"><span class="linenos">479</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"IF(</span><span class="si">{</span><span class="n">d</span><span class="si">}</span><span class="s2"> <> 0, </span><span class="si">{</span><span class="n">n</span><span class="si">}</span><span class="s2"> / </span><span class="si">{</span><span class="n">d</span><span class="si">}</span><span class="s2">, NULL)"</span> </span></pre></div> @@ -3405,9 +3426,9 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#no_tablesample_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="no_tablesample_sql-479"><a href="#no_tablesample_sql-479"><span class="linenos">479</span></a><span class="k">def</span> <span class="nf">no_tablesample_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TableSample</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="no_tablesample_sql-480"><a href="#no_tablesample_sql-480"><span class="linenos">480</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"TABLESAMPLE unsupported"</span><span class="p">)</span> -</span><span id="no_tablesample_sql-481"><a href="#no_tablesample_sql-481"><span class="linenos">481</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="no_tablesample_sql-482"><a href="#no_tablesample_sql-482"><span class="linenos">482</span></a><span class="k">def</span> <span class="nf">no_tablesample_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TableSample</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="no_tablesample_sql-483"><a href="#no_tablesample_sql-483"><span class="linenos">483</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"TABLESAMPLE unsupported"</span><span class="p">)</span> +</span><span id="no_tablesample_sql-484"><a href="#no_tablesample_sql-484"><span class="linenos">484</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> </span></pre></div> @@ -3425,9 +3446,9 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#no_pivot_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="no_pivot_sql-484"><a href="#no_pivot_sql-484"><span class="linenos">484</span></a><span class="k">def</span> <span class="nf">no_pivot_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="no_pivot_sql-485"><a href="#no_pivot_sql-485"><span class="linenos">485</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"PIVOT unsupported"</span><span class="p">)</span> -</span><span id="no_pivot_sql-486"><a href="#no_pivot_sql-486"><span class="linenos">486</span></a> <span class="k">return</span> <span class="s2">""</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="no_pivot_sql-487"><a href="#no_pivot_sql-487"><span class="linenos">487</span></a><span class="k">def</span> <span class="nf">no_pivot_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="no_pivot_sql-488"><a href="#no_pivot_sql-488"><span class="linenos">488</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"PIVOT unsupported"</span><span class="p">)</span> +</span><span id="no_pivot_sql-489"><a href="#no_pivot_sql-489"><span class="linenos">489</span></a> <span class="k">return</span> <span class="s2">""</span> </span></pre></div> @@ -3445,8 +3466,8 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#no_trycast_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="no_trycast_sql-489"><a href="#no_trycast_sql-489"><span class="linenos">489</span></a><span class="k">def</span> <span class="nf">no_trycast_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TryCast</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="no_trycast_sql-490"><a href="#no_trycast_sql-490"><span class="linenos">490</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cast_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="no_trycast_sql-492"><a href="#no_trycast_sql-492"><span class="linenos">492</span></a><span class="k">def</span> <span class="nf">no_trycast_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TryCast</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="no_trycast_sql-493"><a href="#no_trycast_sql-493"><span class="linenos">493</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cast_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -3464,9 +3485,9 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#no_properties_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="no_properties_sql-493"><a href="#no_properties_sql-493"><span class="linenos">493</span></a><span class="k">def</span> <span class="nf">no_properties_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Properties</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="no_properties_sql-494"><a href="#no_properties_sql-494"><span class="linenos">494</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Properties unsupported"</span><span class="p">)</span> -</span><span id="no_properties_sql-495"><a href="#no_properties_sql-495"><span class="linenos">495</span></a> <span class="k">return</span> <span class="s2">""</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="no_properties_sql-496"><a href="#no_properties_sql-496"><span class="linenos">496</span></a><span class="k">def</span> <span class="nf">no_properties_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Properties</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="no_properties_sql-497"><a href="#no_properties_sql-497"><span class="linenos">497</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Properties unsupported"</span><span class="p">)</span> +</span><span id="no_properties_sql-498"><a href="#no_properties_sql-498"><span class="linenos">498</span></a> <span class="k">return</span> <span class="s2">""</span> </span></pre></div> @@ -3484,11 +3505,11 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#no_comment_column_constraint_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="no_comment_column_constraint_sql-498"><a href="#no_comment_column_constraint_sql-498"><span class="linenos">498</span></a><span class="k">def</span> <span class="nf">no_comment_column_constraint_sql</span><span class="p">(</span> -</span><span id="no_comment_column_constraint_sql-499"><a href="#no_comment_column_constraint_sql-499"><span class="linenos">499</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">CommentColumnConstraint</span> -</span><span id="no_comment_column_constraint_sql-500"><a href="#no_comment_column_constraint_sql-500"><span class="linenos">500</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="no_comment_column_constraint_sql-501"><a href="#no_comment_column_constraint_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 class="s2">"CommentColumnConstraint unsupported"</span><span class="p">)</span> -</span><span id="no_comment_column_constraint_sql-502"><a href="#no_comment_column_constraint_sql-502"><span class="linenos">502</span></a> <span class="k">return</span> <span class="s2">""</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="no_comment_column_constraint_sql-501"><a href="#no_comment_column_constraint_sql-501"><span class="linenos">501</span></a><span class="k">def</span> <span class="nf">no_comment_column_constraint_sql</span><span class="p">(</span> +</span><span id="no_comment_column_constraint_sql-502"><a href="#no_comment_column_constraint_sql-502"><span class="linenos">502</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">CommentColumnConstraint</span> +</span><span id="no_comment_column_constraint_sql-503"><a href="#no_comment_column_constraint_sql-503"><span class="linenos">503</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="no_comment_column_constraint_sql-504"><a href="#no_comment_column_constraint_sql-504"><span class="linenos">504</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"CommentColumnConstraint unsupported"</span><span class="p">)</span> +</span><span id="no_comment_column_constraint_sql-505"><a href="#no_comment_column_constraint_sql-505"><span class="linenos">505</span></a> <span class="k">return</span> <span class="s2">""</span> </span></pre></div> @@ -3506,9 +3527,9 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#no_map_from_entries_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="no_map_from_entries_sql-505"><a href="#no_map_from_entries_sql-505"><span class="linenos">505</span></a><span class="k">def</span> <span class="nf">no_map_from_entries_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">MapFromEntries</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="no_map_from_entries_sql-506"><a href="#no_map_from_entries_sql-506"><span class="linenos">506</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"MAP_FROM_ENTRIES unsupported"</span><span class="p">)</span> -</span><span id="no_map_from_entries_sql-507"><a href="#no_map_from_entries_sql-507"><span class="linenos">507</span></a> <span class="k">return</span> <span class="s2">""</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="no_map_from_entries_sql-508"><a href="#no_map_from_entries_sql-508"><span class="linenos">508</span></a><span class="k">def</span> <span class="nf">no_map_from_entries_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">MapFromEntries</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="no_map_from_entries_sql-509"><a href="#no_map_from_entries_sql-509"><span class="linenos">509</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"MAP_FROM_ENTRIES unsupported"</span><span class="p">)</span> +</span><span id="no_map_from_entries_sql-510"><a href="#no_map_from_entries_sql-510"><span class="linenos">510</span></a> <span class="k">return</span> <span class="s2">""</span> </span></pre></div> @@ -3526,13 +3547,13 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#str_position_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="str_position_sql-510"><a href="#str_position_sql-510"><span class="linenos">510</span></a><span class="k">def</span> <span class="nf">str_position_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrPosition</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="str_position_sql-511"><a href="#str_position_sql-511"><span class="linenos">511</span></a> <span class="n">this</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> -</span><span id="str_position_sql-512"><a href="#str_position_sql-512"><span class="linenos">512</span></a> <span class="n">substr</span> <span class="o">=</span> <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">"substr"</span><span class="p">)</span> -</span><span id="str_position_sql-513"><a href="#str_position_sql-513"><span class="linenos">513</span></a> <span class="n">position</span> <span class="o">=</span> <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">"position"</span><span class="p">)</span> -</span><span id="str_position_sql-514"><a href="#str_position_sql-514"><span class="linenos">514</span></a> <span class="k">if</span> <span class="n">position</span><span class="p">:</span> -</span><span id="str_position_sql-515"><a href="#str_position_sql-515"><span class="linenos">515</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"STRPOS(SUBSTR(</span><span class="si">{</span><span class="n">this</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">position</span><span class="si">}</span><span class="s2">), </span><span class="si">{</span><span class="n">substr</span><span class="si">}</span><span class="s2">) + </span><span class="si">{</span><span class="n">position</span><span class="si">}</span><span class="s2"> - 1"</span> -</span><span id="str_position_sql-516"><a href="#str_position_sql-516"><span class="linenos">516</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"STRPOS(</span><span class="si">{</span><span class="n">this</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">substr</span><span class="si">}</span><span class="s2">)"</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="str_position_sql-513"><a href="#str_position_sql-513"><span class="linenos">513</span></a><span class="k">def</span> <span class="nf">str_position_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrPosition</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="str_position_sql-514"><a href="#str_position_sql-514"><span class="linenos">514</span></a> <span class="n">this</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> +</span><span id="str_position_sql-515"><a href="#str_position_sql-515"><span class="linenos">515</span></a> <span class="n">substr</span> <span class="o">=</span> <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">"substr"</span><span class="p">)</span> +</span><span id="str_position_sql-516"><a href="#str_position_sql-516"><span class="linenos">516</span></a> <span class="n">position</span> <span class="o">=</span> <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">"position"</span><span class="p">)</span> +</span><span id="str_position_sql-517"><a href="#str_position_sql-517"><span class="linenos">517</span></a> <span class="k">if</span> <span class="n">position</span><span class="p">:</span> +</span><span id="str_position_sql-518"><a href="#str_position_sql-518"><span class="linenos">518</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"STRPOS(SUBSTR(</span><span class="si">{</span><span class="n">this</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">position</span><span class="si">}</span><span class="s2">), </span><span class="si">{</span><span class="n">substr</span><span class="si">}</span><span class="s2">) + </span><span class="si">{</span><span class="n">position</span><span class="si">}</span><span class="s2"> - 1"</span> +</span><span id="str_position_sql-519"><a href="#str_position_sql-519"><span class="linenos">519</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"STRPOS(</span><span class="si">{</span><span class="n">this</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">substr</span><span class="si">}</span><span class="s2">)"</span> </span></pre></div> @@ -3550,10 +3571,10 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#struct_extract_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="struct_extract_sql-519"><a href="#struct_extract_sql-519"><span class="linenos">519</span></a><span class="k">def</span> <span class="nf">struct_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">StructExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="struct_extract_sql-520"><a href="#struct_extract_sql-520"><span class="linenos">520</span></a> <span class="k">return</span> <span class="p">(</span> -</span><span id="struct_extract_sql-521"><a href="#struct_extract_sql-521"><span class="linenos">521</span></a> <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">expression</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">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">name</span><span class="p">))</span><span class="si">}</span><span class="s2">"</span> -</span><span id="struct_extract_sql-522"><a href="#struct_extract_sql-522"><span class="linenos">522</span></a> <span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="struct_extract_sql-522"><a href="#struct_extract_sql-522"><span class="linenos">522</span></a><span class="k">def</span> <span class="nf">struct_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">StructExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="struct_extract_sql-523"><a href="#struct_extract_sql-523"><span class="linenos">523</span></a> <span class="k">return</span> <span class="p">(</span> +</span><span id="struct_extract_sql-524"><a href="#struct_extract_sql-524"><span class="linenos">524</span></a> <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">expression</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">exp</span><span class="o">.</span><span class="n">to_identifier</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="o">.</span><span class="n">name</span><span class="p">))</span><span class="si">}</span><span class="s2">"</span> +</span><span id="struct_extract_sql-525"><a href="#struct_extract_sql-525"><span class="linenos">525</span></a> <span class="p">)</span> </span></pre></div> @@ -3571,22 +3592,22 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#var_map_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="var_map_sql-525"><a href="#var_map_sql-525"><span class="linenos">525</span></a><span class="k">def</span> <span class="nf">var_map_sql</span><span class="p">(</span> -</span><span id="var_map_sql-526"><a href="#var_map_sql-526"><span class="linenos">526</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Map</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">VarMap</span><span class="p">,</span> <span class="n">map_func_name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"MAP"</span> -</span><span id="var_map_sql-527"><a href="#var_map_sql-527"><span class="linenos">527</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="var_map_sql-528"><a href="#var_map_sql-528"><span class="linenos">528</span></a> <span class="n">keys</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">"keys"</span><span class="p">]</span> -</span><span id="var_map_sql-529"><a href="#var_map_sql-529"><span class="linenos">529</span></a> <span class="n">values</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">"values"</span><span class="p">]</span> -</span><span id="var_map_sql-530"><a href="#var_map_sql-530"><span class="linenos">530</span></a> -</span><span id="var_map_sql-531"><a href="#var_map_sql-531"><span class="linenos">531</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">keys</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Array</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Array</span><span class="p">):</span> -</span><span id="var_map_sql-532"><a href="#var_map_sql-532"><span class="linenos">532</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Cannot convert array columns into map."</span><span class="p">)</span> -</span><span id="var_map_sql-533"><a href="#var_map_sql-533"><span class="linenos">533</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="n">map_func_name</span><span class="p">,</span> <span class="n">keys</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span> -</span><span id="var_map_sql-534"><a href="#var_map_sql-534"><span class="linenos">534</span></a> -</span><span id="var_map_sql-535"><a href="#var_map_sql-535"><span class="linenos">535</span></a> <span class="n">args</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="var_map_sql-536"><a href="#var_map_sql-536"><span class="linenos">536</span></a> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">keys</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> <span class="n">values</span><span class="o">.</span><span class="n">expressions</span><span class="p">):</span> -</span><span id="var_map_sql-537"><a href="#var_map_sql-537"><span class="linenos">537</span></a> <span class="n">args</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">key</span><span class="p">))</span> -</span><span id="var_map_sql-538"><a href="#var_map_sql-538"><span class="linenos">538</span></a> <span class="n">args</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">value</span><span class="p">))</span> -</span><span id="var_map_sql-539"><a href="#var_map_sql-539"><span class="linenos">539</span></a> -</span><span id="var_map_sql-540"><a href="#var_map_sql-540"><span class="linenos">540</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="n">map_func_name</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="var_map_sql-528"><a href="#var_map_sql-528"><span class="linenos">528</span></a><span class="k">def</span> <span class="nf">var_map_sql</span><span class="p">(</span> +</span><span id="var_map_sql-529"><a href="#var_map_sql-529"><span class="linenos">529</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Map</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">VarMap</span><span class="p">,</span> <span class="n">map_func_name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"MAP"</span> +</span><span id="var_map_sql-530"><a href="#var_map_sql-530"><span class="linenos">530</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="var_map_sql-531"><a href="#var_map_sql-531"><span class="linenos">531</span></a> <span class="n">keys</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">"keys"</span><span class="p">]</span> +</span><span id="var_map_sql-532"><a href="#var_map_sql-532"><span class="linenos">532</span></a> <span class="n">values</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">"values"</span><span class="p">]</span> +</span><span id="var_map_sql-533"><a href="#var_map_sql-533"><span class="linenos">533</span></a> +</span><span id="var_map_sql-534"><a href="#var_map_sql-534"><span class="linenos">534</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">keys</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Array</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Array</span><span class="p">):</span> +</span><span id="var_map_sql-535"><a href="#var_map_sql-535"><span class="linenos">535</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Cannot convert array columns into map."</span><span class="p">)</span> +</span><span id="var_map_sql-536"><a href="#var_map_sql-536"><span class="linenos">536</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="n">map_func_name</span><span class="p">,</span> <span class="n">keys</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span> +</span><span id="var_map_sql-537"><a href="#var_map_sql-537"><span class="linenos">537</span></a> +</span><span id="var_map_sql-538"><a href="#var_map_sql-538"><span class="linenos">538</span></a> <span class="n">args</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="var_map_sql-539"><a href="#var_map_sql-539"><span class="linenos">539</span></a> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">keys</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> <span class="n">values</span><span class="o">.</span><span class="n">expressions</span><span class="p">):</span> +</span><span id="var_map_sql-540"><a href="#var_map_sql-540"><span class="linenos">540</span></a> <span class="n">args</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">key</span><span class="p">))</span> +</span><span id="var_map_sql-541"><a href="#var_map_sql-541"><span class="linenos">541</span></a> <span class="n">args</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">value</span><span class="p">))</span> +</span><span id="var_map_sql-542"><a href="#var_map_sql-542"><span class="linenos">542</span></a> +</span><span id="var_map_sql-543"><a href="#var_map_sql-543"><span class="linenos">543</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="n">map_func_name</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span> </span></pre></div> @@ -3604,30 +3625,30 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#format_time_lambda"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="format_time_lambda-543"><a href="#format_time_lambda-543"><span class="linenos">543</span></a><span class="k">def</span> <span class="nf">format_time_lambda</span><span class="p">(</span> -</span><span id="format_time_lambda-544"><a href="#format_time_lambda-544"><span class="linenos">544</span></a> <span class="n">exp_class</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">E</span><span class="p">],</span> <span class="n">dialect</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">default</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span> <span class="o">|</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="format_time_lambda-545"><a href="#format_time_lambda-545"><span class="linenos">545</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">E</span><span class="p">]:</span> -</span><span id="format_time_lambda-546"><a href="#format_time_lambda-546"><span class="linenos">546</span></a><span class="w"> </span><span class="sd">"""Helper used for time expressions.</span> -</span><span id="format_time_lambda-547"><a href="#format_time_lambda-547"><span class="linenos">547</span></a> -</span><span id="format_time_lambda-548"><a href="#format_time_lambda-548"><span class="linenos">548</span></a><span class="sd"> Args:</span> -</span><span id="format_time_lambda-549"><a href="#format_time_lambda-549"><span class="linenos">549</span></a><span class="sd"> exp_class: the expression class to instantiate.</span> -</span><span id="format_time_lambda-550"><a href="#format_time_lambda-550"><span class="linenos">550</span></a><span class="sd"> dialect: target sql dialect.</span> -</span><span id="format_time_lambda-551"><a href="#format_time_lambda-551"><span class="linenos">551</span></a><span class="sd"> default: the default format, True being time.</span> -</span><span id="format_time_lambda-552"><a href="#format_time_lambda-552"><span class="linenos">552</span></a> -</span><span id="format_time_lambda-553"><a href="#format_time_lambda-553"><span class="linenos">553</span></a><span class="sd"> Returns:</span> -</span><span id="format_time_lambda-554"><a href="#format_time_lambda-554"><span class="linenos">554</span></a><span class="sd"> A callable that can be used to return the appropriately formatted time expression.</span> -</span><span id="format_time_lambda-555"><a href="#format_time_lambda-555"><span class="linenos">555</span></a><span class="sd"> """</span> -</span><span id="format_time_lambda-556"><a href="#format_time_lambda-556"><span class="linenos">556</span></a> -</span><span id="format_time_lambda-557"><a href="#format_time_lambda-557"><span class="linenos">557</span></a> <span class="k">def</span> <span class="nf">_format_time</span><span class="p">(</span><span class="n">args</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">):</span> -</span><span id="format_time_lambda-558"><a href="#format_time_lambda-558"><span class="linenos">558</span></a> <span class="k">return</span> <span class="n">exp_class</span><span class="p">(</span> -</span><span id="format_time_lambda-559"><a href="#format_time_lambda-559"><span class="linenos">559</span></a> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> -</span><span id="format_time_lambda-560"><a href="#format_time_lambda-560"><span class="linenos">560</span></a> <span class="nb">format</span><span class="o">=</span><span class="n">Dialect</span><span class="p">[</span><span class="n">dialect</span><span class="p">]</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span> -</span><span id="format_time_lambda-561"><a href="#format_time_lambda-561"><span class="linenos">561</span></a> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> -</span><span id="format_time_lambda-562"><a href="#format_time_lambda-562"><span class="linenos">562</span></a> <span class="ow">or</span> <span class="p">(</span><span class="n">Dialect</span><span class="p">[</span><span class="n">dialect</span><span class="p">]</span><span class="o">.</span><span class="n">TIME_FORMAT</span> <span class="k">if</span> <span class="n">default</span> <span class="ow">is</span> <span class="kc">True</span> <span class="k">else</span> <span class="n">default</span> <span class="ow">or</span> <span class="kc">None</span><span class="p">)</span> -</span><span id="format_time_lambda-563"><a href="#format_time_lambda-563"><span class="linenos">563</span></a> <span class="p">),</span> -</span><span id="format_time_lambda-564"><a href="#format_time_lambda-564"><span class="linenos">564</span></a> <span class="p">)</span> -</span><span id="format_time_lambda-565"><a href="#format_time_lambda-565"><span class="linenos">565</span></a> -</span><span id="format_time_lambda-566"><a href="#format_time_lambda-566"><span class="linenos">566</span></a> <span class="k">return</span> <span class="n">_format_time</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="format_time_lambda-546"><a href="#format_time_lambda-546"><span class="linenos">546</span></a><span class="k">def</span> <span class="nf">format_time_lambda</span><span class="p">(</span> +</span><span id="format_time_lambda-547"><a href="#format_time_lambda-547"><span class="linenos">547</span></a> <span class="n">exp_class</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">E</span><span class="p">],</span> <span class="n">dialect</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">default</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span> <span class="o">|</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="format_time_lambda-548"><a href="#format_time_lambda-548"><span class="linenos">548</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">E</span><span class="p">]:</span> +</span><span id="format_time_lambda-549"><a href="#format_time_lambda-549"><span class="linenos">549</span></a><span class="w"> </span><span class="sd">"""Helper used for time expressions.</span> +</span><span id="format_time_lambda-550"><a href="#format_time_lambda-550"><span class="linenos">550</span></a> +</span><span id="format_time_lambda-551"><a href="#format_time_lambda-551"><span class="linenos">551</span></a><span class="sd"> Args:</span> +</span><span id="format_time_lambda-552"><a href="#format_time_lambda-552"><span class="linenos">552</span></a><span class="sd"> exp_class: the expression class to instantiate.</span> +</span><span id="format_time_lambda-553"><a href="#format_time_lambda-553"><span class="linenos">553</span></a><span class="sd"> dialect: target sql dialect.</span> +</span><span id="format_time_lambda-554"><a href="#format_time_lambda-554"><span class="linenos">554</span></a><span class="sd"> default: the default format, True being time.</span> +</span><span id="format_time_lambda-555"><a href="#format_time_lambda-555"><span class="linenos">555</span></a> +</span><span id="format_time_lambda-556"><a href="#format_time_lambda-556"><span class="linenos">556</span></a><span class="sd"> Returns:</span> +</span><span id="format_time_lambda-557"><a href="#format_time_lambda-557"><span class="linenos">557</span></a><span class="sd"> A callable that can be used to return the appropriately formatted time expression.</span> +</span><span id="format_time_lambda-558"><a href="#format_time_lambda-558"><span class="linenos">558</span></a><span class="sd"> """</span> +</span><span id="format_time_lambda-559"><a href="#format_time_lambda-559"><span class="linenos">559</span></a> +</span><span id="format_time_lambda-560"><a href="#format_time_lambda-560"><span class="linenos">560</span></a> <span class="k">def</span> <span class="nf">_format_time</span><span class="p">(</span><span class="n">args</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">):</span> +</span><span id="format_time_lambda-561"><a href="#format_time_lambda-561"><span class="linenos">561</span></a> <span class="k">return</span> <span class="n">exp_class</span><span class="p">(</span> +</span><span id="format_time_lambda-562"><a href="#format_time_lambda-562"><span class="linenos">562</span></a> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> +</span><span id="format_time_lambda-563"><a href="#format_time_lambda-563"><span class="linenos">563</span></a> <span class="nb">format</span><span class="o">=</span><span class="n">Dialect</span><span class="p">[</span><span class="n">dialect</span><span class="p">]</span><span class="o">.</span><span class="n">format_time</span><span class="p">(</span> +</span><span id="format_time_lambda-564"><a href="#format_time_lambda-564"><span class="linenos">564</span></a> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> +</span><span id="format_time_lambda-565"><a href="#format_time_lambda-565"><span class="linenos">565</span></a> <span class="ow">or</span> <span class="p">(</span><span class="n">Dialect</span><span class="p">[</span><span class="n">dialect</span><span class="p">]</span><span class="o">.</span><span class="n">TIME_FORMAT</span> <span class="k">if</span> <span class="n">default</span> <span class="ow">is</span> <span class="kc">True</span> <span class="k">else</span> <span class="n">default</span> <span class="ow">or</span> <span class="kc">None</span><span class="p">)</span> +</span><span id="format_time_lambda-566"><a href="#format_time_lambda-566"><span class="linenos">566</span></a> <span class="p">),</span> +</span><span id="format_time_lambda-567"><a href="#format_time_lambda-567"><span class="linenos">567</span></a> <span class="p">)</span> +</span><span id="format_time_lambda-568"><a href="#format_time_lambda-568"><span class="linenos">568</span></a> +</span><span id="format_time_lambda-569"><a href="#format_time_lambda-569"><span class="linenos">569</span></a> <span class="k">return</span> <span class="n">_format_time</span> </span></pre></div> @@ -3661,18 +3682,18 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#time_format"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="time_format-569"><a href="#time_format-569"><span class="linenos">569</span></a><span class="k">def</span> <span class="nf">time_format</span><span class="p">(</span> -</span><span id="time_format-570"><a href="#time_format-570"><span class="linenos">570</span></a> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> -</span><span id="time_format-571"><a href="#time_format-571"><span class="linenos">571</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToStr</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrToUnix</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]]:</span> -</span><span id="time_format-572"><a href="#time_format-572"><span class="linenos">572</span></a> <span class="k">def</span> <span class="nf">_time_format</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToStr</span> <span class="o">|</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="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> -</span><span id="time_format-573"><a href="#time_format-573"><span class="linenos">573</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="time_format-574"><a href="#time_format-574"><span class="linenos">574</span></a><span class="sd"> Returns the time format for a given expression, unless it's equivalent</span> -</span><span id="time_format-575"><a href="#time_format-575"><span class="linenos">575</span></a><span class="sd"> to the default time format of the dialect of interest.</span> -</span><span id="time_format-576"><a href="#time_format-576"><span class="linenos">576</span></a><span class="sd"> """</span> -</span><span id="time_format-577"><a href="#time_format-577"><span class="linenos">577</span></a> <span class="n">time_format</span> <span class="o">=</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="time_format-578"><a href="#time_format-578"><span class="linenos">578</span></a> <span class="k">return</span> <span class="n">time_format</span> <span class="k">if</span> <span class="n">time_format</span> <span class="o">!=</span> <span class="n">Dialect</span><span class="o">.</span><span class="n">get_or_raise</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span><span class="o">.</span><span class="n">TIME_FORMAT</span> <span class="k">else</span> <span class="kc">None</span> -</span><span id="time_format-579"><a href="#time_format-579"><span class="linenos">579</span></a> -</span><span id="time_format-580"><a href="#time_format-580"><span class="linenos">580</span></a> <span class="k">return</span> <span class="n">_time_format</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="time_format-572"><a href="#time_format-572"><span class="linenos">572</span></a><span class="k">def</span> <span class="nf">time_format</span><span class="p">(</span> +</span><span id="time_format-573"><a href="#time_format-573"><span class="linenos">573</span></a> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="time_format-574"><a href="#time_format-574"><span class="linenos">574</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToStr</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrToUnix</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]]:</span> +</span><span id="time_format-575"><a href="#time_format-575"><span class="linenos">575</span></a> <span class="k">def</span> <span class="nf">_time_format</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToStr</span> <span class="o">|</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="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="time_format-576"><a href="#time_format-576"><span class="linenos">576</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="time_format-577"><a href="#time_format-577"><span class="linenos">577</span></a><span class="sd"> Returns the time format for a given expression, unless it's equivalent</span> +</span><span id="time_format-578"><a href="#time_format-578"><span class="linenos">578</span></a><span class="sd"> to the default time format of the dialect of interest.</span> +</span><span id="time_format-579"><a href="#time_format-579"><span class="linenos">579</span></a><span class="sd"> """</span> +</span><span id="time_format-580"><a href="#time_format-580"><span class="linenos">580</span></a> <span class="n">time_format</span> <span class="o">=</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="time_format-581"><a href="#time_format-581"><span class="linenos">581</span></a> <span class="k">return</span> <span class="n">time_format</span> <span class="k">if</span> <span class="n">time_format</span> <span class="o">!=</span> <span class="n">Dialect</span><span class="o">.</span><span class="n">get_or_raise</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span><span class="o">.</span><span class="n">TIME_FORMAT</span> <span class="k">else</span> <span class="kc">None</span> +</span><span id="time_format-582"><a href="#time_format-582"><span class="linenos">582</span></a> +</span><span id="time_format-583"><a href="#time_format-583"><span class="linenos">583</span></a> <span class="k">return</span> <span class="n">_time_format</span> </span></pre></div> @@ -3690,26 +3711,26 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#create_with_partitions_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="create_with_partitions_sql-583"><a href="#create_with_partitions_sql-583"><span class="linenos">583</span></a><span class="k">def</span> <span class="nf">create_with_partitions_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Create</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="create_with_partitions_sql-584"><a href="#create_with_partitions_sql-584"><span class="linenos">584</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="create_with_partitions_sql-585"><a href="#create_with_partitions_sql-585"><span class="linenos">585</span></a><span class="sd"> In Hive and Spark, the PARTITIONED BY property acts as an extension of a table's schema. When the</span> -</span><span id="create_with_partitions_sql-586"><a href="#create_with_partitions_sql-586"><span class="linenos">586</span></a><span class="sd"> PARTITIONED BY value is an array of column names, they are transformed into a schema. The corresponding</span> -</span><span id="create_with_partitions_sql-587"><a href="#create_with_partitions_sql-587"><span class="linenos">587</span></a><span class="sd"> columns are removed from the create statement.</span> -</span><span id="create_with_partitions_sql-588"><a href="#create_with_partitions_sql-588"><span class="linenos">588</span></a><span class="sd"> """</span> -</span><span id="create_with_partitions_sql-589"><a href="#create_with_partitions_sql-589"><span class="linenos">589</span></a> <span class="n">has_schema</span> <span class="o">=</span> <span class="nb">isinstance</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">Schema</span><span class="p">)</span> -</span><span id="create_with_partitions_sql-590"><a href="#create_with_partitions_sql-590"><span class="linenos">590</span></a> <span class="n">is_partitionable</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">"kind"</span><span class="p">)</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">"TABLE"</span><span class="p">,</span> <span class="s2">"VIEW"</span><span class="p">)</span> -</span><span id="create_with_partitions_sql-591"><a href="#create_with_partitions_sql-591"><span class="linenos">591</span></a> -</span><span id="create_with_partitions_sql-592"><a href="#create_with_partitions_sql-592"><span class="linenos">592</span></a> <span class="k">if</span> <span class="n">has_schema</span> <span class="ow">and</span> <span class="n">is_partitionable</span><span class="p">:</span> -</span><span id="create_with_partitions_sql-593"><a href="#create_with_partitions_sql-593"><span class="linenos">593</span></a> <span class="n">prop</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">PartitionedByProperty</span><span class="p">)</span> -</span><span id="create_with_partitions_sql-594"><a href="#create_with_partitions_sql-594"><span class="linenos">594</span></a> <span class="k">if</span> <span class="n">prop</span> <span class="ow">and</span> <span class="n">prop</span><span class="o">.</span><span class="n">this</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">prop</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">Schema</span><span class="p">):</span> -</span><span id="create_with_partitions_sql-595"><a href="#create_with_partitions_sql-595"><span class="linenos">595</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="create_with_partitions_sql-596"><a href="#create_with_partitions_sql-596"><span class="linenos">596</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="p">{</span><span class="n">v</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">prop</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">}</span> -</span><span id="create_with_partitions_sql-597"><a href="#create_with_partitions_sql-597"><span class="linenos">597</span></a> <span class="n">partitions</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span> <span class="k">if</span> <span class="n">col</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="n">columns</span><span class="p">]</span> -</span><span id="create_with_partitions_sql-598"><a href="#create_with_partitions_sql-598"><span class="linenos">598</span></a> <span class="n">schema</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="p">[</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span> <span class="k">if</span> <span class="n">e</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">partitions</span><span class="p">])</span> -</span><span id="create_with_partitions_sql-599"><a href="#create_with_partitions_sql-599"><span class="linenos">599</span></a> <span class="n">prop</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">PartitionedByProperty</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Schema</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">partitions</span><span class="p">)))</span> -</span><span id="create_with_partitions_sql-600"><a href="#create_with_partitions_sql-600"><span class="linenos">600</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">schema</span><span class="p">)</span> -</span><span id="create_with_partitions_sql-601"><a href="#create_with_partitions_sql-601"><span class="linenos">601</span></a> -</span><span id="create_with_partitions_sql-602"><a href="#create_with_partitions_sql-602"><span class="linenos">602</span></a> <span class="k">return</span> <span class="bp">self</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="create_with_partitions_sql-586"><a href="#create_with_partitions_sql-586"><span class="linenos">586</span></a><span class="k">def</span> <span class="nf">create_with_partitions_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Create</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="create_with_partitions_sql-587"><a href="#create_with_partitions_sql-587"><span class="linenos">587</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="create_with_partitions_sql-588"><a href="#create_with_partitions_sql-588"><span class="linenos">588</span></a><span class="sd"> In Hive and Spark, the PARTITIONED BY property acts as an extension of a table's schema. When the</span> +</span><span id="create_with_partitions_sql-589"><a href="#create_with_partitions_sql-589"><span class="linenos">589</span></a><span class="sd"> PARTITIONED BY value is an array of column names, they are transformed into a schema. The corresponding</span> +</span><span id="create_with_partitions_sql-590"><a href="#create_with_partitions_sql-590"><span class="linenos">590</span></a><span class="sd"> columns are removed from the create statement.</span> +</span><span id="create_with_partitions_sql-591"><a href="#create_with_partitions_sql-591"><span class="linenos">591</span></a><span class="sd"> """</span> +</span><span id="create_with_partitions_sql-592"><a href="#create_with_partitions_sql-592"><span class="linenos">592</span></a> <span class="n">has_schema</span> <span class="o">=</span> <span class="nb">isinstance</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">Schema</span><span class="p">)</span> +</span><span id="create_with_partitions_sql-593"><a href="#create_with_partitions_sql-593"><span class="linenos">593</span></a> <span class="n">is_partitionable</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">"kind"</span><span class="p">)</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">"TABLE"</span><span class="p">,</span> <span class="s2">"VIEW"</span><span class="p">)</span> +</span><span id="create_with_partitions_sql-594"><a href="#create_with_partitions_sql-594"><span class="linenos">594</span></a> +</span><span id="create_with_partitions_sql-595"><a href="#create_with_partitions_sql-595"><span class="linenos">595</span></a> <span class="k">if</span> <span class="n">has_schema</span> <span class="ow">and</span> <span class="n">is_partitionable</span><span class="p">:</span> +</span><span id="create_with_partitions_sql-596"><a href="#create_with_partitions_sql-596"><span class="linenos">596</span></a> <span class="n">prop</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">PartitionedByProperty</span><span class="p">)</span> +</span><span id="create_with_partitions_sql-597"><a href="#create_with_partitions_sql-597"><span class="linenos">597</span></a> <span class="k">if</span> <span class="n">prop</span> <span class="ow">and</span> <span class="n">prop</span><span class="o">.</span><span class="n">this</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">prop</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">Schema</span><span class="p">):</span> +</span><span id="create_with_partitions_sql-598"><a href="#create_with_partitions_sql-598"><span class="linenos">598</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="create_with_partitions_sql-599"><a href="#create_with_partitions_sql-599"><span class="linenos">599</span></a> <span class="n">columns</span> <span class="o">=</span> <span class="p">{</span><span class="n">v</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">prop</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">}</span> +</span><span id="create_with_partitions_sql-600"><a href="#create_with_partitions_sql-600"><span class="linenos">600</span></a> <span class="n">partitions</span> <span class="o">=</span> <span class="p">[</span><span class="n">col</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span> <span class="k">if</span> <span class="n">col</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="ow">in</span> <span class="n">columns</span><span class="p">]</span> +</span><span id="create_with_partitions_sql-601"><a href="#create_with_partitions_sql-601"><span class="linenos">601</span></a> <span class="n">schema</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="p">[</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">schema</span><span class="o">.</span><span class="n">expressions</span> <span class="k">if</span> <span class="n">e</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">partitions</span><span class="p">])</span> +</span><span id="create_with_partitions_sql-602"><a href="#create_with_partitions_sql-602"><span class="linenos">602</span></a> <span class="n">prop</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">PartitionedByProperty</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Schema</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">partitions</span><span class="p">)))</span> +</span><span id="create_with_partitions_sql-603"><a href="#create_with_partitions_sql-603"><span class="linenos">603</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">schema</span><span class="p">)</span> +</span><span id="create_with_partitions_sql-604"><a href="#create_with_partitions_sql-604"><span class="linenos">604</span></a> +</span><span id="create_with_partitions_sql-605"><a href="#create_with_partitions_sql-605"><span class="linenos">605</span></a> <span class="k">return</span> <span class="bp">self</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> @@ -3731,17 +3752,17 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#parse_date_delta"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="parse_date_delta-605"><a href="#parse_date_delta-605"><span class="linenos">605</span></a><span class="k">def</span> <span class="nf">parse_date_delta</span><span class="p">(</span> -</span><span id="parse_date_delta-606"><a href="#parse_date_delta-606"><span class="linenos">606</span></a> <span class="n">exp_class</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">E</span><span class="p">],</span> <span class="n">unit_mapping</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="parse_date_delta-607"><a href="#parse_date_delta-607"><span class="linenos">607</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">E</span><span class="p">]:</span> -</span><span id="parse_date_delta-608"><a href="#parse_date_delta-608"><span class="linenos">608</span></a> <span class="k">def</span> <span class="nf">inner_func</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">E</span><span class="p">:</span> -</span><span id="parse_date_delta-609"><a href="#parse_date_delta-609"><span class="linenos">609</span></a> <span class="n">unit_based</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span> -</span><span id="parse_date_delta-610"><a href="#parse_date_delta-610"><span class="linenos">610</span></a> <span class="n">this</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">if</span> <span class="n">unit_based</span> <span class="k">else</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> -</span><span id="parse_date_delta-611"><a href="#parse_date_delta-611"><span class="linenos">611</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">if</span> <span class="n">unit_based</span> <span class="k">else</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="s2">"DAY"</span><span class="p">)</span> -</span><span id="parse_date_delta-612"><a href="#parse_date_delta-612"><span class="linenos">612</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">unit_mapping</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">unit</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> <span class="n">unit</span><span class="o">.</span><span class="n">name</span><span class="p">))</span> <span class="k">if</span> <span class="n">unit_mapping</span> <span class="k">else</span> <span class="n">unit</span> -</span><span id="parse_date_delta-613"><a href="#parse_date_delta-613"><span class="linenos">613</span></a> <span class="k">return</span> <span class="n">exp_class</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">)</span> -</span><span id="parse_date_delta-614"><a href="#parse_date_delta-614"><span class="linenos">614</span></a> -</span><span id="parse_date_delta-615"><a href="#parse_date_delta-615"><span class="linenos">615</span></a> <span class="k">return</span> <span class="n">inner_func</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="parse_date_delta-608"><a href="#parse_date_delta-608"><span class="linenos">608</span></a><span class="k">def</span> <span class="nf">parse_date_delta</span><span class="p">(</span> +</span><span id="parse_date_delta-609"><a href="#parse_date_delta-609"><span class="linenos">609</span></a> <span class="n">exp_class</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">E</span><span class="p">],</span> <span class="n">unit_mapping</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="parse_date_delta-610"><a href="#parse_date_delta-610"><span class="linenos">610</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">E</span><span class="p">]:</span> +</span><span id="parse_date_delta-611"><a href="#parse_date_delta-611"><span class="linenos">611</span></a> <span class="k">def</span> <span class="nf">inner_func</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">E</span><span class="p">:</span> +</span><span id="parse_date_delta-612"><a href="#parse_date_delta-612"><span class="linenos">612</span></a> <span class="n">unit_based</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span> +</span><span id="parse_date_delta-613"><a href="#parse_date_delta-613"><span class="linenos">613</span></a> <span class="n">this</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">if</span> <span class="n">unit_based</span> <span class="k">else</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> +</span><span id="parse_date_delta-614"><a href="#parse_date_delta-614"><span class="linenos">614</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">if</span> <span class="n">unit_based</span> <span class="k">else</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="s2">"DAY"</span><span class="p">)</span> +</span><span id="parse_date_delta-615"><a href="#parse_date_delta-615"><span class="linenos">615</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">unit_mapping</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">unit</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> <span class="n">unit</span><span class="o">.</span><span class="n">name</span><span class="p">))</span> <span class="k">if</span> <span class="n">unit_mapping</span> <span class="k">else</span> <span class="n">unit</span> +</span><span id="parse_date_delta-616"><a href="#parse_date_delta-616"><span class="linenos">616</span></a> <span class="k">return</span> <span class="n">exp_class</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">)</span> +</span><span id="parse_date_delta-617"><a href="#parse_date_delta-617"><span class="linenos">617</span></a> +</span><span id="parse_date_delta-618"><a href="#parse_date_delta-618"><span class="linenos">618</span></a> <span class="k">return</span> <span class="n">inner_func</span> </span></pre></div> @@ -3759,27 +3780,27 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#parse_date_delta_with_interval"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="parse_date_delta_with_interval-618"><a href="#parse_date_delta_with_interval-618"><span class="linenos">618</span></a><span class="k">def</span> <span class="nf">parse_date_delta_with_interval</span><span class="p">(</span> -</span><span id="parse_date_delta_with_interval-619"><a href="#parse_date_delta_with_interval-619"><span class="linenos">619</span></a> <span class="n">expression_class</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">E</span><span class="p">],</span> -</span><span id="parse_date_delta_with_interval-620"><a href="#parse_date_delta_with_interval-620"><span class="linenos">620</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">E</span><span class="p">]]:</span> -</span><span id="parse_date_delta_with_interval-621"><a href="#parse_date_delta_with_interval-621"><span class="linenos">621</span></a> <span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">E</span><span class="p">]:</span> -</span><span id="parse_date_delta_with_interval-622"><a href="#parse_date_delta_with_interval-622"><span class="linenos">622</span></a> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o"><</span> <span class="mi">2</span><span class="p">:</span> -</span><span id="parse_date_delta_with_interval-623"><a href="#parse_date_delta_with_interval-623"><span class="linenos">623</span></a> <span class="k">return</span> <span class="kc">None</span> -</span><span id="parse_date_delta_with_interval-624"><a href="#parse_date_delta_with_interval-624"><span class="linenos">624</span></a> -</span><span id="parse_date_delta_with_interval-625"><a href="#parse_date_delta_with_interval-625"><span class="linenos">625</span></a> <span class="n">interval</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> -</span><span id="parse_date_delta_with_interval-626"><a href="#parse_date_delta_with_interval-626"><span class="linenos">626</span></a> -</span><span id="parse_date_delta_with_interval-627"><a href="#parse_date_delta_with_interval-627"><span class="linenos">627</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">interval</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Interval</span><span class="p">):</span> -</span><span id="parse_date_delta_with_interval-628"><a href="#parse_date_delta_with_interval-628"><span class="linenos">628</span></a> <span class="k">raise</span> <span class="n">ParseError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"INTERVAL expression expected but got '</span><span class="si">{</span><span class="n">interval</span><span class="si">}</span><span class="s2">'"</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="parse_date_delta_with_interval-621"><a href="#parse_date_delta_with_interval-621"><span class="linenos">621</span></a><span class="k">def</span> <span class="nf">parse_date_delta_with_interval</span><span class="p">(</span> +</span><span id="parse_date_delta_with_interval-622"><a href="#parse_date_delta_with_interval-622"><span class="linenos">622</span></a> <span class="n">expression_class</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">E</span><span class="p">],</span> +</span><span id="parse_date_delta_with_interval-623"><a href="#parse_date_delta_with_interval-623"><span class="linenos">623</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">E</span><span class="p">]]:</span> +</span><span id="parse_date_delta_with_interval-624"><a href="#parse_date_delta_with_interval-624"><span class="linenos">624</span></a> <span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">E</span><span class="p">]:</span> +</span><span id="parse_date_delta_with_interval-625"><a href="#parse_date_delta_with_interval-625"><span class="linenos">625</span></a> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o"><</span> <span class="mi">2</span><span class="p">:</span> +</span><span id="parse_date_delta_with_interval-626"><a href="#parse_date_delta_with_interval-626"><span class="linenos">626</span></a> <span class="k">return</span> <span class="kc">None</span> +</span><span id="parse_date_delta_with_interval-627"><a href="#parse_date_delta_with_interval-627"><span class="linenos">627</span></a> +</span><span id="parse_date_delta_with_interval-628"><a href="#parse_date_delta_with_interval-628"><span class="linenos">628</span></a> <span class="n">interval</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> </span><span id="parse_date_delta_with_interval-629"><a href="#parse_date_delta_with_interval-629"><span class="linenos">629</span></a> -</span><span id="parse_date_delta_with_interval-630"><a href="#parse_date_delta_with_interval-630"><span class="linenos">630</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">interval</span><span class="o">.</span><span class="n">this</span> -</span><span id="parse_date_delta_with_interval-631"><a href="#parse_date_delta_with_interval-631"><span class="linenos">631</span></a> <span class="k">if</span> <span class="n">expression</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_string</span><span class="p">:</span> -</span><span id="parse_date_delta_with_interval-632"><a href="#parse_date_delta_with_interval-632"><span class="linenos">632</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">number</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> -</span><span id="parse_date_delta_with_interval-633"><a href="#parse_date_delta_with_interval-633"><span class="linenos">633</span></a> -</span><span id="parse_date_delta_with_interval-634"><a href="#parse_date_delta_with_interval-634"><span class="linenos">634</span></a> <span class="k">return</span> <span class="n">expression_class</span><span class="p">(</span> -</span><span id="parse_date_delta_with_interval-635"><a href="#parse_date_delta_with_interval-635"><span class="linenos">635</span></a> <span class="n">this</span><span class="o">=</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="n">interval</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"unit"</span><span class="p">))</span> -</span><span id="parse_date_delta_with_interval-636"><a href="#parse_date_delta_with_interval-636"><span class="linenos">636</span></a> <span class="p">)</span> -</span><span id="parse_date_delta_with_interval-637"><a href="#parse_date_delta_with_interval-637"><span class="linenos">637</span></a> -</span><span id="parse_date_delta_with_interval-638"><a href="#parse_date_delta_with_interval-638"><span class="linenos">638</span></a> <span class="k">return</span> <span class="n">func</span> +</span><span id="parse_date_delta_with_interval-630"><a href="#parse_date_delta_with_interval-630"><span class="linenos">630</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">interval</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Interval</span><span class="p">):</span> +</span><span id="parse_date_delta_with_interval-631"><a href="#parse_date_delta_with_interval-631"><span class="linenos">631</span></a> <span class="k">raise</span> <span class="n">ParseError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"INTERVAL expression expected but got '</span><span class="si">{</span><span class="n">interval</span><span class="si">}</span><span class="s2">'"</span><span class="p">)</span> +</span><span id="parse_date_delta_with_interval-632"><a href="#parse_date_delta_with_interval-632"><span class="linenos">632</span></a> +</span><span id="parse_date_delta_with_interval-633"><a href="#parse_date_delta_with_interval-633"><span class="linenos">633</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">interval</span><span class="o">.</span><span class="n">this</span> +</span><span id="parse_date_delta_with_interval-634"><a href="#parse_date_delta_with_interval-634"><span class="linenos">634</span></a> <span class="k">if</span> <span class="n">expression</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_string</span><span class="p">:</span> +</span><span id="parse_date_delta_with_interval-635"><a href="#parse_date_delta_with_interval-635"><span class="linenos">635</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">number</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> +</span><span id="parse_date_delta_with_interval-636"><a href="#parse_date_delta_with_interval-636"><span class="linenos">636</span></a> +</span><span id="parse_date_delta_with_interval-637"><a href="#parse_date_delta_with_interval-637"><span class="linenos">637</span></a> <span class="k">return</span> <span class="n">expression_class</span><span class="p">(</span> +</span><span id="parse_date_delta_with_interval-638"><a href="#parse_date_delta_with_interval-638"><span class="linenos">638</span></a> <span class="n">this</span><span class="o">=</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">expression</span><span class="o">=</span><span class="n">expression</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</span><span class="n">interval</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"unit"</span><span class="p">))</span> +</span><span id="parse_date_delta_with_interval-639"><a href="#parse_date_delta_with_interval-639"><span class="linenos">639</span></a> <span class="p">)</span> +</span><span id="parse_date_delta_with_interval-640"><a href="#parse_date_delta_with_interval-640"><span class="linenos">640</span></a> +</span><span id="parse_date_delta_with_interval-641"><a href="#parse_date_delta_with_interval-641"><span class="linenos">641</span></a> <span class="k">return</span> <span class="n">func</span> </span></pre></div> @@ -3797,13 +3818,13 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#date_trunc_to_time"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="date_trunc_to_time-641"><a href="#date_trunc_to_time-641"><span class="linenos">641</span></a><span class="k">def</span> <span class="nf">date_trunc_to_time</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">DateTrunc</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">:</span> -</span><span id="date_trunc_to_time-642"><a href="#date_trunc_to_time-642"><span class="linenos">642</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> -</span><span id="date_trunc_to_time-643"><a href="#date_trunc_to_time-643"><span class="linenos">643</span></a> <span class="n">this</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> -</span><span id="date_trunc_to_time-644"><a href="#date_trunc_to_time-644"><span class="linenos">644</span></a> -</span><span id="date_trunc_to_time-645"><a href="#date_trunc_to_time-645"><span class="linenos">645</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">this</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">)</span> <span class="ow">and</span> <span class="n">this</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"date"</span><span class="p">):</span> -</span><span id="date_trunc_to_time-646"><a href="#date_trunc_to_time-646"><span class="linenos">646</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">DateTrunc</span><span class="p">(</span><span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">)</span> -</span><span id="date_trunc_to_time-647"><a href="#date_trunc_to_time-647"><span class="linenos">647</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="date_trunc_to_time-644"><a href="#date_trunc_to_time-644"><span class="linenos">644</span></a><span class="k">def</span> <span class="nf">date_trunc_to_time</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">DateTrunc</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">:</span> +</span><span id="date_trunc_to_time-645"><a href="#date_trunc_to_time-645"><span class="linenos">645</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> +</span><span id="date_trunc_to_time-646"><a href="#date_trunc_to_time-646"><span class="linenos">646</span></a> <span class="n">this</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> +</span><span id="date_trunc_to_time-647"><a href="#date_trunc_to_time-647"><span class="linenos">647</span></a> +</span><span id="date_trunc_to_time-648"><a href="#date_trunc_to_time-648"><span class="linenos">648</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">this</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">)</span> <span class="ow">and</span> <span class="n">this</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"date"</span><span class="p">):</span> +</span><span id="date_trunc_to_time-649"><a href="#date_trunc_to_time-649"><span class="linenos">649</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">DateTrunc</span><span class="p">(</span><span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">)</span> +</span><span id="date_trunc_to_time-650"><a href="#date_trunc_to_time-650"><span class="linenos">650</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">)</span> </span></pre></div> @@ -3821,17 +3842,17 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#date_add_interval_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="date_add_interval_sql-650"><a href="#date_add_interval_sql-650"><span class="linenos">650</span></a><span class="k">def</span> <span class="nf">date_add_interval_sql</span><span class="p">(</span> -</span><span id="date_add_interval_sql-651"><a href="#date_add_interval_sql-651"><span class="linenos">651</span></a> <span class="n">data_type</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">kind</span><span class="p">:</span> <span class="nb">str</span> -</span><span id="date_add_interval_sql-652"><a href="#date_add_interval_sql-652"><span class="linenos">652</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</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="nb">str</span><span class="p">]:</span> -</span><span id="date_add_interval_sql-653"><a href="#date_add_interval_sql-653"><span class="linenos">653</span></a> <span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="date_add_interval_sql-654"><a href="#date_add_interval_sql-654"><span class="linenos">654</span></a> <span class="n">this</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> -</span><span id="date_add_interval_sql-655"><a href="#date_add_interval_sql-655"><span class="linenos">655</span></a> <span class="n">unit</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">"unit"</span><span class="p">)</span> -</span><span id="date_add_interval_sql-656"><a href="#date_add_interval_sql-656"><span class="linenos">656</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">unit</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="k">if</span> <span class="n">unit</span> <span class="k">else</span> <span class="s2">"DAY"</span><span class="p">)</span> -</span><span id="date_add_interval_sql-657"><a href="#date_add_interval_sql-657"><span class="linenos">657</span></a> <span class="n">interval</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Interval</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">)</span> -</span><span id="date_add_interval_sql-658"><a href="#date_add_interval_sql-658"><span class="linenos">658</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">data_type</span><span class="si">}</span><span class="s2">_</span><span class="si">{</span><span class="n">kind</span><span class="si">}</span><span class="s2">(</span><span class="si">{</span><span class="n">this</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">interval</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span> -</span><span id="date_add_interval_sql-659"><a href="#date_add_interval_sql-659"><span class="linenos">659</span></a> -</span><span id="date_add_interval_sql-660"><a href="#date_add_interval_sql-660"><span class="linenos">660</span></a> <span class="k">return</span> <span class="n">func</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="date_add_interval_sql-653"><a href="#date_add_interval_sql-653"><span class="linenos">653</span></a><span class="k">def</span> <span class="nf">date_add_interval_sql</span><span class="p">(</span> +</span><span id="date_add_interval_sql-654"><a href="#date_add_interval_sql-654"><span class="linenos">654</span></a> <span class="n">data_type</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">kind</span><span class="p">:</span> <span class="nb">str</span> +</span><span id="date_add_interval_sql-655"><a href="#date_add_interval_sql-655"><span class="linenos">655</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</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="nb">str</span><span class="p">]:</span> +</span><span id="date_add_interval_sql-656"><a href="#date_add_interval_sql-656"><span class="linenos">656</span></a> <span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="date_add_interval_sql-657"><a href="#date_add_interval_sql-657"><span class="linenos">657</span></a> <span class="n">this</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> +</span><span id="date_add_interval_sql-658"><a href="#date_add_interval_sql-658"><span class="linenos">658</span></a> <span class="n">unit</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">"unit"</span><span class="p">)</span> +</span><span id="date_add_interval_sql-659"><a href="#date_add_interval_sql-659"><span class="linenos">659</span></a> <span class="n">unit</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">unit</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="k">if</span> <span class="n">unit</span> <span class="k">else</span> <span class="s2">"DAY"</span><span class="p">)</span> +</span><span id="date_add_interval_sql-660"><a href="#date_add_interval_sql-660"><span class="linenos">660</span></a> <span class="n">interval</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">Interval</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">unit</span><span class="o">=</span><span class="n">unit</span><span class="p">)</span> +</span><span id="date_add_interval_sql-661"><a href="#date_add_interval_sql-661"><span class="linenos">661</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">data_type</span><span class="si">}</span><span class="s2">_</span><span class="si">{</span><span class="n">kind</span><span class="si">}</span><span class="s2">(</span><span class="si">{</span><span class="n">this</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">interval</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span> +</span><span id="date_add_interval_sql-662"><a href="#date_add_interval_sql-662"><span class="linenos">662</span></a> +</span><span id="date_add_interval_sql-663"><a href="#date_add_interval_sql-663"><span class="linenos">663</span></a> <span class="k">return</span> <span class="n">func</span> </span></pre></div> @@ -3849,10 +3870,10 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#timestamptrunc_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="timestamptrunc_sql-663"><a href="#timestamptrunc_sql-663"><span class="linenos">663</span></a><span class="k">def</span> <span class="nf">timestamptrunc_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="timestamptrunc_sql-664"><a href="#timestamptrunc_sql-664"><span class="linenos">664</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="timestamptrunc_sql-665"><a href="#timestamptrunc_sql-665"><span class="linenos">665</span></a> <span class="s2">"DATE_TRUNC"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</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="ow">or</span> <span class="s2">"day"</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> -</span><span id="timestamptrunc_sql-666"><a href="#timestamptrunc_sql-666"><span class="linenos">666</span></a> <span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="timestamptrunc_sql-666"><a href="#timestamptrunc_sql-666"><span class="linenos">666</span></a><span class="k">def</span> <span class="nf">timestamptrunc_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="timestamptrunc_sql-667"><a href="#timestamptrunc_sql-667"><span class="linenos">667</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="timestamptrunc_sql-668"><a href="#timestamptrunc_sql-668"><span class="linenos">668</span></a> <span class="s2">"DATE_TRUNC"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">string</span><span class="p">(</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="ow">or</span> <span class="s2">"day"</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="timestamptrunc_sql-669"><a href="#timestamptrunc_sql-669"><span class="linenos">669</span></a> <span class="p">)</span> </span></pre></div> @@ -3870,17 +3891,17 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#no_timestamp_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="no_timestamp_sql-669"><a href="#no_timestamp_sql-669"><span class="linenos">669</span></a><span class="k">def</span> <span class="nf">no_timestamp_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Timestamp</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="no_timestamp_sql-670"><a href="#no_timestamp_sql-670"><span class="linenos">670</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">:</span> -</span><span id="no_timestamp_sql-671"><a href="#no_timestamp_sql-671"><span class="linenos">671</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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">to</span><span class="o">=</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">TIMESTAMP</span><span class="p">))</span> -</span><span id="no_timestamp_sql-672"><a href="#no_timestamp_sql-672"><span class="linenos">672</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"expression"</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">in</span> <span class="n">TIMEZONES</span><span class="p">:</span> -</span><span id="no_timestamp_sql-673"><a href="#no_timestamp_sql-673"><span class="linenos">673</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> -</span><span id="no_timestamp_sql-674"><a href="#no_timestamp_sql-674"><span class="linenos">674</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">AtTimeZone</span><span class="p">(</span> -</span><span id="no_timestamp_sql-675"><a href="#no_timestamp_sql-675"><span class="linenos">675</span></a> <span class="n">this</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">to</span><span class="o">=</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">TIMESTAMP</span><span class="p">),</span> -</span><span id="no_timestamp_sql-676"><a href="#no_timestamp_sql-676"><span class="linenos">676</span></a> <span class="n">zone</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> -</span><span id="no_timestamp_sql-677"><a href="#no_timestamp_sql-677"><span class="linenos">677</span></a> <span class="p">)</span> -</span><span id="no_timestamp_sql-678"><a href="#no_timestamp_sql-678"><span class="linenos">678</span></a> <span class="p">)</span> -</span><span id="no_timestamp_sql-679"><a href="#no_timestamp_sql-679"><span class="linenos">679</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">function_fallback_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="no_timestamp_sql-672"><a href="#no_timestamp_sql-672"><span class="linenos">672</span></a><span class="k">def</span> <span class="nf">no_timestamp_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Timestamp</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="no_timestamp_sql-673"><a href="#no_timestamp_sql-673"><span class="linenos">673</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">:</span> +</span><span id="no_timestamp_sql-674"><a href="#no_timestamp_sql-674"><span class="linenos">674</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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">to</span><span class="o">=</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">TIMESTAMP</span><span class="p">))</span> +</span><span id="no_timestamp_sql-675"><a href="#no_timestamp_sql-675"><span class="linenos">675</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">"expression"</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">in</span> <span class="n">TIMEZONES</span><span class="p">:</span> +</span><span id="no_timestamp_sql-676"><a href="#no_timestamp_sql-676"><span class="linenos">676</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> +</span><span id="no_timestamp_sql-677"><a href="#no_timestamp_sql-677"><span class="linenos">677</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">AtTimeZone</span><span class="p">(</span> +</span><span id="no_timestamp_sql-678"><a href="#no_timestamp_sql-678"><span class="linenos">678</span></a> <span class="n">this</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">to</span><span class="o">=</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">TIMESTAMP</span><span class="p">),</span> +</span><span id="no_timestamp_sql-679"><a href="#no_timestamp_sql-679"><span class="linenos">679</span></a> <span class="n">zone</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> +</span><span id="no_timestamp_sql-680"><a href="#no_timestamp_sql-680"><span class="linenos">680</span></a> <span class="p">)</span> +</span><span id="no_timestamp_sql-681"><a href="#no_timestamp_sql-681"><span class="linenos">681</span></a> <span class="p">)</span> +</span><span id="no_timestamp_sql-682"><a href="#no_timestamp_sql-682"><span class="linenos">682</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">function_fallback_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -3898,10 +3919,10 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#locate_to_strposition"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="locate_to_strposition-682"><a href="#locate_to_strposition-682"><span class="linenos">682</span></a><span class="k">def</span> <span class="nf">locate_to_strposition</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">:</span> -</span><span id="locate_to_strposition-683"><a href="#locate_to_strposition-683"><span class="linenos">683</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrPosition</span><span class="p">(</span> -</span><span id="locate_to_strposition-684"><a href="#locate_to_strposition-684"><span class="linenos">684</span></a> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">substr</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">position</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> -</span><span id="locate_to_strposition-685"><a href="#locate_to_strposition-685"><span class="linenos">685</span></a> <span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="locate_to_strposition-685"><a href="#locate_to_strposition-685"><span class="linenos">685</span></a><span class="k">def</span> <span class="nf">locate_to_strposition</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">:</span> +</span><span id="locate_to_strposition-686"><a href="#locate_to_strposition-686"><span class="linenos">686</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrPosition</span><span class="p">(</span> +</span><span id="locate_to_strposition-687"><a href="#locate_to_strposition-687"><span class="linenos">687</span></a> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">substr</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">position</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> +</span><span id="locate_to_strposition-688"><a href="#locate_to_strposition-688"><span class="linenos">688</span></a> <span class="p">)</span> </span></pre></div> @@ -3919,10 +3940,10 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#strposition_to_locate_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="strposition_to_locate_sql-688"><a href="#strposition_to_locate_sql-688"><span class="linenos">688</span></a><span class="k">def</span> <span class="nf">strposition_to_locate_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrPosition</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="strposition_to_locate_sql-689"><a href="#strposition_to_locate_sql-689"><span class="linenos">689</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="strposition_to_locate_sql-690"><a href="#strposition_to_locate_sql-690"><span class="linenos">690</span></a> <span class="s2">"LOCATE"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"substr"</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"position"</span><span class="p">)</span> -</span><span id="strposition_to_locate_sql-691"><a href="#strposition_to_locate_sql-691"><span class="linenos">691</span></a> <span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="strposition_to_locate_sql-691"><a href="#strposition_to_locate_sql-691"><span class="linenos">691</span></a><span class="k">def</span> <span class="nf">strposition_to_locate_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">StrPosition</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="strposition_to_locate_sql-692"><a href="#strposition_to_locate_sql-692"><span class="linenos">692</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="strposition_to_locate_sql-693"><a href="#strposition_to_locate_sql-693"><span class="linenos">693</span></a> <span class="s2">"LOCATE"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"substr"</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"position"</span><span class="p">)</span> +</span><span id="strposition_to_locate_sql-694"><a href="#strposition_to_locate_sql-694"><span class="linenos">694</span></a> <span class="p">)</span> </span></pre></div> @@ -3940,12 +3961,12 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#left_to_substring_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="left_to_substring_sql-694"><a href="#left_to_substring_sql-694"><span class="linenos">694</span></a><span class="k">def</span> <span class="nf">left_to_substring_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Left</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="left_to_substring_sql-695"><a href="#left_to_substring_sql-695"><span class="linenos">695</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> -</span><span id="left_to_substring_sql-696"><a href="#left_to_substring_sql-696"><span class="linenos">696</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Substring</span><span class="p">(</span> -</span><span id="left_to_substring_sql-697"><a href="#left_to_substring_sql-697"><span class="linenos">697</span></a> <span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">number</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">length</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span> -</span><span id="left_to_substring_sql-698"><a href="#left_to_substring_sql-698"><span class="linenos">698</span></a> <span class="p">)</span> -</span><span id="left_to_substring_sql-699"><a href="#left_to_substring_sql-699"><span class="linenos">699</span></a> <span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="left_to_substring_sql-697"><a href="#left_to_substring_sql-697"><span class="linenos">697</span></a><span class="k">def</span> <span class="nf">left_to_substring_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Left</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="left_to_substring_sql-698"><a href="#left_to_substring_sql-698"><span class="linenos">698</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> +</span><span id="left_to_substring_sql-699"><a href="#left_to_substring_sql-699"><span class="linenos">699</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Substring</span><span class="p">(</span> +</span><span id="left_to_substring_sql-700"><a href="#left_to_substring_sql-700"><span class="linenos">700</span></a> <span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="o">.</span><span class="n">number</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">length</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span> +</span><span id="left_to_substring_sql-701"><a href="#left_to_substring_sql-701"><span class="linenos">701</span></a> <span class="p">)</span> +</span><span id="left_to_substring_sql-702"><a href="#left_to_substring_sql-702"><span class="linenos">702</span></a> <span class="p">)</span> </span></pre></div> @@ -3963,13 +3984,13 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#right_to_substring_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="right_to_substring_sql-702"><a href="#right_to_substring_sql-702"><span class="linenos">702</span></a><span class="k">def</span> <span class="nf">right_to_substring_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Left</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="right_to_substring_sql-703"><a href="#right_to_substring_sql-703"><span class="linenos">703</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> -</span><span id="right_to_substring_sql-704"><a href="#right_to_substring_sql-704"><span class="linenos">704</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Substring</span><span class="p">(</span> -</span><span id="right_to_substring_sql-705"><a href="#right_to_substring_sql-705"><span class="linenos">705</span></a> <span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="right_to_substring_sql-706"><a href="#right_to_substring_sql-706"><span class="linenos">706</span></a> <span class="n">start</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Length</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> <span class="o">-</span> <span class="n">exp</span><span class="o">.</span><span class="n">paren</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span> <span class="o">-</span> <span class="mi">1</span><span class="p">),</span> -</span><span id="right_to_substring_sql-707"><a href="#right_to_substring_sql-707"><span class="linenos">707</span></a> <span class="p">)</span> -</span><span id="right_to_substring_sql-708"><a href="#right_to_substring_sql-708"><span class="linenos">708</span></a> <span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="right_to_substring_sql-705"><a href="#right_to_substring_sql-705"><span class="linenos">705</span></a><span class="k">def</span> <span class="nf">right_to_substring_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Left</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="right_to_substring_sql-706"><a href="#right_to_substring_sql-706"><span class="linenos">706</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> +</span><span id="right_to_substring_sql-707"><a href="#right_to_substring_sql-707"><span class="linenos">707</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Substring</span><span class="p">(</span> +</span><span id="right_to_substring_sql-708"><a href="#right_to_substring_sql-708"><span class="linenos">708</span></a> <span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="right_to_substring_sql-709"><a href="#right_to_substring_sql-709"><span class="linenos">709</span></a> <span class="n">start</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Length</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> <span class="o">-</span> <span class="n">exp</span><span class="o">.</span><span class="n">paren</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">expression</span> <span class="o">-</span> <span class="mi">1</span><span class="p">),</span> +</span><span id="right_to_substring_sql-710"><a href="#right_to_substring_sql-710"><span class="linenos">710</span></a> <span class="p">)</span> +</span><span id="right_to_substring_sql-711"><a href="#right_to_substring_sql-711"><span class="linenos">711</span></a> <span class="p">)</span> </span></pre></div> @@ -3987,8 +4008,8 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#timestrtotime_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="timestrtotime_sql-711"><a href="#timestrtotime_sql-711"><span class="linenos">711</span></a><span class="k">def</span> <span class="nf">timestrtotime_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimeStrToTime</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="timestrtotime_sql-712"><a href="#timestrtotime_sql-712"><span class="linenos">712</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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="s2">"timestamp"</span><span class="p">))</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="timestrtotime_sql-714"><a href="#timestrtotime_sql-714"><span class="linenos">714</span></a><span class="k">def</span> <span class="nf">timestrtotime_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimeStrToTime</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="timestrtotime_sql-715"><a href="#timestrtotime_sql-715"><span class="linenos">715</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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="s2">"timestamp"</span><span class="p">))</span> </span></pre></div> @@ -4006,8 +4027,8 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#datestrtodate_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="datestrtodate_sql-715"><a href="#datestrtodate_sql-715"><span class="linenos">715</span></a><span class="k">def</span> <span class="nf">datestrtodate_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DateStrToDate</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="datestrtodate_sql-716"><a href="#datestrtodate_sql-716"><span class="linenos">716</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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="s2">"date"</span><span class="p">))</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="datestrtodate_sql-718"><a href="#datestrtodate_sql-718"><span class="linenos">718</span></a><span class="k">def</span> <span class="nf">datestrtodate_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DateStrToDate</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="datestrtodate_sql-719"><a href="#datestrtodate_sql-719"><span class="linenos">719</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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="s2">"date"</span><span class="p">))</span> </span></pre></div> @@ -4025,14 +4046,14 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#encode_decode_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="encode_decode_sql-720"><a href="#encode_decode_sql-720"><span class="linenos">720</span></a><span class="k">def</span> <span class="nf">encode_decode_sql</span><span class="p">(</span> -</span><span id="encode_decode_sql-721"><a href="#encode_decode_sql-721"><span class="linenos">721</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">replace</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="encode_decode_sql-722"><a href="#encode_decode_sql-722"><span class="linenos">722</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="encode_decode_sql-723"><a href="#encode_decode_sql-723"><span class="linenos">723</span></a> <span class="n">charset</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">"charset"</span><span class="p">)</span> -</span><span id="encode_decode_sql-724"><a href="#encode_decode_sql-724"><span class="linenos">724</span></a> <span class="k">if</span> <span class="n">charset</span> <span class="ow">and</span> <span class="n">charset</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">!=</span> <span class="s2">"utf-8"</span><span class="p">:</span> -</span><span id="encode_decode_sql-725"><a href="#encode_decode_sql-725"><span class="linenos">725</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Expected utf-8 character set, got </span><span class="si">{</span><span class="n">charset</span><span class="si">}</span><span class="s2">."</span><span class="p">)</span> -</span><span id="encode_decode_sql-726"><a href="#encode_decode_sql-726"><span class="linenos">726</span></a> -</span><span id="encode_decode_sql-727"><a href="#encode_decode_sql-727"><span class="linenos">727</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="n">name</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"replace"</span><span class="p">)</span> <span class="k">if</span> <span class="n">replace</span> <span class="k">else</span> <span class="kc">None</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="encode_decode_sql-723"><a href="#encode_decode_sql-723"><span class="linenos">723</span></a><span class="k">def</span> <span class="nf">encode_decode_sql</span><span class="p">(</span> +</span><span id="encode_decode_sql-724"><a href="#encode_decode_sql-724"><span class="linenos">724</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">replace</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="encode_decode_sql-725"><a href="#encode_decode_sql-725"><span class="linenos">725</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="encode_decode_sql-726"><a href="#encode_decode_sql-726"><span class="linenos">726</span></a> <span class="n">charset</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">"charset"</span><span class="p">)</span> +</span><span id="encode_decode_sql-727"><a href="#encode_decode_sql-727"><span class="linenos">727</span></a> <span class="k">if</span> <span class="n">charset</span> <span class="ow">and</span> <span class="n">charset</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">!=</span> <span class="s2">"utf-8"</span><span class="p">:</span> +</span><span id="encode_decode_sql-728"><a href="#encode_decode_sql-728"><span class="linenos">728</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Expected utf-8 character set, got </span><span class="si">{</span><span class="n">charset</span><span class="si">}</span><span class="s2">."</span><span class="p">)</span> +</span><span id="encode_decode_sql-729"><a href="#encode_decode_sql-729"><span class="linenos">729</span></a> +</span><span id="encode_decode_sql-730"><a href="#encode_decode_sql-730"><span class="linenos">730</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="n">name</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"replace"</span><span class="p">)</span> <span class="k">if</span> <span class="n">replace</span> <span class="k">else</span> <span class="kc">None</span><span class="p">)</span> </span></pre></div> @@ -4050,9 +4071,9 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#min_or_least"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="min_or_least-730"><a href="#min_or_least-730"><span class="linenos">730</span></a><span class="k">def</span> <span class="nf">min_or_least</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Min</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="min_or_least-731"><a href="#min_or_least-731"><span class="linenos">731</span></a> <span class="n">name</span> <span class="o">=</span> <span class="s2">"LEAST"</span> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> <span class="k">else</span> <span class="s2">"MIN"</span> -</span><span id="min_or_least-732"><a href="#min_or_least-732"><span class="linenos">732</span></a> <span class="k">return</span> <span class="n">rename_func</span><span class="p">(</span><span class="n">name</span><span class="p">)(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="min_or_least-733"><a href="#min_or_least-733"><span class="linenos">733</span></a><span class="k">def</span> <span class="nf">min_or_least</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Min</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="min_or_least-734"><a href="#min_or_least-734"><span class="linenos">734</span></a> <span class="n">name</span> <span class="o">=</span> <span class="s2">"LEAST"</span> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> <span class="k">else</span> <span class="s2">"MIN"</span> +</span><span id="min_or_least-735"><a href="#min_or_least-735"><span class="linenos">735</span></a> <span class="k">return</span> <span class="n">rename_func</span><span class="p">(</span><span class="n">name</span><span class="p">)(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -4070,9 +4091,9 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#max_or_greatest"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="max_or_greatest-735"><a href="#max_or_greatest-735"><span class="linenos">735</span></a><span class="k">def</span> <span class="nf">max_or_greatest</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Max</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="max_or_greatest-736"><a href="#max_or_greatest-736"><span class="linenos">736</span></a> <span class="n">name</span> <span class="o">=</span> <span class="s2">"GREATEST"</span> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> <span class="k">else</span> <span class="s2">"MAX"</span> -</span><span id="max_or_greatest-737"><a href="#max_or_greatest-737"><span class="linenos">737</span></a> <span class="k">return</span> <span class="n">rename_func</span><span class="p">(</span><span class="n">name</span><span class="p">)(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="max_or_greatest-738"><a href="#max_or_greatest-738"><span class="linenos">738</span></a><span class="k">def</span> <span class="nf">max_or_greatest</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Max</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="max_or_greatest-739"><a href="#max_or_greatest-739"><span class="linenos">739</span></a> <span class="n">name</span> <span class="o">=</span> <span class="s2">"GREATEST"</span> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> <span class="k">else</span> <span class="s2">"MAX"</span> +</span><span id="max_or_greatest-740"><a href="#max_or_greatest-740"><span class="linenos">740</span></a> <span class="k">return</span> <span class="n">rename_func</span><span class="p">(</span><span class="n">name</span><span class="p">)(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -4090,14 +4111,14 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#count_if_to_sum"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="count_if_to_sum-740"><a href="#count_if_to_sum-740"><span class="linenos">740</span></a><span class="k">def</span> <span class="nf">count_if_to_sum</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">CountIf</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="count_if_to_sum-741"><a href="#count_if_to_sum-741"><span class="linenos">741</span></a> <span class="n">cond</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> -</span><span id="count_if_to_sum-742"><a href="#count_if_to_sum-742"><span class="linenos">742</span></a> -</span><span id="count_if_to_sum-743"><a href="#count_if_to_sum-743"><span class="linenos">743</span></a> <span class="k">if</span> <span class="nb">isinstance</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">Distinct</span><span class="p">):</span> -</span><span id="count_if_to_sum-744"><a href="#count_if_to_sum-744"><span class="linenos">744</span></a> <span class="n">cond</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> -</span><span id="count_if_to_sum-745"><a href="#count_if_to_sum-745"><span class="linenos">745</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"DISTINCT is not supported when converting COUNT_IF to SUM"</span><span class="p">)</span> -</span><span id="count_if_to_sum-746"><a href="#count_if_to_sum-746"><span class="linenos">746</span></a> -</span><span id="count_if_to_sum-747"><a href="#count_if_to_sum-747"><span class="linenos">747</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">"sum"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"if"</span><span class="p">,</span> <span class="n">cond</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="count_if_to_sum-743"><a href="#count_if_to_sum-743"><span class="linenos">743</span></a><span class="k">def</span> <span class="nf">count_if_to_sum</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">CountIf</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="count_if_to_sum-744"><a href="#count_if_to_sum-744"><span class="linenos">744</span></a> <span class="n">cond</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="count_if_to_sum-745"><a href="#count_if_to_sum-745"><span class="linenos">745</span></a> +</span><span id="count_if_to_sum-746"><a href="#count_if_to_sum-746"><span class="linenos">746</span></a> <span class="k">if</span> <span class="nb">isinstance</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">Distinct</span><span class="p">):</span> +</span><span id="count_if_to_sum-747"><a href="#count_if_to_sum-747"><span class="linenos">747</span></a> <span class="n">cond</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> +</span><span id="count_if_to_sum-748"><a href="#count_if_to_sum-748"><span class="linenos">748</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"DISTINCT is not supported when converting COUNT_IF to SUM"</span><span class="p">)</span> +</span><span id="count_if_to_sum-749"><a href="#count_if_to_sum-749"><span class="linenos">749</span></a> +</span><span id="count_if_to_sum-750"><a href="#count_if_to_sum-750"><span class="linenos">750</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">"sum"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"if"</span><span class="p">,</span> <span class="n">cond</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> </span></pre></div> @@ -4115,21 +4136,21 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#trim_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="trim_sql-750"><a href="#trim_sql-750"><span class="linenos">750</span></a><span class="k">def</span> <span class="nf">trim_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Trim</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="trim_sql-751"><a href="#trim_sql-751"><span class="linenos">751</span></a> <span class="n">target</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> -</span><span id="trim_sql-752"><a href="#trim_sql-752"><span class="linenos">752</span></a> <span class="n">trim_type</span> <span class="o">=</span> <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">"position"</span><span class="p">)</span> -</span><span id="trim_sql-753"><a href="#trim_sql-753"><span class="linenos">753</span></a> <span class="n">remove_chars</span> <span class="o">=</span> <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">"expression"</span><span class="p">)</span> -</span><span id="trim_sql-754"><a href="#trim_sql-754"><span class="linenos">754</span></a> <span class="n">collation</span> <span class="o">=</span> <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">"collation"</span><span class="p">)</span> -</span><span id="trim_sql-755"><a href="#trim_sql-755"><span class="linenos">755</span></a> -</span><span id="trim_sql-756"><a href="#trim_sql-756"><span class="linenos">756</span></a> <span class="c1"># Use TRIM/LTRIM/RTRIM syntax if the expression isn't database-specific</span> -</span><span id="trim_sql-757"><a href="#trim_sql-757"><span class="linenos">757</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">remove_chars</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">collation</span><span class="p">:</span> -</span><span id="trim_sql-758"><a href="#trim_sql-758"><span class="linenos">758</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">trim_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="trim_sql-759"><a href="#trim_sql-759"><span class="linenos">759</span></a> -</span><span id="trim_sql-760"><a href="#trim_sql-760"><span class="linenos">760</span></a> <span class="n">trim_type</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">trim_type</span><span class="si">}</span><span class="s2"> "</span> <span class="k">if</span> <span class="n">trim_type</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="trim_sql-761"><a href="#trim_sql-761"><span class="linenos">761</span></a> <span class="n">remove_chars</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">remove_chars</span><span class="si">}</span><span class="s2"> "</span> <span class="k">if</span> <span class="n">remove_chars</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="trim_sql-762"><a href="#trim_sql-762"><span class="linenos">762</span></a> <span class="n">from_part</span> <span class="o">=</span> <span class="s2">"FROM "</span> <span class="k">if</span> <span class="n">trim_type</span> <span class="ow">or</span> <span class="n">remove_chars</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="trim_sql-763"><a href="#trim_sql-763"><span class="linenos">763</span></a> <span class="n">collation</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" COLLATE </span><span class="si">{</span><span class="n">collation</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">collation</span> <span class="k">else</span> <span class="s2">""</span> -</span><span id="trim_sql-764"><a href="#trim_sql-764"><span class="linenos">764</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"TRIM(</span><span class="si">{</span><span class="n">trim_type</span><span class="si">}{</span><span class="n">remove_chars</span><span class="si">}{</span><span class="n">from_part</span><span class="si">}{</span><span class="n">target</span><span class="si">}{</span><span class="n">collation</span><span class="si">}</span><span class="s2">)"</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="trim_sql-753"><a href="#trim_sql-753"><span class="linenos">753</span></a><span class="k">def</span> <span class="nf">trim_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Trim</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="trim_sql-754"><a href="#trim_sql-754"><span class="linenos">754</span></a> <span class="n">target</span> <span class="o">=</span> <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">"this"</span><span class="p">)</span> +</span><span id="trim_sql-755"><a href="#trim_sql-755"><span class="linenos">755</span></a> <span class="n">trim_type</span> <span class="o">=</span> <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">"position"</span><span class="p">)</span> +</span><span id="trim_sql-756"><a href="#trim_sql-756"><span class="linenos">756</span></a> <span class="n">remove_chars</span> <span class="o">=</span> <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">"expression"</span><span class="p">)</span> +</span><span id="trim_sql-757"><a href="#trim_sql-757"><span class="linenos">757</span></a> <span class="n">collation</span> <span class="o">=</span> <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">"collation"</span><span class="p">)</span> +</span><span id="trim_sql-758"><a href="#trim_sql-758"><span class="linenos">758</span></a> +</span><span id="trim_sql-759"><a href="#trim_sql-759"><span class="linenos">759</span></a> <span class="c1"># Use TRIM/LTRIM/RTRIM syntax if the expression isn't database-specific</span> +</span><span id="trim_sql-760"><a href="#trim_sql-760"><span class="linenos">760</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">remove_chars</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">collation</span><span class="p">:</span> +</span><span id="trim_sql-761"><a href="#trim_sql-761"><span class="linenos">761</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">trim_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="trim_sql-762"><a href="#trim_sql-762"><span class="linenos">762</span></a> +</span><span id="trim_sql-763"><a href="#trim_sql-763"><span class="linenos">763</span></a> <span class="n">trim_type</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">trim_type</span><span class="si">}</span><span class="s2"> "</span> <span class="k">if</span> <span class="n">trim_type</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="trim_sql-764"><a href="#trim_sql-764"><span class="linenos">764</span></a> <span class="n">remove_chars</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">remove_chars</span><span class="si">}</span><span class="s2"> "</span> <span class="k">if</span> <span class="n">remove_chars</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="trim_sql-765"><a href="#trim_sql-765"><span class="linenos">765</span></a> <span class="n">from_part</span> <span class="o">=</span> <span class="s2">"FROM "</span> <span class="k">if</span> <span class="n">trim_type</span> <span class="ow">or</span> <span class="n">remove_chars</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="trim_sql-766"><a href="#trim_sql-766"><span class="linenos">766</span></a> <span class="n">collation</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" COLLATE </span><span class="si">{</span><span class="n">collation</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">collation</span> <span class="k">else</span> <span class="s2">""</span> +</span><span id="trim_sql-767"><a href="#trim_sql-767"><span class="linenos">767</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"TRIM(</span><span class="si">{</span><span class="n">trim_type</span><span class="si">}{</span><span class="n">remove_chars</span><span class="si">}{</span><span class="n">from_part</span><span class="si">}{</span><span class="n">target</span><span class="si">}{</span><span class="n">collation</span><span class="si">}</span><span class="s2">)"</span> </span></pre></div> @@ -4147,8 +4168,8 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#str_to_time_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="str_to_time_sql-767"><a href="#str_to_time_sql-767"><span class="linenos">767</span></a><span class="k">def</span> <span class="nf">str_to_time_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="str_to_time_sql-768"><a href="#str_to_time_sql-768"><span class="linenos">768</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">"STRPTIME"</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="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> + <div class="pdoc-code codehilite"><pre><span></span><span id="str_to_time_sql-770"><a href="#str_to_time_sql-770"><span class="linenos">770</span></a><span class="k">def</span> <span class="nf">str_to_time_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="str_to_time_sql-771"><a href="#str_to_time_sql-771"><span class="linenos">771</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">"STRPTIME"</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="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></pre></div> @@ -4166,20 +4187,20 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#ts_or_ds_to_date_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="ts_or_ds_to_date_sql-771"><a href="#ts_or_ds_to_date_sql-771"><span class="linenos">771</span></a><span class="k">def</span> <span class="nf">ts_or_ds_to_date_sql</span><span class="p">(</span><span class="n">dialect</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">:</span> -</span><span id="ts_or_ds_to_date_sql-772"><a href="#ts_or_ds_to_date_sql-772"><span class="linenos">772</span></a> <span class="k">def</span> <span class="nf">_ts_or_ds_to_date_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsToDate</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="ts_or_ds_to_date_sql-773"><a href="#ts_or_ds_to_date_sql-773"><span class="linenos">773</span></a> <span class="n">_dialect</span> <span class="o">=</span> <span class="n">Dialect</span><span class="o">.</span><span class="n">get_or_raise</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span> -</span><span id="ts_or_ds_to_date_sql-774"><a href="#ts_or_ds_to_date_sql-774"><span class="linenos">774</span></a> <span class="n">time_format</span> <span class="o">=</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="ts_or_ds_to_date_sql-775"><a href="#ts_or_ds_to_date_sql-775"><span class="linenos">775</span></a> <span class="k">if</span> <span class="n">time_format</span> <span class="ow">and</span> <span class="n">time_format</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="n">_dialect</span><span class="o">.</span><span class="n">TIME_FORMAT</span><span class="p">,</span> <span class="n">_dialect</span><span class="o">.</span><span class="n">DATE_FORMAT</span><span class="p">):</span> -</span><span id="ts_or_ds_to_date_sql-776"><a href="#ts_or_ds_to_date_sql-776"><span class="linenos">776</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> -</span><span id="ts_or_ds_to_date_sql-777"><a href="#ts_or_ds_to_date_sql-777"><span class="linenos">777</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span> -</span><span id="ts_or_ds_to_date_sql-778"><a href="#ts_or_ds_to_date_sql-778"><span class="linenos">778</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">StrToTime</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="nb">format</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">"format"</span><span class="p">]),</span> -</span><span id="ts_or_ds_to_date_sql-779"><a href="#ts_or_ds_to_date_sql-779"><span class="linenos">779</span></a> <span class="s2">"date"</span><span class="p">,</span> -</span><span id="ts_or_ds_to_date_sql-780"><a href="#ts_or_ds_to_date_sql-780"><span class="linenos">780</span></a> <span class="p">)</span> -</span><span id="ts_or_ds_to_date_sql-781"><a href="#ts_or_ds_to_date_sql-781"><span class="linenos">781</span></a> <span class="p">)</span> -</span><span id="ts_or_ds_to_date_sql-782"><a href="#ts_or_ds_to_date_sql-782"><span class="linenos">782</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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="s2">"date"</span><span class="p">))</span> -</span><span id="ts_or_ds_to_date_sql-783"><a href="#ts_or_ds_to_date_sql-783"><span class="linenos">783</span></a> -</span><span id="ts_or_ds_to_date_sql-784"><a href="#ts_or_ds_to_date_sql-784"><span class="linenos">784</span></a> <span class="k">return</span> <span class="n">_ts_or_ds_to_date_sql</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="ts_or_ds_to_date_sql-774"><a href="#ts_or_ds_to_date_sql-774"><span class="linenos">774</span></a><span class="k">def</span> <span class="nf">ts_or_ds_to_date_sql</span><span class="p">(</span><span class="n">dialect</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">:</span> +</span><span id="ts_or_ds_to_date_sql-775"><a href="#ts_or_ds_to_date_sql-775"><span class="linenos">775</span></a> <span class="k">def</span> <span class="nf">_ts_or_ds_to_date_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsToDate</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="ts_or_ds_to_date_sql-776"><a href="#ts_or_ds_to_date_sql-776"><span class="linenos">776</span></a> <span class="n">_dialect</span> <span class="o">=</span> <span class="n">Dialect</span><span class="o">.</span><span class="n">get_or_raise</span><span class="p">(</span><span class="n">dialect</span><span class="p">)</span> +</span><span id="ts_or_ds_to_date_sql-777"><a href="#ts_or_ds_to_date_sql-777"><span class="linenos">777</span></a> <span class="n">time_format</span> <span class="o">=</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="ts_or_ds_to_date_sql-778"><a href="#ts_or_ds_to_date_sql-778"><span class="linenos">778</span></a> <span class="k">if</span> <span class="n">time_format</span> <span class="ow">and</span> <span class="n">time_format</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="n">_dialect</span><span class="o">.</span><span class="n">TIME_FORMAT</span><span class="p">,</span> <span class="n">_dialect</span><span class="o">.</span><span class="n">DATE_FORMAT</span><span class="p">):</span> +</span><span id="ts_or_ds_to_date_sql-779"><a href="#ts_or_ds_to_date_sql-779"><span class="linenos">779</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> +</span><span id="ts_or_ds_to_date_sql-780"><a href="#ts_or_ds_to_date_sql-780"><span class="linenos">780</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span> +</span><span id="ts_or_ds_to_date_sql-781"><a href="#ts_or_ds_to_date_sql-781"><span class="linenos">781</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">StrToTime</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="nb">format</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">"format"</span><span class="p">]),</span> +</span><span id="ts_or_ds_to_date_sql-782"><a href="#ts_or_ds_to_date_sql-782"><span class="linenos">782</span></a> <span class="s2">"date"</span><span class="p">,</span> +</span><span id="ts_or_ds_to_date_sql-783"><a href="#ts_or_ds_to_date_sql-783"><span class="linenos">783</span></a> <span class="p">)</span> +</span><span id="ts_or_ds_to_date_sql-784"><a href="#ts_or_ds_to_date_sql-784"><span class="linenos">784</span></a> <span class="p">)</span> +</span><span id="ts_or_ds_to_date_sql-785"><a href="#ts_or_ds_to_date_sql-785"><span class="linenos">785</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">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="s2">"date"</span><span class="p">))</span> +</span><span id="ts_or_ds_to_date_sql-786"><a href="#ts_or_ds_to_date_sql-786"><span class="linenos">786</span></a> +</span><span id="ts_or_ds_to_date_sql-787"><a href="#ts_or_ds_to_date_sql-787"><span class="linenos">787</span></a> <span class="k">return</span> <span class="n">_ts_or_ds_to_date_sql</span> </span></pre></div> @@ -4197,8 +4218,8 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#concat_to_dpipe_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="concat_to_dpipe_sql-787"><a href="#concat_to_dpipe_sql-787"><span class="linenos">787</span></a><span class="k">def</span> <span class="nf">concat_to_dpipe_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Concat</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="concat_to_dpipe_sql-788"><a href="#concat_to_dpipe_sql-788"><span class="linenos">788</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DPipe</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">y</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">))</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="concat_to_dpipe_sql-790"><a href="#concat_to_dpipe_sql-790"><span class="linenos">790</span></a><span class="k">def</span> <span class="nf">concat_to_dpipe_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Concat</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="concat_to_dpipe_sql-791"><a href="#concat_to_dpipe_sql-791"><span class="linenos">791</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DPipe</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">y</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">))</span> </span></pre></div> @@ -4216,14 +4237,14 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#concat_ws_to_dpipe_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="concat_ws_to_dpipe_sql-791"><a href="#concat_ws_to_dpipe_sql-791"><span class="linenos">791</span></a><span class="k">def</span> <span class="nf">concat_ws_to_dpipe_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ConcatWs</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="concat_ws_to_dpipe_sql-792"><a href="#concat_ws_to_dpipe_sql-792"><span class="linenos">792</span></a> <span class="n">delim</span><span class="p">,</span> <span class="o">*</span><span class="n">rest_args</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> -</span><span id="concat_ws_to_dpipe_sql-793"><a href="#concat_ws_to_dpipe_sql-793"><span class="linenos">793</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> -</span><span id="concat_ws_to_dpipe_sql-794"><a href="#concat_ws_to_dpipe_sql-794"><span class="linenos">794</span></a> <span class="n">reduce</span><span class="p">(</span> -</span><span id="concat_ws_to_dpipe_sql-795"><a href="#concat_ws_to_dpipe_sql-795"><span class="linenos">795</span></a> <span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DPipe</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">DPipe</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">delim</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">y</span><span class="p">)),</span> -</span><span id="concat_ws_to_dpipe_sql-796"><a href="#concat_ws_to_dpipe_sql-796"><span class="linenos">796</span></a> <span class="n">rest_args</span><span class="p">,</span> -</span><span id="concat_ws_to_dpipe_sql-797"><a href="#concat_ws_to_dpipe_sql-797"><span class="linenos">797</span></a> <span class="p">)</span> -</span><span id="concat_ws_to_dpipe_sql-798"><a href="#concat_ws_to_dpipe_sql-798"><span class="linenos">798</span></a> <span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="concat_ws_to_dpipe_sql-794"><a href="#concat_ws_to_dpipe_sql-794"><span class="linenos">794</span></a><span class="k">def</span> <span class="nf">concat_ws_to_dpipe_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ConcatWs</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="concat_ws_to_dpipe_sql-795"><a href="#concat_ws_to_dpipe_sql-795"><span class="linenos">795</span></a> <span class="n">delim</span><span class="p">,</span> <span class="o">*</span><span class="n">rest_args</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="concat_ws_to_dpipe_sql-796"><a href="#concat_ws_to_dpipe_sql-796"><span class="linenos">796</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span> +</span><span id="concat_ws_to_dpipe_sql-797"><a href="#concat_ws_to_dpipe_sql-797"><span class="linenos">797</span></a> <span class="n">reduce</span><span class="p">(</span> +</span><span id="concat_ws_to_dpipe_sql-798"><a href="#concat_ws_to_dpipe_sql-798"><span class="linenos">798</span></a> <span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DPipe</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">DPipe</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">delim</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="n">y</span><span class="p">)),</span> +</span><span id="concat_ws_to_dpipe_sql-799"><a href="#concat_ws_to_dpipe_sql-799"><span class="linenos">799</span></a> <span class="n">rest_args</span><span class="p">,</span> +</span><span id="concat_ws_to_dpipe_sql-800"><a href="#concat_ws_to_dpipe_sql-800"><span class="linenos">800</span></a> <span class="p">)</span> +</span><span id="concat_ws_to_dpipe_sql-801"><a href="#concat_ws_to_dpipe_sql-801"><span class="linenos">801</span></a> <span class="p">)</span> </span></pre></div> @@ -4241,14 +4262,14 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#regexp_extract_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="regexp_extract_sql-801"><a href="#regexp_extract_sql-801"><span class="linenos">801</span></a><span class="k">def</span> <span class="nf">regexp_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">RegexpExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="regexp_extract_sql-802"><a href="#regexp_extract_sql-802"><span class="linenos">802</span></a> <span class="n">bad_args</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="p">(</span><span class="s2">"position"</span><span class="p">,</span> <span class="s2">"occurrence"</span><span class="p">,</span> <span class="s2">"parameters"</span><span class="p">)))</span> -</span><span id="regexp_extract_sql-803"><a href="#regexp_extract_sql-803"><span class="linenos">803</span></a> <span class="k">if</span> <span class="n">bad_args</span><span class="p">:</span> -</span><span id="regexp_extract_sql-804"><a href="#regexp_extract_sql-804"><span class="linenos">804</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"REGEXP_EXTRACT does not support the following arg(s): </span><span class="si">{</span><span class="n">bad_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="regexp_extract_sql-805"><a href="#regexp_extract_sql-805"><span class="linenos">805</span></a> -</span><span id="regexp_extract_sql-806"><a href="#regexp_extract_sql-806"><span class="linenos">806</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span> -</span><span id="regexp_extract_sql-807"><a href="#regexp_extract_sql-807"><span class="linenos">807</span></a> <span class="s2">"REGEXP_EXTRACT"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"group"</span><span class="p">)</span> -</span><span id="regexp_extract_sql-808"><a href="#regexp_extract_sql-808"><span class="linenos">808</span></a> <span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="regexp_extract_sql-804"><a href="#regexp_extract_sql-804"><span class="linenos">804</span></a><span class="k">def</span> <span class="nf">regexp_extract_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">RegexpExtract</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="regexp_extract_sql-805"><a href="#regexp_extract_sql-805"><span class="linenos">805</span></a> <span class="n">bad_args</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="p">(</span><span class="s2">"position"</span><span class="p">,</span> <span class="s2">"occurrence"</span><span class="p">,</span> <span class="s2">"parameters"</span><span class="p">)))</span> +</span><span id="regexp_extract_sql-806"><a href="#regexp_extract_sql-806"><span class="linenos">806</span></a> <span class="k">if</span> <span class="n">bad_args</span><span class="p">:</span> +</span><span id="regexp_extract_sql-807"><a href="#regexp_extract_sql-807"><span class="linenos">807</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"REGEXP_EXTRACT does not support the following arg(s): </span><span class="si">{</span><span class="n">bad_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="regexp_extract_sql-808"><a href="#regexp_extract_sql-808"><span class="linenos">808</span></a> +</span><span id="regexp_extract_sql-809"><a href="#regexp_extract_sql-809"><span class="linenos">809</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span> +</span><span id="regexp_extract_sql-810"><a href="#regexp_extract_sql-810"><span class="linenos">810</span></a> <span class="s2">"REGEXP_EXTRACT"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"group"</span><span class="p">)</span> +</span><span id="regexp_extract_sql-811"><a href="#regexp_extract_sql-811"><span class="linenos">811</span></a> <span class="p">)</span> </span></pre></div> @@ -4266,16 +4287,16 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#regexp_replace_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="regexp_replace_sql-811"><a href="#regexp_replace_sql-811"><span class="linenos">811</span></a><span class="k">def</span> <span class="nf">regexp_replace_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">RegexpReplace</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="regexp_replace_sql-812"><a href="#regexp_replace_sql-812"><span class="linenos">812</span></a> <span class="n">bad_args</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span> -</span><span id="regexp_replace_sql-813"><a href="#regexp_replace_sql-813"><span class="linenos">813</span></a> <span class="nb">filter</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="p">(</span><span class="s2">"position"</span><span class="p">,</span> <span class="s2">"occurrence"</span><span class="p">,</span> <span class="s2">"parameters"</span><span class="p">,</span> <span class="s2">"modifiers"</span><span class="p">))</span> -</span><span id="regexp_replace_sql-814"><a href="#regexp_replace_sql-814"><span class="linenos">814</span></a> <span class="p">)</span> -</span><span id="regexp_replace_sql-815"><a href="#regexp_replace_sql-815"><span class="linenos">815</span></a> <span class="k">if</span> <span class="n">bad_args</span><span class="p">:</span> -</span><span id="regexp_replace_sql-816"><a href="#regexp_replace_sql-816"><span class="linenos">816</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"REGEXP_REPLACE does not support the following arg(s): </span><span class="si">{</span><span class="n">bad_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="regexp_replace_sql-817"><a href="#regexp_replace_sql-817"><span class="linenos">817</span></a> -</span><span id="regexp_replace_sql-818"><a href="#regexp_replace_sql-818"><span class="linenos">818</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span> -</span><span id="regexp_replace_sql-819"><a href="#regexp_replace_sql-819"><span class="linenos">819</span></a> <span class="s2">"REGEXP_REPLACE"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"replacement"</span><span class="p">]</span> -</span><span id="regexp_replace_sql-820"><a href="#regexp_replace_sql-820"><span class="linenos">820</span></a> <span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="regexp_replace_sql-814"><a href="#regexp_replace_sql-814"><span class="linenos">814</span></a><span class="k">def</span> <span class="nf">regexp_replace_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">RegexpReplace</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="regexp_replace_sql-815"><a href="#regexp_replace_sql-815"><span class="linenos">815</span></a> <span class="n">bad_args</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span> +</span><span id="regexp_replace_sql-816"><a href="#regexp_replace_sql-816"><span class="linenos">816</span></a> <span class="nb">filter</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="p">(</span><span class="s2">"position"</span><span class="p">,</span> <span class="s2">"occurrence"</span><span class="p">,</span> <span class="s2">"parameters"</span><span class="p">,</span> <span class="s2">"modifiers"</span><span class="p">))</span> +</span><span id="regexp_replace_sql-817"><a href="#regexp_replace_sql-817"><span class="linenos">817</span></a> <span class="p">)</span> +</span><span id="regexp_replace_sql-818"><a href="#regexp_replace_sql-818"><span class="linenos">818</span></a> <span class="k">if</span> <span class="n">bad_args</span><span class="p">:</span> +</span><span id="regexp_replace_sql-819"><a href="#regexp_replace_sql-819"><span class="linenos">819</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"REGEXP_REPLACE does not support the following arg(s): </span><span class="si">{</span><span class="n">bad_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="regexp_replace_sql-820"><a href="#regexp_replace_sql-820"><span class="linenos">820</span></a> +</span><span id="regexp_replace_sql-821"><a href="#regexp_replace_sql-821"><span class="linenos">821</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span> +</span><span id="regexp_replace_sql-822"><a href="#regexp_replace_sql-822"><span class="linenos">822</span></a> <span class="s2">"REGEXP_REPLACE"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s2">"replacement"</span><span class="p">]</span> +</span><span id="regexp_replace_sql-823"><a href="#regexp_replace_sql-823"><span class="linenos">823</span></a> <span class="p">)</span> </span></pre></div> @@ -4293,26 +4314,26 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#pivot_column_names"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="pivot_column_names-823"><a href="#pivot_column_names-823"><span class="linenos">823</span></a><span class="k">def</span> <span class="nf">pivot_column_names</span><span class="p">(</span><span class="n">aggregations</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">],</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> -</span><span id="pivot_column_names-824"><a href="#pivot_column_names-824"><span class="linenos">824</span></a> <span class="n">names</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="pivot_column_names-825"><a href="#pivot_column_names-825"><span class="linenos">825</span></a> <span class="k">for</span> <span class="n">agg</span> <span class="ow">in</span> <span class="n">aggregations</span><span class="p">:</span> -</span><span id="pivot_column_names-826"><a href="#pivot_column_names-826"><span class="linenos">826</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">agg</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Alias</span><span class="p">):</span> -</span><span id="pivot_column_names-827"><a href="#pivot_column_names-827"><span class="linenos">827</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg</span><span class="o">.</span><span class="n">alias</span><span class="p">)</span> -</span><span id="pivot_column_names-828"><a href="#pivot_column_names-828"><span class="linenos">828</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="pivot_column_names-829"><a href="#pivot_column_names-829"><span class="linenos">829</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="pivot_column_names-830"><a href="#pivot_column_names-830"><span class="linenos">830</span></a><span class="sd"> This case corresponds to aggregations without aliases being used as suffixes</span> -</span><span id="pivot_column_names-831"><a href="#pivot_column_names-831"><span class="linenos">831</span></a><span class="sd"> (e.g. col_avg(foo)). We need to unquote identifiers because they're going to</span> -</span><span id="pivot_column_names-832"><a href="#pivot_column_names-832"><span class="linenos">832</span></a><span class="sd"> be quoted in the base parser's `_parse_pivot` method, due to `to_identifier`.</span> -</span><span id="pivot_column_names-833"><a href="#pivot_column_names-833"><span class="linenos">833</span></a><span class="sd"> Otherwise, we'd end up with `col_avg(`foo`)` (notice the double quotes).</span> -</span><span id="pivot_column_names-834"><a href="#pivot_column_names-834"><span class="linenos">834</span></a><span class="sd"> """</span> -</span><span id="pivot_column_names-835"><a href="#pivot_column_names-835"><span class="linenos">835</span></a> <span class="n">agg_all_unquoted</span> <span class="o">=</span> <span class="n">agg</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span> -</span><span id="pivot_column_names-836"><a href="#pivot_column_names-836"><span class="linenos">836</span></a> <span class="k">lambda</span> <span class="n">node</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">quoted</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> -</span><span id="pivot_column_names-837"><a href="#pivot_column_names-837"><span class="linenos">837</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">)</span> -</span><span id="pivot_column_names-838"><a href="#pivot_column_names-838"><span class="linenos">838</span></a> <span class="k">else</span> <span class="n">node</span> -</span><span id="pivot_column_names-839"><a href="#pivot_column_names-839"><span class="linenos">839</span></a> <span class="p">)</span> -</span><span id="pivot_column_names-840"><a href="#pivot_column_names-840"><span class="linenos">840</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg_all_unquoted</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span> <span class="n">normalize_functions</span><span class="o">=</span><span class="s2">"lower"</span><span class="p">))</span> -</span><span id="pivot_column_names-841"><a href="#pivot_column_names-841"><span class="linenos">841</span></a> -</span><span id="pivot_column_names-842"><a href="#pivot_column_names-842"><span class="linenos">842</span></a> <span class="k">return</span> <span class="n">names</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="pivot_column_names-826"><a href="#pivot_column_names-826"><span class="linenos">826</span></a><span class="k">def</span> <span class="nf">pivot_column_names</span><span class="p">(</span><span class="n">aggregations</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">],</span> <span class="n">dialect</span><span class="p">:</span> <span class="n">DialectType</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> +</span><span id="pivot_column_names-827"><a href="#pivot_column_names-827"><span class="linenos">827</span></a> <span class="n">names</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="pivot_column_names-828"><a href="#pivot_column_names-828"><span class="linenos">828</span></a> <span class="k">for</span> <span class="n">agg</span> <span class="ow">in</span> <span class="n">aggregations</span><span class="p">:</span> +</span><span id="pivot_column_names-829"><a href="#pivot_column_names-829"><span class="linenos">829</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">agg</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Alias</span><span class="p">):</span> +</span><span id="pivot_column_names-830"><a href="#pivot_column_names-830"><span class="linenos">830</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg</span><span class="o">.</span><span class="n">alias</span><span class="p">)</span> +</span><span id="pivot_column_names-831"><a href="#pivot_column_names-831"><span class="linenos">831</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="pivot_column_names-832"><a href="#pivot_column_names-832"><span class="linenos">832</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="pivot_column_names-833"><a href="#pivot_column_names-833"><span class="linenos">833</span></a><span class="sd"> This case corresponds to aggregations without aliases being used as suffixes</span> +</span><span id="pivot_column_names-834"><a href="#pivot_column_names-834"><span class="linenos">834</span></a><span class="sd"> (e.g. col_avg(foo)). We need to unquote identifiers because they're going to</span> +</span><span id="pivot_column_names-835"><a href="#pivot_column_names-835"><span class="linenos">835</span></a><span class="sd"> be quoted in the base parser's `_parse_pivot` method, due to `to_identifier`.</span> +</span><span id="pivot_column_names-836"><a href="#pivot_column_names-836"><span class="linenos">836</span></a><span class="sd"> Otherwise, we'd end up with `col_avg(`foo`)` (notice the double quotes).</span> +</span><span id="pivot_column_names-837"><a href="#pivot_column_names-837"><span class="linenos">837</span></a><span class="sd"> """</span> +</span><span id="pivot_column_names-838"><a href="#pivot_column_names-838"><span class="linenos">838</span></a> <span class="n">agg_all_unquoted</span> <span class="o">=</span> <span class="n">agg</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span> +</span><span id="pivot_column_names-839"><a href="#pivot_column_names-839"><span class="linenos">839</span></a> <span class="k">lambda</span> <span class="n">node</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">quoted</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> +</span><span id="pivot_column_names-840"><a href="#pivot_column_names-840"><span class="linenos">840</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Identifier</span><span class="p">)</span> +</span><span id="pivot_column_names-841"><a href="#pivot_column_names-841"><span class="linenos">841</span></a> <span class="k">else</span> <span class="n">node</span> +</span><span id="pivot_column_names-842"><a href="#pivot_column_names-842"><span class="linenos">842</span></a> <span class="p">)</span> +</span><span id="pivot_column_names-843"><a href="#pivot_column_names-843"><span class="linenos">843</span></a> <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">agg_all_unquoted</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">dialect</span><span class="o">=</span><span class="n">dialect</span><span class="p">,</span> <span class="n">normalize_functions</span><span class="o">=</span><span class="s2">"lower"</span><span class="p">))</span> +</span><span id="pivot_column_names-844"><a href="#pivot_column_names-844"><span class="linenos">844</span></a> +</span><span id="pivot_column_names-845"><a href="#pivot_column_names-845"><span class="linenos">845</span></a> <span class="k">return</span> <span class="n">names</span> </span></pre></div> @@ -4330,8 +4351,8 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#binary_from_function"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="binary_from_function-845"><a href="#binary_from_function-845"><span class="linenos">845</span></a><span class="k">def</span> <span class="nf">binary_from_function</span><span class="p">(</span><span class="n">expr_type</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">B</span><span class="p">])</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">B</span><span class="p">]:</span> -</span><span id="binary_from_function-846"><a href="#binary_from_function-846"><span class="linenos">846</span></a> <span class="k">return</span> <span class="k">lambda</span> <span class="n">args</span><span class="p">:</span> <span class="n">expr_type</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">expression</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="binary_from_function-848"><a href="#binary_from_function-848"><span class="linenos">848</span></a><span class="k">def</span> <span class="nf">binary_from_function</span><span class="p">(</span><span class="n">expr_type</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Type</span><span class="p">[</span><span class="n">B</span><span class="p">])</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">t</span><span class="o">.</span><span class="n">List</span><span class="p">],</span> <span class="n">B</span><span class="p">]:</span> +</span><span id="binary_from_function-849"><a href="#binary_from_function-849"><span class="linenos">849</span></a> <span class="k">return</span> <span class="k">lambda</span> <span class="n">args</span><span class="p">:</span> <span class="n">expr_type</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">expression</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span> </span></pre></div> @@ -4349,8 +4370,8 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#parse_timestamp_trunc"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="parse_timestamp_trunc-850"><a href="#parse_timestamp_trunc-850"><span class="linenos">850</span></a><span class="k">def</span> <span class="nf">parse_timestamp_trunc</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">:</span> -</span><span id="parse_timestamp_trunc-851"><a href="#parse_timestamp_trunc-851"><span class="linenos">851</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">unit</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="parse_timestamp_trunc-853"><a href="#parse_timestamp_trunc-853"><span class="linenos">853</span></a><span class="k">def</span> <span class="nf">parse_timestamp_trunc</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">:</span> +</span><span id="parse_timestamp_trunc-854"><a href="#parse_timestamp_trunc-854"><span class="linenos">854</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">TimestampTrunc</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">unit</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> </span></pre></div> @@ -4368,8 +4389,8 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#any_value_to_max_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="any_value_to_max_sql-854"><a href="#any_value_to_max_sql-854"><span class="linenos">854</span></a><span class="k">def</span> <span class="nf">any_value_to_max_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">AnyValue</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="any_value_to_max_sql-855"><a href="#any_value_to_max_sql-855"><span class="linenos">855</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">"MAX"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="any_value_to_max_sql-857"><a href="#any_value_to_max_sql-857"><span class="linenos">857</span></a><span class="k">def</span> <span class="nf">any_value_to_max_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">AnyValue</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="any_value_to_max_sql-858"><a href="#any_value_to_max_sql-858"><span class="linenos">858</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">"MAX"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">)</span> </span></pre></div> @@ -4387,10 +4408,10 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#bool_xor_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="bool_xor_sql-858"><a href="#bool_xor_sql-858"><span class="linenos">858</span></a><span class="k">def</span> <span class="nf">bool_xor_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Xor</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="bool_xor_sql-859"><a href="#bool_xor_sql-859"><span class="linenos">859</span></a> <span class="n">a</span> <span class="o">=</span> <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="o">.</span><span class="n">left</span><span class="p">)</span> -</span><span id="bool_xor_sql-860"><a href="#bool_xor_sql-860"><span class="linenos">860</span></a> <span class="n">b</span> <span class="o">=</span> <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="o">.</span><span class="n">right</span><span class="p">)</span> -</span><span id="bool_xor_sql-861"><a href="#bool_xor_sql-861"><span class="linenos">861</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"(</span><span class="si">{</span><span class="n">a</span><span class="si">}</span><span class="s2"> AND (NOT </span><span class="si">{</span><span class="n">b</span><span class="si">}</span><span class="s2">)) OR ((NOT </span><span class="si">{</span><span class="n">a</span><span class="si">}</span><span class="s2">) AND </span><span class="si">{</span><span class="n">b</span><span class="si">}</span><span class="s2">)"</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="bool_xor_sql-861"><a href="#bool_xor_sql-861"><span class="linenos">861</span></a><span class="k">def</span> <span class="nf">bool_xor_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Xor</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="bool_xor_sql-862"><a href="#bool_xor_sql-862"><span class="linenos">862</span></a> <span class="n">a</span> <span class="o">=</span> <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="o">.</span><span class="n">left</span><span class="p">)</span> +</span><span id="bool_xor_sql-863"><a href="#bool_xor_sql-863"><span class="linenos">863</span></a> <span class="n">b</span> <span class="o">=</span> <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="o">.</span><span class="n">right</span><span class="p">)</span> +</span><span id="bool_xor_sql-864"><a href="#bool_xor_sql-864"><span class="linenos">864</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"(</span><span class="si">{</span><span class="n">a</span><span class="si">}</span><span class="s2"> AND (NOT </span><span class="si">{</span><span class="n">b</span><span class="si">}</span><span class="s2">)) OR ((NOT </span><span class="si">{</span><span class="n">a</span><span class="si">}</span><span class="s2">) AND </span><span class="si">{</span><span class="n">b</span><span class="si">}</span><span class="s2">)"</span> </span></pre></div> @@ -4408,8 +4429,8 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#json_keyvalue_comma_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="json_keyvalue_comma_sql-865"><a href="#json_keyvalue_comma_sql-865"><span class="linenos">865</span></a><span class="k">def</span> <span class="nf">json_keyvalue_comma_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONKeyValue</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="json_keyvalue_comma_sql-866"><a href="#json_keyvalue_comma_sql-866"><span class="linenos">866</span></a> <span class="k">return</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">expression</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">expression</span><span class="p">,</span><span class="w"> </span><span class="s1">'expression'</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="json_keyvalue_comma_sql-868"><a href="#json_keyvalue_comma_sql-868"><span class="linenos">868</span></a><span class="k">def</span> <span class="nf">json_keyvalue_comma_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONKeyValue</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="json_keyvalue_comma_sql-869"><a href="#json_keyvalue_comma_sql-869"><span class="linenos">869</span></a> <span class="k">return</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">expression</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">expression</span><span class="p">,</span><span class="w"> </span><span class="s1">'expression'</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span> </span></pre></div> @@ -4427,10 +4448,10 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#is_parse_json"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="is_parse_json-869"><a href="#is_parse_json-869"><span class="linenos">869</span></a><span class="k">def</span> <span class="nf">is_parse_json</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="o">-></span> <span class="nb">bool</span><span class="p">:</span> -</span><span id="is_parse_json-870"><a href="#is_parse_json-870"><span class="linenos">870</span></a> <span class="k">return</span> <span class="nb">isinstance</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">ParseJSON</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span> -</span><span id="is_parse_json-871"><a href="#is_parse_json-871"><span class="linenos">871</span></a> <span class="nb">isinstance</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">Cast</span><span class="p">)</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"json"</span><span class="p">)</span> -</span><span id="is_parse_json-872"><a href="#is_parse_json-872"><span class="linenos">872</span></a> <span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="is_parse_json-872"><a href="#is_parse_json-872"><span class="linenos">872</span></a><span class="k">def</span> <span class="nf">is_parse_json</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="o">-></span> <span class="nb">bool</span><span class="p">:</span> +</span><span id="is_parse_json-873"><a href="#is_parse_json-873"><span class="linenos">873</span></a> <span class="k">return</span> <span class="nb">isinstance</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">ParseJSON</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span> +</span><span id="is_parse_json-874"><a href="#is_parse_json-874"><span class="linenos">874</span></a> <span class="nb">isinstance</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">Cast</span><span class="p">)</span> <span class="ow">and</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"json"</span><span class="p">)</span> +</span><span id="is_parse_json-875"><a href="#is_parse_json-875"><span class="linenos">875</span></a> <span class="p">)</span> </span></pre></div> @@ -4448,8 +4469,8 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#isnull_to_is_null"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="isnull_to_is_null-875"><a href="#isnull_to_is_null-875"><span class="linenos">875</span></a><span class="k">def</span> <span class="nf">isnull_to_is_null</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">:</span> -</span><span id="isnull_to_is_null-876"><a href="#isnull_to_is_null-876"><span class="linenos">876</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Paren</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Is</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">null</span><span class="p">()))</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="isnull_to_is_null-878"><a href="#isnull_to_is_null-878"><span class="linenos">878</span></a><span class="k">def</span> <span class="nf">isnull_to_is_null</span><span class="p">(</span><span class="n">args</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="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">:</span> +</span><span id="isnull_to_is_null-879"><a href="#isnull_to_is_null-879"><span class="linenos">879</span></a> <span class="k">return</span> <span class="n">exp</span><span class="o">.</span><span class="n">Paren</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">Is</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">expression</span><span class="o">=</span><span class="n">exp</span><span class="o">.</span><span class="n">null</span><span class="p">()))</span> </span></pre></div> @@ -4467,12 +4488,12 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#generatedasidentitycolumnconstraint_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="generatedasidentitycolumnconstraint_sql-879"><a href="#generatedasidentitycolumnconstraint_sql-879"><span class="linenos">879</span></a><span class="k">def</span> <span class="nf">generatedasidentitycolumnconstraint_sql</span><span class="p">(</span> -</span><span id="generatedasidentitycolumnconstraint_sql-880"><a href="#generatedasidentitycolumnconstraint_sql-880"><span class="linenos">880</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">GeneratedAsIdentityColumnConstraint</span> -</span><span id="generatedasidentitycolumnconstraint_sql-881"><a href="#generatedasidentitycolumnconstraint_sql-881"><span class="linenos">881</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="generatedasidentitycolumnconstraint_sql-882"><a href="#generatedasidentitycolumnconstraint_sql-882"><span class="linenos">882</span></a> <span class="n">start</span> <span class="o">=</span> <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">"start"</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">"1"</span> -</span><span id="generatedasidentitycolumnconstraint_sql-883"><a href="#generatedasidentitycolumnconstraint_sql-883"><span class="linenos">883</span></a> <span class="n">increment</span> <span class="o">=</span> <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">"increment"</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">"1"</span> -</span><span id="generatedasidentitycolumnconstraint_sql-884"><a href="#generatedasidentitycolumnconstraint_sql-884"><span class="linenos">884</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"IDENTITY(</span><span class="si">{</span><span class="n">start</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">increment</span><span class="si">}</span><span class="s2">)"</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="generatedasidentitycolumnconstraint_sql-882"><a href="#generatedasidentitycolumnconstraint_sql-882"><span class="linenos">882</span></a><span class="k">def</span> <span class="nf">generatedasidentitycolumnconstraint_sql</span><span class="p">(</span> +</span><span id="generatedasidentitycolumnconstraint_sql-883"><a href="#generatedasidentitycolumnconstraint_sql-883"><span class="linenos">883</span></a> <span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">GeneratedAsIdentityColumnConstraint</span> +</span><span id="generatedasidentitycolumnconstraint_sql-884"><a href="#generatedasidentitycolumnconstraint_sql-884"><span class="linenos">884</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="generatedasidentitycolumnconstraint_sql-885"><a href="#generatedasidentitycolumnconstraint_sql-885"><span class="linenos">885</span></a> <span class="n">start</span> <span class="o">=</span> <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">"start"</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">"1"</span> +</span><span id="generatedasidentitycolumnconstraint_sql-886"><a href="#generatedasidentitycolumnconstraint_sql-886"><span class="linenos">886</span></a> <span class="n">increment</span> <span class="o">=</span> <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">"increment"</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">"1"</span> +</span><span id="generatedasidentitycolumnconstraint_sql-887"><a href="#generatedasidentitycolumnconstraint_sql-887"><span class="linenos">887</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"IDENTITY(</span><span class="si">{</span><span class="n">start</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">increment</span><span class="si">}</span><span class="s2">)"</span> </span></pre></div> @@ -4490,14 +4511,14 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#arg_max_or_min_no_count"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="arg_max_or_min_no_count-887"><a href="#arg_max_or_min_no_count-887"><span class="linenos">887</span></a><span class="k">def</span> <span class="nf">arg_max_or_min_no_count</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMax</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMin</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> -</span><span id="arg_max_or_min_no_count-888"><a href="#arg_max_or_min_no_count-888"><span class="linenos">888</span></a> <span class="k">def</span> <span class="nf">_arg_max_or_min_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMax</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMin</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="arg_max_or_min_no_count-889"><a href="#arg_max_or_min_no_count-889"><span class="linenos">889</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">"count"</span><span class="p">):</span> -</span><span id="arg_max_or_min_no_count-890"><a href="#arg_max_or_min_no_count-890"><span class="linenos">890</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Only two arguments are supported in function </span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">."</span><span class="p">)</span> -</span><span id="arg_max_or_min_no_count-891"><a href="#arg_max_or_min_no_count-891"><span class="linenos">891</span></a> -</span><span id="arg_max_or_min_no_count-892"><a href="#arg_max_or_min_no_count-892"><span class="linenos">892</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="n">name</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> -</span><span id="arg_max_or_min_no_count-893"><a href="#arg_max_or_min_no_count-893"><span class="linenos">893</span></a> -</span><span id="arg_max_or_min_no_count-894"><a href="#arg_max_or_min_no_count-894"><span class="linenos">894</span></a> <span class="k">return</span> <span class="n">_arg_max_or_min_sql</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="arg_max_or_min_no_count-890"><a href="#arg_max_or_min_no_count-890"><span class="linenos">890</span></a><span class="k">def</span> <span class="nf">arg_max_or_min_no_count</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMax</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMin</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> +</span><span id="arg_max_or_min_no_count-891"><a href="#arg_max_or_min_no_count-891"><span class="linenos">891</span></a> <span class="k">def</span> <span class="nf">_arg_max_or_min_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMax</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">ArgMin</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="arg_max_or_min_no_count-892"><a href="#arg_max_or_min_no_count-892"><span class="linenos">892</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">"count"</span><span class="p">):</span> +</span><span id="arg_max_or_min_no_count-893"><a href="#arg_max_or_min_no_count-893"><span class="linenos">893</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Only two arguments are supported in function </span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">."</span><span class="p">)</span> +</span><span id="arg_max_or_min_no_count-894"><a href="#arg_max_or_min_no_count-894"><span class="linenos">894</span></a> +</span><span id="arg_max_or_min_no_count-895"><a href="#arg_max_or_min_no_count-895"><span class="linenos">895</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="n">name</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span> +</span><span id="arg_max_or_min_no_count-896"><a href="#arg_max_or_min_no_count-896"><span class="linenos">896</span></a> +</span><span id="arg_max_or_min_no_count-897"><a href="#arg_max_or_min_no_count-897"><span class="linenos">897</span></a> <span class="k">return</span> <span class="n">_arg_max_or_min_sql</span> </span></pre></div> @@ -4515,17 +4536,17 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#ts_or_ds_add_cast"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="ts_or_ds_add_cast-897"><a href="#ts_or_ds_add_cast-897"><span class="linenos">897</span></a><span class="k">def</span> <span class="nf">ts_or_ds_add_cast</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">TsOrDsAdd</span><span class="p">)</span> <span class="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsAdd</span><span class="p">:</span> -</span><span id="ts_or_ds_add_cast-898"><a href="#ts_or_ds_add_cast-898"><span class="linenos">898</span></a> <span class="n">this</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> -</span><span id="ts_or_ds_add_cast-899"><a href="#ts_or_ds_add_cast-899"><span class="linenos">899</span></a> -</span><span id="ts_or_ds_add_cast-900"><a href="#ts_or_ds_add_cast-900"><span class="linenos">900</span></a> <span class="n">return_type</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">return_type</span> -</span><span id="ts_or_ds_add_cast-901"><a href="#ts_or_ds_add_cast-901"><span class="linenos">901</span></a> <span class="k">if</span> <span class="n">return_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">DATE</span><span class="p">):</span> -</span><span id="ts_or_ds_add_cast-902"><a href="#ts_or_ds_add_cast-902"><span class="linenos">902</span></a> <span class="c1"># If we need to cast to a DATE, we cast to TIMESTAMP first to make sure we</span> -</span><span id="ts_or_ds_add_cast-903"><a href="#ts_or_ds_add_cast-903"><span class="linenos">903</span></a> <span class="c1"># can truncate timestamp strings, because some dialects can't cast them to DATE</span> -</span><span id="ts_or_ds_add_cast-904"><a href="#ts_or_ds_add_cast-904"><span class="linenos">904</span></a> <span class="n">this</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">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">TIMESTAMP</span><span class="p">)</span> -</span><span id="ts_or_ds_add_cast-905"><a href="#ts_or_ds_add_cast-905"><span class="linenos">905</span></a> -</span><span id="ts_or_ds_add_cast-906"><a href="#ts_or_ds_add_cast-906"><span class="linenos">906</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">this</span><span class="p">,</span> <span class="n">return_type</span><span class="p">))</span> -</span><span id="ts_or_ds_add_cast-907"><a href="#ts_or_ds_add_cast-907"><span class="linenos">907</span></a> <span class="k">return</span> <span class="n">expression</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="ts_or_ds_add_cast-900"><a href="#ts_or_ds_add_cast-900"><span class="linenos">900</span></a><span class="k">def</span> <span class="nf">ts_or_ds_add_cast</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">TsOrDsAdd</span><span class="p">)</span> <span class="o">-></span> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsAdd</span><span class="p">:</span> +</span><span id="ts_or_ds_add_cast-901"><a href="#ts_or_ds_add_cast-901"><span class="linenos">901</span></a> <span class="n">this</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="ts_or_ds_add_cast-902"><a href="#ts_or_ds_add_cast-902"><span class="linenos">902</span></a> +</span><span id="ts_or_ds_add_cast-903"><a href="#ts_or_ds_add_cast-903"><span class="linenos">903</span></a> <span class="n">return_type</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">return_type</span> +</span><span id="ts_or_ds_add_cast-904"><a href="#ts_or_ds_add_cast-904"><span class="linenos">904</span></a> <span class="k">if</span> <span class="n">return_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">DATE</span><span class="p">):</span> +</span><span id="ts_or_ds_add_cast-905"><a href="#ts_or_ds_add_cast-905"><span class="linenos">905</span></a> <span class="c1"># If we need to cast to a DATE, we cast to TIMESTAMP first to make sure we</span> +</span><span id="ts_or_ds_add_cast-906"><a href="#ts_or_ds_add_cast-906"><span class="linenos">906</span></a> <span class="c1"># can truncate timestamp strings, because some dialects can't cast them to DATE</span> +</span><span id="ts_or_ds_add_cast-907"><a href="#ts_or_ds_add_cast-907"><span class="linenos">907</span></a> <span class="n">this</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">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">TIMESTAMP</span><span class="p">)</span> +</span><span id="ts_or_ds_add_cast-908"><a href="#ts_or_ds_add_cast-908"><span class="linenos">908</span></a> +</span><span id="ts_or_ds_add_cast-909"><a href="#ts_or_ds_add_cast-909"><span class="linenos">909</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">this</span><span class="p">,</span> <span class="n">return_type</span><span class="p">))</span> +</span><span id="ts_or_ds_add_cast-910"><a href="#ts_or_ds_add_cast-910"><span class="linenos">910</span></a> <span class="k">return</span> <span class="n">expression</span> </span></pre></div> @@ -4543,16 +4564,16 @@ columns are removed from the create statement.</p> </div> <a class="headerlink" href="#date_delta_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="date_delta_sql-910"><a href="#date_delta_sql-910"><span class="linenos">910</span></a><span class="k">def</span> <span class="nf">date_delta_sql</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">cast</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">DATE_ADD_OR_DIFF</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> -</span><span id="date_delta_sql-911"><a href="#date_delta_sql-911"><span class="linenos">911</span></a> <span class="k">def</span> <span class="nf">_delta_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">DATE_ADD_OR_DIFF</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="date_delta_sql-912"><a href="#date_delta_sql-912"><span class="linenos">912</span></a> <span class="k">if</span> <span class="n">cast</span> <span class="ow">and</span> <span class="nb">isinstance</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">TsOrDsAdd</span><span class="p">):</span> -</span><span id="date_delta_sql-913"><a href="#date_delta_sql-913"><span class="linenos">913</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">ts_or_ds_add_cast</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="date_delta_sql-914"><a href="#date_delta_sql-914"><span class="linenos">914</span></a> -</span><span id="date_delta_sql-915"><a href="#date_delta_sql-915"><span class="linenos">915</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="date_delta_sql-916"><a href="#date_delta_sql-916"><span class="linenos">916</span></a> <span class="n">name</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</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="ow">or</span> <span class="s2">"day"</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> -</span><span id="date_delta_sql-917"><a href="#date_delta_sql-917"><span class="linenos">917</span></a> <span class="p">)</span> -</span><span id="date_delta_sql-918"><a href="#date_delta_sql-918"><span class="linenos">918</span></a> -</span><span id="date_delta_sql-919"><a href="#date_delta_sql-919"><span class="linenos">919</span></a> <span class="k">return</span> <span class="n">_delta_sql</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="date_delta_sql-913"><a href="#date_delta_sql-913"><span class="linenos">913</span></a><span class="k">def</span> <span class="nf">date_delta_sql</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">cast</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="n">Generator</span><span class="p">,</span> <span class="n">DATE_ADD_OR_DIFF</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> +</span><span id="date_delta_sql-914"><a href="#date_delta_sql-914"><span class="linenos">914</span></a> <span class="k">def</span> <span class="nf">_delta_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">DATE_ADD_OR_DIFF</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="date_delta_sql-915"><a href="#date_delta_sql-915"><span class="linenos">915</span></a> <span class="k">if</span> <span class="n">cast</span> <span class="ow">and</span> <span class="nb">isinstance</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">TsOrDsAdd</span><span class="p">):</span> +</span><span id="date_delta_sql-916"><a href="#date_delta_sql-916"><span class="linenos">916</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">ts_or_ds_add_cast</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="date_delta_sql-917"><a href="#date_delta_sql-917"><span class="linenos">917</span></a> +</span><span id="date_delta_sql-918"><a href="#date_delta_sql-918"><span class="linenos">918</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="date_delta_sql-919"><a href="#date_delta_sql-919"><span class="linenos">919</span></a> <span class="n">name</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</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="ow">or</span> <span class="s2">"day"</span><span class="p">),</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">this</span> +</span><span id="date_delta_sql-920"><a href="#date_delta_sql-920"><span class="linenos">920</span></a> <span class="p">)</span> +</span><span id="date_delta_sql-921"><a href="#date_delta_sql-921"><span class="linenos">921</span></a> +</span><span id="date_delta_sql-922"><a href="#date_delta_sql-922"><span class="linenos">922</span></a> <span class="k">return</span> <span class="n">_delta_sql</span> </span></pre></div> |