diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-02-12 06:15:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-02-12 06:15:14 +0000 |
commit | 8fd7374bf370b99577a40d4de1716ad990d5a34b (patch) | |
tree | 061ecaf38b8a390a8a70348eea1fd11233f9e19c /docs/sqlglot/dialects/dialect.html | |
parent | Adding upstream version 21.0.1. (diff) | |
download | sqlglot-8fd7374bf370b99577a40d4de1716ad990d5a34b.tar.xz sqlglot-8fd7374bf370b99577a40d4de1716ad990d5a34b.zip |
Adding upstream version 21.0.2.upstream/21.0.2
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 | 2338 |
1 files changed, 1192 insertions, 1146 deletions
diff --git a/docs/sqlglot/dialects/dialect.html b/docs/sqlglot/dialects/dialect.html index 37bf8ce..7b67d8a 100644 --- a/docs/sqlglot/dialects/dialect.html +++ b/docs/sqlglot/dialects/dialect.html @@ -490,7 +490,10 @@ <a class="function" href="#parse_json_extract_path">parse_json_extract_path</a> </li> <li> - <a class="function" href="#json_path_segments">json_path_segments</a> + <a class="function" href="#json_extract_segments">json_extract_segments</a> + </li> + <li> + <a class="function" href="#json_path_key_only_name">json_path_key_only_name</a> </li> </ul> @@ -536,507 +539,507 @@ </span><span id="L-19"><a href="#L-19"><span class="linenos"> 19</span></a><span class="n">DATE_ADD_OR_SUB</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="n">exp</span><span class="o">.</span><span class="n">DateAdd</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="n">exp</span><span class="o">.</span><span class="n">DateSub</span><span class="p">]</span> </span><span id="L-20"><a href="#L-20"><span class="linenos"> 20</span></a> </span><span id="L-21"><a href="#L-21"><span class="linenos"> 21</span></a><span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">TYPE_CHECKING</span><span class="p">:</span> -</span><span id="L-22"><a href="#L-22"><span class="linenos"> 22</span></a> <span class="kn">from</span> <span class="nn">sqlglot._typing</span> <span class="kn">import</span> <span class="n">B</span><span class="p">,</span> <span class="n">E</span> +</span><span id="L-22"><a href="#L-22"><span class="linenos"> 22</span></a> <span class="kn">from</span> <span class="nn">sqlglot._typing</span> <span class="kn">import</span> <span class="n">B</span><span class="p">,</span> <span class="n">E</span><span class="p">,</span> <span class="n">F</span> </span><span id="L-23"><a href="#L-23"><span class="linenos"> 23</span></a> -</span><span id="L-24"><a href="#L-24"><span class="linenos"> 24</span></a><span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s2">"sqlglot"</span><span class="p">)</span> +</span><span id="L-24"><a href="#L-24"><span class="linenos"> 24</span></a> <span class="n">JSON_EXTRACT_TYPE</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="n">exp</span><span class="o">.</span><span class="n">JSONExtract</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span><span class="p">]</span> </span><span id="L-25"><a href="#L-25"><span class="linenos"> 25</span></a> -</span><span id="L-26"><a href="#L-26"><span class="linenos"> 26</span></a> -</span><span id="L-27"><a href="#L-27"><span class="linenos"> 27</span></a><span class="k">class</span> <span class="nc">Dialects</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">Enum</span><span class="p">):</span> -</span><span id="L-28"><a href="#L-28"><span class="linenos"> 28</span></a><span class="w"> </span><span class="sd">"""Dialects supported by SQLGLot."""</span> -</span><span id="L-29"><a href="#L-29"><span class="linenos"> 29</span></a> -</span><span id="L-30"><a href="#L-30"><span class="linenos"> 30</span></a> <span class="n">DIALECT</span> <span class="o">=</span> <span class="s2">""</span> +</span><span id="L-26"><a href="#L-26"><span class="linenos"> 26</span></a><span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s2">"sqlglot"</span><span class="p">)</span> +</span><span id="L-27"><a href="#L-27"><span class="linenos"> 27</span></a> +</span><span id="L-28"><a href="#L-28"><span class="linenos"> 28</span></a> +</span><span id="L-29"><a href="#L-29"><span class="linenos"> 29</span></a><span class="k">class</span> <span class="nc">Dialects</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">Enum</span><span class="p">):</span> +</span><span id="L-30"><a href="#L-30"><span class="linenos"> 30</span></a><span class="w"> </span><span class="sd">"""Dialects supported by SQLGLot."""</span> </span><span id="L-31"><a href="#L-31"><span class="linenos"> 31</span></a> -</span><span id="L-32"><a href="#L-32"><span class="linenos"> 32</span></a> <span class="n">BIGQUERY</span> <span class="o">=</span> <span class="s2">"bigquery"</span> -</span><span id="L-33"><a href="#L-33"><span class="linenos"> 33</span></a> <span class="n">CLICKHOUSE</span> <span class="o">=</span> <span class="s2">"clickhouse"</span> -</span><span id="L-34"><a href="#L-34"><span class="linenos"> 34</span></a> <span class="n">DATABRICKS</span> <span class="o">=</span> <span class="s2">"databricks"</span> -</span><span id="L-35"><a href="#L-35"><span class="linenos"> 35</span></a> <span class="n">DORIS</span> <span class="o">=</span> <span class="s2">"doris"</span> -</span><span id="L-36"><a href="#L-36"><span class="linenos"> 36</span></a> <span class="n">DRILL</span> <span class="o">=</span> <span class="s2">"drill"</span> -</span><span id="L-37"><a href="#L-37"><span class="linenos"> 37</span></a> <span class="n">DUCKDB</span> <span class="o">=</span> <span class="s2">"duckdb"</span> -</span><span id="L-38"><a href="#L-38"><span class="linenos"> 38</span></a> <span class="n">HIVE</span> <span class="o">=</span> <span class="s2">"hive"</span> -</span><span id="L-39"><a href="#L-39"><span class="linenos"> 39</span></a> <span class="n">MYSQL</span> <span class="o">=</span> <span class="s2">"mysql"</span> -</span><span id="L-40"><a href="#L-40"><span class="linenos"> 40</span></a> <span class="n">ORACLE</span> <span class="o">=</span> <span class="s2">"oracle"</span> -</span><span id="L-41"><a href="#L-41"><span class="linenos"> 41</span></a> <span class="n">POSTGRES</span> <span class="o">=</span> <span class="s2">"postgres"</span> -</span><span id="L-42"><a href="#L-42"><span class="linenos"> 42</span></a> <span class="n">PRESTO</span> <span class="o">=</span> <span class="s2">"presto"</span> -</span><span id="L-43"><a href="#L-43"><span class="linenos"> 43</span></a> <span class="n">REDSHIFT</span> <span class="o">=</span> <span class="s2">"redshift"</span> -</span><span id="L-44"><a href="#L-44"><span class="linenos"> 44</span></a> <span class="n">SNOWFLAKE</span> <span class="o">=</span> <span class="s2">"snowflake"</span> -</span><span id="L-45"><a href="#L-45"><span class="linenos"> 45</span></a> <span class="n">SPARK</span> <span class="o">=</span> <span class="s2">"spark"</span> -</span><span id="L-46"><a href="#L-46"><span class="linenos"> 46</span></a> <span class="n">SPARK2</span> <span class="o">=</span> <span class="s2">"spark2"</span> -</span><span id="L-47"><a href="#L-47"><span class="linenos"> 47</span></a> <span class="n">SQLITE</span> <span class="o">=</span> <span class="s2">"sqlite"</span> -</span><span id="L-48"><a href="#L-48"><span class="linenos"> 48</span></a> <span class="n">STARROCKS</span> <span class="o">=</span> <span class="s2">"starrocks"</span> -</span><span id="L-49"><a href="#L-49"><span class="linenos"> 49</span></a> <span class="n">TABLEAU</span> <span class="o">=</span> <span class="s2">"tableau"</span> -</span><span id="L-50"><a href="#L-50"><span class="linenos"> 50</span></a> <span class="n">TERADATA</span> <span class="o">=</span> <span class="s2">"teradata"</span> -</span><span id="L-51"><a href="#L-51"><span class="linenos"> 51</span></a> <span class="n">TRINO</span> <span class="o">=</span> <span class="s2">"trino"</span> -</span><span id="L-52"><a href="#L-52"><span class="linenos"> 52</span></a> <span class="n">TSQL</span> <span class="o">=</span> <span class="s2">"tsql"</span> -</span><span id="L-53"><a href="#L-53"><span class="linenos"> 53</span></a> -</span><span id="L-54"><a href="#L-54"><span class="linenos"> 54</span></a> -</span><span id="L-55"><a href="#L-55"><span class="linenos"> 55</span></a><span class="k">class</span> <span class="nc">NormalizationStrategy</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">AutoName</span><span class="p">):</span> -</span><span id="L-56"><a href="#L-56"><span class="linenos"> 56</span></a><span class="w"> </span><span class="sd">"""Specifies the strategy according to which identifiers should be normalized."""</span> -</span><span id="L-57"><a href="#L-57"><span class="linenos"> 57</span></a> -</span><span id="L-58"><a href="#L-58"><span class="linenos"> 58</span></a> <span class="n">LOWERCASE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> -</span><span id="L-59"><a href="#L-59"><span class="linenos"> 59</span></a><span class="w"> </span><span class="sd">"""Unquoted identifiers are lowercased."""</span> -</span><span id="L-60"><a href="#L-60"><span class="linenos"> 60</span></a> -</span><span id="L-61"><a href="#L-61"><span class="linenos"> 61</span></a> <span class="n">UPPERCASE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> -</span><span id="L-62"><a href="#L-62"><span class="linenos"> 62</span></a><span class="w"> </span><span class="sd">"""Unquoted identifiers are uppercased."""</span> -</span><span id="L-63"><a href="#L-63"><span class="linenos"> 63</span></a> -</span><span id="L-64"><a href="#L-64"><span class="linenos"> 64</span></a> <span class="n">CASE_SENSITIVE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> -</span><span id="L-65"><a href="#L-65"><span class="linenos"> 65</span></a><span class="w"> </span><span class="sd">"""Always case-sensitive, regardless of quotes."""</span> -</span><span id="L-66"><a href="#L-66"><span class="linenos"> 66</span></a> -</span><span id="L-67"><a href="#L-67"><span class="linenos"> 67</span></a> <span class="n">CASE_INSENSITIVE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> -</span><span id="L-68"><a href="#L-68"><span class="linenos"> 68</span></a><span class="w"> </span><span class="sd">"""Always case-insensitive, regardless of quotes."""</span> -</span><span id="L-69"><a href="#L-69"><span class="linenos"> 69</span></a> -</span><span id="L-70"><a href="#L-70"><span class="linenos"> 70</span></a> -</span><span id="L-71"><a href="#L-71"><span class="linenos"> 71</span></a><span class="k">class</span> <span class="nc">_Dialect</span><span class="p">(</span><span class="nb">type</span><span class="p">):</span> -</span><span id="L-72"><a href="#L-72"><span class="linenos"> 72</span></a> <span class="n">classes</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="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="o">=</span> <span class="p">{}</span> -</span><span id="L-73"><a href="#L-73"><span class="linenos"> 73</span></a> -</span><span id="L-74"><a href="#L-74"><span class="linenos"> 74</span></a> <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">cls</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-75"><a href="#L-75"><span class="linenos"> 75</span></a> <span class="k">if</span> <span class="bp">cls</span> <span class="ow">is</span> <span class="n">other</span><span class="p">:</span> -</span><span id="L-76"><a href="#L-76"><span class="linenos"> 76</span></a> <span class="k">return</span> <span class="kc">True</span> -</span><span id="L-77"><a href="#L-77"><span class="linenos"> 77</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> -</span><span id="L-78"><a href="#L-78"><span class="linenos"> 78</span></a> <span class="k">return</span> <span class="bp">cls</span> <span class="ow">is</span> <span class="bp">cls</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">other</span><span class="p">)</span> -</span><span id="L-79"><a href="#L-79"><span class="linenos"> 79</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">Dialect</span><span class="p">):</span> -</span><span id="L-80"><a href="#L-80"><span class="linenos"> 80</span></a> <span class="k">return</span> <span class="bp">cls</span> <span class="ow">is</span> <span class="nb">type</span><span class="p">(</span><span class="n">other</span><span class="p">)</span> -</span><span id="L-81"><a href="#L-81"><span class="linenos"> 81</span></a> -</span><span id="L-82"><a href="#L-82"><span class="linenos"> 82</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="L-32"><a href="#L-32"><span class="linenos"> 32</span></a> <span class="n">DIALECT</span> <span class="o">=</span> <span class="s2">""</span> +</span><span id="L-33"><a href="#L-33"><span class="linenos"> 33</span></a> +</span><span id="L-34"><a href="#L-34"><span class="linenos"> 34</span></a> <span class="n">BIGQUERY</span> <span class="o">=</span> <span class="s2">"bigquery"</span> +</span><span id="L-35"><a href="#L-35"><span class="linenos"> 35</span></a> <span class="n">CLICKHOUSE</span> <span class="o">=</span> <span class="s2">"clickhouse"</span> +</span><span id="L-36"><a href="#L-36"><span class="linenos"> 36</span></a> <span class="n">DATABRICKS</span> <span class="o">=</span> <span class="s2">"databricks"</span> +</span><span id="L-37"><a href="#L-37"><span class="linenos"> 37</span></a> <span class="n">DORIS</span> <span class="o">=</span> <span class="s2">"doris"</span> +</span><span id="L-38"><a href="#L-38"><span class="linenos"> 38</span></a> <span class="n">DRILL</span> <span class="o">=</span> <span class="s2">"drill"</span> +</span><span id="L-39"><a href="#L-39"><span class="linenos"> 39</span></a> <span class="n">DUCKDB</span> <span class="o">=</span> <span class="s2">"duckdb"</span> +</span><span id="L-40"><a href="#L-40"><span class="linenos"> 40</span></a> <span class="n">HIVE</span> <span class="o">=</span> <span class="s2">"hive"</span> +</span><span id="L-41"><a href="#L-41"><span class="linenos"> 41</span></a> <span class="n">MYSQL</span> <span class="o">=</span> <span class="s2">"mysql"</span> +</span><span id="L-42"><a href="#L-42"><span class="linenos"> 42</span></a> <span class="n">ORACLE</span> <span class="o">=</span> <span class="s2">"oracle"</span> +</span><span id="L-43"><a href="#L-43"><span class="linenos"> 43</span></a> <span class="n">POSTGRES</span> <span class="o">=</span> <span class="s2">"postgres"</span> +</span><span id="L-44"><a href="#L-44"><span class="linenos"> 44</span></a> <span class="n">PRESTO</span> <span class="o">=</span> <span class="s2">"presto"</span> +</span><span id="L-45"><a href="#L-45"><span class="linenos"> 45</span></a> <span class="n">REDSHIFT</span> <span class="o">=</span> <span class="s2">"redshift"</span> +</span><span id="L-46"><a href="#L-46"><span class="linenos"> 46</span></a> <span class="n">SNOWFLAKE</span> <span class="o">=</span> <span class="s2">"snowflake"</span> +</span><span id="L-47"><a href="#L-47"><span class="linenos"> 47</span></a> <span class="n">SPARK</span> <span class="o">=</span> <span class="s2">"spark"</span> +</span><span id="L-48"><a href="#L-48"><span class="linenos"> 48</span></a> <span class="n">SPARK2</span> <span class="o">=</span> <span class="s2">"spark2"</span> +</span><span id="L-49"><a href="#L-49"><span class="linenos"> 49</span></a> <span class="n">SQLITE</span> <span class="o">=</span> <span class="s2">"sqlite"</span> +</span><span id="L-50"><a href="#L-50"><span class="linenos"> 50</span></a> <span class="n">STARROCKS</span> <span class="o">=</span> <span class="s2">"starrocks"</span> +</span><span id="L-51"><a href="#L-51"><span class="linenos"> 51</span></a> <span class="n">TABLEAU</span> <span class="o">=</span> <span class="s2">"tableau"</span> +</span><span id="L-52"><a href="#L-52"><span class="linenos"> 52</span></a> <span class="n">TERADATA</span> <span class="o">=</span> <span class="s2">"teradata"</span> +</span><span id="L-53"><a href="#L-53"><span class="linenos"> 53</span></a> <span class="n">TRINO</span> <span class="o">=</span> <span class="s2">"trino"</span> +</span><span id="L-54"><a href="#L-54"><span class="linenos"> 54</span></a> <span class="n">TSQL</span> <span class="o">=</span> <span class="s2">"tsql"</span> +</span><span id="L-55"><a href="#L-55"><span class="linenos"> 55</span></a> +</span><span id="L-56"><a href="#L-56"><span class="linenos"> 56</span></a> +</span><span id="L-57"><a href="#L-57"><span class="linenos"> 57</span></a><span class="k">class</span> <span class="nc">NormalizationStrategy</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">AutoName</span><span class="p">):</span> +</span><span id="L-58"><a href="#L-58"><span class="linenos"> 58</span></a><span class="w"> </span><span class="sd">"""Specifies the strategy according to which identifiers should be normalized."""</span> +</span><span id="L-59"><a href="#L-59"><span class="linenos"> 59</span></a> +</span><span id="L-60"><a href="#L-60"><span class="linenos"> 60</span></a> <span class="n">LOWERCASE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> +</span><span id="L-61"><a href="#L-61"><span class="linenos"> 61</span></a><span class="w"> </span><span class="sd">"""Unquoted identifiers are lowercased."""</span> +</span><span id="L-62"><a href="#L-62"><span class="linenos"> 62</span></a> +</span><span id="L-63"><a href="#L-63"><span class="linenos"> 63</span></a> <span class="n">UPPERCASE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> +</span><span id="L-64"><a href="#L-64"><span class="linenos"> 64</span></a><span class="w"> </span><span class="sd">"""Unquoted identifiers are uppercased."""</span> +</span><span id="L-65"><a href="#L-65"><span class="linenos"> 65</span></a> +</span><span id="L-66"><a href="#L-66"><span class="linenos"> 66</span></a> <span class="n">CASE_SENSITIVE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> +</span><span id="L-67"><a href="#L-67"><span class="linenos"> 67</span></a><span class="w"> </span><span class="sd">"""Always case-sensitive, regardless of quotes."""</span> +</span><span id="L-68"><a href="#L-68"><span class="linenos"> 68</span></a> +</span><span id="L-69"><a href="#L-69"><span class="linenos"> 69</span></a> <span class="n">CASE_INSENSITIVE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> +</span><span id="L-70"><a href="#L-70"><span class="linenos"> 70</span></a><span class="w"> </span><span class="sd">"""Always case-insensitive, regardless of quotes."""</span> +</span><span id="L-71"><a href="#L-71"><span class="linenos"> 71</span></a> +</span><span id="L-72"><a href="#L-72"><span class="linenos"> 72</span></a> +</span><span id="L-73"><a href="#L-73"><span class="linenos"> 73</span></a><span class="k">class</span> <span class="nc">_Dialect</span><span class="p">(</span><span class="nb">type</span><span class="p">):</span> +</span><span id="L-74"><a href="#L-74"><span class="linenos"> 74</span></a> <span class="n">classes</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="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="o">=</span> <span class="p">{}</span> +</span><span id="L-75"><a href="#L-75"><span class="linenos"> 75</span></a> +</span><span id="L-76"><a href="#L-76"><span class="linenos"> 76</span></a> <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">cls</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-77"><a href="#L-77"><span class="linenos"> 77</span></a> <span class="k">if</span> <span class="bp">cls</span> <span class="ow">is</span> <span class="n">other</span><span class="p">:</span> +</span><span id="L-78"><a href="#L-78"><span class="linenos"> 78</span></a> <span class="k">return</span> <span class="kc">True</span> +</span><span id="L-79"><a href="#L-79"><span class="linenos"> 79</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span> +</span><span id="L-80"><a href="#L-80"><span class="linenos"> 80</span></a> <span class="k">return</span> <span class="bp">cls</span> <span class="ow">is</span> <span class="bp">cls</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">other</span><span class="p">)</span> +</span><span id="L-81"><a href="#L-81"><span class="linenos"> 81</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">Dialect</span><span class="p">):</span> +</span><span id="L-82"><a href="#L-82"><span class="linenos"> 82</span></a> <span class="k">return</span> <span class="bp">cls</span> <span class="ow">is</span> <span class="nb">type</span><span class="p">(</span><span class="n">other</span><span class="p">)</span> </span><span id="L-83"><a href="#L-83"><span class="linenos"> 83</span></a> -</span><span id="L-84"><a href="#L-84"><span class="linenos"> 84</span></a> <span class="k">def</span> <span class="fm">__hash__</span><span class="p">(</span><span class="bp">cls</span><span class="p">)</span> <span class="o">-></span> <span class="nb">int</span><span class="p">:</span> -</span><span id="L-85"><a href="#L-85"><span class="linenos"> 85</span></a> <span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="vm">__name__</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span> -</span><span id="L-86"><a href="#L-86"><span class="linenos"> 86</span></a> -</span><span id="L-87"><a href="#L-87"><span class="linenos"> 87</span></a> <span class="nd">@classmethod</span> -</span><span id="L-88"><a href="#L-88"><span class="linenos"> 88</span></a> <span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">key</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">Type</span><span class="p">[</span><span class="n">Dialect</span><span class="p">]:</span> -</span><span id="L-89"><a href="#L-89"><span class="linenos"> 89</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">classes</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> -</span><span id="L-90"><a href="#L-90"><span class="linenos"> 90</span></a> -</span><span id="L-91"><a href="#L-91"><span class="linenos"> 91</span></a> <span class="nd">@classmethod</span> -</span><span id="L-92"><a href="#L-92"><span class="linenos"> 92</span></a> <span class="k">def</span> <span class="nf">get</span><span class="p">(</span> -</span><span id="L-93"><a href="#L-93"><span class="linenos"> 93</span></a> <span class="bp">cls</span><span class="p">,</span> <span class="n">key</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="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="o">=</span> <span class="kc">None</span> -</span><span id="L-94"><a href="#L-94"><span class="linenos"> 94</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">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><span id="L-95"><a href="#L-95"><span class="linenos"> 95</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">classes</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">default</span><span class="p">)</span> -</span><span id="L-96"><a href="#L-96"><span class="linenos"> 96</span></a> -</span><span id="L-97"><a href="#L-97"><span class="linenos"> 97</span></a> <span class="k">def</span> <span class="fm">__new__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">clsname</span><span class="p">,</span> <span class="n">bases</span><span class="p">,</span> <span class="n">attrs</span><span class="p">):</span> -</span><span id="L-98"><a href="#L-98"><span class="linenos"> 98</span></a> <span class="n">klass</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__new__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">clsname</span><span class="p">,</span> <span class="n">bases</span><span class="p">,</span> <span class="n">attrs</span><span class="p">)</span> -</span><span id="L-99"><a href="#L-99"><span class="linenos"> 99</span></a> <span class="n">enum</span> <span class="o">=</span> <span class="n">Dialects</span><span class="o">.</span><span class="n">__members__</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">clsname</span><span class="o">.</span><span class="n">upper</span><span class="p">())</span> -</span><span id="L-100"><a href="#L-100"><span class="linenos"> 100</span></a> <span class="bp">cls</span><span class="o">.</span><span class="n">classes</span><span class="p">[</span><span class="n">enum</span><span class="o">.</span><span class="n">value</span> <span class="k">if</span> <span class="n">enum</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">clsname</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span> <span class="o">=</span> <span class="n">klass</span> -</span><span id="L-101"><a href="#L-101"><span class="linenos"> 101</span></a> -</span><span id="L-102"><a href="#L-102"><span class="linenos"> 102</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">TIME_TRIE</span> <span class="o">=</span> <span class="n">new_trie</span><span class="p">(</span><span class="n">klass</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">)</span> -</span><span id="L-103"><a href="#L-103"><span class="linenos"> 103</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">FORMAT_TRIE</span> <span class="o">=</span> <span class="p">(</span> -</span><span id="L-104"><a href="#L-104"><span class="linenos"> 104</span></a> <span class="n">new_trie</span><span class="p">(</span><span class="n">klass</span><span class="o">.</span><span class="n">FORMAT_MAPPING</span><span class="p">)</span> <span class="k">if</span> <span class="n">klass</span><span class="o">.</span><span class="n">FORMAT_MAPPING</span> <span class="k">else</span> <span class="n">klass</span><span class="o">.</span><span class="n">TIME_TRIE</span> -</span><span id="L-105"><a href="#L-105"><span class="linenos"> 105</span></a> <span class="p">)</span> -</span><span id="L-106"><a href="#L-106"><span class="linenos"> 106</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">INVERSE_TIME_MAPPING</span> <span class="o">=</span> <span class="p">{</span><span class="n">v</span><span class="p">:</span> <span class="n">k</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">klass</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span> -</span><span id="L-107"><a href="#L-107"><span class="linenos"> 107</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">INVERSE_TIME_TRIE</span> <span class="o">=</span> <span class="n">new_trie</span><span class="p">(</span><span class="n">klass</span><span class="o">.</span><span class="n">INVERSE_TIME_MAPPING</span><span class="p">)</span> -</span><span id="L-108"><a href="#L-108"><span class="linenos"> 108</span></a> -</span><span id="L-109"><a href="#L-109"><span class="linenos"> 109</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">INVERSE_ESCAPE_SEQUENCES</span> <span class="o">=</span> <span class="p">{</span><span class="n">v</span><span class="p">:</span> <span class="n">k</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">klass</span><span class="o">.</span><span class="n">ESCAPE_SEQUENCES</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span> +</span><span id="L-84"><a href="#L-84"><span class="linenos"> 84</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="L-85"><a href="#L-85"><span class="linenos"> 85</span></a> +</span><span id="L-86"><a href="#L-86"><span class="linenos"> 86</span></a> <span class="k">def</span> <span class="fm">__hash__</span><span class="p">(</span><span class="bp">cls</span><span class="p">)</span> <span class="o">-></span> <span class="nb">int</span><span class="p">:</span> +</span><span id="L-87"><a href="#L-87"><span class="linenos"> 87</span></a> <span class="k">return</span> <span class="nb">hash</span><span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="vm">__name__</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span> +</span><span id="L-88"><a href="#L-88"><span class="linenos"> 88</span></a> +</span><span id="L-89"><a href="#L-89"><span class="linenos"> 89</span></a> <span class="nd">@classmethod</span> +</span><span id="L-90"><a href="#L-90"><span class="linenos"> 90</span></a> <span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">key</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">Type</span><span class="p">[</span><span class="n">Dialect</span><span class="p">]:</span> +</span><span id="L-91"><a href="#L-91"><span class="linenos"> 91</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">classes</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> +</span><span id="L-92"><a href="#L-92"><span class="linenos"> 92</span></a> +</span><span id="L-93"><a href="#L-93"><span class="linenos"> 93</span></a> <span class="nd">@classmethod</span> +</span><span id="L-94"><a href="#L-94"><span class="linenos"> 94</span></a> <span class="k">def</span> <span class="nf">get</span><span class="p">(</span> +</span><span id="L-95"><a href="#L-95"><span class="linenos"> 95</span></a> <span class="bp">cls</span><span class="p">,</span> <span class="n">key</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="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="o">=</span> <span class="kc">None</span> +</span><span id="L-96"><a href="#L-96"><span class="linenos"> 96</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">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><span id="L-97"><a href="#L-97"><span class="linenos"> 97</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">classes</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">default</span><span class="p">)</span> +</span><span id="L-98"><a href="#L-98"><span class="linenos"> 98</span></a> +</span><span id="L-99"><a href="#L-99"><span class="linenos"> 99</span></a> <span class="k">def</span> <span class="fm">__new__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">clsname</span><span class="p">,</span> <span class="n">bases</span><span class="p">,</span> <span class="n">attrs</span><span class="p">):</span> +</span><span id="L-100"><a href="#L-100"><span class="linenos"> 100</span></a> <span class="n">klass</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__new__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">clsname</span><span class="p">,</span> <span class="n">bases</span><span class="p">,</span> <span class="n">attrs</span><span class="p">)</span> +</span><span id="L-101"><a href="#L-101"><span class="linenos"> 101</span></a> <span class="n">enum</span> <span class="o">=</span> <span class="n">Dialects</span><span class="o">.</span><span class="n">__members__</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">clsname</span><span class="o">.</span><span class="n">upper</span><span class="p">())</span> +</span><span id="L-102"><a href="#L-102"><span class="linenos"> 102</span></a> <span class="bp">cls</span><span class="o">.</span><span class="n">classes</span><span class="p">[</span><span class="n">enum</span><span class="o">.</span><span class="n">value</span> <span class="k">if</span> <span class="n">enum</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">clsname</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span> <span class="o">=</span> <span class="n">klass</span> +</span><span id="L-103"><a href="#L-103"><span class="linenos"> 103</span></a> +</span><span id="L-104"><a href="#L-104"><span class="linenos"> 104</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">TIME_TRIE</span> <span class="o">=</span> <span class="n">new_trie</span><span class="p">(</span><span class="n">klass</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="p">)</span> +</span><span id="L-105"><a href="#L-105"><span class="linenos"> 105</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">FORMAT_TRIE</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="L-106"><a href="#L-106"><span class="linenos"> 106</span></a> <span class="n">new_trie</span><span class="p">(</span><span class="n">klass</span><span class="o">.</span><span class="n">FORMAT_MAPPING</span><span class="p">)</span> <span class="k">if</span> <span class="n">klass</span><span class="o">.</span><span class="n">FORMAT_MAPPING</span> <span class="k">else</span> <span class="n">klass</span><span class="o">.</span><span class="n">TIME_TRIE</span> +</span><span id="L-107"><a href="#L-107"><span class="linenos"> 107</span></a> <span class="p">)</span> +</span><span id="L-108"><a href="#L-108"><span class="linenos"> 108</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">INVERSE_TIME_MAPPING</span> <span class="o">=</span> <span class="p">{</span><span class="n">v</span><span class="p">:</span> <span class="n">k</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">klass</span><span class="o">.</span><span class="n">TIME_MAPPING</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span> +</span><span id="L-109"><a href="#L-109"><span class="linenos"> 109</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">INVERSE_TIME_TRIE</span> <span class="o">=</span> <span class="n">new_trie</span><span class="p">(</span><span class="n">klass</span><span class="o">.</span><span class="n">INVERSE_TIME_MAPPING</span><span class="p">)</span> </span><span id="L-110"><a href="#L-110"><span class="linenos"> 110</span></a> -</span><span id="L-111"><a href="#L-111"><span class="linenos"> 111</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">tokenizer_class</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">klass</span><span class="p">,</span> <span class="s2">"Tokenizer"</span><span class="p">,</span> <span class="n">Tokenizer</span><span class="p">)</span> -</span><span id="L-112"><a href="#L-112"><span class="linenos"> 112</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">parser_class</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">klass</span><span class="p">,</span> <span class="s2">"Parser"</span><span class="p">,</span> <span class="n">Parser</span><span class="p">)</span> -</span><span id="L-113"><a href="#L-113"><span class="linenos"> 113</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">generator_class</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">klass</span><span class="p">,</span> <span class="s2">"Generator"</span><span class="p">,</span> <span class="n">Generator</span><span class="p">)</span> -</span><span id="L-114"><a href="#L-114"><span class="linenos"> 114</span></a> -</span><span id="L-115"><a href="#L-115"><span class="linenos"> 115</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">QUOTE_START</span><span class="p">,</span> <span class="n">klass</span><span class="o">.</span><span class="n">QUOTE_END</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">klass</span><span class="o">.</span><span class="n">tokenizer_class</span><span class="o">.</span><span class="n">_QUOTES</span><span class="o">.</span><span class="n">items</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span> -</span><span id="L-116"><a href="#L-116"><span class="linenos"> 116</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">IDENTIFIER_START</span><span class="p">,</span> <span class="n">klass</span><span class="o">.</span><span class="n">IDENTIFIER_END</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span> -</span><span id="L-117"><a href="#L-117"><span class="linenos"> 117</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">tokenizer_class</span><span class="o">.</span><span class="n">_IDENTIFIERS</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> -</span><span id="L-118"><a href="#L-118"><span class="linenos"> 118</span></a> <span class="p">)[</span><span class="mi">0</span><span class="p">]</span> -</span><span id="L-119"><a href="#L-119"><span class="linenos"> 119</span></a> -</span><span id="L-120"><a href="#L-120"><span class="linenos"> 120</span></a> <span class="k">def</span> <span class="nf">get_start_end</span><span class="p">(</span><span class="n">token_type</span><span class="p">:</span> <span class="n">TokenType</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</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="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-121"><a href="#L-121"><span class="linenos"> 121</span></a> <span class="k">return</span> <span class="nb">next</span><span class="p">(</span> -</span><span id="L-122"><a href="#L-122"><span class="linenos"> 122</span></a> <span class="p">(</span> -</span><span id="L-123"><a href="#L-123"><span class="linenos"> 123</span></a> <span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span> -</span><span id="L-124"><a href="#L-124"><span class="linenos"> 124</span></a> <span class="k">for</span> <span class="n">s</span><span class="p">,</span> <span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="ow">in</span> <span class="n">klass</span><span class="o">.</span><span class="n">tokenizer_class</span><span class="o">.</span><span class="n">_FORMAT_STRINGS</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> -</span><span id="L-125"><a href="#L-125"><span class="linenos"> 125</span></a> <span class="k">if</span> <span class="n">t</span> <span class="o">==</span> <span class="n">token_type</span> -</span><span id="L-126"><a href="#L-126"><span class="linenos"> 126</span></a> <span class="p">),</span> -</span><span id="L-127"><a href="#L-127"><span class="linenos"> 127</span></a> <span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span> -</span><span id="L-128"><a href="#L-128"><span class="linenos"> 128</span></a> <span class="p">)</span> -</span><span id="L-129"><a href="#L-129"><span class="linenos"> 129</span></a> -</span><span id="L-130"><a href="#L-130"><span class="linenos"> 130</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">BIT_START</span><span class="p">,</span> <span class="n">klass</span><span class="o">.</span><span class="n">BIT_END</span> <span class="o">=</span> <span class="n">get_start_end</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">BIT_STRING</span><span class="p">)</span> -</span><span id="L-131"><a href="#L-131"><span class="linenos"> 131</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">HEX_START</span><span class="p">,</span> <span class="n">klass</span><span class="o">.</span><span class="n">HEX_END</span> <span class="o">=</span> <span class="n">get_start_end</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">HEX_STRING</span><span class="p">)</span> -</span><span id="L-132"><a href="#L-132"><span class="linenos"> 132</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">BYTE_START</span><span class="p">,</span> <span class="n">klass</span><span class="o">.</span><span class="n">BYTE_END</span> <span class="o">=</span> <span class="n">get_start_end</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">BYTE_STRING</span><span class="p">)</span> -</span><span id="L-133"><a href="#L-133"><span class="linenos"> 133</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">UNICODE_START</span><span class="p">,</span> <span class="n">klass</span><span class="o">.</span><span class="n">UNICODE_END</span> <span class="o">=</span> <span class="n">get_start_end</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">UNICODE_STRING</span><span class="p">)</span> -</span><span id="L-134"><a href="#L-134"><span class="linenos"> 134</span></a> -</span><span id="L-135"><a href="#L-135"><span class="linenos"> 135</span></a> <span class="k">if</span> <span class="n">enum</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">""</span><span class="p">,</span> <span class="s2">"bigquery"</span><span class="p">):</span> -</span><span id="L-136"><a href="#L-136"><span class="linenos"> 136</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">generator_class</span><span class="o">.</span><span class="n">SELECT_KINDS</span> <span class="o">=</span> <span class="p">()</span> -</span><span id="L-137"><a href="#L-137"><span class="linenos"> 137</span></a> -</span><span id="L-138"><a href="#L-138"><span class="linenos"> 138</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">klass</span><span class="o">.</span><span class="n">SUPPORTS_SEMI_ANTI_JOIN</span><span class="p">:</span> -</span><span id="L-139"><a href="#L-139"><span class="linenos"> 139</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">parser_class</span><span class="o">.</span><span class="n">TABLE_ALIAS_TOKENS</span> <span class="o">=</span> <span class="n">klass</span><span class="o">.</span><span class="n">parser_class</span><span class="o">.</span><span class="n">TABLE_ALIAS_TOKENS</span> <span class="o">|</span> <span class="p">{</span> -</span><span id="L-140"><a href="#L-140"><span class="linenos"> 140</span></a> <span class="n">TokenType</span><span class="o">.</span><span class="n">ANTI</span><span class="p">,</span> -</span><span id="L-141"><a href="#L-141"><span class="linenos"> 141</span></a> <span class="n">TokenType</span><span class="o">.</span><span class="n">SEMI</span><span class="p">,</span> -</span><span id="L-142"><a href="#L-142"><span class="linenos"> 142</span></a> <span class="p">}</span> -</span><span id="L-143"><a href="#L-143"><span class="linenos"> 143</span></a> -</span><span id="L-144"><a href="#L-144"><span class="linenos"> 144</span></a> <span class="k">return</span> <span class="n">klass</span> +</span><span id="L-111"><a href="#L-111"><span class="linenos"> 111</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">INVERSE_ESCAPE_SEQUENCES</span> <span class="o">=</span> <span class="p">{</span><span class="n">v</span><span class="p">:</span> <span class="n">k</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">klass</span><span class="o">.</span><span class="n">ESCAPE_SEQUENCES</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span> +</span><span id="L-112"><a href="#L-112"><span class="linenos"> 112</span></a> +</span><span id="L-113"><a href="#L-113"><span class="linenos"> 113</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">tokenizer_class</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">klass</span><span class="p">,</span> <span class="s2">"Tokenizer"</span><span class="p">,</span> <span class="n">Tokenizer</span><span class="p">)</span> +</span><span id="L-114"><a href="#L-114"><span class="linenos"> 114</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">parser_class</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">klass</span><span class="p">,</span> <span class="s2">"Parser"</span><span class="p">,</span> <span class="n">Parser</span><span class="p">)</span> +</span><span id="L-115"><a href="#L-115"><span class="linenos"> 115</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">generator_class</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">klass</span><span class="p">,</span> <span class="s2">"Generator"</span><span class="p">,</span> <span class="n">Generator</span><span class="p">)</span> +</span><span id="L-116"><a href="#L-116"><span class="linenos"> 116</span></a> +</span><span id="L-117"><a href="#L-117"><span class="linenos"> 117</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">QUOTE_START</span><span class="p">,</span> <span class="n">klass</span><span class="o">.</span><span class="n">QUOTE_END</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">klass</span><span class="o">.</span><span class="n">tokenizer_class</span><span class="o">.</span><span class="n">_QUOTES</span><span class="o">.</span><span class="n">items</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span> +</span><span id="L-118"><a href="#L-118"><span class="linenos"> 118</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">IDENTIFIER_START</span><span class="p">,</span> <span class="n">klass</span><span class="o">.</span><span class="n">IDENTIFIER_END</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span> +</span><span id="L-119"><a href="#L-119"><span class="linenos"> 119</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">tokenizer_class</span><span class="o">.</span><span class="n">_IDENTIFIERS</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> +</span><span id="L-120"><a href="#L-120"><span class="linenos"> 120</span></a> <span class="p">)[</span><span class="mi">0</span><span class="p">]</span> +</span><span id="L-121"><a href="#L-121"><span class="linenos"> 121</span></a> +</span><span id="L-122"><a href="#L-122"><span class="linenos"> 122</span></a> <span class="k">def</span> <span class="nf">get_start_end</span><span class="p">(</span><span class="n">token_type</span><span class="p">:</span> <span class="n">TokenType</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</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="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-123"><a href="#L-123"><span class="linenos"> 123</span></a> <span class="k">return</span> <span class="nb">next</span><span class="p">(</span> +</span><span id="L-124"><a href="#L-124"><span class="linenos"> 124</span></a> <span class="p">(</span> +</span><span id="L-125"><a href="#L-125"><span class="linenos"> 125</span></a> <span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span> +</span><span id="L-126"><a href="#L-126"><span class="linenos"> 126</span></a> <span class="k">for</span> <span class="n">s</span><span class="p">,</span> <span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="ow">in</span> <span class="n">klass</span><span class="o">.</span><span class="n">tokenizer_class</span><span class="o">.</span><span class="n">_FORMAT_STRINGS</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> +</span><span id="L-127"><a href="#L-127"><span class="linenos"> 127</span></a> <span class="k">if</span> <span class="n">t</span> <span class="o">==</span> <span class="n">token_type</span> +</span><span id="L-128"><a href="#L-128"><span class="linenos"> 128</span></a> <span class="p">),</span> +</span><span id="L-129"><a href="#L-129"><span class="linenos"> 129</span></a> <span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span> +</span><span id="L-130"><a href="#L-130"><span class="linenos"> 130</span></a> <span class="p">)</span> +</span><span id="L-131"><a href="#L-131"><span class="linenos"> 131</span></a> +</span><span id="L-132"><a href="#L-132"><span class="linenos"> 132</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">BIT_START</span><span class="p">,</span> <span class="n">klass</span><span class="o">.</span><span class="n">BIT_END</span> <span class="o">=</span> <span class="n">get_start_end</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">BIT_STRING</span><span class="p">)</span> +</span><span id="L-133"><a href="#L-133"><span class="linenos"> 133</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">HEX_START</span><span class="p">,</span> <span class="n">klass</span><span class="o">.</span><span class="n">HEX_END</span> <span class="o">=</span> <span class="n">get_start_end</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">HEX_STRING</span><span class="p">)</span> +</span><span id="L-134"><a href="#L-134"><span class="linenos"> 134</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">BYTE_START</span><span class="p">,</span> <span class="n">klass</span><span class="o">.</span><span class="n">BYTE_END</span> <span class="o">=</span> <span class="n">get_start_end</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">BYTE_STRING</span><span class="p">)</span> +</span><span id="L-135"><a href="#L-135"><span class="linenos"> 135</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">UNICODE_START</span><span class="p">,</span> <span class="n">klass</span><span class="o">.</span><span class="n">UNICODE_END</span> <span class="o">=</span> <span class="n">get_start_end</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">UNICODE_STRING</span><span class="p">)</span> +</span><span id="L-136"><a href="#L-136"><span class="linenos"> 136</span></a> +</span><span id="L-137"><a href="#L-137"><span class="linenos"> 137</span></a> <span class="k">if</span> <span class="n">enum</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">""</span><span class="p">,</span> <span class="s2">"bigquery"</span><span class="p">):</span> +</span><span id="L-138"><a href="#L-138"><span class="linenos"> 138</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">generator_class</span><span class="o">.</span><span class="n">SELECT_KINDS</span> <span class="o">=</span> <span class="p">()</span> +</span><span id="L-139"><a href="#L-139"><span class="linenos"> 139</span></a> +</span><span id="L-140"><a href="#L-140"><span class="linenos"> 140</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">klass</span><span class="o">.</span><span class="n">SUPPORTS_SEMI_ANTI_JOIN</span><span class="p">:</span> +</span><span id="L-141"><a href="#L-141"><span class="linenos"> 141</span></a> <span class="n">klass</span><span class="o">.</span><span class="n">parser_class</span><span class="o">.</span><span class="n">TABLE_ALIAS_TOKENS</span> <span class="o">=</span> <span class="n">klass</span><span class="o">.</span><span class="n">parser_class</span><span class="o">.</span><span class="n">TABLE_ALIAS_TOKENS</span> <span class="o">|</span> <span class="p">{</span> +</span><span id="L-142"><a href="#L-142"><span class="linenos"> 142</span></a> <span class="n">TokenType</span><span class="o">.</span><span class="n">ANTI</span><span class="p">,</span> +</span><span id="L-143"><a href="#L-143"><span class="linenos"> 143</span></a> <span class="n">TokenType</span><span class="o">.</span><span class="n">SEMI</span><span class="p">,</span> +</span><span id="L-144"><a href="#L-144"><span class="linenos"> 144</span></a> <span class="p">}</span> </span><span id="L-145"><a href="#L-145"><span class="linenos"> 145</span></a> -</span><span id="L-146"><a href="#L-146"><span class="linenos"> 146</span></a> -</span><span id="L-147"><a href="#L-147"><span class="linenos"> 147</span></a><span class="k">class</span> <span class="nc">Dialect</span><span class="p">(</span><span class="n">metaclass</span><span class="o">=</span><span class="n">_Dialect</span><span class="p">):</span> -</span><span id="L-148"><a href="#L-148"><span class="linenos"> 148</span></a> <span class="n">INDEX_OFFSET</span> <span class="o">=</span> <span class="mi">0</span> -</span><span id="L-149"><a href="#L-149"><span class="linenos"> 149</span></a><span class="w"> </span><span class="sd">"""Determines the base index offset for arrays."""</span> -</span><span id="L-150"><a href="#L-150"><span class="linenos"> 150</span></a> -</span><span id="L-151"><a href="#L-151"><span class="linenos"> 151</span></a> <span class="n">WEEK_OFFSET</span> <span class="o">=</span> <span class="mi">0</span> -</span><span id="L-152"><a href="#L-152"><span class="linenos"> 152</span></a><span class="w"> </span><span class="sd">"""Determines the day of week of DATE_TRUNC(week). Defaults to 0 (Monday). -1 would be Sunday."""</span> -</span><span id="L-153"><a href="#L-153"><span class="linenos"> 153</span></a> -</span><span id="L-154"><a href="#L-154"><span class="linenos"> 154</span></a> <span class="n">UNNEST_COLUMN_ONLY</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-155"><a href="#L-155"><span class="linenos"> 155</span></a><span class="w"> </span><span class="sd">"""Determines whether or not `UNNEST` table aliases are treated as column aliases."""</span> -</span><span id="L-156"><a href="#L-156"><span class="linenos"> 156</span></a> -</span><span id="L-157"><a href="#L-157"><span class="linenos"> 157</span></a> <span class="n">ALIAS_POST_TABLESAMPLE</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-158"><a href="#L-158"><span class="linenos"> 158</span></a><span class="w"> </span><span class="sd">"""Determines whether or not the table alias comes after tablesample."""</span> -</span><span id="L-159"><a href="#L-159"><span class="linenos"> 159</span></a> -</span><span id="L-160"><a href="#L-160"><span class="linenos"> 160</span></a> <span class="n">TABLESAMPLE_SIZE_IS_PERCENT</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-161"><a href="#L-161"><span class="linenos"> 161</span></a><span class="w"> </span><span class="sd">"""Determines whether or not a size in the table sample clause represents percentage."""</span> -</span><span id="L-162"><a href="#L-162"><span class="linenos"> 162</span></a> -</span><span id="L-163"><a href="#L-163"><span class="linenos"> 163</span></a> <span class="n">NORMALIZATION_STRATEGY</span> <span class="o">=</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">LOWERCASE</span> -</span><span id="L-164"><a href="#L-164"><span class="linenos"> 164</span></a><span class="w"> </span><span class="sd">"""Specifies the strategy according to which identifiers should be normalized."""</span> -</span><span id="L-165"><a href="#L-165"><span class="linenos"> 165</span></a> -</span><span id="L-166"><a href="#L-166"><span class="linenos"> 166</span></a> <span class="n">IDENTIFIERS_CAN_START_WITH_DIGIT</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-167"><a href="#L-167"><span class="linenos"> 167</span></a><span class="w"> </span><span class="sd">"""Determines whether or not an unquoted identifier can start with a digit."""</span> -</span><span id="L-168"><a href="#L-168"><span class="linenos"> 168</span></a> -</span><span id="L-169"><a href="#L-169"><span class="linenos"> 169</span></a> <span class="n">DPIPE_IS_STRING_CONCAT</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="L-170"><a href="#L-170"><span class="linenos"> 170</span></a><span class="w"> </span><span class="sd">"""Determines whether or not the DPIPE token (`||`) is a string concatenation operator."""</span> -</span><span id="L-171"><a href="#L-171"><span class="linenos"> 171</span></a> -</span><span id="L-172"><a href="#L-172"><span class="linenos"> 172</span></a> <span class="n">STRICT_STRING_CONCAT</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-173"><a href="#L-173"><span class="linenos"> 173</span></a><span class="w"> </span><span class="sd">"""Determines whether or not `CONCAT`'s arguments must be strings."""</span> -</span><span id="L-174"><a href="#L-174"><span class="linenos"> 174</span></a> -</span><span id="L-175"><a href="#L-175"><span class="linenos"> 175</span></a> <span class="n">SUPPORTS_USER_DEFINED_TYPES</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="L-176"><a href="#L-176"><span class="linenos"> 176</span></a><span class="w"> </span><span class="sd">"""Determines whether or not user-defined data types are supported."""</span> -</span><span id="L-177"><a href="#L-177"><span class="linenos"> 177</span></a> -</span><span id="L-178"><a href="#L-178"><span class="linenos"> 178</span></a> <span class="n">SUPPORTS_SEMI_ANTI_JOIN</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="L-179"><a href="#L-179"><span class="linenos"> 179</span></a><span class="w"> </span><span class="sd">"""Determines whether or not `SEMI` or `ANTI` joins are supported."""</span> -</span><span id="L-180"><a href="#L-180"><span class="linenos"> 180</span></a> -</span><span id="L-181"><a href="#L-181"><span class="linenos"> 181</span></a> <span class="n">NORMALIZE_FUNCTIONS</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">|</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"upper"</span> -</span><span id="L-182"><a href="#L-182"><span class="linenos"> 182</span></a><span class="w"> </span><span class="sd">"""Determines how function names are going to be normalized."""</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="n">LOG_BASE_FIRST</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="L-185"><a href="#L-185"><span class="linenos"> 185</span></a><span class="w"> </span><span class="sd">"""Determines whether the base comes first in the `LOG` function."""</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="n">NULL_ORDERING</span> <span class="o">=</span> <span class="s2">"nulls_are_small"</span> -</span><span id="L-188"><a href="#L-188"><span class="linenos"> 188</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-189"><a href="#L-189"><span class="linenos"> 189</span></a><span class="sd"> Indicates the default `NULL` ordering method to use if not explicitly set.</span> -</span><span id="L-190"><a href="#L-190"><span class="linenos"> 190</span></a><span class="sd"> Possible values: `"nulls_are_small"`, `"nulls_are_large"`, `"nulls_are_last"`</span> -</span><span id="L-191"><a href="#L-191"><span class="linenos"> 191</span></a><span class="sd"> """</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="n">TYPED_DIVISION</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-194"><a href="#L-194"><span class="linenos"> 194</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-195"><a href="#L-195"><span class="linenos"> 195</span></a><span class="sd"> Whether the behavior of `a / b` depends on the types of `a` and `b`.</span> -</span><span id="L-196"><a href="#L-196"><span class="linenos"> 196</span></a><span class="sd"> False means `a / b` is always float division.</span> -</span><span id="L-197"><a href="#L-197"><span class="linenos"> 197</span></a><span class="sd"> True means `a / b` is integer division if both `a` and `b` are integers.</span> -</span><span id="L-198"><a href="#L-198"><span class="linenos"> 198</span></a><span class="sd"> """</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="n">SAFE_DIVISION</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-201"><a href="#L-201"><span class="linenos"> 201</span></a><span class="w"> </span><span class="sd">"""Determines whether division by zero throws an error (`False`) or returns NULL (`True`)."""</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="n">CONCAT_COALESCE</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-204"><a href="#L-204"><span class="linenos"> 204</span></a><span class="w"> </span><span class="sd">"""A `NULL` arg in `CONCAT` yields `NULL` by default, but in some dialects it yields an empty string."""</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="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-207"><a href="#L-207"><span class="linenos"> 207</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-208"><a href="#L-208"><span class="linenos"> 208</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-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">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="w"> </span><span class="sd">"""Associates this dialect's time formats with their equivalent Python `strftime` format."""</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="c1"># https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#format_model_rules_date_time</span> -</span><span id="L-214"><a href="#L-214"><span class="linenos"> 214</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-215"><a href="#L-215"><span class="linenos"> 215</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-216"><a href="#L-216"><span class="linenos"> 216</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-217"><a href="#L-217"><span class="linenos"> 217</span></a><span class="sd"> Helper which is used for parsing the special syntax `CAST(x AS DATE FORMAT 'yyyy')`.</span> -</span><span id="L-218"><a href="#L-218"><span class="linenos"> 218</span></a><span class="sd"> If empty, the corresponding trie will be constructed off of `TIME_MAPPING`.</span> -</span><span id="L-219"><a href="#L-219"><span class="linenos"> 219</span></a><span class="sd"> """</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="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-222"><a href="#L-222"><span class="linenos"> 222</span></a><span class="w"> </span><span class="sd">"""Mapping of an unescaped escape sequence to the corresponding character."""</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="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-225"><a href="#L-225"><span class="linenos"> 225</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-226"><a href="#L-226"><span class="linenos"> 226</span></a><span class="sd"> Columns that are auto-generated by the engine corresponding to this dialect.</span> -</span><span id="L-227"><a href="#L-227"><span class="linenos"> 227</span></a><span class="sd"> For example, such columns may be excluded from `SELECT *` queries.</span> -</span><span id="L-228"><a href="#L-228"><span class="linenos"> 228</span></a><span class="sd"> """</span> -</span><span id="L-229"><a href="#L-229"><span class="linenos"> 229</span></a> -</span><span id="L-230"><a href="#L-230"><span class="linenos"> 230</span></a> <span class="n">PREFER_CTE_ALIAS_COLUMN</span> <span class="o">=</span> <span class="kc">False</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"> Some dialects, such as Snowflake, allow you to reference a CTE column alias in the</span> -</span><span id="L-233"><a href="#L-233"><span class="linenos"> 233</span></a><span class="sd"> HAVING clause of the CTE. This flag will cause the CTE alias columns to override</span> -</span><span id="L-234"><a href="#L-234"><span class="linenos"> 234</span></a><span class="sd"> any projection aliases in the subquery.</span> -</span><span id="L-235"><a href="#L-235"><span class="linenos"> 235</span></a> -</span><span id="L-236"><a href="#L-236"><span class="linenos"> 236</span></a><span class="sd"> For example,</span> -</span><span id="L-237"><a href="#L-237"><span class="linenos"> 237</span></a><span class="sd"> WITH y(c) AS (</span> -</span><span id="L-238"><a href="#L-238"><span class="linenos"> 238</span></a><span class="sd"> SELECT SUM(a) FROM (SELECT 1 a) AS x HAVING c > 0</span> -</span><span id="L-239"><a href="#L-239"><span class="linenos"> 239</span></a><span class="sd"> ) SELECT c FROM y;</span> -</span><span id="L-240"><a href="#L-240"><span class="linenos"> 240</span></a> -</span><span id="L-241"><a href="#L-241"><span class="linenos"> 241</span></a><span class="sd"> will be rewritten as</span> +</span><span id="L-146"><a href="#L-146"><span class="linenos"> 146</span></a> <span class="k">return</span> <span class="n">klass</span> +</span><span id="L-147"><a href="#L-147"><span class="linenos"> 147</span></a> +</span><span id="L-148"><a href="#L-148"><span class="linenos"> 148</span></a> +</span><span id="L-149"><a href="#L-149"><span class="linenos"> 149</span></a><span class="k">class</span> <span class="nc">Dialect</span><span class="p">(</span><span class="n">metaclass</span><span class="o">=</span><span class="n">_Dialect</span><span class="p">):</span> +</span><span id="L-150"><a href="#L-150"><span class="linenos"> 150</span></a> <span class="n">INDEX_OFFSET</span> <span class="o">=</span> <span class="mi">0</span> +</span><span id="L-151"><a href="#L-151"><span class="linenos"> 151</span></a><span class="w"> </span><span class="sd">"""Determines the base index offset for arrays."""</span> +</span><span id="L-152"><a href="#L-152"><span class="linenos"> 152</span></a> +</span><span id="L-153"><a href="#L-153"><span class="linenos"> 153</span></a> <span class="n">WEEK_OFFSET</span> <span class="o">=</span> <span class="mi">0</span> +</span><span id="L-154"><a href="#L-154"><span class="linenos"> 154</span></a><span class="w"> </span><span class="sd">"""Determines the day of week of DATE_TRUNC(week). Defaults to 0 (Monday). -1 would be Sunday."""</span> +</span><span id="L-155"><a href="#L-155"><span class="linenos"> 155</span></a> +</span><span id="L-156"><a href="#L-156"><span class="linenos"> 156</span></a> <span class="n">UNNEST_COLUMN_ONLY</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-157"><a href="#L-157"><span class="linenos"> 157</span></a><span class="w"> </span><span class="sd">"""Determines whether or not `UNNEST` table aliases are treated as column aliases."""</span> +</span><span id="L-158"><a href="#L-158"><span class="linenos"> 158</span></a> +</span><span id="L-159"><a href="#L-159"><span class="linenos"> 159</span></a> <span class="n">ALIAS_POST_TABLESAMPLE</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-160"><a href="#L-160"><span class="linenos"> 160</span></a><span class="w"> </span><span class="sd">"""Determines whether or not the table alias comes after tablesample."""</span> +</span><span id="L-161"><a href="#L-161"><span class="linenos"> 161</span></a> +</span><span id="L-162"><a href="#L-162"><span class="linenos"> 162</span></a> <span class="n">TABLESAMPLE_SIZE_IS_PERCENT</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-163"><a href="#L-163"><span class="linenos"> 163</span></a><span class="w"> </span><span class="sd">"""Determines whether or not a size in the table sample clause represents percentage."""</span> +</span><span id="L-164"><a href="#L-164"><span class="linenos"> 164</span></a> +</span><span id="L-165"><a href="#L-165"><span class="linenos"> 165</span></a> <span class="n">NORMALIZATION_STRATEGY</span> <span class="o">=</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">LOWERCASE</span> +</span><span id="L-166"><a href="#L-166"><span class="linenos"> 166</span></a><span class="w"> </span><span class="sd">"""Specifies the strategy according to which identifiers should be normalized."""</span> +</span><span id="L-167"><a href="#L-167"><span class="linenos"> 167</span></a> +</span><span id="L-168"><a href="#L-168"><span class="linenos"> 168</span></a> <span class="n">IDENTIFIERS_CAN_START_WITH_DIGIT</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-169"><a href="#L-169"><span class="linenos"> 169</span></a><span class="w"> </span><span class="sd">"""Determines whether or not an unquoted identifier can start with a digit."""</span> +</span><span id="L-170"><a href="#L-170"><span class="linenos"> 170</span></a> +</span><span id="L-171"><a href="#L-171"><span class="linenos"> 171</span></a> <span class="n">DPIPE_IS_STRING_CONCAT</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="L-172"><a href="#L-172"><span class="linenos"> 172</span></a><span class="w"> </span><span class="sd">"""Determines whether or not the DPIPE token (`||`) is a string concatenation operator."""</span> +</span><span id="L-173"><a href="#L-173"><span class="linenos"> 173</span></a> +</span><span id="L-174"><a href="#L-174"><span class="linenos"> 174</span></a> <span class="n">STRICT_STRING_CONCAT</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-175"><a href="#L-175"><span class="linenos"> 175</span></a><span class="w"> </span><span class="sd">"""Determines whether or not `CONCAT`'s arguments must be strings."""</span> +</span><span id="L-176"><a href="#L-176"><span class="linenos"> 176</span></a> +</span><span id="L-177"><a href="#L-177"><span class="linenos"> 177</span></a> <span class="n">SUPPORTS_USER_DEFINED_TYPES</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="L-178"><a href="#L-178"><span class="linenos"> 178</span></a><span class="w"> </span><span class="sd">"""Determines whether or not user-defined data types are supported."""</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">SUPPORTS_SEMI_ANTI_JOIN</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="L-181"><a href="#L-181"><span class="linenos"> 181</span></a><span class="w"> </span><span class="sd">"""Determines whether or not `SEMI` or `ANTI` joins are supported."""</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">NORMALIZE_FUNCTIONS</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">|</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"upper"</span> +</span><span id="L-184"><a href="#L-184"><span class="linenos"> 184</span></a><span class="w"> </span><span class="sd">"""Determines how function names are going to be normalized."""</span> +</span><span id="L-185"><a href="#L-185"><span class="linenos"> 185</span></a> +</span><span id="L-186"><a href="#L-186"><span class="linenos"> 186</span></a> <span class="n">LOG_BASE_FIRST</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="L-187"><a href="#L-187"><span class="linenos"> 187</span></a><span class="w"> </span><span class="sd">"""Determines whether the base comes first in the `LOG` function."""</span> +</span><span id="L-188"><a href="#L-188"><span class="linenos"> 188</span></a> +</span><span id="L-189"><a href="#L-189"><span class="linenos"> 189</span></a> <span class="n">NULL_ORDERING</span> <span class="o">=</span> <span class="s2">"nulls_are_small"</span> +</span><span id="L-190"><a href="#L-190"><span class="linenos"> 190</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-191"><a href="#L-191"><span class="linenos"> 191</span></a><span class="sd"> Indicates the default `NULL` ordering method to use if not explicitly set.</span> +</span><span id="L-192"><a href="#L-192"><span class="linenos"> 192</span></a><span class="sd"> Possible values: `"nulls_are_small"`, `"nulls_are_large"`, `"nulls_are_last"`</span> +</span><span id="L-193"><a href="#L-193"><span class="linenos"> 193</span></a><span class="sd"> """</span> +</span><span id="L-194"><a href="#L-194"><span class="linenos"> 194</span></a> +</span><span id="L-195"><a href="#L-195"><span class="linenos"> 195</span></a> <span class="n">TYPED_DIVISION</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-196"><a href="#L-196"><span class="linenos"> 196</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-197"><a href="#L-197"><span class="linenos"> 197</span></a><span class="sd"> Whether the behavior of `a / b` depends on the types of `a` and `b`.</span> +</span><span id="L-198"><a href="#L-198"><span class="linenos"> 198</span></a><span class="sd"> False means `a / b` is always float division.</span> +</span><span id="L-199"><a href="#L-199"><span class="linenos"> 199</span></a><span class="sd"> True means `a / b` is integer division if both `a` and `b` are integers.</span> +</span><span id="L-200"><a href="#L-200"><span class="linenos"> 200</span></a><span class="sd"> """</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">SAFE_DIVISION</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-203"><a href="#L-203"><span class="linenos"> 203</span></a><span class="w"> </span><span class="sd">"""Determines whether division by zero throws an error (`False`) or returns NULL (`True`)."""</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">CONCAT_COALESCE</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-206"><a href="#L-206"><span class="linenos"> 206</span></a><span class="w"> </span><span class="sd">"""A `NULL` arg in `CONCAT` yields `NULL` by default, but in some dialects it yields an empty string."""</span> +</span><span id="L-207"><a href="#L-207"><span class="linenos"> 207</span></a> +</span><span id="L-208"><a href="#L-208"><span class="linenos"> 208</span></a> <span class="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-209"><a href="#L-209"><span class="linenos"> 209</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-210"><a href="#L-210"><span class="linenos"> 210</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-211"><a href="#L-211"><span class="linenos"> 211</span></a> +</span><span id="L-212"><a href="#L-212"><span class="linenos"> 212</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-213"><a href="#L-213"><span class="linenos"> 213</span></a><span class="w"> </span><span class="sd">"""Associates this dialect's time formats with their equivalent Python `strftime` format."""</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"># https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#format_model_rules_date_time</span> +</span><span id="L-216"><a href="#L-216"><span class="linenos"> 216</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-217"><a href="#L-217"><span class="linenos"> 217</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-218"><a href="#L-218"><span class="linenos"> 218</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-219"><a href="#L-219"><span class="linenos"> 219</span></a><span class="sd"> Helper which is used for parsing the special syntax `CAST(x AS DATE FORMAT 'yyyy')`.</span> +</span><span id="L-220"><a href="#L-220"><span class="linenos"> 220</span></a><span class="sd"> If empty, the corresponding trie will be constructed off of `TIME_MAPPING`.</span> +</span><span id="L-221"><a href="#L-221"><span class="linenos"> 221</span></a><span class="sd"> """</span> +</span><span id="L-222"><a href="#L-222"><span class="linenos"> 222</span></a> +</span><span id="L-223"><a href="#L-223"><span class="linenos"> 223</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-224"><a href="#L-224"><span class="linenos"> 224</span></a><span class="w"> </span><span class="sd">"""Mapping of an unescaped escape sequence to the corresponding character."""</span> +</span><span id="L-225"><a href="#L-225"><span class="linenos"> 225</span></a> +</span><span id="L-226"><a href="#L-226"><span class="linenos"> 226</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-227"><a href="#L-227"><span class="linenos"> 227</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-228"><a href="#L-228"><span class="linenos"> 228</span></a><span class="sd"> Columns that are auto-generated by the engine corresponding to this dialect.</span> +</span><span id="L-229"><a href="#L-229"><span class="linenos"> 229</span></a><span class="sd"> For example, such columns may be excluded from `SELECT *` queries.</span> +</span><span id="L-230"><a href="#L-230"><span class="linenos"> 230</span></a><span class="sd"> """</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="n">PREFER_CTE_ALIAS_COLUMN</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-233"><a href="#L-233"><span class="linenos"> 233</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-234"><a href="#L-234"><span class="linenos"> 234</span></a><span class="sd"> Some dialects, such as Snowflake, allow you to reference a CTE column alias in the</span> +</span><span id="L-235"><a href="#L-235"><span class="linenos"> 235</span></a><span class="sd"> HAVING clause of the CTE. This flag will cause the CTE alias columns to override</span> +</span><span id="L-236"><a href="#L-236"><span class="linenos"> 236</span></a><span class="sd"> any projection aliases in the subquery.</span> +</span><span id="L-237"><a href="#L-237"><span class="linenos"> 237</span></a> +</span><span id="L-238"><a href="#L-238"><span class="linenos"> 238</span></a><span class="sd"> For example,</span> +</span><span id="L-239"><a href="#L-239"><span class="linenos"> 239</span></a><span class="sd"> WITH y(c) AS (</span> +</span><span id="L-240"><a href="#L-240"><span class="linenos"> 240</span></a><span class="sd"> SELECT SUM(a) FROM (SELECT 1 a) AS x HAVING c > 0</span> +</span><span id="L-241"><a href="#L-241"><span class="linenos"> 241</span></a><span class="sd"> ) SELECT c FROM y;</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"> WITH y(c) AS (</span> -</span><span id="L-244"><a href="#L-244"><span class="linenos"> 244</span></a><span class="sd"> SELECT SUM(a) AS c FROM (SELECT 1 AS a) AS x HAVING c > 0</span> -</span><span id="L-245"><a href="#L-245"><span class="linenos"> 245</span></a><span class="sd"> ) SELECT c FROM y;</span> -</span><span id="L-246"><a href="#L-246"><span class="linenos"> 246</span></a><span class="sd"> """</span> -</span><span id="L-247"><a href="#L-247"><span class="linenos"> 247</span></a> -</span><span id="L-248"><a href="#L-248"><span class="linenos"> 248</span></a> <span class="c1"># --- Autofilled ---</span> +</span><span id="L-243"><a href="#L-243"><span class="linenos"> 243</span></a><span class="sd"> will be rewritten as</span> +</span><span id="L-244"><a href="#L-244"><span class="linenos"> 244</span></a> +</span><span id="L-245"><a href="#L-245"><span class="linenos"> 245</span></a><span class="sd"> WITH y(c) AS (</span> +</span><span id="L-246"><a href="#L-246"><span class="linenos"> 246</span></a><span class="sd"> SELECT SUM(a) AS c FROM (SELECT 1 AS a) AS x HAVING c > 0</span> +</span><span id="L-247"><a href="#L-247"><span class="linenos"> 247</span></a><span class="sd"> ) SELECT c FROM y;</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="n">tokenizer_class</span> <span class="o">=</span> <span class="n">Tokenizer</span> -</span><span id="L-251"><a href="#L-251"><span class="linenos"> 251</span></a> <span class="n">parser_class</span> <span class="o">=</span> <span class="n">Parser</span> -</span><span id="L-252"><a href="#L-252"><span class="linenos"> 252</span></a> <span class="n">generator_class</span> <span class="o">=</span> <span class="n">Generator</span> -</span><span id="L-253"><a href="#L-253"><span class="linenos"> 253</span></a> -</span><span id="L-254"><a href="#L-254"><span class="linenos"> 254</span></a> <span class="c1"># A trie of the time_mapping keys</span> -</span><span id="L-255"><a href="#L-255"><span class="linenos"> 255</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-256"><a href="#L-256"><span class="linenos"> 256</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-257"><a href="#L-257"><span class="linenos"> 257</span></a> -</span><span id="L-258"><a href="#L-258"><span class="linenos"> 258</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-259"><a href="#L-259"><span class="linenos"> 259</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-260"><a href="#L-260"><span class="linenos"> 260</span></a> -</span><span id="L-261"><a href="#L-261"><span class="linenos"> 261</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-250"><a href="#L-250"><span class="linenos"> 250</span></a> <span class="c1"># --- Autofilled ---</span> +</span><span id="L-251"><a href="#L-251"><span class="linenos"> 251</span></a> +</span><span id="L-252"><a href="#L-252"><span class="linenos"> 252</span></a> <span class="n">tokenizer_class</span> <span class="o">=</span> <span class="n">Tokenizer</span> +</span><span id="L-253"><a href="#L-253"><span class="linenos"> 253</span></a> <span class="n">parser_class</span> <span class="o">=</span> <span class="n">Parser</span> +</span><span id="L-254"><a href="#L-254"><span class="linenos"> 254</span></a> <span class="n">generator_class</span> <span class="o">=</span> <span class="n">Generator</span> +</span><span id="L-255"><a href="#L-255"><span class="linenos"> 255</span></a> +</span><span id="L-256"><a href="#L-256"><span class="linenos"> 256</span></a> <span class="c1"># A trie of the time_mapping keys</span> +</span><span id="L-257"><a href="#L-257"><span class="linenos"> 257</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-258"><a href="#L-258"><span class="linenos"> 258</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-259"><a href="#L-259"><span class="linenos"> 259</span></a> +</span><span id="L-260"><a href="#L-260"><span class="linenos"> 260</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-261"><a href="#L-261"><span class="linenos"> 261</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-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="c1"># Delimiters for string literals and identifiers</span> -</span><span id="L-264"><a href="#L-264"><span class="linenos"> 264</span></a> <span class="n">QUOTE_START</span> <span class="o">=</span> <span class="s2">"'"</span> -</span><span id="L-265"><a href="#L-265"><span class="linenos"> 265</span></a> <span class="n">QUOTE_END</span> <span class="o">=</span> <span class="s2">"'"</span> -</span><span id="L-266"><a href="#L-266"><span class="linenos"> 266</span></a> <span class="n">IDENTIFIER_START</span> <span class="o">=</span> <span class="s1">'"'</span> -</span><span id="L-267"><a href="#L-267"><span class="linenos"> 267</span></a> <span class="n">IDENTIFIER_END</span> <span class="o">=</span> <span class="s1">'"'</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="c1"># Delimiters for bit, hex, byte and unicode literals</span> -</span><span id="L-270"><a href="#L-270"><span class="linenos"> 270</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-271"><a href="#L-271"><span class="linenos"> 271</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-272"><a href="#L-272"><span class="linenos"> 272</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-273"><a href="#L-273"><span class="linenos"> 273</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-274"><a href="#L-274"><span class="linenos"> 274</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-275"><a href="#L-275"><span class="linenos"> 275</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-276"><a href="#L-276"><span class="linenos"> 276</span></a> <span class="n">UNICODE_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-277"><a href="#L-277"><span class="linenos"> 277</span></a> <span class="n">UNICODE_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-278"><a href="#L-278"><span class="linenos"> 278</span></a> -</span><span id="L-279"><a href="#L-279"><span class="linenos"> 279</span></a> <span class="nd">@classmethod</span> -</span><span id="L-280"><a href="#L-280"><span class="linenos"> 280</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-281"><a href="#L-281"><span class="linenos"> 281</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-282"><a href="#L-282"><span class="linenos"> 282</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-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="sd"> Args:</span> -</span><span id="L-285"><a href="#L-285"><span class="linenos"> 285</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-286"><a href="#L-286"><span class="linenos"> 286</span></a><span class="sd"> additional key-value pairs that are separated by commas and are used to specify</span> -</span><span id="L-287"><a href="#L-287"><span class="linenos"> 287</span></a><span class="sd"> dialect settings, such as whether the dialect's identifiers are case-sensitive.</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="sd"> Example:</span> -</span><span id="L-290"><a href="#L-290"><span class="linenos"> 290</span></a><span class="sd"> >>> dialect = dialect_class = get_or_raise("duckdb")</span> -</span><span id="L-291"><a href="#L-291"><span class="linenos"> 291</span></a><span class="sd"> >>> dialect = get_or_raise("mysql, normalization_strategy = case_sensitive")</span> -</span><span id="L-292"><a href="#L-292"><span class="linenos"> 292</span></a> -</span><span id="L-293"><a href="#L-293"><span class="linenos"> 293</span></a><span class="sd"> Returns:</span> -</span><span id="L-294"><a href="#L-294"><span class="linenos"> 294</span></a><span class="sd"> The corresponding Dialect instance.</span> -</span><span id="L-295"><a href="#L-295"><span class="linenos"> 295</span></a><span class="sd"> """</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">if</span> <span class="ow">not</span> <span class="n">dialect</span><span class="p">:</span> -</span><span id="L-298"><a href="#L-298"><span class="linenos"> 298</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span> -</span><span id="L-299"><a href="#L-299"><span class="linenos"> 299</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-300"><a href="#L-300"><span class="linenos"> 300</span></a> <span class="k">return</span> <span class="n">dialect</span><span class="p">()</span> -</span><span id="L-301"><a href="#L-301"><span class="linenos"> 301</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-302"><a href="#L-302"><span class="linenos"> 302</span></a> <span class="k">return</span> <span class="n">dialect</span> -</span><span id="L-303"><a href="#L-303"><span class="linenos"> 303</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-304"><a href="#L-304"><span class="linenos"> 304</span></a> <span class="k">try</span><span class="p">:</span> -</span><span id="L-305"><a href="#L-305"><span class="linenos"> 305</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-306"><a href="#L-306"><span class="linenos"> 306</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-307"><a href="#L-307"><span class="linenos"> 307</span></a> <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> -</span><span id="L-308"><a href="#L-308"><span class="linenos"> 308</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> -</span><span id="L-309"><a href="#L-309"><span class="linenos"> 309</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-310"><a href="#L-310"><span class="linenos"> 310</span></a> <span class="s2">"Please use the correct format: 'dialect [, k1 = v2 [, ...]]'."</span> -</span><span id="L-311"><a href="#L-311"><span class="linenos"> 311</span></a> <span class="p">)</span> -</span><span id="L-312"><a href="#L-312"><span class="linenos"> 312</span></a> -</span><span id="L-313"><a href="#L-313"><span class="linenos"> 313</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-314"><a href="#L-314"><span class="linenos"> 314</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-315"><a href="#L-315"><span class="linenos"> 315</span></a> <span class="kn">from</span> <span class="nn">difflib</span> <span class="kn">import</span> <span class="n">get_close_matches</span> -</span><span id="L-316"><a href="#L-316"><span class="linenos"> 316</span></a> -</span><span id="L-317"><a href="#L-317"><span class="linenos"> 317</span></a> <span class="n">similar</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">get_close_matches</span><span class="p">(</span><span class="n">dialect_name</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">classes</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">""</span> -</span><span id="L-318"><a href="#L-318"><span class="linenos"> 318</span></a> <span class="k">if</span> <span class="n">similar</span><span class="p">:</span> -</span><span id="L-319"><a href="#L-319"><span class="linenos"> 319</span></a> <span class="n">similar</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" Did you mean </span><span class="si">{</span><span class="n">similar</span><span class="si">}</span><span class="s2">?"</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="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="si">{</span><span class="n">similar</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="L-263"><a href="#L-263"><span class="linenos"> 263</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-264"><a href="#L-264"><span class="linenos"> 264</span></a> +</span><span id="L-265"><a href="#L-265"><span class="linenos"> 265</span></a> <span class="c1"># Delimiters for string literals and identifiers</span> +</span><span id="L-266"><a href="#L-266"><span class="linenos"> 266</span></a> <span class="n">QUOTE_START</span> <span class="o">=</span> <span class="s2">"'"</span> +</span><span id="L-267"><a href="#L-267"><span class="linenos"> 267</span></a> <span class="n">QUOTE_END</span> <span class="o">=</span> <span class="s2">"'"</span> +</span><span id="L-268"><a href="#L-268"><span class="linenos"> 268</span></a> <span class="n">IDENTIFIER_START</span> <span class="o">=</span> <span class="s1">'"'</span> +</span><span id="L-269"><a href="#L-269"><span class="linenos"> 269</span></a> <span class="n">IDENTIFIER_END</span> <span class="o">=</span> <span class="s1">'"'</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="c1"># Delimiters for bit, hex, byte and unicode literals</span> +</span><span id="L-272"><a href="#L-272"><span class="linenos"> 272</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-273"><a href="#L-273"><span class="linenos"> 273</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-274"><a href="#L-274"><span class="linenos"> 274</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-275"><a href="#L-275"><span class="linenos"> 275</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-276"><a href="#L-276"><span class="linenos"> 276</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-277"><a href="#L-277"><span class="linenos"> 277</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-278"><a href="#L-278"><span class="linenos"> 278</span></a> <span class="n">UNICODE_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-279"><a href="#L-279"><span class="linenos"> 279</span></a> <span class="n">UNICODE_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-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="nd">@classmethod</span> +</span><span id="L-282"><a href="#L-282"><span class="linenos"> 282</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-283"><a href="#L-283"><span class="linenos"> 283</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-284"><a href="#L-284"><span class="linenos"> 284</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-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="sd"> Args:</span> +</span><span id="L-287"><a href="#L-287"><span class="linenos"> 287</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-288"><a href="#L-288"><span class="linenos"> 288</span></a><span class="sd"> additional key-value pairs that are separated by commas and are used to specify</span> +</span><span id="L-289"><a href="#L-289"><span class="linenos"> 289</span></a><span class="sd"> dialect settings, such as whether the dialect's identifiers are case-sensitive.</span> +</span><span id="L-290"><a href="#L-290"><span class="linenos"> 290</span></a> +</span><span id="L-291"><a href="#L-291"><span class="linenos"> 291</span></a><span class="sd"> Example:</span> +</span><span id="L-292"><a href="#L-292"><span class="linenos"> 292</span></a><span class="sd"> >>> dialect = dialect_class = get_or_raise("duckdb")</span> +</span><span id="L-293"><a href="#L-293"><span class="linenos"> 293</span></a><span class="sd"> >>> dialect = get_or_raise("mysql, normalization_strategy = case_sensitive")</span> +</span><span id="L-294"><a href="#L-294"><span class="linenos"> 294</span></a> +</span><span id="L-295"><a href="#L-295"><span class="linenos"> 295</span></a><span class="sd"> Returns:</span> +</span><span id="L-296"><a href="#L-296"><span class="linenos"> 296</span></a><span class="sd"> The corresponding Dialect instance.</span> +</span><span id="L-297"><a href="#L-297"><span class="linenos"> 297</span></a><span class="sd"> """</span> +</span><span id="L-298"><a href="#L-298"><span class="linenos"> 298</span></a> +</span><span id="L-299"><a href="#L-299"><span class="linenos"> 299</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-300"><a href="#L-300"><span class="linenos"> 300</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span> +</span><span id="L-301"><a href="#L-301"><span class="linenos"> 301</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-302"><a href="#L-302"><span class="linenos"> 302</span></a> <span class="k">return</span> <span class="n">dialect</span><span class="p">()</span> +</span><span id="L-303"><a href="#L-303"><span class="linenos"> 303</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-304"><a href="#L-304"><span class="linenos"> 304</span></a> <span class="k">return</span> <span class="n">dialect</span> +</span><span id="L-305"><a href="#L-305"><span class="linenos"> 305</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-306"><a href="#L-306"><span class="linenos"> 306</span></a> <span class="k">try</span><span class="p">:</span> +</span><span id="L-307"><a href="#L-307"><span class="linenos"> 307</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-308"><a href="#L-308"><span class="linenos"> 308</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-309"><a href="#L-309"><span class="linenos"> 309</span></a> <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> +</span><span id="L-310"><a href="#L-310"><span class="linenos"> 310</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> +</span><span id="L-311"><a href="#L-311"><span class="linenos"> 311</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-312"><a href="#L-312"><span class="linenos"> 312</span></a> <span class="s2">"Please use the correct format: 'dialect [, k1 = v2 [, ...]]'."</span> +</span><span id="L-313"><a href="#L-313"><span class="linenos"> 313</span></a> <span class="p">)</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="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-316"><a href="#L-316"><span class="linenos"> 316</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-317"><a href="#L-317"><span class="linenos"> 317</span></a> <span class="kn">from</span> <span class="nn">difflib</span> <span class="kn">import</span> <span class="n">get_close_matches</span> +</span><span id="L-318"><a href="#L-318"><span class="linenos"> 318</span></a> +</span><span id="L-319"><a href="#L-319"><span class="linenos"> 319</span></a> <span class="n">similar</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">get_close_matches</span><span class="p">(</span><span class="n">dialect_name</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">classes</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">""</span> +</span><span id="L-320"><a href="#L-320"><span class="linenos"> 320</span></a> <span class="k">if</span> <span class="n">similar</span><span class="p">:</span> +</span><span id="L-321"><a href="#L-321"><span class="linenos"> 321</span></a> <span class="n">similar</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" Did you mean </span><span class="si">{</span><span class="n">similar</span><span class="si">}</span><span class="s2">?"</span> </span><span id="L-322"><a href="#L-322"><span class="linenos"> 322</span></a> -</span><span id="L-323"><a href="#L-323"><span class="linenos"> 323</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-323"><a href="#L-323"><span class="linenos"> 323</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="si">{</span><span class="n">similar</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> </span><span id="L-324"><a href="#L-324"><span class="linenos"> 324</span></a> -</span><span id="L-325"><a href="#L-325"><span class="linenos"> 325</span></a> <span class="k">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-325"><a href="#L-325"><span class="linenos"> 325</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-326"><a href="#L-326"><span class="linenos"> 326</span></a> -</span><span id="L-327"><a href="#L-327"><span class="linenos"> 327</span></a> <span class="nd">@classmethod</span> -</span><span id="L-328"><a href="#L-328"><span class="linenos"> 328</span></a> <span class="k">def</span> <span class="nf">format_time</span><span class="p">(</span> -</span><span id="L-329"><a href="#L-329"><span class="linenos"> 329</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-330"><a href="#L-330"><span class="linenos"> 330</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-331"><a href="#L-331"><span class="linenos"> 331</span></a><span class="w"> </span><span class="sd">"""Converts a time format in this dialect to its equivalent Python `strftime` format."""</span> -</span><span id="L-332"><a href="#L-332"><span class="linenos"> 332</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-333"><a href="#L-333"><span class="linenos"> 333</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-334"><a href="#L-334"><span class="linenos"> 334</span></a> <span class="c1"># the time formats are quoted</span> -</span><span id="L-335"><a href="#L-335"><span class="linenos"> 335</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-336"><a href="#L-336"><span class="linenos"> 336</span></a> <span class="p">)</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">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-339"><a href="#L-339"><span class="linenos"> 339</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-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">return</span> <span class="n">expression</span> +</span><span id="L-327"><a href="#L-327"><span class="linenos"> 327</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-328"><a href="#L-328"><span class="linenos"> 328</span></a> +</span><span id="L-329"><a href="#L-329"><span class="linenos"> 329</span></a> <span class="nd">@classmethod</span> +</span><span id="L-330"><a href="#L-330"><span class="linenos"> 330</span></a> <span class="k">def</span> <span class="nf">format_time</span><span class="p">(</span> +</span><span id="L-331"><a href="#L-331"><span class="linenos"> 331</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-332"><a href="#L-332"><span class="linenos"> 332</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-333"><a href="#L-333"><span class="linenos"> 333</span></a><span class="w"> </span><span class="sd">"""Converts a time format in this dialect to its equivalent Python `strftime` format."""</span> +</span><span id="L-334"><a href="#L-334"><span class="linenos"> 334</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-335"><a href="#L-335"><span class="linenos"> 335</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-336"><a href="#L-336"><span class="linenos"> 336</span></a> <span class="c1"># the time formats are quoted</span> +</span><span id="L-337"><a href="#L-337"><span class="linenos"> 337</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-338"><a href="#L-338"><span class="linenos"> 338</span></a> <span class="p">)</span> +</span><span id="L-339"><a href="#L-339"><span class="linenos"> 339</span></a> +</span><span id="L-340"><a href="#L-340"><span class="linenos"> 340</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-341"><a href="#L-341"><span class="linenos"> 341</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-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="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-344"><a href="#L-344"><span class="linenos"> 344</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-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="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-347"><a href="#L-347"><span class="linenos"> 347</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-348"><a href="#L-348"><span class="linenos"> 348</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="L-349"><a href="#L-349"><span class="linenos"> 349</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-350"><a href="#L-350"><span class="linenos"> 350</span></a> -</span><span id="L-351"><a href="#L-351"><span class="linenos"> 351</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-352"><a href="#L-352"><span class="linenos"> 352</span></a> <span class="c1"># Does not currently take dialect state into account</span> -</span><span id="L-353"><a href="#L-353"><span class="linenos"> 353</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-354"><a href="#L-354"><span class="linenos"> 354</span></a> -</span><span id="L-355"><a href="#L-355"><span class="linenos"> 355</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-356"><a href="#L-356"><span class="linenos"> 356</span></a> <span class="c1"># Does not currently take dialect state into account</span> -</span><span id="L-357"><a href="#L-357"><span class="linenos"> 357</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-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="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-360"><a href="#L-360"><span class="linenos"> 360</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-361"><a href="#L-361"><span class="linenos"> 361</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-362"><a href="#L-362"><span class="linenos"> 362</span></a> -</span><span id="L-363"><a href="#L-363"><span class="linenos"> 363</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-364"><a href="#L-364"><span class="linenos"> 364</span></a><span class="sd"> lowercases all unquoted identifiers. On the other hand, Snowflake uppercases them, so</span> -</span><span id="L-365"><a href="#L-365"><span class="linenos"> 365</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-366"><a href="#L-366"><span class="linenos"> 366</span></a><span class="sd"> and so any normalization would be prohibited in order to avoid "breaking" the identifier.</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="sd"> There are also dialects like Spark, which are case-insensitive even when quotes are</span> -</span><span id="L-369"><a href="#L-369"><span class="linenos"> 369</span></a><span class="sd"> present, and dialects like MySQL, whose resolution rules match those employed by the</span> -</span><span id="L-370"><a href="#L-370"><span class="linenos"> 370</span></a><span class="sd"> underlying operating system, for example they may always be case-sensitive in Linux.</span> -</span><span id="L-371"><a href="#L-371"><span class="linenos"> 371</span></a> -</span><span id="L-372"><a href="#L-372"><span class="linenos"> 372</span></a><span class="sd"> Finally, the normalization behavior of some engines can even be controlled through flags,</span> -</span><span id="L-373"><a href="#L-373"><span class="linenos"> 373</span></a><span class="sd"> like in Redshift's case, where users can explicitly set enable_case_sensitive_identifier.</span> -</span><span id="L-374"><a href="#L-374"><span class="linenos"> 374</span></a> -</span><span id="L-375"><a href="#L-375"><span class="linenos"> 375</span></a><span class="sd"> SQLGlot aims to understand and handle all of these different behaviors gracefully, so</span> -</span><span id="L-376"><a href="#L-376"><span class="linenos"> 376</span></a><span class="sd"> that it can analyze queries in the optimizer and successfully capture their semantics.</span> -</span><span id="L-377"><a href="#L-377"><span class="linenos"> 377</span></a><span class="sd"> """</span> -</span><span id="L-378"><a href="#L-378"><span class="linenos"> 378</span></a> <span class="k">if</span> <span class="p">(</span> -</span><span id="L-379"><a href="#L-379"><span class="linenos"> 379</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-380"><a href="#L-380"><span class="linenos"> 380</span></a> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_SENSITIVE</span> -</span><span id="L-381"><a href="#L-381"><span class="linenos"> 381</span></a> <span class="ow">and</span> <span class="p">(</span> -</span><span id="L-382"><a href="#L-382"><span class="linenos"> 382</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-383"><a href="#L-383"><span class="linenos"> 383</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-384"><a href="#L-384"><span class="linenos"> 384</span></a> <span class="p">)</span> -</span><span id="L-385"><a href="#L-385"><span class="linenos"> 385</span></a> <span class="p">):</span> -</span><span id="L-386"><a href="#L-386"><span class="linenos"> 386</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> -</span><span id="L-387"><a href="#L-387"><span class="linenos"> 387</span></a> <span class="s2">"this"</span><span class="p">,</span> -</span><span id="L-388"><a href="#L-388"><span class="linenos"> 388</span></a> <span class="p">(</span> -</span><span id="L-389"><a href="#L-389"><span class="linenos"> 389</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-390"><a href="#L-390"><span class="linenos"> 390</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-391"><a href="#L-391"><span class="linenos"> 391</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-392"><a href="#L-392"><span class="linenos"> 392</span></a> <span class="p">),</span> -</span><span id="L-393"><a href="#L-393"><span class="linenos"> 393</span></a> <span class="p">)</span> -</span><span id="L-394"><a href="#L-394"><span class="linenos"> 394</span></a> -</span><span id="L-395"><a href="#L-395"><span class="linenos"> 395</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="L-343"><a href="#L-343"><span class="linenos"> 343</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="L-344"><a href="#L-344"><span class="linenos"> 344</span></a> +</span><span id="L-345"><a href="#L-345"><span class="linenos"> 345</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-346"><a href="#L-346"><span class="linenos"> 346</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-347"><a href="#L-347"><span class="linenos"> 347</span></a> +</span><span id="L-348"><a href="#L-348"><span class="linenos"> 348</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-349"><a href="#L-349"><span class="linenos"> 349</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-350"><a href="#L-350"><span class="linenos"> 350</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="L-351"><a href="#L-351"><span class="linenos"> 351</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-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="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-354"><a href="#L-354"><span class="linenos"> 354</span></a> <span class="c1"># Does not currently take dialect state into account</span> +</span><span id="L-355"><a href="#L-355"><span class="linenos"> 355</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-356"><a href="#L-356"><span class="linenos"> 356</span></a> +</span><span id="L-357"><a href="#L-357"><span class="linenos"> 357</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-358"><a href="#L-358"><span class="linenos"> 358</span></a> <span class="c1"># Does not currently take dialect state into account</span> +</span><span id="L-359"><a href="#L-359"><span class="linenos"> 359</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-360"><a href="#L-360"><span class="linenos"> 360</span></a> +</span><span id="L-361"><a href="#L-361"><span class="linenos"> 361</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-362"><a href="#L-362"><span class="linenos"> 362</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-363"><a href="#L-363"><span class="linenos"> 363</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-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="sd"> For example, an identifier like `FoO` would be resolved as `foo` in Postgres, because it</span> +</span><span id="L-366"><a href="#L-366"><span class="linenos"> 366</span></a><span class="sd"> lowercases all unquoted identifiers. On the other hand, Snowflake uppercases them, so</span> +</span><span id="L-367"><a href="#L-367"><span class="linenos"> 367</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-368"><a href="#L-368"><span class="linenos"> 368</span></a><span class="sd"> and so any normalization would be prohibited in order to avoid "breaking" the identifier.</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="sd"> There are also dialects like Spark, which are case-insensitive even when quotes are</span> +</span><span id="L-371"><a href="#L-371"><span class="linenos"> 371</span></a><span class="sd"> present, and dialects like MySQL, whose resolution rules match those employed by the</span> +</span><span id="L-372"><a href="#L-372"><span class="linenos"> 372</span></a><span class="sd"> underlying operating system, for example they may always be case-sensitive in Linux.</span> +</span><span id="L-373"><a href="#L-373"><span class="linenos"> 373</span></a> +</span><span id="L-374"><a href="#L-374"><span class="linenos"> 374</span></a><span class="sd"> Finally, the normalization behavior of some engines can even be controlled through flags,</span> +</span><span id="L-375"><a href="#L-375"><span class="linenos"> 375</span></a><span class="sd"> like in Redshift's case, where users can explicitly set enable_case_sensitive_identifier.</span> +</span><span id="L-376"><a href="#L-376"><span class="linenos"> 376</span></a> +</span><span id="L-377"><a href="#L-377"><span class="linenos"> 377</span></a><span class="sd"> SQLGlot aims to understand and handle all of these different behaviors gracefully, so</span> +</span><span id="L-378"><a href="#L-378"><span class="linenos"> 378</span></a><span class="sd"> that it can analyze queries in the optimizer and successfully capture their semantics.</span> +</span><span id="L-379"><a href="#L-379"><span class="linenos"> 379</span></a><span class="sd"> """</span> +</span><span id="L-380"><a href="#L-380"><span class="linenos"> 380</span></a> <span class="k">if</span> <span class="p">(</span> +</span><span id="L-381"><a href="#L-381"><span class="linenos"> 381</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-382"><a href="#L-382"><span class="linenos"> 382</span></a> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_SENSITIVE</span> +</span><span id="L-383"><a href="#L-383"><span class="linenos"> 383</span></a> <span class="ow">and</span> <span class="p">(</span> +</span><span id="L-384"><a href="#L-384"><span class="linenos"> 384</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-385"><a href="#L-385"><span class="linenos"> 385</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-386"><a href="#L-386"><span class="linenos"> 386</span></a> <span class="p">)</span> +</span><span id="L-387"><a href="#L-387"><span class="linenos"> 387</span></a> <span class="p">):</span> +</span><span id="L-388"><a href="#L-388"><span class="linenos"> 388</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="L-389"><a href="#L-389"><span class="linenos"> 389</span></a> <span class="s2">"this"</span><span class="p">,</span> +</span><span id="L-390"><a href="#L-390"><span class="linenos"> 390</span></a> <span class="p">(</span> +</span><span id="L-391"><a href="#L-391"><span class="linenos"> 391</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-392"><a href="#L-392"><span class="linenos"> 392</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-393"><a href="#L-393"><span class="linenos"> 393</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-394"><a href="#L-394"><span class="linenos"> 394</span></a> <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">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-398"><a href="#L-398"><span class="linenos"> 398</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-399"><a href="#L-399"><span class="linenos"> 399</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-400"><a href="#L-400"><span class="linenos"> 400</span></a> <span class="k">return</span> <span class="kc">False</span> -</span><span id="L-401"><a href="#L-401"><span class="linenos"> 401</span></a> -</span><span id="L-402"><a href="#L-402"><span class="linenos"> 402</span></a> <span class="n">unsafe</span> <span class="o">=</span> <span class="p">(</span> -</span><span id="L-403"><a href="#L-403"><span class="linenos"> 403</span></a> <span class="nb">str</span><span class="o">.</span><span class="n">islower</span> -</span><span id="L-404"><a href="#L-404"><span class="linenos"> 404</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-405"><a href="#L-405"><span class="linenos"> 405</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-406"><a href="#L-406"><span class="linenos"> 406</span></a> <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="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-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">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-410"><a href="#L-410"><span class="linenos"> 410</span></a><span class="w"> </span><span class="sd">"""Checks if text can be identified given an identify option.</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 class="sd"> Args:</span> -</span><span id="L-413"><a href="#L-413"><span class="linenos"> 413</span></a><span class="sd"> text: The text to check.</span> -</span><span id="L-414"><a href="#L-414"><span class="linenos"> 414</span></a><span class="sd"> identify:</span> -</span><span id="L-415"><a href="#L-415"><span class="linenos"> 415</span></a><span class="sd"> `"always"` or `True`: Always returns `True`.</span> -</span><span id="L-416"><a href="#L-416"><span class="linenos"> 416</span></a><span class="sd"> `"safe"`: Only returns `True` if the identifier is case-insensitive.</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 class="sd"> Returns:</span> -</span><span id="L-419"><a href="#L-419"><span class="linenos"> 419</span></a><span class="sd"> Whether or not the given text can be identified.</span> -</span><span id="L-420"><a href="#L-420"><span class="linenos"> 420</span></a><span class="sd"> """</span> -</span><span id="L-421"><a href="#L-421"><span class="linenos"> 421</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-422"><a href="#L-422"><span class="linenos"> 422</span></a> <span class="k">return</span> <span class="kc">True</span> -</span><span id="L-423"><a href="#L-423"><span class="linenos"> 423</span></a> -</span><span id="L-424"><a href="#L-424"><span class="linenos"> 424</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-425"><a href="#L-425"><span class="linenos"> 425</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-426"><a href="#L-426"><span class="linenos"> 426</span></a> -</span><span id="L-427"><a href="#L-427"><span class="linenos"> 427</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="L-397"><a href="#L-397"><span class="linenos"> 397</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="L-398"><a href="#L-398"><span class="linenos"> 398</span></a> +</span><span id="L-399"><a href="#L-399"><span class="linenos"> 399</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-400"><a href="#L-400"><span class="linenos"> 400</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-401"><a href="#L-401"><span class="linenos"> 401</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-402"><a href="#L-402"><span class="linenos"> 402</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="L-403"><a href="#L-403"><span class="linenos"> 403</span></a> +</span><span id="L-404"><a href="#L-404"><span class="linenos"> 404</span></a> <span class="n">unsafe</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="L-405"><a href="#L-405"><span class="linenos"> 405</span></a> <span class="nb">str</span><span class="o">.</span><span class="n">islower</span> +</span><span id="L-406"><a href="#L-406"><span class="linenos"> 406</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-407"><a href="#L-407"><span class="linenos"> 407</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-408"><a href="#L-408"><span class="linenos"> 408</span></a> <span class="p">)</span> +</span><span id="L-409"><a href="#L-409"><span class="linenos"> 409</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-410"><a href="#L-410"><span class="linenos"> 410</span></a> +</span><span id="L-411"><a href="#L-411"><span class="linenos"> 411</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-412"><a href="#L-412"><span class="linenos"> 412</span></a><span class="w"> </span><span class="sd">"""Checks if text can be identified given an identify option.</span> +</span><span id="L-413"><a href="#L-413"><span class="linenos"> 413</span></a> +</span><span id="L-414"><a href="#L-414"><span class="linenos"> 414</span></a><span class="sd"> Args:</span> +</span><span id="L-415"><a href="#L-415"><span class="linenos"> 415</span></a><span class="sd"> text: The text to check.</span> +</span><span id="L-416"><a href="#L-416"><span class="linenos"> 416</span></a><span class="sd"> identify:</span> +</span><span id="L-417"><a href="#L-417"><span class="linenos"> 417</span></a><span class="sd"> `"always"` or `True`: Always returns `True`.</span> +</span><span id="L-418"><a href="#L-418"><span class="linenos"> 418</span></a><span class="sd"> `"safe"`: Only returns `True` if the identifier is case-insensitive.</span> +</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="sd"> Returns:</span> +</span><span id="L-421"><a href="#L-421"><span class="linenos"> 421</span></a><span class="sd"> Whether or not the given text can be identified.</span> +</span><span id="L-422"><a href="#L-422"><span class="linenos"> 422</span></a><span class="sd"> """</span> +</span><span id="L-423"><a href="#L-423"><span class="linenos"> 423</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-424"><a href="#L-424"><span class="linenos"> 424</span></a> <span class="k">return</span> <span class="kc">True</span> +</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">if</span> <span class="n">identify</span> <span class="o">==</span> <span class="s2">"safe"</span><span class="p">:</span> +</span><span id="L-427"><a href="#L-427"><span class="linenos"> 427</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-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">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-430"><a href="#L-430"><span class="linenos"> 430</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-431"><a href="#L-431"><span class="linenos"> 431</span></a><span class="sd"> Adds quotes to a given identifier.</span> -</span><span id="L-432"><a href="#L-432"><span class="linenos"> 432</span></a> -</span><span id="L-433"><a href="#L-433"><span class="linenos"> 433</span></a><span class="sd"> Args:</span> -</span><span id="L-434"><a href="#L-434"><span class="linenos"> 434</span></a><span class="sd"> expression: The expression of interest. If it's not an `Identifier`, this method is a no-op.</span> -</span><span id="L-435"><a href="#L-435"><span class="linenos"> 435</span></a><span class="sd"> identify: If set to `False`, the quotes will only be added if the identifier is deemed</span> -</span><span id="L-436"><a href="#L-436"><span class="linenos"> 436</span></a><span class="sd"> "unsafe", with respect to its characters and this dialect's normalization strategy.</span> -</span><span id="L-437"><a href="#L-437"><span class="linenos"> 437</span></a><span class="sd"> """</span> -</span><span id="L-438"><a href="#L-438"><span class="linenos"> 438</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-439"><a href="#L-439"><span class="linenos"> 439</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-440"><a href="#L-440"><span class="linenos"> 440</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> -</span><span id="L-441"><a href="#L-441"><span class="linenos"> 441</span></a> <span class="s2">"quoted"</span><span class="p">,</span> -</span><span id="L-442"><a href="#L-442"><span class="linenos"> 442</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-443"><a href="#L-443"><span class="linenos"> 443</span></a> <span class="p">)</span> -</span><span id="L-444"><a href="#L-444"><span class="linenos"> 444</span></a> -</span><span id="L-445"><a href="#L-445"><span class="linenos"> 445</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="L-429"><a href="#L-429"><span class="linenos"> 429</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="L-430"><a href="#L-430"><span class="linenos"> 430</span></a> +</span><span id="L-431"><a href="#L-431"><span class="linenos"> 431</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-432"><a href="#L-432"><span class="linenos"> 432</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-433"><a href="#L-433"><span class="linenos"> 433</span></a><span class="sd"> Adds quotes to a given identifier.</span> +</span><span id="L-434"><a href="#L-434"><span class="linenos"> 434</span></a> +</span><span id="L-435"><a href="#L-435"><span class="linenos"> 435</span></a><span class="sd"> Args:</span> +</span><span id="L-436"><a href="#L-436"><span class="linenos"> 436</span></a><span class="sd"> expression: The expression of interest. If it's not an `Identifier`, this method is a no-op.</span> +</span><span id="L-437"><a href="#L-437"><span class="linenos"> 437</span></a><span class="sd"> identify: If set to `False`, the quotes will only be added if the identifier is deemed</span> +</span><span id="L-438"><a href="#L-438"><span class="linenos"> 438</span></a><span class="sd"> "unsafe", with respect to its characters and this dialect's normalization strategy.</span> +</span><span id="L-439"><a href="#L-439"><span class="linenos"> 439</span></a><span class="sd"> """</span> +</span><span id="L-440"><a href="#L-440"><span class="linenos"> 440</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-441"><a href="#L-441"><span class="linenos"> 441</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-442"><a href="#L-442"><span class="linenos"> 442</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="L-443"><a href="#L-443"><span class="linenos"> 443</span></a> <span class="s2">"quoted"</span><span class="p">,</span> +</span><span id="L-444"><a href="#L-444"><span class="linenos"> 444</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-445"><a href="#L-445"><span class="linenos"> 445</span></a> <span class="p">)</span> </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">to_json_path</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</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 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-448"><a href="#L-448"><span class="linenos"> 448</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="p">):</span> -</span><span id="L-449"><a href="#L-449"><span class="linenos"> 449</span></a> <span class="n">path_text</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">name</span> -</span><span id="L-450"><a href="#L-450"><span class="linenos"> 450</span></a> <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">is_number</span><span class="p">:</span> -</span><span id="L-451"><a href="#L-451"><span class="linenos"> 451</span></a> <span class="n">path_text</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"[</span><span class="si">{</span><span class="n">path_text</span><span class="si">}</span><span class="s2">]"</span> -</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 class="k">try</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="n">parse_json_path</span><span class="p">(</span><span class="n">path_text</span><span class="p">)</span> -</span><span id="L-455"><a href="#L-455"><span class="linenos"> 455</span></a> <span class="k">except</span> <span class="n">ParseError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> -</span><span id="L-456"><a href="#L-456"><span class="linenos"> 456</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid JSON path syntax. </span><span class="si">{</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="L-457"><a href="#L-457"><span class="linenos"> 457</span></a> -</span><span id="L-458"><a href="#L-458"><span class="linenos"> 458</span></a> <span class="k">return</span> <span class="n">path</span> +</span><span id="L-447"><a href="#L-447"><span class="linenos"> 447</span></a> <span class="k">return</span> <span class="n">expression</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 class="k">def</span> <span class="nf">to_json_path</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</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 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-450"><a href="#L-450"><span class="linenos"> 450</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="p">):</span> +</span><span id="L-451"><a href="#L-451"><span class="linenos"> 451</span></a> <span class="n">path_text</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">name</span> +</span><span id="L-452"><a href="#L-452"><span class="linenos"> 452</span></a> <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">is_number</span><span class="p">:</span> +</span><span id="L-453"><a href="#L-453"><span class="linenos"> 453</span></a> <span class="n">path_text</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"[</span><span class="si">{</span><span class="n">path_text</span><span class="si">}</span><span class="s2">]"</span> +</span><span id="L-454"><a href="#L-454"><span class="linenos"> 454</span></a> +</span><span id="L-455"><a href="#L-455"><span class="linenos"> 455</span></a> <span class="k">try</span><span class="p">:</span> +</span><span id="L-456"><a href="#L-456"><span class="linenos"> 456</span></a> <span class="k">return</span> <span class="n">parse_json_path</span><span class="p">(</span><span class="n">path_text</span><span class="p">)</span> +</span><span id="L-457"><a href="#L-457"><span class="linenos"> 457</span></a> <span class="k">except</span> <span class="n">ParseError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> +</span><span id="L-458"><a href="#L-458"><span class="linenos"> 458</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid JSON path syntax. </span><span class="si">{</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> </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">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-461"><a href="#L-461"><span class="linenos"> 461</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-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">parse_into</span><span class="p">(</span> -</span><span id="L-464"><a href="#L-464"><span class="linenos"> 464</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-465"><a href="#L-465"><span class="linenos"> 465</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-466"><a href="#L-466"><span class="linenos"> 466</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-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">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-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">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-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 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-472"><a href="#L-472"><span class="linenos"> 472</span></a> <span class="k">return</span> <span class="p">[</span> -</span><span id="L-473"><a href="#L-473"><span class="linenos"> 473</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-474"><a href="#L-474"><span class="linenos"> 474</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-475"><a href="#L-475"><span class="linenos"> 475</span></a> <span class="p">]</span> -</span><span id="L-476"><a href="#L-476"><span class="linenos"> 476</span></a> -</span><span id="L-477"><a href="#L-477"><span class="linenos"> 477</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-478"><a href="#L-478"><span class="linenos"> 478</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-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 class="nd">@property</span> -</span><span id="L-481"><a href="#L-481"><span class="linenos"> 481</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-482"><a href="#L-482"><span class="linenos"> 482</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-483"><a href="#L-483"><span class="linenos"> 483</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-484"><a href="#L-484"><span class="linenos"> 484</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-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">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-487"><a href="#L-487"><span class="linenos"> 487</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-488"><a href="#L-488"><span class="linenos"> 488</span></a> -</span><span id="L-489"><a href="#L-489"><span class="linenos"> 489</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-490"><a href="#L-490"><span class="linenos"> 490</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-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><span id="L-493"><a href="#L-493"><span class="linenos"> 493</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-460"><a href="#L-460"><span class="linenos"> 460</span></a> <span class="k">return</span> <span class="n">path</span> +</span><span id="L-461"><a href="#L-461"><span class="linenos"> 461</span></a> +</span><span id="L-462"><a href="#L-462"><span class="linenos"> 462</span></a> <span class="k">def</span> <span class="nf">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-463"><a href="#L-463"><span class="linenos"> 463</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-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">parse_into</span><span class="p">(</span> +</span><span id="L-466"><a href="#L-466"><span class="linenos"> 466</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-467"><a href="#L-467"><span class="linenos"> 467</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-468"><a href="#L-468"><span class="linenos"> 468</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-469"><a href="#L-469"><span class="linenos"> 469</span></a> +</span><span id="L-470"><a href="#L-470"><span class="linenos"> 470</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-471"><a href="#L-471"><span class="linenos"> 471</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-472"><a href="#L-472"><span class="linenos"> 472</span></a> +</span><span id="L-473"><a href="#L-473"><span class="linenos"> 473</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-474"><a href="#L-474"><span class="linenos"> 474</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="L-475"><a href="#L-475"><span class="linenos"> 475</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-476"><a href="#L-476"><span class="linenos"> 476</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-477"><a href="#L-477"><span class="linenos"> 477</span></a> <span class="p">]</span> +</span><span id="L-478"><a href="#L-478"><span class="linenos"> 478</span></a> +</span><span id="L-479"><a href="#L-479"><span class="linenos"> 479</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-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">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-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 class="nd">@property</span> +</span><span id="L-483"><a href="#L-483"><span class="linenos"> 483</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-484"><a href="#L-484"><span class="linenos"> 484</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-485"><a href="#L-485"><span class="linenos"> 485</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-486"><a href="#L-486"><span class="linenos"> 486</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-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">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-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">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-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 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-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">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-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><span id="L-496"><a href="#L-496"><span class="linenos"> 496</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-497"><a href="#L-497"><span class="linenos"> 497</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-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">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-501"><a href="#L-501"><span class="linenos"> 501</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-502"><a href="#L-502"><span class="linenos"> 502</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-503"><a href="#L-503"><span class="linenos"> 503</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"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-504"><a href="#L-504"><span class="linenos"> 504</span></a> -</span><span id="L-505"><a href="#L-505"><span class="linenos"> 505</span></a> -</span><span id="L-506"><a href="#L-506"><span class="linenos"> 506</span></a><span class="k">def</span> <span class="nf">if_sql</span><span class="p">(</span> -</span><span id="L-507"><a href="#L-507"><span class="linenos"> 507</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-508"><a href="#L-508"><span class="linenos"> 508</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-509"><a href="#L-509"><span class="linenos"> 509</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-510"><a href="#L-510"><span class="linenos"> 510</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-511"><a href="#L-511"><span class="linenos"> 511</span></a> <span class="n">name</span><span class="p">,</span> -</span><span id="L-512"><a href="#L-512"><span class="linenos"> 512</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> -</span><span id="L-513"><a href="#L-513"><span class="linenos"> 513</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-514"><a href="#L-514"><span class="linenos"> 514</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-515"><a href="#L-515"><span class="linenos"> 515</span></a> <span class="p">)</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 class="k">return</span> <span class="n">_if_sql</span> +</span><span id="L-495"><a href="#L-495"><span class="linenos"> 495</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-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><span id="L-498"><a href="#L-498"><span class="linenos"> 498</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-499"><a href="#L-499"><span class="linenos"> 499</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-500"><a href="#L-500"><span class="linenos"> 500</span></a> +</span><span id="L-501"><a href="#L-501"><span class="linenos"> 501</span></a> +</span><span id="L-502"><a href="#L-502"><span class="linenos"> 502</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-503"><a href="#L-503"><span class="linenos"> 503</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-504"><a href="#L-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">"APPROX_COUNT_DISTINCT does not support accuracy"</span><span class="p">)</span> +</span><span id="L-505"><a href="#L-505"><span class="linenos"> 505</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-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><span id="L-508"><a href="#L-508"><span class="linenos"> 508</span></a><span class="k">def</span> <span class="nf">if_sql</span><span class="p">(</span> +</span><span id="L-509"><a href="#L-509"><span class="linenos"> 509</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-510"><a href="#L-510"><span class="linenos"> 510</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-511"><a href="#L-511"><span class="linenos"> 511</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-512"><a href="#L-512"><span class="linenos"> 512</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-513"><a href="#L-513"><span class="linenos"> 513</span></a> <span class="n">name</span><span class="p">,</span> +</span><span id="L-514"><a href="#L-514"><span class="linenos"> 514</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> +</span><span id="L-515"><a href="#L-515"><span class="linenos"> 515</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-516"><a href="#L-516"><span class="linenos"> 516</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-517"><a href="#L-517"><span class="linenos"> 517</span></a> <span class="p">)</span> </span><span id="L-518"><a href="#L-518"><span class="linenos"> 518</span></a> -</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 class="k">def</span> <span class="nf">arrow_json_extract_sql</span><span class="p">(</span> -</span><span id="L-521"><a href="#L-521"><span class="linenos"> 521</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">JSONExtract</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span> -</span><span id="L-522"><a href="#L-522"><span class="linenos"> 522</span></a><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="n">_if_sql</span> +</span><span id="L-520"><a href="#L-520"><span class="linenos"> 520</span></a> +</span><span id="L-521"><a href="#L-521"><span class="linenos"> 521</span></a> +</span><span id="L-522"><a href="#L-522"><span class="linenos"> 522</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">JSON_EXTRACT_TYPE</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> </span><span id="L-523"><a href="#L-523"><span class="linenos"> 523</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><span id="L-524"><a href="#L-524"><span class="linenos"> 524</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">JSON_TYPE_REQUIRED_FOR_EXTRACTION</span> <span class="ow">and</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">Literal</span><span class="p">)</span> <span class="ow">and</span> <span class="n">this</span><span class="o">.</span><span class="n">is_string</span><span class="p">:</span> </span><span id="L-525"><a href="#L-525"><span class="linenos"> 525</span></a> <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="s2">"json"</span><span class="p">))</span> @@ -1528,45 +1531,60 @@ </span><span id="L-1011"><a href="#L-1011"><span class="linenos">1011</span></a> </span><span id="L-1012"><a href="#L-1012"><span class="linenos">1012</span></a> </span><span id="L-1013"><a href="#L-1013"><span class="linenos">1013</span></a><span class="k">def</span> <span class="nf">parse_json_extract_path</span><span class="p">(</span> -</span><span id="L-1014"><a href="#L-1014"><span class="linenos">1014</span></a> <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">E</span><span class="p">],</span> -</span><span id="L-1015"><a href="#L-1015"><span class="linenos">1015</span></a> <span class="n">supports_null_if_invalid</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> -</span><span id="L-1016"><a href="#L-1016"><span class="linenos">1016</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-1017"><a href="#L-1017"><span class="linenos">1017</span></a> <span class="k">def</span> <span class="nf">_parse_json_extract_path</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-1018"><a href="#L-1018"><span class="linenos">1018</span></a> <span class="n">null_if_invalid</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-1019"><a href="#L-1019"><span class="linenos">1019</span></a> -</span><span id="L-1020"><a href="#L-1020"><span class="linenos">1020</span></a> <span class="n">segments</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">JSONPathPart</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">JSONPathRoot</span><span class="p">()]</span> -</span><span id="L-1021"><a href="#L-1021"><span class="linenos">1021</span></a> <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span> -</span><span id="L-1022"><a href="#L-1022"><span class="linenos">1022</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="p">):</span> -</span><span id="L-1023"><a href="#L-1023"><span class="linenos">1023</span></a> <span class="n">text</span> <span class="o">=</span> <span class="n">arg</span><span class="o">.</span><span class="n">name</span> -</span><span id="L-1024"><a href="#L-1024"><span class="linenos">1024</span></a> <span class="k">if</span> <span class="n">is_int</span><span class="p">(</span><span class="n">text</span><span class="p">):</span> -</span><span id="L-1025"><a href="#L-1025"><span class="linenos">1025</span></a> <span class="n">segments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">JSONPathSubscript</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">text</span><span class="p">)))</span> -</span><span id="L-1026"><a href="#L-1026"><span class="linenos">1026</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="L-1027"><a href="#L-1027"><span class="linenos">1027</span></a> <span class="n">segments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">JSONPathKey</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">text</span><span class="p">))</span> -</span><span id="L-1028"><a href="#L-1028"><span class="linenos">1028</span></a> <span class="k">elif</span> <span class="n">supports_null_if_invalid</span><span class="p">:</span> -</span><span id="L-1029"><a href="#L-1029"><span class="linenos">1029</span></a> <span class="n">null_if_invalid</span> <span class="o">=</span> <span class="n">arg</span> -</span><span id="L-1030"><a href="#L-1030"><span class="linenos">1030</span></a> -</span><span id="L-1031"><a href="#L-1031"><span class="linenos">1031</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-1032"><a href="#L-1032"><span class="linenos">1032</span></a> <span class="n">jsonpath</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONPath</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">segments</span><span class="p">)</span> -</span><span id="L-1033"><a href="#L-1033"><span class="linenos">1033</span></a> -</span><span id="L-1034"><a href="#L-1034"><span class="linenos">1034</span></a> <span class="c1"># This is done to avoid failing in the expression validator due to the arg count</span> -</span><span id="L-1035"><a href="#L-1035"><span class="linenos">1035</span></a> <span class="k">del</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">:]</span> -</span><span id="L-1036"><a href="#L-1036"><span class="linenos">1036</span></a> -</span><span id="L-1037"><a href="#L-1037"><span class="linenos">1037</span></a> <span class="k">if</span> <span class="n">expr_type</span> <span class="ow">is</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span><span class="p">:</span> -</span><span id="L-1038"><a href="#L-1038"><span class="linenos">1038</span></a> <span class="k">return</span> <span class="n">expr_type</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">jsonpath</span><span class="p">,</span> <span class="n">null_if_invalid</span><span class="o">=</span><span class="n">null_if_invalid</span><span class="p">)</span> -</span><span id="L-1039"><a href="#L-1039"><span class="linenos">1039</span></a> -</span><span id="L-1040"><a href="#L-1040"><span class="linenos">1040</span></a> <span class="k">return</span> <span class="n">expr_type</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">jsonpath</span><span class="p">)</span> -</span><span id="L-1041"><a href="#L-1041"><span class="linenos">1041</span></a> -</span><span id="L-1042"><a href="#L-1042"><span class="linenos">1042</span></a> <span class="k">return</span> <span class="n">_parse_json_extract_path</span> -</span><span id="L-1043"><a href="#L-1043"><span class="linenos">1043</span></a> -</span><span id="L-1044"><a href="#L-1044"><span class="linenos">1044</span></a> -</span><span id="L-1045"><a href="#L-1045"><span class="linenos">1045</span></a><span class="k">def</span> <span class="nf">json_path_segments</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">JSONPath</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-1046"><a href="#L-1046"><span class="linenos">1046</span></a> <span class="n">segments</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="L-1047"><a href="#L-1047"><span class="linenos">1047</span></a> <span class="k">for</span> <span class="n">segment</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> -</span><span id="L-1048"><a href="#L-1048"><span class="linenos">1048</span></a> <span class="n">path</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">segment</span><span class="p">)</span> -</span><span id="L-1049"><a href="#L-1049"><span class="linenos">1049</span></a> <span class="k">if</span> <span class="n">path</span><span class="p">:</span> -</span><span id="L-1050"><a href="#L-1050"><span class="linenos">1050</span></a> <span class="n">segments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">dialect</span><span class="o">.</span><span class="n">QUOTE_START</span><span class="si">}{</span><span class="n">path</span><span class="si">}{</span><span class="bp">self</span><span class="o">.</span><span class="n">dialect</span><span class="o">.</span><span class="n">QUOTE_END</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="L-1051"><a href="#L-1051"><span class="linenos">1051</span></a> -</span><span id="L-1052"><a href="#L-1052"><span class="linenos">1052</span></a> <span class="k">return</span> <span class="n">segments</span> +</span><span id="L-1014"><a href="#L-1014"><span class="linenos">1014</span></a> <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">F</span><span class="p">],</span> <span class="n">zero_based_indexing</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="L-1015"><a href="#L-1015"><span class="linenos">1015</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">F</span><span class="p">]:</span> +</span><span id="L-1016"><a href="#L-1016"><span class="linenos">1016</span></a> <span class="k">def</span> <span class="nf">_parse_json_extract_path</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">F</span><span class="p">:</span> +</span><span id="L-1017"><a href="#L-1017"><span class="linenos">1017</span></a> <span class="n">segments</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">JSONPathPart</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">JSONPathRoot</span><span class="p">()]</span> +</span><span id="L-1018"><a href="#L-1018"><span class="linenos">1018</span></a> <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span> +</span><span id="L-1019"><a href="#L-1019"><span class="linenos">1019</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="p">):</span> +</span><span id="L-1020"><a href="#L-1020"><span class="linenos">1020</span></a> <span class="c1"># We use the fallback parser because we can't really transpile non-literals safely</span> +</span><span id="L-1021"><a href="#L-1021"><span class="linenos">1021</span></a> <span class="k">return</span> <span class="n">expr_type</span><span class="o">.</span><span class="n">from_arg_list</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> +</span><span id="L-1022"><a href="#L-1022"><span class="linenos">1022</span></a> +</span><span id="L-1023"><a href="#L-1023"><span class="linenos">1023</span></a> <span class="n">text</span> <span class="o">=</span> <span class="n">arg</span><span class="o">.</span><span class="n">name</span> +</span><span id="L-1024"><a href="#L-1024"><span class="linenos">1024</span></a> <span class="k">if</span> <span class="n">is_int</span><span class="p">(</span><span class="n">text</span><span class="p">):</span> +</span><span id="L-1025"><a href="#L-1025"><span class="linenos">1025</span></a> <span class="n">index</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">text</span><span class="p">)</span> +</span><span id="L-1026"><a href="#L-1026"><span class="linenos">1026</span></a> <span class="n">segments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> +</span><span id="L-1027"><a href="#L-1027"><span class="linenos">1027</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONPathSubscript</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">index</span> <span class="k">if</span> <span class="n">zero_based_indexing</span> <span class="k">else</span> <span class="n">index</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> +</span><span id="L-1028"><a href="#L-1028"><span class="linenos">1028</span></a> <span class="p">)</span> +</span><span id="L-1029"><a href="#L-1029"><span class="linenos">1029</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="L-1030"><a href="#L-1030"><span class="linenos">1030</span></a> <span class="n">segments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">JSONPathKey</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">text</span><span class="p">))</span> +</span><span id="L-1031"><a href="#L-1031"><span class="linenos">1031</span></a> +</span><span id="L-1032"><a href="#L-1032"><span class="linenos">1032</span></a> <span class="c1"># This is done to avoid failing in the expression validator due to the arg count</span> +</span><span id="L-1033"><a href="#L-1033"><span class="linenos">1033</span></a> <span class="k">del</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">:]</span> +</span><span id="L-1034"><a href="#L-1034"><span class="linenos">1034</span></a> <span class="k">return</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">exp</span><span class="o">.</span><span class="n">JSONPath</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">segments</span><span class="p">))</span> +</span><span id="L-1035"><a href="#L-1035"><span class="linenos">1035</span></a> +</span><span id="L-1036"><a href="#L-1036"><span class="linenos">1036</span></a> <span class="k">return</span> <span class="n">_parse_json_extract_path</span> +</span><span id="L-1037"><a href="#L-1037"><span class="linenos">1037</span></a> +</span><span id="L-1038"><a href="#L-1038"><span class="linenos">1038</span></a> +</span><span id="L-1039"><a href="#L-1039"><span class="linenos">1039</span></a><span class="k">def</span> <span class="nf">json_extract_segments</span><span class="p">(</span> +</span><span id="L-1040"><a href="#L-1040"><span class="linenos">1040</span></a> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">quoted_index</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="L-1041"><a href="#L-1041"><span class="linenos">1041</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">JSON_EXTRACT_TYPE</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> +</span><span id="L-1042"><a href="#L-1042"><span class="linenos">1042</span></a> <span class="k">def</span> <span class="nf">_json_extract_segments</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">JSON_EXTRACT_TYPE</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-1043"><a href="#L-1043"><span class="linenos">1043</span></a> <span class="n">path</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span> +</span><span id="L-1044"><a href="#L-1044"><span class="linenos">1044</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONPath</span><span class="p">):</span> +</span><span id="L-1045"><a href="#L-1045"><span class="linenos">1045</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-1046"><a href="#L-1046"><span class="linenos">1046</span></a> +</span><span id="L-1047"><a href="#L-1047"><span class="linenos">1047</span></a> <span class="n">segments</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="L-1048"><a href="#L-1048"><span class="linenos">1048</span></a> <span class="k">for</span> <span class="n">segment</span> <span class="ow">in</span> <span class="n">path</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="L-1049"><a href="#L-1049"><span class="linenos">1049</span></a> <span class="n">path</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">segment</span><span class="p">)</span> +</span><span id="L-1050"><a href="#L-1050"><span class="linenos">1050</span></a> <span class="k">if</span> <span class="n">path</span><span class="p">:</span> +</span><span id="L-1051"><a href="#L-1051"><span class="linenos">1051</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">segment</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONPathPart</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span> +</span><span id="L-1052"><a href="#L-1052"><span class="linenos">1052</span></a> <span class="n">quoted_index</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">segment</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONPathSubscript</span><span class="p">)</span> +</span><span id="L-1053"><a href="#L-1053"><span class="linenos">1053</span></a> <span class="p">):</span> +</span><span id="L-1054"><a href="#L-1054"><span class="linenos">1054</span></a> <span class="n">path</span> <span class="o">=</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">dialect</span><span class="o">.</span><span class="n">QUOTE_START</span><span class="si">}{</span><span class="n">path</span><span class="si">}{</span><span class="bp">self</span><span class="o">.</span><span class="n">dialect</span><span class="o">.</span><span class="n">QUOTE_END</span><span class="si">}</span><span class="s2">"</span> +</span><span id="L-1055"><a href="#L-1055"><span class="linenos">1055</span></a> +</span><span id="L-1056"><a href="#L-1056"><span class="linenos">1056</span></a> <span class="n">segments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> +</span><span id="L-1057"><a href="#L-1057"><span class="linenos">1057</span></a> +</span><span id="L-1058"><a href="#L-1058"><span class="linenos">1058</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="o">*</span><span class="n">segments</span><span class="p">)</span> +</span><span id="L-1059"><a href="#L-1059"><span class="linenos">1059</span></a> +</span><span id="L-1060"><a href="#L-1060"><span class="linenos">1060</span></a> <span class="k">return</span> <span class="n">_json_extract_segments</span> +</span><span id="L-1061"><a href="#L-1061"><span class="linenos">1061</span></a> +</span><span id="L-1062"><a href="#L-1062"><span class="linenos">1062</span></a> +</span><span id="L-1063"><a href="#L-1063"><span class="linenos">1063</span></a><span class="k">def</span> <span class="nf">json_path_key_only_name</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">JSONPathKey</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-1064"><a href="#L-1064"><span class="linenos">1064</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">JSONPathWildcard</span><span class="p">):</span> +</span><span id="L-1065"><a href="#L-1065"><span class="linenos">1065</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Unsupported wildcard in JSONPathKey expression"</span><span class="p">)</span> +</span><span id="L-1066"><a href="#L-1066"><span class="linenos">1066</span></a> +</span><span id="L-1067"><a href="#L-1067"><span class="linenos">1067</span></a> <span class="k">return</span> <span class="n">expression</span><span class="o">.</span><span class="n">name</span> </span></pre></div> @@ -1620,32 +1638,32 @@ </div> <a class="headerlink" href="#Dialects"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialects-28"><a href="#Dialects-28"><span class="linenos">28</span></a><span class="k">class</span> <span class="nc">Dialects</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">Enum</span><span class="p">):</span> -</span><span id="Dialects-29"><a href="#Dialects-29"><span class="linenos">29</span></a><span class="w"> </span><span class="sd">"""Dialects supported by SQLGLot."""</span> -</span><span id="Dialects-30"><a href="#Dialects-30"><span class="linenos">30</span></a> -</span><span id="Dialects-31"><a href="#Dialects-31"><span class="linenos">31</span></a> <span class="n">DIALECT</span> <span class="o">=</span> <span class="s2">""</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialects-30"><a href="#Dialects-30"><span class="linenos">30</span></a><span class="k">class</span> <span class="nc">Dialects</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">Enum</span><span class="p">):</span> +</span><span id="Dialects-31"><a href="#Dialects-31"><span class="linenos">31</span></a><span class="w"> </span><span class="sd">"""Dialects supported by SQLGLot."""</span> </span><span id="Dialects-32"><a href="#Dialects-32"><span class="linenos">32</span></a> -</span><span id="Dialects-33"><a href="#Dialects-33"><span class="linenos">33</span></a> <span class="n">BIGQUERY</span> <span class="o">=</span> <span class="s2">"bigquery"</span> -</span><span id="Dialects-34"><a href="#Dialects-34"><span class="linenos">34</span></a> <span class="n">CLICKHOUSE</span> <span class="o">=</span> <span class="s2">"clickhouse"</span> -</span><span id="Dialects-35"><a href="#Dialects-35"><span class="linenos">35</span></a> <span class="n">DATABRICKS</span> <span class="o">=</span> <span class="s2">"databricks"</span> -</span><span id="Dialects-36"><a href="#Dialects-36"><span class="linenos">36</span></a> <span class="n">DORIS</span> <span class="o">=</span> <span class="s2">"doris"</span> -</span><span id="Dialects-37"><a href="#Dialects-37"><span class="linenos">37</span></a> <span class="n">DRILL</span> <span class="o">=</span> <span class="s2">"drill"</span> -</span><span id="Dialects-38"><a href="#Dialects-38"><span class="linenos">38</span></a> <span class="n">DUCKDB</span> <span class="o">=</span> <span class="s2">"duckdb"</span> -</span><span id="Dialects-39"><a href="#Dialects-39"><span class="linenos">39</span></a> <span class="n">HIVE</span> <span class="o">=</span> <span class="s2">"hive"</span> -</span><span id="Dialects-40"><a href="#Dialects-40"><span class="linenos">40</span></a> <span class="n">MYSQL</span> <span class="o">=</span> <span class="s2">"mysql"</span> -</span><span id="Dialects-41"><a href="#Dialects-41"><span class="linenos">41</span></a> <span class="n">ORACLE</span> <span class="o">=</span> <span class="s2">"oracle"</span> -</span><span id="Dialects-42"><a href="#Dialects-42"><span class="linenos">42</span></a> <span class="n">POSTGRES</span> <span class="o">=</span> <span class="s2">"postgres"</span> -</span><span id="Dialects-43"><a href="#Dialects-43"><span class="linenos">43</span></a> <span class="n">PRESTO</span> <span class="o">=</span> <span class="s2">"presto"</span> -</span><span id="Dialects-44"><a href="#Dialects-44"><span class="linenos">44</span></a> <span class="n">REDSHIFT</span> <span class="o">=</span> <span class="s2">"redshift"</span> -</span><span id="Dialects-45"><a href="#Dialects-45"><span class="linenos">45</span></a> <span class="n">SNOWFLAKE</span> <span class="o">=</span> <span class="s2">"snowflake"</span> -</span><span id="Dialects-46"><a href="#Dialects-46"><span class="linenos">46</span></a> <span class="n">SPARK</span> <span class="o">=</span> <span class="s2">"spark"</span> -</span><span id="Dialects-47"><a href="#Dialects-47"><span class="linenos">47</span></a> <span class="n">SPARK2</span> <span class="o">=</span> <span class="s2">"spark2"</span> -</span><span id="Dialects-48"><a href="#Dialects-48"><span class="linenos">48</span></a> <span class="n">SQLITE</span> <span class="o">=</span> <span class="s2">"sqlite"</span> -</span><span id="Dialects-49"><a href="#Dialects-49"><span class="linenos">49</span></a> <span class="n">STARROCKS</span> <span class="o">=</span> <span class="s2">"starrocks"</span> -</span><span id="Dialects-50"><a href="#Dialects-50"><span class="linenos">50</span></a> <span class="n">TABLEAU</span> <span class="o">=</span> <span class="s2">"tableau"</span> -</span><span id="Dialects-51"><a href="#Dialects-51"><span class="linenos">51</span></a> <span class="n">TERADATA</span> <span class="o">=</span> <span class="s2">"teradata"</span> -</span><span id="Dialects-52"><a href="#Dialects-52"><span class="linenos">52</span></a> <span class="n">TRINO</span> <span class="o">=</span> <span class="s2">"trino"</span> -</span><span id="Dialects-53"><a href="#Dialects-53"><span class="linenos">53</span></a> <span class="n">TSQL</span> <span class="o">=</span> <span class="s2">"tsql"</span> +</span><span id="Dialects-33"><a href="#Dialects-33"><span class="linenos">33</span></a> <span class="n">DIALECT</span> <span class="o">=</span> <span class="s2">""</span> +</span><span id="Dialects-34"><a href="#Dialects-34"><span class="linenos">34</span></a> +</span><span id="Dialects-35"><a href="#Dialects-35"><span class="linenos">35</span></a> <span class="n">BIGQUERY</span> <span class="o">=</span> <span class="s2">"bigquery"</span> +</span><span id="Dialects-36"><a href="#Dialects-36"><span class="linenos">36</span></a> <span class="n">CLICKHOUSE</span> <span class="o">=</span> <span class="s2">"clickhouse"</span> +</span><span id="Dialects-37"><a href="#Dialects-37"><span class="linenos">37</span></a> <span class="n">DATABRICKS</span> <span class="o">=</span> <span class="s2">"databricks"</span> +</span><span id="Dialects-38"><a href="#Dialects-38"><span class="linenos">38</span></a> <span class="n">DORIS</span> <span class="o">=</span> <span class="s2">"doris"</span> +</span><span id="Dialects-39"><a href="#Dialects-39"><span class="linenos">39</span></a> <span class="n">DRILL</span> <span class="o">=</span> <span class="s2">"drill"</span> +</span><span id="Dialects-40"><a href="#Dialects-40"><span class="linenos">40</span></a> <span class="n">DUCKDB</span> <span class="o">=</span> <span class="s2">"duckdb"</span> +</span><span id="Dialects-41"><a href="#Dialects-41"><span class="linenos">41</span></a> <span class="n">HIVE</span> <span class="o">=</span> <span class="s2">"hive"</span> +</span><span id="Dialects-42"><a href="#Dialects-42"><span class="linenos">42</span></a> <span class="n">MYSQL</span> <span class="o">=</span> <span class="s2">"mysql"</span> +</span><span id="Dialects-43"><a href="#Dialects-43"><span class="linenos">43</span></a> <span class="n">ORACLE</span> <span class="o">=</span> <span class="s2">"oracle"</span> +</span><span id="Dialects-44"><a href="#Dialects-44"><span class="linenos">44</span></a> <span class="n">POSTGRES</span> <span class="o">=</span> <span class="s2">"postgres"</span> +</span><span id="Dialects-45"><a href="#Dialects-45"><span class="linenos">45</span></a> <span class="n">PRESTO</span> <span class="o">=</span> <span class="s2">"presto"</span> +</span><span id="Dialects-46"><a href="#Dialects-46"><span class="linenos">46</span></a> <span class="n">REDSHIFT</span> <span class="o">=</span> <span class="s2">"redshift"</span> +</span><span id="Dialects-47"><a href="#Dialects-47"><span class="linenos">47</span></a> <span class="n">SNOWFLAKE</span> <span class="o">=</span> <span class="s2">"snowflake"</span> +</span><span id="Dialects-48"><a href="#Dialects-48"><span class="linenos">48</span></a> <span class="n">SPARK</span> <span class="o">=</span> <span class="s2">"spark"</span> +</span><span id="Dialects-49"><a href="#Dialects-49"><span class="linenos">49</span></a> <span class="n">SPARK2</span> <span class="o">=</span> <span class="s2">"spark2"</span> +</span><span id="Dialects-50"><a href="#Dialects-50"><span class="linenos">50</span></a> <span class="n">SQLITE</span> <span class="o">=</span> <span class="s2">"sqlite"</span> +</span><span id="Dialects-51"><a href="#Dialects-51"><span class="linenos">51</span></a> <span class="n">STARROCKS</span> <span class="o">=</span> <span class="s2">"starrocks"</span> +</span><span id="Dialects-52"><a href="#Dialects-52"><span class="linenos">52</span></a> <span class="n">TABLEAU</span> <span class="o">=</span> <span class="s2">"tableau"</span> +</span><span id="Dialects-53"><a href="#Dialects-53"><span class="linenos">53</span></a> <span class="n">TERADATA</span> <span class="o">=</span> <span class="s2">"teradata"</span> +</span><span id="Dialects-54"><a href="#Dialects-54"><span class="linenos">54</span></a> <span class="n">TRINO</span> <span class="o">=</span> <span class="s2">"trino"</span> +</span><span id="Dialects-55"><a href="#Dialects-55"><span class="linenos">55</span></a> <span class="n">TSQL</span> <span class="o">=</span> <span class="s2">"tsql"</span> </span></pre></div> @@ -1989,20 +2007,20 @@ </div> <a class="headerlink" href="#NormalizationStrategy"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="NormalizationStrategy-56"><a href="#NormalizationStrategy-56"><span class="linenos">56</span></a><span class="k">class</span> <span class="nc">NormalizationStrategy</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">AutoName</span><span class="p">):</span> -</span><span id="NormalizationStrategy-57"><a href="#NormalizationStrategy-57"><span class="linenos">57</span></a><span class="w"> </span><span class="sd">"""Specifies the strategy according to which identifiers should be normalized."""</span> -</span><span id="NormalizationStrategy-58"><a href="#NormalizationStrategy-58"><span class="linenos">58</span></a> -</span><span id="NormalizationStrategy-59"><a href="#NormalizationStrategy-59"><span class="linenos">59</span></a> <span class="n">LOWERCASE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> -</span><span id="NormalizationStrategy-60"><a href="#NormalizationStrategy-60"><span class="linenos">60</span></a><span class="w"> </span><span class="sd">"""Unquoted identifiers are lowercased."""</span> -</span><span id="NormalizationStrategy-61"><a href="#NormalizationStrategy-61"><span class="linenos">61</span></a> -</span><span id="NormalizationStrategy-62"><a href="#NormalizationStrategy-62"><span class="linenos">62</span></a> <span class="n">UPPERCASE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> -</span><span id="NormalizationStrategy-63"><a href="#NormalizationStrategy-63"><span class="linenos">63</span></a><span class="w"> </span><span class="sd">"""Unquoted identifiers are uppercased."""</span> -</span><span id="NormalizationStrategy-64"><a href="#NormalizationStrategy-64"><span class="linenos">64</span></a> -</span><span id="NormalizationStrategy-65"><a href="#NormalizationStrategy-65"><span class="linenos">65</span></a> <span class="n">CASE_SENSITIVE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> -</span><span id="NormalizationStrategy-66"><a href="#NormalizationStrategy-66"><span class="linenos">66</span></a><span class="w"> </span><span class="sd">"""Always case-sensitive, regardless of quotes."""</span> -</span><span id="NormalizationStrategy-67"><a href="#NormalizationStrategy-67"><span class="linenos">67</span></a> -</span><span id="NormalizationStrategy-68"><a href="#NormalizationStrategy-68"><span class="linenos">68</span></a> <span class="n">CASE_INSENSITIVE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> -</span><span id="NormalizationStrategy-69"><a href="#NormalizationStrategy-69"><span class="linenos">69</span></a><span class="w"> </span><span class="sd">"""Always case-insensitive, regardless of quotes."""</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="NormalizationStrategy-58"><a href="#NormalizationStrategy-58"><span class="linenos">58</span></a><span class="k">class</span> <span class="nc">NormalizationStrategy</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">AutoName</span><span class="p">):</span> +</span><span id="NormalizationStrategy-59"><a href="#NormalizationStrategy-59"><span class="linenos">59</span></a><span class="w"> </span><span class="sd">"""Specifies the strategy according to which identifiers should be normalized."""</span> +</span><span id="NormalizationStrategy-60"><a href="#NormalizationStrategy-60"><span class="linenos">60</span></a> +</span><span id="NormalizationStrategy-61"><a href="#NormalizationStrategy-61"><span class="linenos">61</span></a> <span class="n">LOWERCASE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> +</span><span id="NormalizationStrategy-62"><a href="#NormalizationStrategy-62"><span class="linenos">62</span></a><span class="w"> </span><span class="sd">"""Unquoted identifiers are lowercased."""</span> +</span><span id="NormalizationStrategy-63"><a href="#NormalizationStrategy-63"><span class="linenos">63</span></a> +</span><span id="NormalizationStrategy-64"><a href="#NormalizationStrategy-64"><span class="linenos">64</span></a> <span class="n">UPPERCASE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> +</span><span id="NormalizationStrategy-65"><a href="#NormalizationStrategy-65"><span class="linenos">65</span></a><span class="w"> </span><span class="sd">"""Unquoted identifiers are uppercased."""</span> +</span><span id="NormalizationStrategy-66"><a href="#NormalizationStrategy-66"><span class="linenos">66</span></a> +</span><span id="NormalizationStrategy-67"><a href="#NormalizationStrategy-67"><span class="linenos">67</span></a> <span class="n">CASE_SENSITIVE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> +</span><span id="NormalizationStrategy-68"><a href="#NormalizationStrategy-68"><span class="linenos">68</span></a><span class="w"> </span><span class="sd">"""Always case-sensitive, regardless of quotes."""</span> +</span><span id="NormalizationStrategy-69"><a href="#NormalizationStrategy-69"><span class="linenos">69</span></a> +</span><span id="NormalizationStrategy-70"><a href="#NormalizationStrategy-70"><span class="linenos">70</span></a> <span class="n">CASE_INSENSITIVE</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span> +</span><span id="NormalizationStrategy-71"><a href="#NormalizationStrategy-71"><span class="linenos">71</span></a><span class="w"> </span><span class="sd">"""Always case-insensitive, regardless of quotes."""</span> </span></pre></div> @@ -2138,350 +2156,350 @@ </div> <a class="headerlink" href="#Dialect"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect-148"><a href="#Dialect-148"><span class="linenos">148</span></a><span class="k">class</span> <span class="nc">Dialect</span><span class="p">(</span><span class="n">metaclass</span><span class="o">=</span><span class="n">_Dialect</span><span class="p">):</span> -</span><span id="Dialect-149"><a href="#Dialect-149"><span class="linenos">149</span></a> <span class="n">INDEX_OFFSET</span> <span class="o">=</span> <span class="mi">0</span> -</span><span id="Dialect-150"><a href="#Dialect-150"><span class="linenos">150</span></a><span class="w"> </span><span class="sd">"""Determines the base index offset for arrays."""</span> -</span><span id="Dialect-151"><a href="#Dialect-151"><span class="linenos">151</span></a> -</span><span id="Dialect-152"><a href="#Dialect-152"><span class="linenos">152</span></a> <span class="n">WEEK_OFFSET</span> <span class="o">=</span> <span class="mi">0</span> -</span><span id="Dialect-153"><a href="#Dialect-153"><span class="linenos">153</span></a><span class="w"> </span><span class="sd">"""Determines the day of week of DATE_TRUNC(week). Defaults to 0 (Monday). -1 would be Sunday."""</span> -</span><span id="Dialect-154"><a href="#Dialect-154"><span class="linenos">154</span></a> -</span><span id="Dialect-155"><a href="#Dialect-155"><span class="linenos">155</span></a> <span class="n">UNNEST_COLUMN_ONLY</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Dialect-156"><a href="#Dialect-156"><span class="linenos">156</span></a><span class="w"> </span><span class="sd">"""Determines whether or not `UNNEST` table aliases are treated as column aliases."""</span> -</span><span id="Dialect-157"><a href="#Dialect-157"><span class="linenos">157</span></a> -</span><span id="Dialect-158"><a href="#Dialect-158"><span class="linenos">158</span></a> <span class="n">ALIAS_POST_TABLESAMPLE</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Dialect-159"><a href="#Dialect-159"><span class="linenos">159</span></a><span class="w"> </span><span class="sd">"""Determines whether or not the table alias comes after tablesample."""</span> -</span><span id="Dialect-160"><a href="#Dialect-160"><span class="linenos">160</span></a> -</span><span id="Dialect-161"><a href="#Dialect-161"><span class="linenos">161</span></a> <span class="n">TABLESAMPLE_SIZE_IS_PERCENT</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Dialect-162"><a href="#Dialect-162"><span class="linenos">162</span></a><span class="w"> </span><span class="sd">"""Determines whether or not a size in the table sample clause represents percentage."""</span> -</span><span id="Dialect-163"><a href="#Dialect-163"><span class="linenos">163</span></a> -</span><span id="Dialect-164"><a href="#Dialect-164"><span class="linenos">164</span></a> <span class="n">NORMALIZATION_STRATEGY</span> <span class="o">=</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">LOWERCASE</span> -</span><span id="Dialect-165"><a href="#Dialect-165"><span class="linenos">165</span></a><span class="w"> </span><span class="sd">"""Specifies the strategy according to which identifiers should be normalized."""</span> -</span><span id="Dialect-166"><a href="#Dialect-166"><span class="linenos">166</span></a> -</span><span id="Dialect-167"><a href="#Dialect-167"><span class="linenos">167</span></a> <span class="n">IDENTIFIERS_CAN_START_WITH_DIGIT</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Dialect-168"><a href="#Dialect-168"><span class="linenos">168</span></a><span class="w"> </span><span class="sd">"""Determines whether or not an unquoted identifier can start with a digit."""</span> -</span><span id="Dialect-169"><a href="#Dialect-169"><span class="linenos">169</span></a> -</span><span id="Dialect-170"><a href="#Dialect-170"><span class="linenos">170</span></a> <span class="n">DPIPE_IS_STRING_CONCAT</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Dialect-171"><a href="#Dialect-171"><span class="linenos">171</span></a><span class="w"> </span><span class="sd">"""Determines whether or not the DPIPE token (`||`) is a string concatenation operator."""</span> -</span><span id="Dialect-172"><a href="#Dialect-172"><span class="linenos">172</span></a> -</span><span id="Dialect-173"><a href="#Dialect-173"><span class="linenos">173</span></a> <span class="n">STRICT_STRING_CONCAT</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Dialect-174"><a href="#Dialect-174"><span class="linenos">174</span></a><span class="w"> </span><span class="sd">"""Determines whether or not `CONCAT`'s arguments must be strings."""</span> -</span><span id="Dialect-175"><a href="#Dialect-175"><span class="linenos">175</span></a> -</span><span id="Dialect-176"><a href="#Dialect-176"><span class="linenos">176</span></a> <span class="n">SUPPORTS_USER_DEFINED_TYPES</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Dialect-177"><a href="#Dialect-177"><span class="linenos">177</span></a><span class="w"> </span><span class="sd">"""Determines whether or not user-defined data types are supported."""</span> -</span><span id="Dialect-178"><a href="#Dialect-178"><span class="linenos">178</span></a> -</span><span id="Dialect-179"><a href="#Dialect-179"><span class="linenos">179</span></a> <span class="n">SUPPORTS_SEMI_ANTI_JOIN</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Dialect-180"><a href="#Dialect-180"><span class="linenos">180</span></a><span class="w"> </span><span class="sd">"""Determines whether or not `SEMI` or `ANTI` joins are supported."""</span> -</span><span id="Dialect-181"><a href="#Dialect-181"><span class="linenos">181</span></a> -</span><span id="Dialect-182"><a href="#Dialect-182"><span class="linenos">182</span></a> <span class="n">NORMALIZE_FUNCTIONS</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">|</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"upper"</span> -</span><span id="Dialect-183"><a href="#Dialect-183"><span class="linenos">183</span></a><span class="w"> </span><span class="sd">"""Determines how function names are going to be normalized."""</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="n">LOG_BASE_FIRST</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Dialect-186"><a href="#Dialect-186"><span class="linenos">186</span></a><span class="w"> </span><span class="sd">"""Determines whether the base comes first in the `LOG` function."""</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="n">NULL_ORDERING</span> <span class="o">=</span> <span class="s2">"nulls_are_small"</span> -</span><span id="Dialect-189"><a href="#Dialect-189"><span class="linenos">189</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect-190"><a href="#Dialect-190"><span class="linenos">190</span></a><span class="sd"> Indicates the default `NULL` ordering method to use if not explicitly set.</span> -</span><span id="Dialect-191"><a href="#Dialect-191"><span class="linenos">191</span></a><span class="sd"> Possible values: `"nulls_are_small"`, `"nulls_are_large"`, `"nulls_are_last"`</span> -</span><span id="Dialect-192"><a href="#Dialect-192"><span class="linenos">192</span></a><span class="sd"> """</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="n">TYPED_DIVISION</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Dialect-195"><a href="#Dialect-195"><span class="linenos">195</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect-196"><a href="#Dialect-196"><span class="linenos">196</span></a><span class="sd"> Whether the behavior of `a / b` depends on the types of `a` and `b`.</span> -</span><span id="Dialect-197"><a href="#Dialect-197"><span class="linenos">197</span></a><span class="sd"> False means `a / b` is always float division.</span> -</span><span id="Dialect-198"><a href="#Dialect-198"><span class="linenos">198</span></a><span class="sd"> True means `a / b` is integer division if both `a` and `b` are integers.</span> -</span><span id="Dialect-199"><a href="#Dialect-199"><span class="linenos">199</span></a><span class="sd"> """</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="n">SAFE_DIVISION</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Dialect-202"><a href="#Dialect-202"><span class="linenos">202</span></a><span class="w"> </span><span class="sd">"""Determines whether division by zero throws an error (`False`) or returns NULL (`True`)."""</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="n">CONCAT_COALESCE</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Dialect-205"><a href="#Dialect-205"><span class="linenos">205</span></a><span class="w"> </span><span class="sd">"""A `NULL` arg in `CONCAT` yields `NULL` by default, but in some dialects it yields an empty string."""</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="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-208"><a href="#Dialect-208"><span class="linenos">208</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-209"><a href="#Dialect-209"><span class="linenos">209</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-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">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="w"> </span><span class="sd">"""Associates this dialect's time formats with their equivalent Python `strftime` format."""</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="c1"># https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#format_model_rules_date_time</span> -</span><span id="Dialect-215"><a href="#Dialect-215"><span class="linenos">215</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-216"><a href="#Dialect-216"><span class="linenos">216</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-217"><a href="#Dialect-217"><span class="linenos">217</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect-218"><a href="#Dialect-218"><span class="linenos">218</span></a><span class="sd"> Helper which is used for parsing the special syntax `CAST(x AS DATE FORMAT 'yyyy')`.</span> -</span><span id="Dialect-219"><a href="#Dialect-219"><span class="linenos">219</span></a><span class="sd"> If empty, the corresponding trie will be constructed off of `TIME_MAPPING`.</span> -</span><span id="Dialect-220"><a href="#Dialect-220"><span class="linenos">220</span></a><span class="sd"> """</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="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-223"><a href="#Dialect-223"><span class="linenos">223</span></a><span class="w"> </span><span class="sd">"""Mapping of an unescaped escape sequence to the corresponding character."""</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="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-226"><a href="#Dialect-226"><span class="linenos">226</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect-227"><a href="#Dialect-227"><span class="linenos">227</span></a><span class="sd"> Columns that are auto-generated by the engine corresponding to this dialect.</span> -</span><span id="Dialect-228"><a href="#Dialect-228"><span class="linenos">228</span></a><span class="sd"> For example, such columns may be excluded from `SELECT *` queries.</span> -</span><span id="Dialect-229"><a href="#Dialect-229"><span class="linenos">229</span></a><span class="sd"> """</span> -</span><span id="Dialect-230"><a href="#Dialect-230"><span class="linenos">230</span></a> -</span><span id="Dialect-231"><a href="#Dialect-231"><span class="linenos">231</span></a> <span class="n">PREFER_CTE_ALIAS_COLUMN</span> <span class="o">=</span> <span class="kc">False</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"> Some dialects, such as Snowflake, allow you to reference a CTE column alias in the</span> -</span><span id="Dialect-234"><a href="#Dialect-234"><span class="linenos">234</span></a><span class="sd"> HAVING clause of the CTE. This flag will cause the CTE alias columns to override</span> -</span><span id="Dialect-235"><a href="#Dialect-235"><span class="linenos">235</span></a><span class="sd"> any projection aliases in the subquery.</span> -</span><span id="Dialect-236"><a href="#Dialect-236"><span class="linenos">236</span></a> -</span><span id="Dialect-237"><a href="#Dialect-237"><span class="linenos">237</span></a><span class="sd"> For example,</span> -</span><span id="Dialect-238"><a href="#Dialect-238"><span class="linenos">238</span></a><span class="sd"> WITH y(c) AS (</span> -</span><span id="Dialect-239"><a href="#Dialect-239"><span class="linenos">239</span></a><span class="sd"> SELECT SUM(a) FROM (SELECT 1 a) AS x HAVING c > 0</span> -</span><span id="Dialect-240"><a href="#Dialect-240"><span class="linenos">240</span></a><span class="sd"> ) SELECT c FROM y;</span> -</span><span id="Dialect-241"><a href="#Dialect-241"><span class="linenos">241</span></a> -</span><span id="Dialect-242"><a href="#Dialect-242"><span class="linenos">242</span></a><span class="sd"> will be rewritten as</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect-150"><a href="#Dialect-150"><span class="linenos">150</span></a><span class="k">class</span> <span class="nc">Dialect</span><span class="p">(</span><span class="n">metaclass</span><span class="o">=</span><span class="n">_Dialect</span><span class="p">):</span> +</span><span id="Dialect-151"><a href="#Dialect-151"><span class="linenos">151</span></a> <span class="n">INDEX_OFFSET</span> <span class="o">=</span> <span class="mi">0</span> +</span><span id="Dialect-152"><a href="#Dialect-152"><span class="linenos">152</span></a><span class="w"> </span><span class="sd">"""Determines the base index offset for arrays."""</span> +</span><span id="Dialect-153"><a href="#Dialect-153"><span class="linenos">153</span></a> +</span><span id="Dialect-154"><a href="#Dialect-154"><span class="linenos">154</span></a> <span class="n">WEEK_OFFSET</span> <span class="o">=</span> <span class="mi">0</span> +</span><span id="Dialect-155"><a href="#Dialect-155"><span class="linenos">155</span></a><span class="w"> </span><span class="sd">"""Determines the day of week of DATE_TRUNC(week). Defaults to 0 (Monday). -1 would be Sunday."""</span> +</span><span id="Dialect-156"><a href="#Dialect-156"><span class="linenos">156</span></a> +</span><span id="Dialect-157"><a href="#Dialect-157"><span class="linenos">157</span></a> <span class="n">UNNEST_COLUMN_ONLY</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Dialect-158"><a href="#Dialect-158"><span class="linenos">158</span></a><span class="w"> </span><span class="sd">"""Determines whether or not `UNNEST` table aliases are treated as column aliases."""</span> +</span><span id="Dialect-159"><a href="#Dialect-159"><span class="linenos">159</span></a> +</span><span id="Dialect-160"><a href="#Dialect-160"><span class="linenos">160</span></a> <span class="n">ALIAS_POST_TABLESAMPLE</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Dialect-161"><a href="#Dialect-161"><span class="linenos">161</span></a><span class="w"> </span><span class="sd">"""Determines whether or not the table alias comes after tablesample."""</span> +</span><span id="Dialect-162"><a href="#Dialect-162"><span class="linenos">162</span></a> +</span><span id="Dialect-163"><a href="#Dialect-163"><span class="linenos">163</span></a> <span class="n">TABLESAMPLE_SIZE_IS_PERCENT</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Dialect-164"><a href="#Dialect-164"><span class="linenos">164</span></a><span class="w"> </span><span class="sd">"""Determines whether or not a size in the table sample clause represents percentage."""</span> +</span><span id="Dialect-165"><a href="#Dialect-165"><span class="linenos">165</span></a> +</span><span id="Dialect-166"><a href="#Dialect-166"><span class="linenos">166</span></a> <span class="n">NORMALIZATION_STRATEGY</span> <span class="o">=</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">LOWERCASE</span> +</span><span id="Dialect-167"><a href="#Dialect-167"><span class="linenos">167</span></a><span class="w"> </span><span class="sd">"""Specifies the strategy according to which identifiers should be normalized."""</span> +</span><span id="Dialect-168"><a href="#Dialect-168"><span class="linenos">168</span></a> +</span><span id="Dialect-169"><a href="#Dialect-169"><span class="linenos">169</span></a> <span class="n">IDENTIFIERS_CAN_START_WITH_DIGIT</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Dialect-170"><a href="#Dialect-170"><span class="linenos">170</span></a><span class="w"> </span><span class="sd">"""Determines whether or not an unquoted identifier can start with a digit."""</span> +</span><span id="Dialect-171"><a href="#Dialect-171"><span class="linenos">171</span></a> +</span><span id="Dialect-172"><a href="#Dialect-172"><span class="linenos">172</span></a> <span class="n">DPIPE_IS_STRING_CONCAT</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Dialect-173"><a href="#Dialect-173"><span class="linenos">173</span></a><span class="w"> </span><span class="sd">"""Determines whether or not the DPIPE token (`||`) is a string concatenation operator."""</span> +</span><span id="Dialect-174"><a href="#Dialect-174"><span class="linenos">174</span></a> +</span><span id="Dialect-175"><a href="#Dialect-175"><span class="linenos">175</span></a> <span class="n">STRICT_STRING_CONCAT</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Dialect-176"><a href="#Dialect-176"><span class="linenos">176</span></a><span class="w"> </span><span class="sd">"""Determines whether or not `CONCAT`'s arguments must be strings."""</span> +</span><span id="Dialect-177"><a href="#Dialect-177"><span class="linenos">177</span></a> +</span><span id="Dialect-178"><a href="#Dialect-178"><span class="linenos">178</span></a> <span class="n">SUPPORTS_USER_DEFINED_TYPES</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Dialect-179"><a href="#Dialect-179"><span class="linenos">179</span></a><span class="w"> </span><span class="sd">"""Determines whether or not user-defined data types are supported."""</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">SUPPORTS_SEMI_ANTI_JOIN</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Dialect-182"><a href="#Dialect-182"><span class="linenos">182</span></a><span class="w"> </span><span class="sd">"""Determines whether or not `SEMI` or `ANTI` joins are supported."""</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">NORMALIZE_FUNCTIONS</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">|</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"upper"</span> +</span><span id="Dialect-185"><a href="#Dialect-185"><span class="linenos">185</span></a><span class="w"> </span><span class="sd">"""Determines how function names are going to be normalized."""</span> +</span><span id="Dialect-186"><a href="#Dialect-186"><span class="linenos">186</span></a> +</span><span id="Dialect-187"><a href="#Dialect-187"><span class="linenos">187</span></a> <span class="n">LOG_BASE_FIRST</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Dialect-188"><a href="#Dialect-188"><span class="linenos">188</span></a><span class="w"> </span><span class="sd">"""Determines whether the base comes first in the `LOG` function."""</span> +</span><span id="Dialect-189"><a href="#Dialect-189"><span class="linenos">189</span></a> +</span><span id="Dialect-190"><a href="#Dialect-190"><span class="linenos">190</span></a> <span class="n">NULL_ORDERING</span> <span class="o">=</span> <span class="s2">"nulls_are_small"</span> +</span><span id="Dialect-191"><a href="#Dialect-191"><span class="linenos">191</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect-192"><a href="#Dialect-192"><span class="linenos">192</span></a><span class="sd"> Indicates the default `NULL` ordering method to use if not explicitly set.</span> +</span><span id="Dialect-193"><a href="#Dialect-193"><span class="linenos">193</span></a><span class="sd"> Possible values: `"nulls_are_small"`, `"nulls_are_large"`, `"nulls_are_last"`</span> +</span><span id="Dialect-194"><a href="#Dialect-194"><span class="linenos">194</span></a><span class="sd"> """</span> +</span><span id="Dialect-195"><a href="#Dialect-195"><span class="linenos">195</span></a> +</span><span id="Dialect-196"><a href="#Dialect-196"><span class="linenos">196</span></a> <span class="n">TYPED_DIVISION</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Dialect-197"><a href="#Dialect-197"><span class="linenos">197</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect-198"><a href="#Dialect-198"><span class="linenos">198</span></a><span class="sd"> Whether the behavior of `a / b` depends on the types of `a` and `b`.</span> +</span><span id="Dialect-199"><a href="#Dialect-199"><span class="linenos">199</span></a><span class="sd"> False means `a / b` is always float division.</span> +</span><span id="Dialect-200"><a href="#Dialect-200"><span class="linenos">200</span></a><span class="sd"> True means `a / b` is integer division if both `a` and `b` are integers.</span> +</span><span id="Dialect-201"><a href="#Dialect-201"><span class="linenos">201</span></a><span class="sd"> """</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">SAFE_DIVISION</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Dialect-204"><a href="#Dialect-204"><span class="linenos">204</span></a><span class="w"> </span><span class="sd">"""Determines whether division by zero throws an error (`False`) or returns NULL (`True`)."""</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">CONCAT_COALESCE</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Dialect-207"><a href="#Dialect-207"><span class="linenos">207</span></a><span class="w"> </span><span class="sd">"""A `NULL` arg in `CONCAT` yields `NULL` by default, but in some dialects it yields an empty string."""</span> +</span><span id="Dialect-208"><a href="#Dialect-208"><span class="linenos">208</span></a> +</span><span id="Dialect-209"><a href="#Dialect-209"><span class="linenos">209</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-210"><a href="#Dialect-210"><span class="linenos">210</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-211"><a href="#Dialect-211"><span class="linenos">211</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-212"><a href="#Dialect-212"><span class="linenos">212</span></a> +</span><span id="Dialect-213"><a href="#Dialect-213"><span class="linenos">213</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-214"><a href="#Dialect-214"><span class="linenos">214</span></a><span class="w"> </span><span class="sd">"""Associates this dialect's time formats with their equivalent Python `strftime` format."""</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"># https://cloud.google.com/bigquery/docs/reference/standard-sql/format-elements#format_model_rules_date_time</span> +</span><span id="Dialect-217"><a href="#Dialect-217"><span class="linenos">217</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-218"><a href="#Dialect-218"><span class="linenos">218</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-219"><a href="#Dialect-219"><span class="linenos">219</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect-220"><a href="#Dialect-220"><span class="linenos">220</span></a><span class="sd"> Helper which is used for parsing the special syntax `CAST(x AS DATE FORMAT 'yyyy')`.</span> +</span><span id="Dialect-221"><a href="#Dialect-221"><span class="linenos">221</span></a><span class="sd"> If empty, the corresponding trie will be constructed off of `TIME_MAPPING`.</span> +</span><span id="Dialect-222"><a href="#Dialect-222"><span class="linenos">222</span></a><span class="sd"> """</span> +</span><span id="Dialect-223"><a href="#Dialect-223"><span class="linenos">223</span></a> +</span><span id="Dialect-224"><a href="#Dialect-224"><span class="linenos">224</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-225"><a href="#Dialect-225"><span class="linenos">225</span></a><span class="w"> </span><span class="sd">"""Mapping of an unescaped escape sequence to the corresponding character."""</span> +</span><span id="Dialect-226"><a href="#Dialect-226"><span class="linenos">226</span></a> +</span><span id="Dialect-227"><a href="#Dialect-227"><span class="linenos">227</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-228"><a href="#Dialect-228"><span class="linenos">228</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect-229"><a href="#Dialect-229"><span class="linenos">229</span></a><span class="sd"> Columns that are auto-generated by the engine corresponding to this dialect.</span> +</span><span id="Dialect-230"><a href="#Dialect-230"><span class="linenos">230</span></a><span class="sd"> For example, such columns may be excluded from `SELECT *` queries.</span> +</span><span id="Dialect-231"><a href="#Dialect-231"><span class="linenos">231</span></a><span class="sd"> """</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="n">PREFER_CTE_ALIAS_COLUMN</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Dialect-234"><a href="#Dialect-234"><span class="linenos">234</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect-235"><a href="#Dialect-235"><span class="linenos">235</span></a><span class="sd"> Some dialects, such as Snowflake, allow you to reference a CTE column alias in the</span> +</span><span id="Dialect-236"><a href="#Dialect-236"><span class="linenos">236</span></a><span class="sd"> HAVING clause of the CTE. This flag will cause the CTE alias columns to override</span> +</span><span id="Dialect-237"><a href="#Dialect-237"><span class="linenos">237</span></a><span class="sd"> any projection aliases in the subquery.</span> +</span><span id="Dialect-238"><a href="#Dialect-238"><span class="linenos">238</span></a> +</span><span id="Dialect-239"><a href="#Dialect-239"><span class="linenos">239</span></a><span class="sd"> For example,</span> +</span><span id="Dialect-240"><a href="#Dialect-240"><span class="linenos">240</span></a><span class="sd"> WITH y(c) AS (</span> +</span><span id="Dialect-241"><a href="#Dialect-241"><span class="linenos">241</span></a><span class="sd"> SELECT SUM(a) FROM (SELECT 1 a) AS x HAVING c > 0</span> +</span><span id="Dialect-242"><a href="#Dialect-242"><span class="linenos">242</span></a><span class="sd"> ) SELECT c FROM y;</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"> WITH y(c) AS (</span> -</span><span id="Dialect-245"><a href="#Dialect-245"><span class="linenos">245</span></a><span class="sd"> SELECT SUM(a) AS c FROM (SELECT 1 AS a) AS x HAVING c > 0</span> -</span><span id="Dialect-246"><a href="#Dialect-246"><span class="linenos">246</span></a><span class="sd"> ) SELECT c FROM y;</span> -</span><span id="Dialect-247"><a href="#Dialect-247"><span class="linenos">247</span></a><span class="sd"> """</span> -</span><span id="Dialect-248"><a href="#Dialect-248"><span class="linenos">248</span></a> -</span><span id="Dialect-249"><a href="#Dialect-249"><span class="linenos">249</span></a> <span class="c1"># --- Autofilled ---</span> +</span><span id="Dialect-244"><a href="#Dialect-244"><span class="linenos">244</span></a><span class="sd"> will be rewritten as</span> +</span><span id="Dialect-245"><a href="#Dialect-245"><span class="linenos">245</span></a> +</span><span id="Dialect-246"><a href="#Dialect-246"><span class="linenos">246</span></a><span class="sd"> WITH y(c) AS (</span> +</span><span id="Dialect-247"><a href="#Dialect-247"><span class="linenos">247</span></a><span class="sd"> SELECT SUM(a) AS c FROM (SELECT 1 AS a) AS x HAVING c > 0</span> +</span><span id="Dialect-248"><a href="#Dialect-248"><span class="linenos">248</span></a><span class="sd"> ) SELECT c FROM y;</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="n">tokenizer_class</span> <span class="o">=</span> <span class="n">Tokenizer</span> -</span><span id="Dialect-252"><a href="#Dialect-252"><span class="linenos">252</span></a> <span class="n">parser_class</span> <span class="o">=</span> <span class="n">Parser</span> -</span><span id="Dialect-253"><a href="#Dialect-253"><span class="linenos">253</span></a> <span class="n">generator_class</span> <span class="o">=</span> <span class="n">Generator</span> -</span><span id="Dialect-254"><a href="#Dialect-254"><span class="linenos">254</span></a> -</span><span id="Dialect-255"><a href="#Dialect-255"><span class="linenos">255</span></a> <span class="c1"># A trie of the time_mapping keys</span> -</span><span id="Dialect-256"><a href="#Dialect-256"><span class="linenos">256</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-257"><a href="#Dialect-257"><span class="linenos">257</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-258"><a href="#Dialect-258"><span class="linenos">258</span></a> -</span><span id="Dialect-259"><a href="#Dialect-259"><span class="linenos">259</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-260"><a href="#Dialect-260"><span class="linenos">260</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-261"><a href="#Dialect-261"><span class="linenos">261</span></a> -</span><span id="Dialect-262"><a href="#Dialect-262"><span class="linenos">262</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-251"><a href="#Dialect-251"><span class="linenos">251</span></a> <span class="c1"># --- Autofilled ---</span> +</span><span id="Dialect-252"><a href="#Dialect-252"><span class="linenos">252</span></a> +</span><span id="Dialect-253"><a href="#Dialect-253"><span class="linenos">253</span></a> <span class="n">tokenizer_class</span> <span class="o">=</span> <span class="n">Tokenizer</span> +</span><span id="Dialect-254"><a href="#Dialect-254"><span class="linenos">254</span></a> <span class="n">parser_class</span> <span class="o">=</span> <span class="n">Parser</span> +</span><span id="Dialect-255"><a href="#Dialect-255"><span class="linenos">255</span></a> <span class="n">generator_class</span> <span class="o">=</span> <span class="n">Generator</span> +</span><span id="Dialect-256"><a href="#Dialect-256"><span class="linenos">256</span></a> +</span><span id="Dialect-257"><a href="#Dialect-257"><span class="linenos">257</span></a> <span class="c1"># A trie of the time_mapping keys</span> +</span><span id="Dialect-258"><a href="#Dialect-258"><span class="linenos">258</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-259"><a href="#Dialect-259"><span class="linenos">259</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-260"><a href="#Dialect-260"><span class="linenos">260</span></a> +</span><span id="Dialect-261"><a href="#Dialect-261"><span class="linenos">261</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-262"><a href="#Dialect-262"><span class="linenos">262</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-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="c1"># Delimiters for string literals and identifiers</span> -</span><span id="Dialect-265"><a href="#Dialect-265"><span class="linenos">265</span></a> <span class="n">QUOTE_START</span> <span class="o">=</span> <span class="s2">"'"</span> -</span><span id="Dialect-266"><a href="#Dialect-266"><span class="linenos">266</span></a> <span class="n">QUOTE_END</span> <span class="o">=</span> <span class="s2">"'"</span> -</span><span id="Dialect-267"><a href="#Dialect-267"><span class="linenos">267</span></a> <span class="n">IDENTIFIER_START</span> <span class="o">=</span> <span class="s1">'"'</span> -</span><span id="Dialect-268"><a href="#Dialect-268"><span class="linenos">268</span></a> <span class="n">IDENTIFIER_END</span> <span class="o">=</span> <span class="s1">'"'</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="c1"># Delimiters for bit, hex, byte and unicode literals</span> -</span><span id="Dialect-271"><a href="#Dialect-271"><span class="linenos">271</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-272"><a href="#Dialect-272"><span class="linenos">272</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-273"><a href="#Dialect-273"><span class="linenos">273</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-274"><a href="#Dialect-274"><span class="linenos">274</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-275"><a href="#Dialect-275"><span class="linenos">275</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-276"><a href="#Dialect-276"><span class="linenos">276</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-277"><a href="#Dialect-277"><span class="linenos">277</span></a> <span class="n">UNICODE_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-278"><a href="#Dialect-278"><span class="linenos">278</span></a> <span class="n">UNICODE_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-279"><a href="#Dialect-279"><span class="linenos">279</span></a> -</span><span id="Dialect-280"><a href="#Dialect-280"><span class="linenos">280</span></a> <span class="nd">@classmethod</span> -</span><span id="Dialect-281"><a href="#Dialect-281"><span class="linenos">281</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-282"><a href="#Dialect-282"><span class="linenos">282</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect-283"><a href="#Dialect-283"><span class="linenos">283</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-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="sd"> Args:</span> -</span><span id="Dialect-286"><a href="#Dialect-286"><span class="linenos">286</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-287"><a href="#Dialect-287"><span class="linenos">287</span></a><span class="sd"> additional key-value pairs that are separated by commas and are used to specify</span> -</span><span id="Dialect-288"><a href="#Dialect-288"><span class="linenos">288</span></a><span class="sd"> dialect settings, such as whether the dialect's identifiers are case-sensitive.</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="sd"> Example:</span> -</span><span id="Dialect-291"><a href="#Dialect-291"><span class="linenos">291</span></a><span class="sd"> >>> dialect = dialect_class = get_or_raise("duckdb")</span> -</span><span id="Dialect-292"><a href="#Dialect-292"><span class="linenos">292</span></a><span class="sd"> >>> dialect = get_or_raise("mysql, normalization_strategy = case_sensitive")</span> -</span><span id="Dialect-293"><a href="#Dialect-293"><span class="linenos">293</span></a> -</span><span id="Dialect-294"><a href="#Dialect-294"><span class="linenos">294</span></a><span class="sd"> Returns:</span> -</span><span id="Dialect-295"><a href="#Dialect-295"><span class="linenos">295</span></a><span class="sd"> The corresponding Dialect instance.</span> -</span><span id="Dialect-296"><a href="#Dialect-296"><span class="linenos">296</span></a><span class="sd"> """</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">if</span> <span class="ow">not</span> <span class="n">dialect</span><span class="p">:</span> -</span><span id="Dialect-299"><a href="#Dialect-299"><span class="linenos">299</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span> -</span><span id="Dialect-300"><a href="#Dialect-300"><span class="linenos">300</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-301"><a href="#Dialect-301"><span class="linenos">301</span></a> <span class="k">return</span> <span class="n">dialect</span><span class="p">()</span> -</span><span id="Dialect-302"><a href="#Dialect-302"><span class="linenos">302</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-303"><a href="#Dialect-303"><span class="linenos">303</span></a> <span class="k">return</span> <span class="n">dialect</span> -</span><span id="Dialect-304"><a href="#Dialect-304"><span class="linenos">304</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-305"><a href="#Dialect-305"><span class="linenos">305</span></a> <span class="k">try</span><span class="p">:</span> -</span><span id="Dialect-306"><a href="#Dialect-306"><span class="linenos">306</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-307"><a href="#Dialect-307"><span class="linenos">307</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-308"><a href="#Dialect-308"><span class="linenos">308</span></a> <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> -</span><span id="Dialect-309"><a href="#Dialect-309"><span class="linenos">309</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> -</span><span id="Dialect-310"><a href="#Dialect-310"><span class="linenos">310</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-311"><a href="#Dialect-311"><span class="linenos">311</span></a> <span class="s2">"Please use the correct format: 'dialect [, k1 = v2 [, ...]]'."</span> -</span><span id="Dialect-312"><a href="#Dialect-312"><span class="linenos">312</span></a> <span class="p">)</span> -</span><span id="Dialect-313"><a href="#Dialect-313"><span class="linenos">313</span></a> -</span><span id="Dialect-314"><a href="#Dialect-314"><span class="linenos">314</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-315"><a href="#Dialect-315"><span class="linenos">315</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-316"><a href="#Dialect-316"><span class="linenos">316</span></a> <span class="kn">from</span> <span class="nn">difflib</span> <span class="kn">import</span> <span class="n">get_close_matches</span> -</span><span id="Dialect-317"><a href="#Dialect-317"><span class="linenos">317</span></a> -</span><span id="Dialect-318"><a href="#Dialect-318"><span class="linenos">318</span></a> <span class="n">similar</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">get_close_matches</span><span class="p">(</span><span class="n">dialect_name</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">classes</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">""</span> -</span><span id="Dialect-319"><a href="#Dialect-319"><span class="linenos">319</span></a> <span class="k">if</span> <span class="n">similar</span><span class="p">:</span> -</span><span id="Dialect-320"><a href="#Dialect-320"><span class="linenos">320</span></a> <span class="n">similar</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" Did you mean </span><span class="si">{</span><span class="n">similar</span><span class="si">}</span><span class="s2">?"</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="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="si">{</span><span class="n">similar</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="Dialect-264"><a href="#Dialect-264"><span class="linenos">264</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-265"><a href="#Dialect-265"><span class="linenos">265</span></a> +</span><span id="Dialect-266"><a href="#Dialect-266"><span class="linenos">266</span></a> <span class="c1"># Delimiters for string literals and identifiers</span> +</span><span id="Dialect-267"><a href="#Dialect-267"><span class="linenos">267</span></a> <span class="n">QUOTE_START</span> <span class="o">=</span> <span class="s2">"'"</span> +</span><span id="Dialect-268"><a href="#Dialect-268"><span class="linenos">268</span></a> <span class="n">QUOTE_END</span> <span class="o">=</span> <span class="s2">"'"</span> +</span><span id="Dialect-269"><a href="#Dialect-269"><span class="linenos">269</span></a> <span class="n">IDENTIFIER_START</span> <span class="o">=</span> <span class="s1">'"'</span> +</span><span id="Dialect-270"><a href="#Dialect-270"><span class="linenos">270</span></a> <span class="n">IDENTIFIER_END</span> <span class="o">=</span> <span class="s1">'"'</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="c1"># Delimiters for bit, hex, byte and unicode literals</span> +</span><span id="Dialect-273"><a href="#Dialect-273"><span class="linenos">273</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-274"><a href="#Dialect-274"><span class="linenos">274</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-275"><a href="#Dialect-275"><span class="linenos">275</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-276"><a href="#Dialect-276"><span class="linenos">276</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-277"><a href="#Dialect-277"><span class="linenos">277</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-278"><a href="#Dialect-278"><span class="linenos">278</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-279"><a href="#Dialect-279"><span class="linenos">279</span></a> <span class="n">UNICODE_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-280"><a href="#Dialect-280"><span class="linenos">280</span></a> <span class="n">UNICODE_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-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="nd">@classmethod</span> +</span><span id="Dialect-283"><a href="#Dialect-283"><span class="linenos">283</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-284"><a href="#Dialect-284"><span class="linenos">284</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect-285"><a href="#Dialect-285"><span class="linenos">285</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-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="sd"> Args:</span> +</span><span id="Dialect-288"><a href="#Dialect-288"><span class="linenos">288</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-289"><a href="#Dialect-289"><span class="linenos">289</span></a><span class="sd"> additional key-value pairs that are separated by commas and are used to specify</span> +</span><span id="Dialect-290"><a href="#Dialect-290"><span class="linenos">290</span></a><span class="sd"> dialect settings, such as whether the dialect's identifiers are case-sensitive.</span> +</span><span id="Dialect-291"><a href="#Dialect-291"><span class="linenos">291</span></a> +</span><span id="Dialect-292"><a href="#Dialect-292"><span class="linenos">292</span></a><span class="sd"> Example:</span> +</span><span id="Dialect-293"><a href="#Dialect-293"><span class="linenos">293</span></a><span class="sd"> >>> dialect = dialect_class = get_or_raise("duckdb")</span> +</span><span id="Dialect-294"><a href="#Dialect-294"><span class="linenos">294</span></a><span class="sd"> >>> dialect = get_or_raise("mysql, normalization_strategy = case_sensitive")</span> +</span><span id="Dialect-295"><a href="#Dialect-295"><span class="linenos">295</span></a> +</span><span id="Dialect-296"><a href="#Dialect-296"><span class="linenos">296</span></a><span class="sd"> Returns:</span> +</span><span id="Dialect-297"><a href="#Dialect-297"><span class="linenos">297</span></a><span class="sd"> The corresponding Dialect instance.</span> +</span><span id="Dialect-298"><a href="#Dialect-298"><span class="linenos">298</span></a><span class="sd"> """</span> +</span><span id="Dialect-299"><a href="#Dialect-299"><span class="linenos">299</span></a> +</span><span id="Dialect-300"><a href="#Dialect-300"><span class="linenos">300</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-301"><a href="#Dialect-301"><span class="linenos">301</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span> +</span><span id="Dialect-302"><a href="#Dialect-302"><span class="linenos">302</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-303"><a href="#Dialect-303"><span class="linenos">303</span></a> <span class="k">return</span> <span class="n">dialect</span><span class="p">()</span> +</span><span id="Dialect-304"><a href="#Dialect-304"><span class="linenos">304</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-305"><a href="#Dialect-305"><span class="linenos">305</span></a> <span class="k">return</span> <span class="n">dialect</span> +</span><span id="Dialect-306"><a href="#Dialect-306"><span class="linenos">306</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-307"><a href="#Dialect-307"><span class="linenos">307</span></a> <span class="k">try</span><span class="p">:</span> +</span><span id="Dialect-308"><a href="#Dialect-308"><span class="linenos">308</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-309"><a href="#Dialect-309"><span class="linenos">309</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-310"><a href="#Dialect-310"><span class="linenos">310</span></a> <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> +</span><span id="Dialect-311"><a href="#Dialect-311"><span class="linenos">311</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> +</span><span id="Dialect-312"><a href="#Dialect-312"><span class="linenos">312</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-313"><a href="#Dialect-313"><span class="linenos">313</span></a> <span class="s2">"Please use the correct format: 'dialect [, k1 = v2 [, ...]]'."</span> +</span><span id="Dialect-314"><a href="#Dialect-314"><span class="linenos">314</span></a> <span class="p">)</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="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-317"><a href="#Dialect-317"><span class="linenos">317</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-318"><a href="#Dialect-318"><span class="linenos">318</span></a> <span class="kn">from</span> <span class="nn">difflib</span> <span class="kn">import</span> <span class="n">get_close_matches</span> +</span><span id="Dialect-319"><a href="#Dialect-319"><span class="linenos">319</span></a> +</span><span id="Dialect-320"><a href="#Dialect-320"><span class="linenos">320</span></a> <span class="n">similar</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">get_close_matches</span><span class="p">(</span><span class="n">dialect_name</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">classes</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">""</span> +</span><span id="Dialect-321"><a href="#Dialect-321"><span class="linenos">321</span></a> <span class="k">if</span> <span class="n">similar</span><span class="p">:</span> +</span><span id="Dialect-322"><a href="#Dialect-322"><span class="linenos">322</span></a> <span class="n">similar</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" Did you mean </span><span class="si">{</span><span class="n">similar</span><span class="si">}</span><span class="s2">?"</span> </span><span id="Dialect-323"><a href="#Dialect-323"><span class="linenos">323</span></a> -</span><span id="Dialect-324"><a href="#Dialect-324"><span class="linenos">324</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-324"><a href="#Dialect-324"><span class="linenos">324</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="si">{</span><span class="n">similar</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> </span><span id="Dialect-325"><a href="#Dialect-325"><span class="linenos">325</span></a> -</span><span id="Dialect-326"><a href="#Dialect-326"><span class="linenos">326</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-326"><a href="#Dialect-326"><span class="linenos">326</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-327"><a href="#Dialect-327"><span class="linenos">327</span></a> -</span><span id="Dialect-328"><a href="#Dialect-328"><span class="linenos">328</span></a> <span class="nd">@classmethod</span> -</span><span id="Dialect-329"><a href="#Dialect-329"><span class="linenos">329</span></a> <span class="k">def</span> <span class="nf">format_time</span><span class="p">(</span> -</span><span id="Dialect-330"><a href="#Dialect-330"><span class="linenos">330</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-331"><a href="#Dialect-331"><span class="linenos">331</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-332"><a href="#Dialect-332"><span class="linenos">332</span></a><span class="w"> </span><span class="sd">"""Converts a time format in this dialect to its equivalent Python `strftime` format."""</span> -</span><span id="Dialect-333"><a href="#Dialect-333"><span class="linenos">333</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-334"><a href="#Dialect-334"><span class="linenos">334</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-335"><a href="#Dialect-335"><span class="linenos">335</span></a> <span class="c1"># the time formats are quoted</span> -</span><span id="Dialect-336"><a href="#Dialect-336"><span class="linenos">336</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-337"><a href="#Dialect-337"><span class="linenos">337</span></a> <span class="p">)</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">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-340"><a href="#Dialect-340"><span class="linenos">340</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-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">return</span> <span class="n">expression</span> +</span><span id="Dialect-328"><a href="#Dialect-328"><span class="linenos">328</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-329"><a href="#Dialect-329"><span class="linenos">329</span></a> +</span><span id="Dialect-330"><a href="#Dialect-330"><span class="linenos">330</span></a> <span class="nd">@classmethod</span> +</span><span id="Dialect-331"><a href="#Dialect-331"><span class="linenos">331</span></a> <span class="k">def</span> <span class="nf">format_time</span><span class="p">(</span> +</span><span id="Dialect-332"><a href="#Dialect-332"><span class="linenos">332</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-333"><a href="#Dialect-333"><span class="linenos">333</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-334"><a href="#Dialect-334"><span class="linenos">334</span></a><span class="w"> </span><span class="sd">"""Converts a time format in this dialect to its equivalent Python `strftime` format."""</span> +</span><span id="Dialect-335"><a href="#Dialect-335"><span class="linenos">335</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-336"><a href="#Dialect-336"><span class="linenos">336</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-337"><a href="#Dialect-337"><span class="linenos">337</span></a> <span class="c1"># the time formats are quoted</span> +</span><span id="Dialect-338"><a href="#Dialect-338"><span class="linenos">338</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-339"><a href="#Dialect-339"><span class="linenos">339</span></a> <span class="p">)</span> +</span><span id="Dialect-340"><a href="#Dialect-340"><span class="linenos">340</span></a> +</span><span id="Dialect-341"><a href="#Dialect-341"><span class="linenos">341</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-342"><a href="#Dialect-342"><span class="linenos">342</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-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="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-345"><a href="#Dialect-345"><span class="linenos">345</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-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="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-348"><a href="#Dialect-348"><span class="linenos">348</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-349"><a href="#Dialect-349"><span class="linenos">349</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Dialect-350"><a href="#Dialect-350"><span class="linenos">350</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-351"><a href="#Dialect-351"><span class="linenos">351</span></a> -</span><span id="Dialect-352"><a href="#Dialect-352"><span class="linenos">352</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-353"><a href="#Dialect-353"><span class="linenos">353</span></a> <span class="c1"># Does not currently take dialect state into account</span> -</span><span id="Dialect-354"><a href="#Dialect-354"><span class="linenos">354</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-355"><a href="#Dialect-355"><span class="linenos">355</span></a> -</span><span id="Dialect-356"><a href="#Dialect-356"><span class="linenos">356</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-357"><a href="#Dialect-357"><span class="linenos">357</span></a> <span class="c1"># Does not currently take dialect state into account</span> -</span><span id="Dialect-358"><a href="#Dialect-358"><span class="linenos">358</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-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="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-361"><a href="#Dialect-361"><span class="linenos">361</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect-362"><a href="#Dialect-362"><span class="linenos">362</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-363"><a href="#Dialect-363"><span class="linenos">363</span></a> -</span><span id="Dialect-364"><a href="#Dialect-364"><span class="linenos">364</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-365"><a href="#Dialect-365"><span class="linenos">365</span></a><span class="sd"> lowercases all unquoted identifiers. On the other hand, Snowflake uppercases them, so</span> -</span><span id="Dialect-366"><a href="#Dialect-366"><span class="linenos">366</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-367"><a href="#Dialect-367"><span class="linenos">367</span></a><span class="sd"> and so any normalization would be prohibited in order to avoid "breaking" the identifier.</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="sd"> There are also dialects like Spark, which are case-insensitive even when quotes are</span> -</span><span id="Dialect-370"><a href="#Dialect-370"><span class="linenos">370</span></a><span class="sd"> present, and dialects like MySQL, whose resolution rules match those employed by the</span> -</span><span id="Dialect-371"><a href="#Dialect-371"><span class="linenos">371</span></a><span class="sd"> underlying operating system, for example they may always be case-sensitive in Linux.</span> -</span><span id="Dialect-372"><a href="#Dialect-372"><span class="linenos">372</span></a> -</span><span id="Dialect-373"><a href="#Dialect-373"><span class="linenos">373</span></a><span class="sd"> Finally, the normalization behavior of some engines can even be controlled through flags,</span> -</span><span id="Dialect-374"><a href="#Dialect-374"><span class="linenos">374</span></a><span class="sd"> like in Redshift's case, where users can explicitly set enable_case_sensitive_identifier.</span> -</span><span id="Dialect-375"><a href="#Dialect-375"><span class="linenos">375</span></a> -</span><span id="Dialect-376"><a href="#Dialect-376"><span class="linenos">376</span></a><span class="sd"> SQLGlot aims to understand and handle all of these different behaviors gracefully, so</span> -</span><span id="Dialect-377"><a href="#Dialect-377"><span class="linenos">377</span></a><span class="sd"> that it can analyze queries in the optimizer and successfully capture their semantics.</span> -</span><span id="Dialect-378"><a href="#Dialect-378"><span class="linenos">378</span></a><span class="sd"> """</span> -</span><span id="Dialect-379"><a href="#Dialect-379"><span class="linenos">379</span></a> <span class="k">if</span> <span class="p">(</span> -</span><span id="Dialect-380"><a href="#Dialect-380"><span class="linenos">380</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-381"><a href="#Dialect-381"><span class="linenos">381</span></a> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_SENSITIVE</span> -</span><span id="Dialect-382"><a href="#Dialect-382"><span class="linenos">382</span></a> <span class="ow">and</span> <span class="p">(</span> -</span><span id="Dialect-383"><a href="#Dialect-383"><span class="linenos">383</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-384"><a href="#Dialect-384"><span class="linenos">384</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-385"><a href="#Dialect-385"><span class="linenos">385</span></a> <span class="p">)</span> -</span><span id="Dialect-386"><a href="#Dialect-386"><span class="linenos">386</span></a> <span class="p">):</span> -</span><span id="Dialect-387"><a href="#Dialect-387"><span class="linenos">387</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> -</span><span id="Dialect-388"><a href="#Dialect-388"><span class="linenos">388</span></a> <span class="s2">"this"</span><span class="p">,</span> -</span><span id="Dialect-389"><a href="#Dialect-389"><span class="linenos">389</span></a> <span class="p">(</span> -</span><span id="Dialect-390"><a href="#Dialect-390"><span class="linenos">390</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-391"><a href="#Dialect-391"><span class="linenos">391</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-392"><a href="#Dialect-392"><span class="linenos">392</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-393"><a href="#Dialect-393"><span class="linenos">393</span></a> <span class="p">),</span> -</span><span id="Dialect-394"><a href="#Dialect-394"><span class="linenos">394</span></a> <span class="p">)</span> -</span><span id="Dialect-395"><a href="#Dialect-395"><span class="linenos">395</span></a> -</span><span id="Dialect-396"><a href="#Dialect-396"><span class="linenos">396</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="Dialect-344"><a href="#Dialect-344"><span class="linenos">344</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="Dialect-345"><a href="#Dialect-345"><span class="linenos">345</span></a> +</span><span id="Dialect-346"><a href="#Dialect-346"><span class="linenos">346</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-347"><a href="#Dialect-347"><span class="linenos">347</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-348"><a href="#Dialect-348"><span class="linenos">348</span></a> +</span><span id="Dialect-349"><a href="#Dialect-349"><span class="linenos">349</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-350"><a href="#Dialect-350"><span class="linenos">350</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-351"><a href="#Dialect-351"><span class="linenos">351</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Dialect-352"><a href="#Dialect-352"><span class="linenos">352</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-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="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-355"><a href="#Dialect-355"><span class="linenos">355</span></a> <span class="c1"># Does not currently take dialect state into account</span> +</span><span id="Dialect-356"><a href="#Dialect-356"><span class="linenos">356</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-357"><a href="#Dialect-357"><span class="linenos">357</span></a> +</span><span id="Dialect-358"><a href="#Dialect-358"><span class="linenos">358</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-359"><a href="#Dialect-359"><span class="linenos">359</span></a> <span class="c1"># Does not currently take dialect state into account</span> +</span><span id="Dialect-360"><a href="#Dialect-360"><span class="linenos">360</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-361"><a href="#Dialect-361"><span class="linenos">361</span></a> +</span><span id="Dialect-362"><a href="#Dialect-362"><span class="linenos">362</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-363"><a href="#Dialect-363"><span class="linenos">363</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect-364"><a href="#Dialect-364"><span class="linenos">364</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-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="sd"> For example, an identifier like `FoO` would be resolved as `foo` in Postgres, because it</span> +</span><span id="Dialect-367"><a href="#Dialect-367"><span class="linenos">367</span></a><span class="sd"> lowercases all unquoted identifiers. On the other hand, Snowflake uppercases them, so</span> +</span><span id="Dialect-368"><a href="#Dialect-368"><span class="linenos">368</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-369"><a href="#Dialect-369"><span class="linenos">369</span></a><span class="sd"> and so any normalization would be prohibited in order to avoid "breaking" the identifier.</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="sd"> There are also dialects like Spark, which are case-insensitive even when quotes are</span> +</span><span id="Dialect-372"><a href="#Dialect-372"><span class="linenos">372</span></a><span class="sd"> present, and dialects like MySQL, whose resolution rules match those employed by the</span> +</span><span id="Dialect-373"><a href="#Dialect-373"><span class="linenos">373</span></a><span class="sd"> underlying operating system, for example they may always be case-sensitive in Linux.</span> +</span><span id="Dialect-374"><a href="#Dialect-374"><span class="linenos">374</span></a> +</span><span id="Dialect-375"><a href="#Dialect-375"><span class="linenos">375</span></a><span class="sd"> Finally, the normalization behavior of some engines can even be controlled through flags,</span> +</span><span id="Dialect-376"><a href="#Dialect-376"><span class="linenos">376</span></a><span class="sd"> like in Redshift's case, where users can explicitly set enable_case_sensitive_identifier.</span> +</span><span id="Dialect-377"><a href="#Dialect-377"><span class="linenos">377</span></a> +</span><span id="Dialect-378"><a href="#Dialect-378"><span class="linenos">378</span></a><span class="sd"> SQLGlot aims to understand and handle all of these different behaviors gracefully, so</span> +</span><span id="Dialect-379"><a href="#Dialect-379"><span class="linenos">379</span></a><span class="sd"> that it can analyze queries in the optimizer and successfully capture their semantics.</span> +</span><span id="Dialect-380"><a href="#Dialect-380"><span class="linenos">380</span></a><span class="sd"> """</span> +</span><span id="Dialect-381"><a href="#Dialect-381"><span class="linenos">381</span></a> <span class="k">if</span> <span class="p">(</span> +</span><span id="Dialect-382"><a href="#Dialect-382"><span class="linenos">382</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-383"><a href="#Dialect-383"><span class="linenos">383</span></a> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_SENSITIVE</span> +</span><span id="Dialect-384"><a href="#Dialect-384"><span class="linenos">384</span></a> <span class="ow">and</span> <span class="p">(</span> +</span><span id="Dialect-385"><a href="#Dialect-385"><span class="linenos">385</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-386"><a href="#Dialect-386"><span class="linenos">386</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-387"><a href="#Dialect-387"><span class="linenos">387</span></a> <span class="p">)</span> +</span><span id="Dialect-388"><a href="#Dialect-388"><span class="linenos">388</span></a> <span class="p">):</span> +</span><span id="Dialect-389"><a href="#Dialect-389"><span class="linenos">389</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="Dialect-390"><a href="#Dialect-390"><span class="linenos">390</span></a> <span class="s2">"this"</span><span class="p">,</span> +</span><span id="Dialect-391"><a href="#Dialect-391"><span class="linenos">391</span></a> <span class="p">(</span> +</span><span id="Dialect-392"><a href="#Dialect-392"><span class="linenos">392</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-393"><a href="#Dialect-393"><span class="linenos">393</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-394"><a href="#Dialect-394"><span class="linenos">394</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-395"><a href="#Dialect-395"><span class="linenos">395</span></a> <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">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-399"><a href="#Dialect-399"><span class="linenos">399</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-400"><a href="#Dialect-400"><span class="linenos">400</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-401"><a href="#Dialect-401"><span class="linenos">401</span></a> <span class="k">return</span> <span class="kc">False</span> -</span><span id="Dialect-402"><a href="#Dialect-402"><span class="linenos">402</span></a> -</span><span id="Dialect-403"><a href="#Dialect-403"><span class="linenos">403</span></a> <span class="n">unsafe</span> <span class="o">=</span> <span class="p">(</span> -</span><span id="Dialect-404"><a href="#Dialect-404"><span class="linenos">404</span></a> <span class="nb">str</span><span class="o">.</span><span class="n">islower</span> -</span><span id="Dialect-405"><a href="#Dialect-405"><span class="linenos">405</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-406"><a href="#Dialect-406"><span class="linenos">406</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-407"><a href="#Dialect-407"><span class="linenos">407</span></a> <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="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-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">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-411"><a href="#Dialect-411"><span class="linenos">411</span></a><span class="w"> </span><span class="sd">"""Checks if text can be identified given an identify option.</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="sd"> Args:</span> -</span><span id="Dialect-414"><a href="#Dialect-414"><span class="linenos">414</span></a><span class="sd"> text: The text to check.</span> -</span><span id="Dialect-415"><a href="#Dialect-415"><span class="linenos">415</span></a><span class="sd"> identify:</span> -</span><span id="Dialect-416"><a href="#Dialect-416"><span class="linenos">416</span></a><span class="sd"> `"always"` or `True`: Always returns `True`.</span> -</span><span id="Dialect-417"><a href="#Dialect-417"><span class="linenos">417</span></a><span class="sd"> `"safe"`: Only returns `True` if the identifier is case-insensitive.</span> -</span><span id="Dialect-418"><a href="#Dialect-418"><span class="linenos">418</span></a> -</span><span id="Dialect-419"><a href="#Dialect-419"><span class="linenos">419</span></a><span class="sd"> Returns:</span> -</span><span id="Dialect-420"><a href="#Dialect-420"><span class="linenos">420</span></a><span class="sd"> Whether or not the given text can be identified.</span> -</span><span id="Dialect-421"><a href="#Dialect-421"><span class="linenos">421</span></a><span class="sd"> """</span> -</span><span id="Dialect-422"><a href="#Dialect-422"><span class="linenos">422</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-423"><a href="#Dialect-423"><span class="linenos">423</span></a> <span class="k">return</span> <span class="kc">True</span> -</span><span id="Dialect-424"><a href="#Dialect-424"><span class="linenos">424</span></a> -</span><span id="Dialect-425"><a href="#Dialect-425"><span class="linenos">425</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-426"><a href="#Dialect-426"><span class="linenos">426</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-427"><a href="#Dialect-427"><span class="linenos">427</span></a> -</span><span id="Dialect-428"><a href="#Dialect-428"><span class="linenos">428</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="Dialect-398"><a href="#Dialect-398"><span class="linenos">398</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="Dialect-399"><a href="#Dialect-399"><span class="linenos">399</span></a> +</span><span id="Dialect-400"><a href="#Dialect-400"><span class="linenos">400</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-401"><a href="#Dialect-401"><span class="linenos">401</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-402"><a href="#Dialect-402"><span class="linenos">402</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-403"><a href="#Dialect-403"><span class="linenos">403</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="Dialect-404"><a href="#Dialect-404"><span class="linenos">404</span></a> +</span><span id="Dialect-405"><a href="#Dialect-405"><span class="linenos">405</span></a> <span class="n">unsafe</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="Dialect-406"><a href="#Dialect-406"><span class="linenos">406</span></a> <span class="nb">str</span><span class="o">.</span><span class="n">islower</span> +</span><span id="Dialect-407"><a href="#Dialect-407"><span class="linenos">407</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-408"><a href="#Dialect-408"><span class="linenos">408</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-409"><a href="#Dialect-409"><span class="linenos">409</span></a> <span class="p">)</span> +</span><span id="Dialect-410"><a href="#Dialect-410"><span class="linenos">410</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-411"><a href="#Dialect-411"><span class="linenos">411</span></a> +</span><span id="Dialect-412"><a href="#Dialect-412"><span class="linenos">412</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-413"><a href="#Dialect-413"><span class="linenos">413</span></a><span class="w"> </span><span class="sd">"""Checks if text can be identified given an identify option.</span> +</span><span id="Dialect-414"><a href="#Dialect-414"><span class="linenos">414</span></a> +</span><span id="Dialect-415"><a href="#Dialect-415"><span class="linenos">415</span></a><span class="sd"> Args:</span> +</span><span id="Dialect-416"><a href="#Dialect-416"><span class="linenos">416</span></a><span class="sd"> text: The text to check.</span> +</span><span id="Dialect-417"><a href="#Dialect-417"><span class="linenos">417</span></a><span class="sd"> identify:</span> +</span><span id="Dialect-418"><a href="#Dialect-418"><span class="linenos">418</span></a><span class="sd"> `"always"` or `True`: Always returns `True`.</span> +</span><span id="Dialect-419"><a href="#Dialect-419"><span class="linenos">419</span></a><span class="sd"> `"safe"`: Only returns `True` if the identifier is case-insensitive.</span> +</span><span id="Dialect-420"><a href="#Dialect-420"><span class="linenos">420</span></a> +</span><span id="Dialect-421"><a href="#Dialect-421"><span class="linenos">421</span></a><span class="sd"> Returns:</span> +</span><span id="Dialect-422"><a href="#Dialect-422"><span class="linenos">422</span></a><span class="sd"> Whether or not the given text can be identified.</span> +</span><span id="Dialect-423"><a href="#Dialect-423"><span class="linenos">423</span></a><span class="sd"> """</span> +</span><span id="Dialect-424"><a href="#Dialect-424"><span class="linenos">424</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-425"><a href="#Dialect-425"><span class="linenos">425</span></a> <span class="k">return</span> <span class="kc">True</span> +</span><span id="Dialect-426"><a href="#Dialect-426"><span class="linenos">426</span></a> +</span><span id="Dialect-427"><a href="#Dialect-427"><span class="linenos">427</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-428"><a href="#Dialect-428"><span class="linenos">428</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-429"><a href="#Dialect-429"><span class="linenos">429</span></a> -</span><span id="Dialect-430"><a href="#Dialect-430"><span class="linenos">430</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-431"><a href="#Dialect-431"><span class="linenos">431</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect-432"><a href="#Dialect-432"><span class="linenos">432</span></a><span class="sd"> Adds quotes to a given identifier.</span> -</span><span id="Dialect-433"><a href="#Dialect-433"><span class="linenos">433</span></a> -</span><span id="Dialect-434"><a href="#Dialect-434"><span class="linenos">434</span></a><span class="sd"> Args:</span> -</span><span id="Dialect-435"><a href="#Dialect-435"><span class="linenos">435</span></a><span class="sd"> expression: The expression of interest. If it's not an `Identifier`, this method is a no-op.</span> -</span><span id="Dialect-436"><a href="#Dialect-436"><span class="linenos">436</span></a><span class="sd"> identify: If set to `False`, the quotes will only be added if the identifier is deemed</span> -</span><span id="Dialect-437"><a href="#Dialect-437"><span class="linenos">437</span></a><span class="sd"> "unsafe", with respect to its characters and this dialect's normalization strategy.</span> -</span><span id="Dialect-438"><a href="#Dialect-438"><span class="linenos">438</span></a><span class="sd"> """</span> -</span><span id="Dialect-439"><a href="#Dialect-439"><span class="linenos">439</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-440"><a href="#Dialect-440"><span class="linenos">440</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-441"><a href="#Dialect-441"><span class="linenos">441</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> -</span><span id="Dialect-442"><a href="#Dialect-442"><span class="linenos">442</span></a> <span class="s2">"quoted"</span><span class="p">,</span> -</span><span id="Dialect-443"><a href="#Dialect-443"><span class="linenos">443</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-444"><a href="#Dialect-444"><span class="linenos">444</span></a> <span class="p">)</span> -</span><span id="Dialect-445"><a href="#Dialect-445"><span class="linenos">445</span></a> -</span><span id="Dialect-446"><a href="#Dialect-446"><span class="linenos">446</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="Dialect-430"><a href="#Dialect-430"><span class="linenos">430</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="Dialect-431"><a href="#Dialect-431"><span class="linenos">431</span></a> +</span><span id="Dialect-432"><a href="#Dialect-432"><span class="linenos">432</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-433"><a href="#Dialect-433"><span class="linenos">433</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect-434"><a href="#Dialect-434"><span class="linenos">434</span></a><span class="sd"> Adds quotes to a given identifier.</span> +</span><span id="Dialect-435"><a href="#Dialect-435"><span class="linenos">435</span></a> +</span><span id="Dialect-436"><a href="#Dialect-436"><span class="linenos">436</span></a><span class="sd"> Args:</span> +</span><span id="Dialect-437"><a href="#Dialect-437"><span class="linenos">437</span></a><span class="sd"> expression: The expression of interest. If it's not an `Identifier`, this method is a no-op.</span> +</span><span id="Dialect-438"><a href="#Dialect-438"><span class="linenos">438</span></a><span class="sd"> identify: If set to `False`, the quotes will only be added if the identifier is deemed</span> +</span><span id="Dialect-439"><a href="#Dialect-439"><span class="linenos">439</span></a><span class="sd"> "unsafe", with respect to its characters and this dialect's normalization strategy.</span> +</span><span id="Dialect-440"><a href="#Dialect-440"><span class="linenos">440</span></a><span class="sd"> """</span> +</span><span id="Dialect-441"><a href="#Dialect-441"><span class="linenos">441</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-442"><a href="#Dialect-442"><span class="linenos">442</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-443"><a href="#Dialect-443"><span class="linenos">443</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span> +</span><span id="Dialect-444"><a href="#Dialect-444"><span class="linenos">444</span></a> <span class="s2">"quoted"</span><span class="p">,</span> +</span><span id="Dialect-445"><a href="#Dialect-445"><span class="linenos">445</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-446"><a href="#Dialect-446"><span class="linenos">446</span></a> <span class="p">)</span> </span><span id="Dialect-447"><a href="#Dialect-447"><span class="linenos">447</span></a> -</span><span id="Dialect-448"><a href="#Dialect-448"><span class="linenos">448</span></a> <span class="k">def</span> <span class="nf">to_json_path</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</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 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-449"><a href="#Dialect-449"><span class="linenos">449</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="p">):</span> -</span><span id="Dialect-450"><a href="#Dialect-450"><span class="linenos">450</span></a> <span class="n">path_text</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">name</span> -</span><span id="Dialect-451"><a href="#Dialect-451"><span class="linenos">451</span></a> <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">is_number</span><span class="p">:</span> -</span><span id="Dialect-452"><a href="#Dialect-452"><span class="linenos">452</span></a> <span class="n">path_text</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"[</span><span class="si">{</span><span class="n">path_text</span><span class="si">}</span><span class="s2">]"</span> -</span><span id="Dialect-453"><a href="#Dialect-453"><span class="linenos">453</span></a> -</span><span id="Dialect-454"><a href="#Dialect-454"><span class="linenos">454</span></a> <span class="k">try</span><span class="p">:</span> -</span><span id="Dialect-455"><a href="#Dialect-455"><span class="linenos">455</span></a> <span class="k">return</span> <span class="n">parse_json_path</span><span class="p">(</span><span class="n">path_text</span><span class="p">)</span> -</span><span id="Dialect-456"><a href="#Dialect-456"><span class="linenos">456</span></a> <span class="k">except</span> <span class="n">ParseError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> -</span><span id="Dialect-457"><a href="#Dialect-457"><span class="linenos">457</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid JSON path syntax. </span><span class="si">{</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="Dialect-458"><a href="#Dialect-458"><span class="linenos">458</span></a> -</span><span id="Dialect-459"><a href="#Dialect-459"><span class="linenos">459</span></a> <span class="k">return</span> <span class="n">path</span> +</span><span id="Dialect-448"><a href="#Dialect-448"><span class="linenos">448</span></a> <span class="k">return</span> <span class="n">expression</span> +</span><span id="Dialect-449"><a href="#Dialect-449"><span class="linenos">449</span></a> +</span><span id="Dialect-450"><a href="#Dialect-450"><span class="linenos">450</span></a> <span class="k">def</span> <span class="nf">to_json_path</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</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 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-451"><a href="#Dialect-451"><span class="linenos">451</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="p">):</span> +</span><span id="Dialect-452"><a href="#Dialect-452"><span class="linenos">452</span></a> <span class="n">path_text</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">name</span> +</span><span id="Dialect-453"><a href="#Dialect-453"><span class="linenos">453</span></a> <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">is_number</span><span class="p">:</span> +</span><span id="Dialect-454"><a href="#Dialect-454"><span class="linenos">454</span></a> <span class="n">path_text</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"[</span><span class="si">{</span><span class="n">path_text</span><span class="si">}</span><span class="s2">]"</span> +</span><span id="Dialect-455"><a href="#Dialect-455"><span class="linenos">455</span></a> +</span><span id="Dialect-456"><a href="#Dialect-456"><span class="linenos">456</span></a> <span class="k">try</span><span class="p">:</span> +</span><span id="Dialect-457"><a href="#Dialect-457"><span class="linenos">457</span></a> <span class="k">return</span> <span class="n">parse_json_path</span><span class="p">(</span><span class="n">path_text</span><span class="p">)</span> +</span><span id="Dialect-458"><a href="#Dialect-458"><span class="linenos">458</span></a> <span class="k">except</span> <span class="n">ParseError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> +</span><span id="Dialect-459"><a href="#Dialect-459"><span class="linenos">459</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid JSON path syntax. </span><span class="si">{</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> </span><span id="Dialect-460"><a href="#Dialect-460"><span class="linenos">460</span></a> -</span><span id="Dialect-461"><a href="#Dialect-461"><span class="linenos">461</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-462"><a href="#Dialect-462"><span class="linenos">462</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-463"><a href="#Dialect-463"><span class="linenos">463</span></a> -</span><span id="Dialect-464"><a href="#Dialect-464"><span class="linenos">464</span></a> <span class="k">def</span> <span class="nf">parse_into</span><span class="p">(</span> -</span><span id="Dialect-465"><a href="#Dialect-465"><span class="linenos">465</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-466"><a href="#Dialect-466"><span class="linenos">466</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-467"><a href="#Dialect-467"><span class="linenos">467</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-468"><a href="#Dialect-468"><span class="linenos">468</span></a> -</span><span id="Dialect-469"><a href="#Dialect-469"><span class="linenos">469</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-470"><a href="#Dialect-470"><span class="linenos">470</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-471"><a href="#Dialect-471"><span class="linenos">471</span></a> -</span><span id="Dialect-472"><a href="#Dialect-472"><span class="linenos">472</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-473"><a href="#Dialect-473"><span class="linenos">473</span></a> <span class="k">return</span> <span class="p">[</span> -</span><span id="Dialect-474"><a href="#Dialect-474"><span class="linenos">474</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-475"><a href="#Dialect-475"><span class="linenos">475</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-476"><a href="#Dialect-476"><span class="linenos">476</span></a> <span class="p">]</span> -</span><span id="Dialect-477"><a href="#Dialect-477"><span class="linenos">477</span></a> -</span><span id="Dialect-478"><a href="#Dialect-478"><span class="linenos">478</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-479"><a href="#Dialect-479"><span class="linenos">479</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-480"><a href="#Dialect-480"><span class="linenos">480</span></a> -</span><span id="Dialect-481"><a href="#Dialect-481"><span class="linenos">481</span></a> <span class="nd">@property</span> -</span><span id="Dialect-482"><a href="#Dialect-482"><span class="linenos">482</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-483"><a href="#Dialect-483"><span class="linenos">483</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-484"><a href="#Dialect-484"><span class="linenos">484</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-485"><a href="#Dialect-485"><span class="linenos">485</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-486"><a href="#Dialect-486"><span class="linenos">486</span></a> -</span><span id="Dialect-487"><a href="#Dialect-487"><span class="linenos">487</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-488"><a href="#Dialect-488"><span class="linenos">488</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-489"><a href="#Dialect-489"><span class="linenos">489</span></a> -</span><span id="Dialect-490"><a href="#Dialect-490"><span class="linenos">490</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-491"><a href="#Dialect-491"><span class="linenos">491</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-461"><a href="#Dialect-461"><span class="linenos">461</span></a> <span class="k">return</span> <span class="n">path</span> +</span><span id="Dialect-462"><a href="#Dialect-462"><span class="linenos">462</span></a> +</span><span id="Dialect-463"><a href="#Dialect-463"><span class="linenos">463</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-464"><a href="#Dialect-464"><span class="linenos">464</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-465"><a href="#Dialect-465"><span class="linenos">465</span></a> +</span><span id="Dialect-466"><a href="#Dialect-466"><span class="linenos">466</span></a> <span class="k">def</span> <span class="nf">parse_into</span><span class="p">(</span> +</span><span id="Dialect-467"><a href="#Dialect-467"><span class="linenos">467</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-468"><a href="#Dialect-468"><span class="linenos">468</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-469"><a href="#Dialect-469"><span class="linenos">469</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-470"><a href="#Dialect-470"><span class="linenos">470</span></a> +</span><span id="Dialect-471"><a href="#Dialect-471"><span class="linenos">471</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-472"><a href="#Dialect-472"><span class="linenos">472</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-473"><a href="#Dialect-473"><span class="linenos">473</span></a> +</span><span id="Dialect-474"><a href="#Dialect-474"><span class="linenos">474</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-475"><a href="#Dialect-475"><span class="linenos">475</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="Dialect-476"><a href="#Dialect-476"><span class="linenos">476</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-477"><a href="#Dialect-477"><span class="linenos">477</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-478"><a href="#Dialect-478"><span class="linenos">478</span></a> <span class="p">]</span> +</span><span id="Dialect-479"><a href="#Dialect-479"><span class="linenos">479</span></a> +</span><span id="Dialect-480"><a href="#Dialect-480"><span class="linenos">480</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-481"><a href="#Dialect-481"><span class="linenos">481</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-482"><a href="#Dialect-482"><span class="linenos">482</span></a> +</span><span id="Dialect-483"><a href="#Dialect-483"><span class="linenos">483</span></a> <span class="nd">@property</span> +</span><span id="Dialect-484"><a href="#Dialect-484"><span class="linenos">484</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-485"><a href="#Dialect-485"><span class="linenos">485</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-486"><a href="#Dialect-486"><span class="linenos">486</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-487"><a href="#Dialect-487"><span class="linenos">487</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-488"><a href="#Dialect-488"><span class="linenos">488</span></a> +</span><span id="Dialect-489"><a href="#Dialect-489"><span class="linenos">489</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-490"><a href="#Dialect-490"><span class="linenos">490</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-491"><a href="#Dialect-491"><span class="linenos">491</span></a> +</span><span id="Dialect-492"><a href="#Dialect-492"><span class="linenos">492</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-493"><a href="#Dialect-493"><span class="linenos">493</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> @@ -2497,13 +2515,13 @@ </div> <a class="headerlink" href="#Dialect.__init__"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.__init__-344"><a href="#Dialect.__init__-344"><span class="linenos">344</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__-345"><a href="#Dialect.__init__-345"><span class="linenos">345</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__-346"><a href="#Dialect.__init__-346"><span class="linenos">346</span></a> -</span><span id="Dialect.__init__-347"><a href="#Dialect.__init__-347"><span class="linenos">347</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__-348"><a href="#Dialect.__init__-348"><span class="linenos">348</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__-349"><a href="#Dialect.__init__-349"><span class="linenos">349</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="Dialect.__init__-350"><a href="#Dialect.__init__-350"><span class="linenos">350</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__-346"><a href="#Dialect.__init__-346"><span class="linenos">346</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__-347"><a href="#Dialect.__init__-347"><span class="linenos">347</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__-348"><a href="#Dialect.__init__-348"><span class="linenos">348</span></a> +</span><span id="Dialect.__init__-349"><a href="#Dialect.__init__-349"><span class="linenos">349</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__-350"><a href="#Dialect.__init__-350"><span class="linenos">350</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__-351"><a href="#Dialect.__init__-351"><span class="linenos">351</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="Dialect.__init__-352"><a href="#Dialect.__init__-352"><span class="linenos">352</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> @@ -3125,53 +3143,53 @@ WITH y(c) AS ( </div> <a class="headerlink" href="#Dialect.get_or_raise"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.get_or_raise-280"><a href="#Dialect.get_or_raise-280"><span class="linenos">280</span></a> <span class="nd">@classmethod</span> -</span><span id="Dialect.get_or_raise-281"><a href="#Dialect.get_or_raise-281"><span class="linenos">281</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-282"><a href="#Dialect.get_or_raise-282"><span class="linenos">282</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect.get_or_raise-283"><a href="#Dialect.get_or_raise-283"><span class="linenos">283</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-284"><a href="#Dialect.get_or_raise-284"><span class="linenos">284</span></a> -</span><span id="Dialect.get_or_raise-285"><a href="#Dialect.get_or_raise-285"><span class="linenos">285</span></a><span class="sd"> Args:</span> -</span><span id="Dialect.get_or_raise-286"><a href="#Dialect.get_or_raise-286"><span class="linenos">286</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-287"><a href="#Dialect.get_or_raise-287"><span class="linenos">287</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-288"><a href="#Dialect.get_or_raise-288"><span class="linenos">288</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-289"><a href="#Dialect.get_or_raise-289"><span class="linenos">289</span></a> -</span><span id="Dialect.get_or_raise-290"><a href="#Dialect.get_or_raise-290"><span class="linenos">290</span></a><span class="sd"> Example:</span> -</span><span id="Dialect.get_or_raise-291"><a href="#Dialect.get_or_raise-291"><span class="linenos">291</span></a><span class="sd"> >>> dialect = dialect_class = get_or_raise("duckdb")</span> -</span><span id="Dialect.get_or_raise-292"><a href="#Dialect.get_or_raise-292"><span class="linenos">292</span></a><span class="sd"> >>> dialect = get_or_raise("mysql, normalization_strategy = case_sensitive")</span> -</span><span id="Dialect.get_or_raise-293"><a href="#Dialect.get_or_raise-293"><span class="linenos">293</span></a> -</span><span id="Dialect.get_or_raise-294"><a href="#Dialect.get_or_raise-294"><span class="linenos">294</span></a><span class="sd"> Returns:</span> -</span><span id="Dialect.get_or_raise-295"><a href="#Dialect.get_or_raise-295"><span class="linenos">295</span></a><span class="sd"> The corresponding Dialect instance.</span> -</span><span id="Dialect.get_or_raise-296"><a href="#Dialect.get_or_raise-296"><span class="linenos">296</span></a><span class="sd"> """</span> -</span><span id="Dialect.get_or_raise-297"><a href="#Dialect.get_or_raise-297"><span class="linenos">297</span></a> -</span><span id="Dialect.get_or_raise-298"><a href="#Dialect.get_or_raise-298"><span class="linenos">298</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-299"><a href="#Dialect.get_or_raise-299"><span class="linenos">299</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span> -</span><span id="Dialect.get_or_raise-300"><a href="#Dialect.get_or_raise-300"><span class="linenos">300</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-301"><a href="#Dialect.get_or_raise-301"><span class="linenos">301</span></a> <span class="k">return</span> <span class="n">dialect</span><span class="p">()</span> -</span><span id="Dialect.get_or_raise-302"><a href="#Dialect.get_or_raise-302"><span class="linenos">302</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-303"><a href="#Dialect.get_or_raise-303"><span class="linenos">303</span></a> <span class="k">return</span> <span class="n">dialect</span> -</span><span id="Dialect.get_or_raise-304"><a href="#Dialect.get_or_raise-304"><span class="linenos">304</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-305"><a href="#Dialect.get_or_raise-305"><span class="linenos">305</span></a> <span class="k">try</span><span class="p">:</span> -</span><span id="Dialect.get_or_raise-306"><a href="#Dialect.get_or_raise-306"><span class="linenos">306</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-307"><a href="#Dialect.get_or_raise-307"><span class="linenos">307</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-308"><a href="#Dialect.get_or_raise-308"><span class="linenos">308</span></a> <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> -</span><span id="Dialect.get_or_raise-309"><a href="#Dialect.get_or_raise-309"><span class="linenos">309</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> -</span><span id="Dialect.get_or_raise-310"><a href="#Dialect.get_or_raise-310"><span class="linenos">310</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-311"><a href="#Dialect.get_or_raise-311"><span class="linenos">311</span></a> <span class="s2">"Please use the correct format: 'dialect [, k1 = v2 [, ...]]'."</span> -</span><span id="Dialect.get_or_raise-312"><a href="#Dialect.get_or_raise-312"><span class="linenos">312</span></a> <span class="p">)</span> -</span><span id="Dialect.get_or_raise-313"><a href="#Dialect.get_or_raise-313"><span class="linenos">313</span></a> -</span><span id="Dialect.get_or_raise-314"><a href="#Dialect.get_or_raise-314"><span class="linenos">314</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-315"><a href="#Dialect.get_or_raise-315"><span class="linenos">315</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-316"><a href="#Dialect.get_or_raise-316"><span class="linenos">316</span></a> <span class="kn">from</span> <span class="nn">difflib</span> <span class="kn">import</span> <span class="n">get_close_matches</span> -</span><span id="Dialect.get_or_raise-317"><a href="#Dialect.get_or_raise-317"><span class="linenos">317</span></a> -</span><span id="Dialect.get_or_raise-318"><a href="#Dialect.get_or_raise-318"><span class="linenos">318</span></a> <span class="n">similar</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">get_close_matches</span><span class="p">(</span><span class="n">dialect_name</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">classes</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">""</span> -</span><span id="Dialect.get_or_raise-319"><a href="#Dialect.get_or_raise-319"><span class="linenos">319</span></a> <span class="k">if</span> <span class="n">similar</span><span class="p">:</span> -</span><span id="Dialect.get_or_raise-320"><a href="#Dialect.get_or_raise-320"><span class="linenos">320</span></a> <span class="n">similar</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" Did you mean </span><span class="si">{</span><span class="n">similar</span><span class="si">}</span><span class="s2">?"</span> -</span><span id="Dialect.get_or_raise-321"><a href="#Dialect.get_or_raise-321"><span class="linenos">321</span></a> -</span><span id="Dialect.get_or_raise-322"><a href="#Dialect.get_or_raise-322"><span class="linenos">322</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="si">{</span><span class="n">similar</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-282"><a href="#Dialect.get_or_raise-282"><span class="linenos">282</span></a> <span class="nd">@classmethod</span> +</span><span id="Dialect.get_or_raise-283"><a href="#Dialect.get_or_raise-283"><span class="linenos">283</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-284"><a href="#Dialect.get_or_raise-284"><span class="linenos">284</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect.get_or_raise-285"><a href="#Dialect.get_or_raise-285"><span class="linenos">285</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-286"><a href="#Dialect.get_or_raise-286"><span class="linenos">286</span></a> +</span><span id="Dialect.get_or_raise-287"><a href="#Dialect.get_or_raise-287"><span class="linenos">287</span></a><span class="sd"> Args:</span> +</span><span id="Dialect.get_or_raise-288"><a href="#Dialect.get_or_raise-288"><span class="linenos">288</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-289"><a href="#Dialect.get_or_raise-289"><span class="linenos">289</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-290"><a href="#Dialect.get_or_raise-290"><span class="linenos">290</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-291"><a href="#Dialect.get_or_raise-291"><span class="linenos">291</span></a> +</span><span id="Dialect.get_or_raise-292"><a href="#Dialect.get_or_raise-292"><span class="linenos">292</span></a><span class="sd"> Example:</span> +</span><span id="Dialect.get_or_raise-293"><a href="#Dialect.get_or_raise-293"><span class="linenos">293</span></a><span class="sd"> >>> dialect = dialect_class = get_or_raise("duckdb")</span> +</span><span id="Dialect.get_or_raise-294"><a href="#Dialect.get_or_raise-294"><span class="linenos">294</span></a><span class="sd"> >>> dialect = get_or_raise("mysql, normalization_strategy = case_sensitive")</span> +</span><span id="Dialect.get_or_raise-295"><a href="#Dialect.get_or_raise-295"><span class="linenos">295</span></a> +</span><span id="Dialect.get_or_raise-296"><a href="#Dialect.get_or_raise-296"><span class="linenos">296</span></a><span class="sd"> Returns:</span> +</span><span id="Dialect.get_or_raise-297"><a href="#Dialect.get_or_raise-297"><span class="linenos">297</span></a><span class="sd"> The corresponding Dialect instance.</span> +</span><span id="Dialect.get_or_raise-298"><a href="#Dialect.get_or_raise-298"><span class="linenos">298</span></a><span class="sd"> """</span> +</span><span id="Dialect.get_or_raise-299"><a href="#Dialect.get_or_raise-299"><span class="linenos">299</span></a> +</span><span id="Dialect.get_or_raise-300"><a href="#Dialect.get_or_raise-300"><span class="linenos">300</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-301"><a href="#Dialect.get_or_raise-301"><span class="linenos">301</span></a> <span class="k">return</span> <span class="bp">cls</span><span class="p">()</span> +</span><span id="Dialect.get_or_raise-302"><a href="#Dialect.get_or_raise-302"><span class="linenos">302</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-303"><a href="#Dialect.get_or_raise-303"><span class="linenos">303</span></a> <span class="k">return</span> <span class="n">dialect</span><span class="p">()</span> +</span><span id="Dialect.get_or_raise-304"><a href="#Dialect.get_or_raise-304"><span class="linenos">304</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-305"><a href="#Dialect.get_or_raise-305"><span class="linenos">305</span></a> <span class="k">return</span> <span class="n">dialect</span> +</span><span id="Dialect.get_or_raise-306"><a href="#Dialect.get_or_raise-306"><span class="linenos">306</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-307"><a href="#Dialect.get_or_raise-307"><span class="linenos">307</span></a> <span class="k">try</span><span class="p">:</span> +</span><span id="Dialect.get_or_raise-308"><a href="#Dialect.get_or_raise-308"><span class="linenos">308</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-309"><a href="#Dialect.get_or_raise-309"><span class="linenos">309</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-310"><a href="#Dialect.get_or_raise-310"><span class="linenos">310</span></a> <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> +</span><span id="Dialect.get_or_raise-311"><a href="#Dialect.get_or_raise-311"><span class="linenos">311</span></a> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span> +</span><span id="Dialect.get_or_raise-312"><a href="#Dialect.get_or_raise-312"><span class="linenos">312</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-313"><a href="#Dialect.get_or_raise-313"><span class="linenos">313</span></a> <span class="s2">"Please use the correct format: 'dialect [, k1 = v2 [, ...]]'."</span> +</span><span id="Dialect.get_or_raise-314"><a href="#Dialect.get_or_raise-314"><span class="linenos">314</span></a> <span class="p">)</span> +</span><span id="Dialect.get_or_raise-315"><a href="#Dialect.get_or_raise-315"><span class="linenos">315</span></a> +</span><span id="Dialect.get_or_raise-316"><a href="#Dialect.get_or_raise-316"><span class="linenos">316</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-317"><a href="#Dialect.get_or_raise-317"><span class="linenos">317</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-318"><a href="#Dialect.get_or_raise-318"><span class="linenos">318</span></a> <span class="kn">from</span> <span class="nn">difflib</span> <span class="kn">import</span> <span class="n">get_close_matches</span> +</span><span id="Dialect.get_or_raise-319"><a href="#Dialect.get_or_raise-319"><span class="linenos">319</span></a> +</span><span id="Dialect.get_or_raise-320"><a href="#Dialect.get_or_raise-320"><span class="linenos">320</span></a> <span class="n">similar</span> <span class="o">=</span> <span class="n">seq_get</span><span class="p">(</span><span class="n">get_close_matches</span><span class="p">(</span><span class="n">dialect_name</span><span class="p">,</span> <span class="bp">cls</span><span class="o">.</span><span class="n">classes</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span> <span class="s2">""</span> +</span><span id="Dialect.get_or_raise-321"><a href="#Dialect.get_or_raise-321"><span class="linenos">321</span></a> <span class="k">if</span> <span class="n">similar</span><span class="p">:</span> +</span><span id="Dialect.get_or_raise-322"><a href="#Dialect.get_or_raise-322"><span class="linenos">322</span></a> <span class="n">similar</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">" Did you mean </span><span class="si">{</span><span class="n">similar</span><span class="si">}</span><span class="s2">?"</span> </span><span id="Dialect.get_or_raise-323"><a href="#Dialect.get_or_raise-323"><span class="linenos">323</span></a> -</span><span id="Dialect.get_or_raise-324"><a href="#Dialect.get_or_raise-324"><span class="linenos">324</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-324"><a href="#Dialect.get_or_raise-324"><span class="linenos">324</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="si">{</span><span class="n">similar</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> </span><span id="Dialect.get_or_raise-325"><a href="#Dialect.get_or_raise-325"><span class="linenos">325</span></a> -</span><span id="Dialect.get_or_raise-326"><a href="#Dialect.get_or_raise-326"><span class="linenos">326</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.get_or_raise-326"><a href="#Dialect.get_or_raise-326"><span class="linenos">326</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-327"><a href="#Dialect.get_or_raise-327"><span class="linenos">327</span></a> +</span><span id="Dialect.get_or_raise-328"><a href="#Dialect.get_or_raise-328"><span class="linenos">328</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> @@ -3216,21 +3234,21 @@ 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-328"><a href="#Dialect.format_time-328"><span class="linenos">328</span></a> <span class="nd">@classmethod</span> -</span><span id="Dialect.format_time-329"><a href="#Dialect.format_time-329"><span class="linenos">329</span></a> <span class="k">def</span> <span class="nf">format_time</span><span class="p">(</span> -</span><span id="Dialect.format_time-330"><a href="#Dialect.format_time-330"><span class="linenos">330</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-331"><a href="#Dialect.format_time-331"><span class="linenos">331</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-332"><a href="#Dialect.format_time-332"><span class="linenos">332</span></a><span class="w"> </span><span class="sd">"""Converts a time format in this dialect to its equivalent Python `strftime` format."""</span> -</span><span id="Dialect.format_time-333"><a href="#Dialect.format_time-333"><span class="linenos">333</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-334"><a href="#Dialect.format_time-334"><span class="linenos">334</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-335"><a href="#Dialect.format_time-335"><span class="linenos">335</span></a> <span class="c1"># the time formats are quoted</span> -</span><span id="Dialect.format_time-336"><a href="#Dialect.format_time-336"><span class="linenos">336</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-337"><a href="#Dialect.format_time-337"><span class="linenos">337</span></a> <span class="p">)</span> -</span><span id="Dialect.format_time-338"><a href="#Dialect.format_time-338"><span class="linenos">338</span></a> -</span><span id="Dialect.format_time-339"><a href="#Dialect.format_time-339"><span class="linenos">339</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-340"><a href="#Dialect.format_time-340"><span class="linenos">340</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-341"><a href="#Dialect.format_time-341"><span class="linenos">341</span></a> -</span><span id="Dialect.format_time-342"><a href="#Dialect.format_time-342"><span class="linenos">342</span></a> <span class="k">return</span> <span class="n">expression</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.format_time-330"><a href="#Dialect.format_time-330"><span class="linenos">330</span></a> <span class="nd">@classmethod</span> +</span><span id="Dialect.format_time-331"><a href="#Dialect.format_time-331"><span class="linenos">331</span></a> <span class="k">def</span> <span class="nf">format_time</span><span class="p">(</span> +</span><span id="Dialect.format_time-332"><a href="#Dialect.format_time-332"><span class="linenos">332</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-333"><a href="#Dialect.format_time-333"><span class="linenos">333</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-334"><a href="#Dialect.format_time-334"><span class="linenos">334</span></a><span class="w"> </span><span class="sd">"""Converts a time format in this dialect to its equivalent Python `strftime` format."""</span> +</span><span id="Dialect.format_time-335"><a href="#Dialect.format_time-335"><span class="linenos">335</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-336"><a href="#Dialect.format_time-336"><span class="linenos">336</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-337"><a href="#Dialect.format_time-337"><span class="linenos">337</span></a> <span class="c1"># the time formats are quoted</span> +</span><span id="Dialect.format_time-338"><a href="#Dialect.format_time-338"><span class="linenos">338</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-339"><a href="#Dialect.format_time-339"><span class="linenos">339</span></a> <span class="p">)</span> +</span><span id="Dialect.format_time-340"><a href="#Dialect.format_time-340"><span class="linenos">340</span></a> +</span><span id="Dialect.format_time-341"><a href="#Dialect.format_time-341"><span class="linenos">341</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-342"><a href="#Dialect.format_time-342"><span class="linenos">342</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-343"><a href="#Dialect.format_time-343"><span class="linenos">343</span></a> +</span><span id="Dialect.format_time-344"><a href="#Dialect.format_time-344"><span class="linenos">344</span></a> <span class="k">return</span> <span class="n">expression</span> </span></pre></div> @@ -3250,43 +3268,43 @@ 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-360"><a href="#Dialect.normalize_identifier-360"><span class="linenos">360</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-361"><a href="#Dialect.normalize_identifier-361"><span class="linenos">361</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect.normalize_identifier-362"><a href="#Dialect.normalize_identifier-362"><span class="linenos">362</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-363"><a href="#Dialect.normalize_identifier-363"><span class="linenos">363</span></a> -</span><span id="Dialect.normalize_identifier-364"><a href="#Dialect.normalize_identifier-364"><span class="linenos">364</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-365"><a href="#Dialect.normalize_identifier-365"><span class="linenos">365</span></a><span class="sd"> lowercases all unquoted identifiers. On the other hand, Snowflake uppercases them, so</span> -</span><span id="Dialect.normalize_identifier-366"><a href="#Dialect.normalize_identifier-366"><span class="linenos">366</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-367"><a href="#Dialect.normalize_identifier-367"><span class="linenos">367</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-368"><a href="#Dialect.normalize_identifier-368"><span class="linenos">368</span></a> -</span><span id="Dialect.normalize_identifier-369"><a href="#Dialect.normalize_identifier-369"><span class="linenos">369</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-370"><a href="#Dialect.normalize_identifier-370"><span class="linenos">370</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-371"><a href="#Dialect.normalize_identifier-371"><span class="linenos">371</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-372"><a href="#Dialect.normalize_identifier-372"><span class="linenos">372</span></a> -</span><span id="Dialect.normalize_identifier-373"><a href="#Dialect.normalize_identifier-373"><span class="linenos">373</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-374"><a href="#Dialect.normalize_identifier-374"><span class="linenos">374</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-375"><a href="#Dialect.normalize_identifier-375"><span class="linenos">375</span></a> -</span><span id="Dialect.normalize_identifier-376"><a href="#Dialect.normalize_identifier-376"><span class="linenos">376</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-377"><a href="#Dialect.normalize_identifier-377"><span class="linenos">377</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-378"><a href="#Dialect.normalize_identifier-378"><span class="linenos">378</span></a><span class="sd"> """</span> -</span><span id="Dialect.normalize_identifier-379"><a href="#Dialect.normalize_identifier-379"><span class="linenos">379</span></a> <span class="k">if</span> <span class="p">(</span> -</span><span id="Dialect.normalize_identifier-380"><a href="#Dialect.normalize_identifier-380"><span class="linenos">380</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-381"><a href="#Dialect.normalize_identifier-381"><span class="linenos">381</span></a> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_SENSITIVE</span> -</span><span id="Dialect.normalize_identifier-382"><a href="#Dialect.normalize_identifier-382"><span class="linenos">382</span></a> <span class="ow">and</span> <span class="p">(</span> -</span><span id="Dialect.normalize_identifier-383"><a href="#Dialect.normalize_identifier-383"><span class="linenos">383</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-384"><a href="#Dialect.normalize_identifier-384"><span class="linenos">384</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-385"><a href="#Dialect.normalize_identifier-385"><span class="linenos">385</span></a> <span class="p">)</span> -</span><span id="Dialect.normalize_identifier-386"><a href="#Dialect.normalize_identifier-386"><span class="linenos">386</span></a> <span class="p">):</span> -</span><span id="Dialect.normalize_identifier-387"><a href="#Dialect.normalize_identifier-387"><span class="linenos">387</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-388"><a href="#Dialect.normalize_identifier-388"><span class="linenos">388</span></a> <span class="s2">"this"</span><span class="p">,</span> -</span><span id="Dialect.normalize_identifier-389"><a href="#Dialect.normalize_identifier-389"><span class="linenos">389</span></a> <span class="p">(</span> -</span><span id="Dialect.normalize_identifier-390"><a href="#Dialect.normalize_identifier-390"><span class="linenos">390</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-391"><a href="#Dialect.normalize_identifier-391"><span class="linenos">391</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-392"><a href="#Dialect.normalize_identifier-392"><span class="linenos">392</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-393"><a href="#Dialect.normalize_identifier-393"><span class="linenos">393</span></a> <span class="p">),</span> -</span><span id="Dialect.normalize_identifier-394"><a href="#Dialect.normalize_identifier-394"><span class="linenos">394</span></a> <span class="p">)</span> -</span><span id="Dialect.normalize_identifier-395"><a href="#Dialect.normalize_identifier-395"><span class="linenos">395</span></a> -</span><span id="Dialect.normalize_identifier-396"><a href="#Dialect.normalize_identifier-396"><span class="linenos">396</span></a> <span class="k">return</span> <span class="n">expression</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.normalize_identifier-362"><a href="#Dialect.normalize_identifier-362"><span class="linenos">362</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-363"><a href="#Dialect.normalize_identifier-363"><span class="linenos">363</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect.normalize_identifier-364"><a href="#Dialect.normalize_identifier-364"><span class="linenos">364</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-365"><a href="#Dialect.normalize_identifier-365"><span class="linenos">365</span></a> +</span><span id="Dialect.normalize_identifier-366"><a href="#Dialect.normalize_identifier-366"><span class="linenos">366</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-367"><a href="#Dialect.normalize_identifier-367"><span class="linenos">367</span></a><span class="sd"> lowercases all unquoted identifiers. On the other hand, Snowflake uppercases them, so</span> +</span><span id="Dialect.normalize_identifier-368"><a href="#Dialect.normalize_identifier-368"><span class="linenos">368</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-369"><a href="#Dialect.normalize_identifier-369"><span class="linenos">369</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-370"><a href="#Dialect.normalize_identifier-370"><span class="linenos">370</span></a> +</span><span id="Dialect.normalize_identifier-371"><a href="#Dialect.normalize_identifier-371"><span class="linenos">371</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-372"><a href="#Dialect.normalize_identifier-372"><span class="linenos">372</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-373"><a href="#Dialect.normalize_identifier-373"><span class="linenos">373</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-374"><a href="#Dialect.normalize_identifier-374"><span class="linenos">374</span></a> +</span><span id="Dialect.normalize_identifier-375"><a href="#Dialect.normalize_identifier-375"><span class="linenos">375</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-376"><a href="#Dialect.normalize_identifier-376"><span class="linenos">376</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-377"><a href="#Dialect.normalize_identifier-377"><span class="linenos">377</span></a> +</span><span id="Dialect.normalize_identifier-378"><a href="#Dialect.normalize_identifier-378"><span class="linenos">378</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-379"><a href="#Dialect.normalize_identifier-379"><span class="linenos">379</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-380"><a href="#Dialect.normalize_identifier-380"><span class="linenos">380</span></a><span class="sd"> """</span> +</span><span id="Dialect.normalize_identifier-381"><a href="#Dialect.normalize_identifier-381"><span class="linenos">381</span></a> <span class="k">if</span> <span class="p">(</span> +</span><span id="Dialect.normalize_identifier-382"><a href="#Dialect.normalize_identifier-382"><span class="linenos">382</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-383"><a href="#Dialect.normalize_identifier-383"><span class="linenos">383</span></a> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalization_strategy</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">NormalizationStrategy</span><span class="o">.</span><span class="n">CASE_SENSITIVE</span> +</span><span id="Dialect.normalize_identifier-384"><a href="#Dialect.normalize_identifier-384"><span class="linenos">384</span></a> <span class="ow">and</span> <span class="p">(</span> +</span><span id="Dialect.normalize_identifier-385"><a href="#Dialect.normalize_identifier-385"><span class="linenos">385</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-386"><a href="#Dialect.normalize_identifier-386"><span class="linenos">386</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-387"><a href="#Dialect.normalize_identifier-387"><span class="linenos">387</span></a> <span class="p">)</span> +</span><span id="Dialect.normalize_identifier-388"><a href="#Dialect.normalize_identifier-388"><span class="linenos">388</span></a> <span class="p">):</span> +</span><span id="Dialect.normalize_identifier-389"><a href="#Dialect.normalize_identifier-389"><span class="linenos">389</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-390"><a href="#Dialect.normalize_identifier-390"><span class="linenos">390</span></a> <span class="s2">"this"</span><span class="p">,</span> +</span><span id="Dialect.normalize_identifier-391"><a href="#Dialect.normalize_identifier-391"><span class="linenos">391</span></a> <span class="p">(</span> +</span><span id="Dialect.normalize_identifier-392"><a href="#Dialect.normalize_identifier-392"><span class="linenos">392</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-393"><a href="#Dialect.normalize_identifier-393"><span class="linenos">393</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-394"><a href="#Dialect.normalize_identifier-394"><span class="linenos">394</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-395"><a href="#Dialect.normalize_identifier-395"><span class="linenos">395</span></a> <span class="p">),</span> +</span><span id="Dialect.normalize_identifier-396"><a href="#Dialect.normalize_identifier-396"><span class="linenos">396</span></a> <span class="p">)</span> +</span><span id="Dialect.normalize_identifier-397"><a href="#Dialect.normalize_identifier-397"><span class="linenos">397</span></a> +</span><span id="Dialect.normalize_identifier-398"><a href="#Dialect.normalize_identifier-398"><span class="linenos">398</span></a> <span class="k">return</span> <span class="n">expression</span> </span></pre></div> @@ -3321,17 +3339,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-398"><a href="#Dialect.case_sensitive-398"><span class="linenos">398</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-399"><a href="#Dialect.case_sensitive-399"><span class="linenos">399</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-400"><a href="#Dialect.case_sensitive-400"><span class="linenos">400</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-401"><a href="#Dialect.case_sensitive-401"><span class="linenos">401</span></a> <span class="k">return</span> <span class="kc">False</span> -</span><span id="Dialect.case_sensitive-402"><a href="#Dialect.case_sensitive-402"><span class="linenos">402</span></a> -</span><span id="Dialect.case_sensitive-403"><a href="#Dialect.case_sensitive-403"><span class="linenos">403</span></a> <span class="n">unsafe</span> <span class="o">=</span> <span class="p">(</span> -</span><span id="Dialect.case_sensitive-404"><a href="#Dialect.case_sensitive-404"><span class="linenos">404</span></a> <span class="nb">str</span><span class="o">.</span><span class="n">islower</span> -</span><span id="Dialect.case_sensitive-405"><a href="#Dialect.case_sensitive-405"><span class="linenos">405</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-406"><a href="#Dialect.case_sensitive-406"><span class="linenos">406</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-407"><a href="#Dialect.case_sensitive-407"><span class="linenos">407</span></a> <span class="p">)</span> -</span><span id="Dialect.case_sensitive-408"><a href="#Dialect.case_sensitive-408"><span class="linenos">408</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-400"><a href="#Dialect.case_sensitive-400"><span class="linenos">400</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-401"><a href="#Dialect.case_sensitive-401"><span class="linenos">401</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-402"><a href="#Dialect.case_sensitive-402"><span class="linenos">402</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-403"><a href="#Dialect.case_sensitive-403"><span class="linenos">403</span></a> <span class="k">return</span> <span class="kc">False</span> +</span><span id="Dialect.case_sensitive-404"><a href="#Dialect.case_sensitive-404"><span class="linenos">404</span></a> +</span><span id="Dialect.case_sensitive-405"><a href="#Dialect.case_sensitive-405"><span class="linenos">405</span></a> <span class="n">unsafe</span> <span class="o">=</span> <span class="p">(</span> +</span><span id="Dialect.case_sensitive-406"><a href="#Dialect.case_sensitive-406"><span class="linenos">406</span></a> <span class="nb">str</span><span class="o">.</span><span class="n">islower</span> +</span><span id="Dialect.case_sensitive-407"><a href="#Dialect.case_sensitive-407"><span class="linenos">407</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-408"><a href="#Dialect.case_sensitive-408"><span class="linenos">408</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-409"><a href="#Dialect.case_sensitive-409"><span class="linenos">409</span></a> <span class="p">)</span> +</span><span id="Dialect.case_sensitive-410"><a href="#Dialect.case_sensitive-410"><span class="linenos">410</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> @@ -3351,25 +3369,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-410"><a href="#Dialect.can_identify-410"><span class="linenos">410</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-411"><a href="#Dialect.can_identify-411"><span class="linenos">411</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-412"><a href="#Dialect.can_identify-412"><span class="linenos">412</span></a> -</span><span id="Dialect.can_identify-413"><a href="#Dialect.can_identify-413"><span class="linenos">413</span></a><span class="sd"> Args:</span> -</span><span id="Dialect.can_identify-414"><a href="#Dialect.can_identify-414"><span class="linenos">414</span></a><span class="sd"> text: The text to check.</span> -</span><span id="Dialect.can_identify-415"><a href="#Dialect.can_identify-415"><span class="linenos">415</span></a><span class="sd"> identify:</span> -</span><span id="Dialect.can_identify-416"><a href="#Dialect.can_identify-416"><span class="linenos">416</span></a><span class="sd"> `"always"` or `True`: Always returns `True`.</span> -</span><span id="Dialect.can_identify-417"><a href="#Dialect.can_identify-417"><span class="linenos">417</span></a><span class="sd"> `"safe"`: Only returns `True` if the identifier is case-insensitive.</span> -</span><span id="Dialect.can_identify-418"><a href="#Dialect.can_identify-418"><span class="linenos">418</span></a> -</span><span id="Dialect.can_identify-419"><a href="#Dialect.can_identify-419"><span class="linenos">419</span></a><span class="sd"> Returns:</span> -</span><span id="Dialect.can_identify-420"><a href="#Dialect.can_identify-420"><span class="linenos">420</span></a><span class="sd"> Whether or not the given text can be identified.</span> -</span><span id="Dialect.can_identify-421"><a href="#Dialect.can_identify-421"><span class="linenos">421</span></a><span class="sd"> """</span> -</span><span id="Dialect.can_identify-422"><a href="#Dialect.can_identify-422"><span class="linenos">422</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-423"><a href="#Dialect.can_identify-423"><span class="linenos">423</span></a> <span class="k">return</span> <span class="kc">True</span> -</span><span id="Dialect.can_identify-424"><a href="#Dialect.can_identify-424"><span class="linenos">424</span></a> -</span><span id="Dialect.can_identify-425"><a href="#Dialect.can_identify-425"><span class="linenos">425</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-426"><a href="#Dialect.can_identify-426"><span class="linenos">426</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-427"><a href="#Dialect.can_identify-427"><span class="linenos">427</span></a> -</span><span id="Dialect.can_identify-428"><a href="#Dialect.can_identify-428"><span class="linenos">428</span></a> <span class="k">return</span> <span class="kc">False</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.can_identify-412"><a href="#Dialect.can_identify-412"><span class="linenos">412</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-413"><a href="#Dialect.can_identify-413"><span class="linenos">413</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-414"><a href="#Dialect.can_identify-414"><span class="linenos">414</span></a> +</span><span id="Dialect.can_identify-415"><a href="#Dialect.can_identify-415"><span class="linenos">415</span></a><span class="sd"> Args:</span> +</span><span id="Dialect.can_identify-416"><a href="#Dialect.can_identify-416"><span class="linenos">416</span></a><span class="sd"> text: The text to check.</span> +</span><span id="Dialect.can_identify-417"><a href="#Dialect.can_identify-417"><span class="linenos">417</span></a><span class="sd"> identify:</span> +</span><span id="Dialect.can_identify-418"><a href="#Dialect.can_identify-418"><span class="linenos">418</span></a><span class="sd"> `"always"` or `True`: Always returns `True`.</span> +</span><span id="Dialect.can_identify-419"><a href="#Dialect.can_identify-419"><span class="linenos">419</span></a><span class="sd"> `"safe"`: Only returns `True` if the identifier is case-insensitive.</span> +</span><span id="Dialect.can_identify-420"><a href="#Dialect.can_identify-420"><span class="linenos">420</span></a> +</span><span id="Dialect.can_identify-421"><a href="#Dialect.can_identify-421"><span class="linenos">421</span></a><span class="sd"> Returns:</span> +</span><span id="Dialect.can_identify-422"><a href="#Dialect.can_identify-422"><span class="linenos">422</span></a><span class="sd"> Whether or not the given text can be identified.</span> +</span><span id="Dialect.can_identify-423"><a href="#Dialect.can_identify-423"><span class="linenos">423</span></a><span class="sd"> """</span> +</span><span id="Dialect.can_identify-424"><a href="#Dialect.can_identify-424"><span class="linenos">424</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-425"><a href="#Dialect.can_identify-425"><span class="linenos">425</span></a> <span class="k">return</span> <span class="kc">True</span> +</span><span id="Dialect.can_identify-426"><a href="#Dialect.can_identify-426"><span class="linenos">426</span></a> +</span><span id="Dialect.can_identify-427"><a href="#Dialect.can_identify-427"><span class="linenos">427</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-428"><a href="#Dialect.can_identify-428"><span class="linenos">428</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-429"><a href="#Dialect.can_identify-429"><span class="linenos">429</span></a> +</span><span id="Dialect.can_identify-430"><a href="#Dialect.can_identify-430"><span class="linenos">430</span></a> <span class="k">return</span> <span class="kc">False</span> </span></pre></div> @@ -3403,23 +3421,23 @@ 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-430"><a href="#Dialect.quote_identifier-430"><span class="linenos">430</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-431"><a href="#Dialect.quote_identifier-431"><span class="linenos">431</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Dialect.quote_identifier-432"><a href="#Dialect.quote_identifier-432"><span class="linenos">432</span></a><span class="sd"> Adds quotes to a given identifier.</span> -</span><span id="Dialect.quote_identifier-433"><a href="#Dialect.quote_identifier-433"><span class="linenos">433</span></a> -</span><span id="Dialect.quote_identifier-434"><a href="#Dialect.quote_identifier-434"><span class="linenos">434</span></a><span class="sd"> Args:</span> -</span><span id="Dialect.quote_identifier-435"><a href="#Dialect.quote_identifier-435"><span class="linenos">435</span></a><span class="sd"> expression: The expression of interest. If it's not an `Identifier`, this method is a no-op.</span> -</span><span id="Dialect.quote_identifier-436"><a href="#Dialect.quote_identifier-436"><span class="linenos">436</span></a><span class="sd"> identify: If set to `False`, the quotes will only be added if the identifier is deemed</span> -</span><span id="Dialect.quote_identifier-437"><a href="#Dialect.quote_identifier-437"><span class="linenos">437</span></a><span class="sd"> "unsafe", with respect to its characters and this dialect's normalization strategy.</span> -</span><span id="Dialect.quote_identifier-438"><a href="#Dialect.quote_identifier-438"><span class="linenos">438</span></a><span class="sd"> """</span> -</span><span id="Dialect.quote_identifier-439"><a href="#Dialect.quote_identifier-439"><span class="linenos">439</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-440"><a href="#Dialect.quote_identifier-440"><span class="linenos">440</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-441"><a href="#Dialect.quote_identifier-441"><span class="linenos">441</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-442"><a href="#Dialect.quote_identifier-442"><span class="linenos">442</span></a> <span class="s2">"quoted"</span><span class="p">,</span> -</span><span id="Dialect.quote_identifier-443"><a href="#Dialect.quote_identifier-443"><span class="linenos">443</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-444"><a href="#Dialect.quote_identifier-444"><span class="linenos">444</span></a> <span class="p">)</span> -</span><span id="Dialect.quote_identifier-445"><a href="#Dialect.quote_identifier-445"><span class="linenos">445</span></a> -</span><span id="Dialect.quote_identifier-446"><a href="#Dialect.quote_identifier-446"><span class="linenos">446</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-432"><a href="#Dialect.quote_identifier-432"><span class="linenos">432</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-433"><a href="#Dialect.quote_identifier-433"><span class="linenos">433</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Dialect.quote_identifier-434"><a href="#Dialect.quote_identifier-434"><span class="linenos">434</span></a><span class="sd"> Adds quotes to a given identifier.</span> +</span><span id="Dialect.quote_identifier-435"><a href="#Dialect.quote_identifier-435"><span class="linenos">435</span></a> +</span><span id="Dialect.quote_identifier-436"><a href="#Dialect.quote_identifier-436"><span class="linenos">436</span></a><span class="sd"> Args:</span> +</span><span id="Dialect.quote_identifier-437"><a href="#Dialect.quote_identifier-437"><span class="linenos">437</span></a><span class="sd"> expression: The expression of interest. If it's not an `Identifier`, this method is a no-op.</span> +</span><span id="Dialect.quote_identifier-438"><a href="#Dialect.quote_identifier-438"><span class="linenos">438</span></a><span class="sd"> identify: If set to `False`, the quotes will only be added if the identifier is deemed</span> +</span><span id="Dialect.quote_identifier-439"><a href="#Dialect.quote_identifier-439"><span class="linenos">439</span></a><span class="sd"> "unsafe", with respect to its characters and this dialect's normalization strategy.</span> +</span><span id="Dialect.quote_identifier-440"><a href="#Dialect.quote_identifier-440"><span class="linenos">440</span></a><span class="sd"> """</span> +</span><span id="Dialect.quote_identifier-441"><a href="#Dialect.quote_identifier-441"><span class="linenos">441</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-442"><a href="#Dialect.quote_identifier-442"><span class="linenos">442</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-443"><a href="#Dialect.quote_identifier-443"><span class="linenos">443</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-444"><a href="#Dialect.quote_identifier-444"><span class="linenos">444</span></a> <span class="s2">"quoted"</span><span class="p">,</span> +</span><span id="Dialect.quote_identifier-445"><a href="#Dialect.quote_identifier-445"><span class="linenos">445</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-446"><a href="#Dialect.quote_identifier-446"><span class="linenos">446</span></a> <span class="p">)</span> +</span><span id="Dialect.quote_identifier-447"><a href="#Dialect.quote_identifier-447"><span class="linenos">447</span></a> +</span><span id="Dialect.quote_identifier-448"><a href="#Dialect.quote_identifier-448"><span class="linenos">448</span></a> <span class="k">return</span> <span class="n">expression</span> </span></pre></div> @@ -3447,18 +3465,18 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#Dialect.to_json_path"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.to_json_path-448"><a href="#Dialect.to_json_path-448"><span class="linenos">448</span></a> <span class="k">def</span> <span class="nf">to_json_path</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</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 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.to_json_path-449"><a href="#Dialect.to_json_path-449"><span class="linenos">449</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="p">):</span> -</span><span id="Dialect.to_json_path-450"><a href="#Dialect.to_json_path-450"><span class="linenos">450</span></a> <span class="n">path_text</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">name</span> -</span><span id="Dialect.to_json_path-451"><a href="#Dialect.to_json_path-451"><span class="linenos">451</span></a> <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">is_number</span><span class="p">:</span> -</span><span id="Dialect.to_json_path-452"><a href="#Dialect.to_json_path-452"><span class="linenos">452</span></a> <span class="n">path_text</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"[</span><span class="si">{</span><span class="n">path_text</span><span class="si">}</span><span class="s2">]"</span> -</span><span id="Dialect.to_json_path-453"><a href="#Dialect.to_json_path-453"><span class="linenos">453</span></a> -</span><span id="Dialect.to_json_path-454"><a href="#Dialect.to_json_path-454"><span class="linenos">454</span></a> <span class="k">try</span><span class="p">:</span> -</span><span id="Dialect.to_json_path-455"><a href="#Dialect.to_json_path-455"><span class="linenos">455</span></a> <span class="k">return</span> <span class="n">parse_json_path</span><span class="p">(</span><span class="n">path_text</span><span class="p">)</span> -</span><span id="Dialect.to_json_path-456"><a href="#Dialect.to_json_path-456"><span class="linenos">456</span></a> <span class="k">except</span> <span class="n">ParseError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> -</span><span id="Dialect.to_json_path-457"><a href="#Dialect.to_json_path-457"><span class="linenos">457</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid JSON path syntax. </span><span class="si">{</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="Dialect.to_json_path-458"><a href="#Dialect.to_json_path-458"><span class="linenos">458</span></a> -</span><span id="Dialect.to_json_path-459"><a href="#Dialect.to_json_path-459"><span class="linenos">459</span></a> <span class="k">return</span> <span class="n">path</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.to_json_path-450"><a href="#Dialect.to_json_path-450"><span class="linenos">450</span></a> <span class="k">def</span> <span class="nf">to_json_path</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</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 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.to_json_path-451"><a href="#Dialect.to_json_path-451"><span class="linenos">451</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="p">):</span> +</span><span id="Dialect.to_json_path-452"><a href="#Dialect.to_json_path-452"><span class="linenos">452</span></a> <span class="n">path_text</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">name</span> +</span><span id="Dialect.to_json_path-453"><a href="#Dialect.to_json_path-453"><span class="linenos">453</span></a> <span class="k">if</span> <span class="n">path</span><span class="o">.</span><span class="n">is_number</span><span class="p">:</span> +</span><span id="Dialect.to_json_path-454"><a href="#Dialect.to_json_path-454"><span class="linenos">454</span></a> <span class="n">path_text</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"[</span><span class="si">{</span><span class="n">path_text</span><span class="si">}</span><span class="s2">]"</span> +</span><span id="Dialect.to_json_path-455"><a href="#Dialect.to_json_path-455"><span class="linenos">455</span></a> +</span><span id="Dialect.to_json_path-456"><a href="#Dialect.to_json_path-456"><span class="linenos">456</span></a> <span class="k">try</span><span class="p">:</span> +</span><span id="Dialect.to_json_path-457"><a href="#Dialect.to_json_path-457"><span class="linenos">457</span></a> <span class="k">return</span> <span class="n">parse_json_path</span><span class="p">(</span><span class="n">path_text</span><span class="p">)</span> +</span><span id="Dialect.to_json_path-458"><a href="#Dialect.to_json_path-458"><span class="linenos">458</span></a> <span class="k">except</span> <span class="n">ParseError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> +</span><span id="Dialect.to_json_path-459"><a href="#Dialect.to_json_path-459"><span class="linenos">459</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Invalid JSON path syntax. </span><span class="si">{</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="Dialect.to_json_path-460"><a href="#Dialect.to_json_path-460"><span class="linenos">460</span></a> +</span><span id="Dialect.to_json_path-461"><a href="#Dialect.to_json_path-461"><span class="linenos">461</span></a> <span class="k">return</span> <span class="n">path</span> </span></pre></div> @@ -3476,8 +3494,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-461"><a href="#Dialect.parse-461"><span class="linenos">461</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-462"><a href="#Dialect.parse-462"><span class="linenos">462</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-463"><a href="#Dialect.parse-463"><span class="linenos">463</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-464"><a href="#Dialect.parse-464"><span class="linenos">464</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> @@ -3495,10 +3513,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-464"><a href="#Dialect.parse_into-464"><span class="linenos">464</span></a> <span class="k">def</span> <span class="nf">parse_into</span><span class="p">(</span> -</span><span id="Dialect.parse_into-465"><a href="#Dialect.parse_into-465"><span class="linenos">465</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-466"><a href="#Dialect.parse_into-466"><span class="linenos">466</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-467"><a href="#Dialect.parse_into-467"><span class="linenos">467</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-466"><a href="#Dialect.parse_into-466"><span class="linenos">466</span></a> <span class="k">def</span> <span class="nf">parse_into</span><span class="p">(</span> +</span><span id="Dialect.parse_into-467"><a href="#Dialect.parse_into-467"><span class="linenos">467</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-468"><a href="#Dialect.parse_into-468"><span class="linenos">468</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-469"><a href="#Dialect.parse_into-469"><span class="linenos">469</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> @@ -3516,8 +3534,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-469"><a href="#Dialect.generate-469"><span class="linenos">469</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-470"><a href="#Dialect.generate-470"><span class="linenos">470</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-471"><a href="#Dialect.generate-471"><span class="linenos">471</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-472"><a href="#Dialect.generate-472"><span class="linenos">472</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> @@ -3535,11 +3553,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-472"><a href="#Dialect.transpile-472"><span class="linenos">472</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-473"><a href="#Dialect.transpile-473"><span class="linenos">473</span></a> <span class="k">return</span> <span class="p">[</span> -</span><span id="Dialect.transpile-474"><a href="#Dialect.transpile-474"><span class="linenos">474</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-475"><a href="#Dialect.transpile-475"><span class="linenos">475</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-476"><a href="#Dialect.transpile-476"><span class="linenos">476</span></a> <span class="p">]</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.transpile-474"><a href="#Dialect.transpile-474"><span class="linenos">474</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-475"><a href="#Dialect.transpile-475"><span class="linenos">475</span></a> <span class="k">return</span> <span class="p">[</span> +</span><span id="Dialect.transpile-476"><a href="#Dialect.transpile-476"><span class="linenos">476</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-477"><a href="#Dialect.transpile-477"><span class="linenos">477</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-478"><a href="#Dialect.transpile-478"><span class="linenos">478</span></a> <span class="p">]</span> </span></pre></div> @@ -3557,8 +3575,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-478"><a href="#Dialect.tokenize-478"><span class="linenos">478</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-479"><a href="#Dialect.tokenize-479"><span class="linenos">479</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-480"><a href="#Dialect.tokenize-480"><span class="linenos">480</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-481"><a href="#Dialect.tokenize-481"><span class="linenos">481</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> @@ -3574,11 +3592,11 @@ that it can analyze queries in the optimizer and successfully capture their sema </div> <a class="headerlink" href="#Dialect.tokenizer"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.tokenizer-481"><a href="#Dialect.tokenizer-481"><span class="linenos">481</span></a> <span class="nd">@property</span> -</span><span id="Dialect.tokenizer-482"><a href="#Dialect.tokenizer-482"><span class="linenos">482</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.tokenizer-483"><a href="#Dialect.tokenizer-483"><span class="linenos">483</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.tokenizer-484"><a href="#Dialect.tokenizer-484"><span class="linenos">484</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.tokenizer-485"><a href="#Dialect.tokenizer-485"><span class="linenos">485</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_tokenizer</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Dialect.tokenizer-483"><a href="#Dialect.tokenizer-483"><span class="linenos">483</span></a> <span class="nd">@property</span> +</span><span id="Dialect.tokenizer-484"><a href="#Dialect.tokenizer-484"><span class="linenos">484</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.tokenizer-485"><a href="#Dialect.tokenizer-485"><span class="linenos">485</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.tokenizer-486"><a href="#Dialect.tokenizer-486"><span class="linenos">486</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.tokenizer-487"><a href="#Dialect.tokenizer-487"><span class="linenos">487</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_tokenizer</span> </span></pre></div> @@ -3596,8 +3614,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-487"><a href="#Dialect.parser-487"><span class="linenos">487</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-488"><a href="#Dialect.parser-488"><span class="linenos">488</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-489"><a href="#Dialect.parser-489"><span class="linenos">489</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-490"><a href="#Dialect.parser-490"><span class="linenos">490</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> @@ -3615,8 +3633,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-490"><a href="#Dialect.generator-490"><span class="linenos">490</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-491"><a href="#Dialect.generator-491"><span class="linenos">491</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-492"><a href="#Dialect.generator-492"><span class="linenos">492</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-493"><a href="#Dialect.generator-493"><span class="linenos">493</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> @@ -3648,8 +3666,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-497"><a href="#rename_func-497"><span class="linenos">497</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-498"><a href="#rename_func-498"><span class="linenos">498</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-499"><a href="#rename_func-499"><span class="linenos">499</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-500"><a href="#rename_func-500"><span class="linenos">500</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> @@ -3667,10 +3685,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-501"><a href="#approx_count_distinct_sql-501"><span class="linenos">501</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-502"><a href="#approx_count_distinct_sql-502"><span class="linenos">502</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-503"><a href="#approx_count_distinct_sql-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">"APPROX_COUNT_DISTINCT does not support accuracy"</span><span class="p">)</span> -</span><span id="approx_count_distinct_sql-504"><a href="#approx_count_distinct_sql-504"><span class="linenos">504</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"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-503"><a href="#approx_count_distinct_sql-503"><span class="linenos">503</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-504"><a href="#approx_count_distinct_sql-504"><span class="linenos">504</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-505"><a href="#approx_count_distinct_sql-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">"APPROX_COUNT_DISTINCT does not support accuracy"</span><span class="p">)</span> +</span><span id="approx_count_distinct_sql-506"><a href="#approx_count_distinct_sql-506"><span class="linenos">506</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> @@ -3688,18 +3706,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-507"><a href="#if_sql-507"><span class="linenos">507</span></a><span class="k">def</span> <span class="nf">if_sql</span><span class="p">(</span> -</span><span id="if_sql-508"><a href="#if_sql-508"><span class="linenos">508</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-509"><a href="#if_sql-509"><span class="linenos">509</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-510"><a href="#if_sql-510"><span class="linenos">510</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-511"><a href="#if_sql-511"><span class="linenos">511</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-512"><a href="#if_sql-512"><span class="linenos">512</span></a> <span class="n">name</span><span class="p">,</span> -</span><span id="if_sql-513"><a href="#if_sql-513"><span class="linenos">513</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-514"><a href="#if_sql-514"><span class="linenos">514</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-515"><a href="#if_sql-515"><span class="linenos">515</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-516"><a href="#if_sql-516"><span class="linenos">516</span></a> <span class="p">)</span> -</span><span id="if_sql-517"><a href="#if_sql-517"><span class="linenos">517</span></a> -</span><span id="if_sql-518"><a href="#if_sql-518"><span class="linenos">518</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-509"><a href="#if_sql-509"><span class="linenos">509</span></a><span class="k">def</span> <span class="nf">if_sql</span><span class="p">(</span> +</span><span id="if_sql-510"><a href="#if_sql-510"><span class="linenos">510</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-511"><a href="#if_sql-511"><span class="linenos">511</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-512"><a href="#if_sql-512"><span class="linenos">512</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-513"><a href="#if_sql-513"><span class="linenos">513</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-514"><a href="#if_sql-514"><span class="linenos">514</span></a> <span class="n">name</span><span class="p">,</span> +</span><span id="if_sql-515"><a href="#if_sql-515"><span class="linenos">515</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-516"><a href="#if_sql-516"><span class="linenos">516</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-517"><a href="#if_sql-517"><span class="linenos">517</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-518"><a href="#if_sql-518"><span class="linenos">518</span></a> <span class="p">)</span> +</span><span id="if_sql-519"><a href="#if_sql-519"><span class="linenos">519</span></a> +</span><span id="if_sql-520"><a href="#if_sql-520"><span class="linenos">520</span></a> <span class="k">return</span> <span class="n">_if_sql</span> </span></pre></div> @@ -3711,15 +3729,13 @@ that it can analyze queries in the optimizer and successfully capture their sema <div class="attr function"> <span class="def">def</span> - <span class="name">arrow_json_extract_sql</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span><span class="p">:</span> <span class="n"><a href="../generator.html#Generator">sqlglot.generator.Generator</a></span>,</span><span class="param"> <span class="n">expression</span><span class="p">:</span> <span class="n"><a href="../expressions.html#JSONExtract">sqlglot.expressions.JSONExtract</a></span> <span class="o">|</span> <span class="n"><a href="../expressions.html#JSONExtractScalar">sqlglot.expressions.JSONExtractScalar</a></span></span><span class="return-annotation">) -> <span class="nb">str</span>:</span></span> + <span class="name">arrow_json_extract_sql</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span><span class="p">:</span> <span class="n"><a href="../generator.html#Generator">sqlglot.generator.Generator</a></span>,</span><span class="param"> <span class="n">expression</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n"><a href="../expressions.html#JSONExtract">sqlglot.expressions.JSONExtract</a></span><span class="p">,</span> <span class="n"><a href="../expressions.html#JSONExtractScalar">sqlglot.expressions.JSONExtractScalar</a></span><span class="p">]</span></span><span class="return-annotation">) -> <span class="nb">str</span>:</span></span> <label class="view-source-button" for="arrow_json_extract_sql-view-source"><span>View Source</span></label> </div> <a class="headerlink" href="#arrow_json_extract_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="arrow_json_extract_sql-521"><a href="#arrow_json_extract_sql-521"><span class="linenos">521</span></a><span class="k">def</span> <span class="nf">arrow_json_extract_sql</span><span class="p">(</span> -</span><span id="arrow_json_extract_sql-522"><a href="#arrow_json_extract_sql-522"><span class="linenos">522</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">JSONExtract</span> <span class="o">|</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span> -</span><span id="arrow_json_extract_sql-523"><a href="#arrow_json_extract_sql-523"><span class="linenos">523</span></a><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="arrow_json_extract_sql-523"><a href="#arrow_json_extract_sql-523"><span class="linenos">523</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">JSON_EXTRACT_TYPE</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-524"><a href="#arrow_json_extract_sql-524"><span class="linenos">524</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><span id="arrow_json_extract_sql-525"><a href="#arrow_json_extract_sql-525"><span class="linenos">525</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">JSON_TYPE_REQUIRED_FOR_EXTRACTION</span> <span class="ow">and</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">Literal</span><span class="p">)</span> <span class="ow">and</span> <span class="n">this</span><span class="o">.</span><span class="n">is_string</span><span class="p">:</span> </span><span id="arrow_json_extract_sql-526"><a href="#arrow_json_extract_sql-526"><span class="linenos">526</span></a> <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="s2">"json"</span><span class="p">))</span> @@ -5004,67 +5020,97 @@ columns are removed from the create statement.</p> <div class="attr function"> <span class="def">def</span> - <span class="name">parse_json_extract_path</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">expr_type</span><span class="p">:</span> <span class="n">Type</span><span class="p">[</span><span class="o">~</span><span class="n">E</span><span class="p">]</span>,</span><span class="param"> <span class="n">supports_null_if_invalid</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span></span><span class="return-annotation">) -> <span class="n">Callable</span><span class="p">[[</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> + <span class="name">parse_json_extract_path</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">expr_type</span><span class="p">:</span> <span class="n">Type</span><span class="p">[</span><span class="o">~</span><span class="n">F</span><span class="p">]</span>,</span><span class="param"> <span class="n">zero_based_indexing</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span></span><span class="return-annotation">) -> <span class="n">Callable</span><span class="p">[[</span><span class="n">List</span><span class="p">],</span> <span class="o">~</span><span class="n">F</span><span class="p">]</span>:</span></span> <label class="view-source-button" for="parse_json_extract_path-view-source"><span>View Source</span></label> </div> <a class="headerlink" href="#parse_json_extract_path"></a> <div class="pdoc-code codehilite"><pre><span></span><span id="parse_json_extract_path-1014"><a href="#parse_json_extract_path-1014"><span class="linenos">1014</span></a><span class="k">def</span> <span class="nf">parse_json_extract_path</span><span class="p">(</span> -</span><span id="parse_json_extract_path-1015"><a href="#parse_json_extract_path-1015"><span class="linenos">1015</span></a> <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">E</span><span class="p">],</span> -</span><span id="parse_json_extract_path-1016"><a href="#parse_json_extract_path-1016"><span class="linenos">1016</span></a> <span class="n">supports_null_if_invalid</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> -</span><span id="parse_json_extract_path-1017"><a href="#parse_json_extract_path-1017"><span class="linenos">1017</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_json_extract_path-1018"><a href="#parse_json_extract_path-1018"><span class="linenos">1018</span></a> <span class="k">def</span> <span class="nf">_parse_json_extract_path</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_json_extract_path-1019"><a href="#parse_json_extract_path-1019"><span class="linenos">1019</span></a> <span class="n">null_if_invalid</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="parse_json_extract_path-1020"><a href="#parse_json_extract_path-1020"><span class="linenos">1020</span></a> -</span><span id="parse_json_extract_path-1021"><a href="#parse_json_extract_path-1021"><span class="linenos">1021</span></a> <span class="n">segments</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">JSONPathPart</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">JSONPathRoot</span><span class="p">()]</span> -</span><span id="parse_json_extract_path-1022"><a href="#parse_json_extract_path-1022"><span class="linenos">1022</span></a> <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span> -</span><span id="parse_json_extract_path-1023"><a href="#parse_json_extract_path-1023"><span class="linenos">1023</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="p">):</span> -</span><span id="parse_json_extract_path-1024"><a href="#parse_json_extract_path-1024"><span class="linenos">1024</span></a> <span class="n">text</span> <span class="o">=</span> <span class="n">arg</span><span class="o">.</span><span class="n">name</span> -</span><span id="parse_json_extract_path-1025"><a href="#parse_json_extract_path-1025"><span class="linenos">1025</span></a> <span class="k">if</span> <span class="n">is_int</span><span class="p">(</span><span class="n">text</span><span class="p">):</span> -</span><span id="parse_json_extract_path-1026"><a href="#parse_json_extract_path-1026"><span class="linenos">1026</span></a> <span class="n">segments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">JSONPathSubscript</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">text</span><span class="p">)))</span> -</span><span id="parse_json_extract_path-1027"><a href="#parse_json_extract_path-1027"><span class="linenos">1027</span></a> <span class="k">else</span><span class="p">:</span> -</span><span id="parse_json_extract_path-1028"><a href="#parse_json_extract_path-1028"><span class="linenos">1028</span></a> <span class="n">segments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">JSONPathKey</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">text</span><span class="p">))</span> -</span><span id="parse_json_extract_path-1029"><a href="#parse_json_extract_path-1029"><span class="linenos">1029</span></a> <span class="k">elif</span> <span class="n">supports_null_if_invalid</span><span class="p">:</span> -</span><span id="parse_json_extract_path-1030"><a href="#parse_json_extract_path-1030"><span class="linenos">1030</span></a> <span class="n">null_if_invalid</span> <span class="o">=</span> <span class="n">arg</span> -</span><span id="parse_json_extract_path-1031"><a href="#parse_json_extract_path-1031"><span class="linenos">1031</span></a> -</span><span id="parse_json_extract_path-1032"><a href="#parse_json_extract_path-1032"><span class="linenos">1032</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="parse_json_extract_path-1033"><a href="#parse_json_extract_path-1033"><span class="linenos">1033</span></a> <span class="n">jsonpath</span> <span class="o">=</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONPath</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">segments</span><span class="p">)</span> -</span><span id="parse_json_extract_path-1034"><a href="#parse_json_extract_path-1034"><span class="linenos">1034</span></a> -</span><span id="parse_json_extract_path-1035"><a href="#parse_json_extract_path-1035"><span class="linenos">1035</span></a> <span class="c1"># This is done to avoid failing in the expression validator due to the arg count</span> -</span><span id="parse_json_extract_path-1036"><a href="#parse_json_extract_path-1036"><span class="linenos">1036</span></a> <span class="k">del</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">:]</span> -</span><span id="parse_json_extract_path-1037"><a href="#parse_json_extract_path-1037"><span class="linenos">1037</span></a> -</span><span id="parse_json_extract_path-1038"><a href="#parse_json_extract_path-1038"><span class="linenos">1038</span></a> <span class="k">if</span> <span class="n">expr_type</span> <span class="ow">is</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span><span class="p">:</span> -</span><span id="parse_json_extract_path-1039"><a href="#parse_json_extract_path-1039"><span class="linenos">1039</span></a> <span class="k">return</span> <span class="n">expr_type</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">jsonpath</span><span class="p">,</span> <span class="n">null_if_invalid</span><span class="o">=</span><span class="n">null_if_invalid</span><span class="p">)</span> -</span><span id="parse_json_extract_path-1040"><a href="#parse_json_extract_path-1040"><span class="linenos">1040</span></a> -</span><span id="parse_json_extract_path-1041"><a href="#parse_json_extract_path-1041"><span class="linenos">1041</span></a> <span class="k">return</span> <span class="n">expr_type</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">jsonpath</span><span class="p">)</span> -</span><span id="parse_json_extract_path-1042"><a href="#parse_json_extract_path-1042"><span class="linenos">1042</span></a> -</span><span id="parse_json_extract_path-1043"><a href="#parse_json_extract_path-1043"><span class="linenos">1043</span></a> <span class="k">return</span> <span class="n">_parse_json_extract_path</span> +</span><span id="parse_json_extract_path-1015"><a href="#parse_json_extract_path-1015"><span class="linenos">1015</span></a> <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">F</span><span class="p">],</span> <span class="n">zero_based_indexing</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="parse_json_extract_path-1016"><a href="#parse_json_extract_path-1016"><span class="linenos">1016</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">F</span><span class="p">]:</span> +</span><span id="parse_json_extract_path-1017"><a href="#parse_json_extract_path-1017"><span class="linenos">1017</span></a> <span class="k">def</span> <span class="nf">_parse_json_extract_path</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">F</span><span class="p">:</span> +</span><span id="parse_json_extract_path-1018"><a href="#parse_json_extract_path-1018"><span class="linenos">1018</span></a> <span class="n">segments</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">JSONPathPart</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">JSONPathRoot</span><span class="p">()]</span> +</span><span id="parse_json_extract_path-1019"><a href="#parse_json_extract_path-1019"><span class="linenos">1019</span></a> <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span> +</span><span id="parse_json_extract_path-1020"><a href="#parse_json_extract_path-1020"><span class="linenos">1020</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Literal</span><span class="p">):</span> +</span><span id="parse_json_extract_path-1021"><a href="#parse_json_extract_path-1021"><span class="linenos">1021</span></a> <span class="c1"># We use the fallback parser because we can't really transpile non-literals safely</span> +</span><span id="parse_json_extract_path-1022"><a href="#parse_json_extract_path-1022"><span class="linenos">1022</span></a> <span class="k">return</span> <span class="n">expr_type</span><span class="o">.</span><span class="n">from_arg_list</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> +</span><span id="parse_json_extract_path-1023"><a href="#parse_json_extract_path-1023"><span class="linenos">1023</span></a> +</span><span id="parse_json_extract_path-1024"><a href="#parse_json_extract_path-1024"><span class="linenos">1024</span></a> <span class="n">text</span> <span class="o">=</span> <span class="n">arg</span><span class="o">.</span><span class="n">name</span> +</span><span id="parse_json_extract_path-1025"><a href="#parse_json_extract_path-1025"><span class="linenos">1025</span></a> <span class="k">if</span> <span class="n">is_int</span><span class="p">(</span><span class="n">text</span><span class="p">):</span> +</span><span id="parse_json_extract_path-1026"><a href="#parse_json_extract_path-1026"><span class="linenos">1026</span></a> <span class="n">index</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">text</span><span class="p">)</span> +</span><span id="parse_json_extract_path-1027"><a href="#parse_json_extract_path-1027"><span class="linenos">1027</span></a> <span class="n">segments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> +</span><span id="parse_json_extract_path-1028"><a href="#parse_json_extract_path-1028"><span class="linenos">1028</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONPathSubscript</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">index</span> <span class="k">if</span> <span class="n">zero_based_indexing</span> <span class="k">else</span> <span class="n">index</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> +</span><span id="parse_json_extract_path-1029"><a href="#parse_json_extract_path-1029"><span class="linenos">1029</span></a> <span class="p">)</span> +</span><span id="parse_json_extract_path-1030"><a href="#parse_json_extract_path-1030"><span class="linenos">1030</span></a> <span class="k">else</span><span class="p">:</span> +</span><span id="parse_json_extract_path-1031"><a href="#parse_json_extract_path-1031"><span class="linenos">1031</span></a> <span class="n">segments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">JSONPathKey</span><span class="p">(</span><span class="n">this</span><span class="o">=</span><span class="n">text</span><span class="p">))</span> +</span><span id="parse_json_extract_path-1032"><a href="#parse_json_extract_path-1032"><span class="linenos">1032</span></a> +</span><span id="parse_json_extract_path-1033"><a href="#parse_json_extract_path-1033"><span class="linenos">1033</span></a> <span class="c1"># This is done to avoid failing in the expression validator due to the arg count</span> +</span><span id="parse_json_extract_path-1034"><a href="#parse_json_extract_path-1034"><span class="linenos">1034</span></a> <span class="k">del</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">:]</span> +</span><span id="parse_json_extract_path-1035"><a href="#parse_json_extract_path-1035"><span class="linenos">1035</span></a> <span class="k">return</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">exp</span><span class="o">.</span><span class="n">JSONPath</span><span class="p">(</span><span class="n">expressions</span><span class="o">=</span><span class="n">segments</span><span class="p">))</span> +</span><span id="parse_json_extract_path-1036"><a href="#parse_json_extract_path-1036"><span class="linenos">1036</span></a> +</span><span id="parse_json_extract_path-1037"><a href="#parse_json_extract_path-1037"><span class="linenos">1037</span></a> <span class="k">return</span> <span class="n">_parse_json_extract_path</span> +</span></pre></div> + + + + + </section> + <section id="json_extract_segments"> + <input id="json_extract_segments-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> +<div class="attr function"> + + <span class="def">def</span> + <span class="name">json_extract_segments</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>,</span><span class="param"> <span class="n">quoted_index</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span></span><span class="return-annotation">) -> <span class="n">Callable</span><span class="p">[[</span><span class="n"><a href="../generator.html#Generator">sqlglot.generator.Generator</a></span><span class="p">,</span> <span class="n">Union</span><span class="p">[</span><span class="n"><a href="../expressions.html#JSONExtract">sqlglot.expressions.JSONExtract</a></span><span class="p">,</span> <span class="n"><a href="../expressions.html#JSONExtractScalar">sqlglot.expressions.JSONExtractScalar</a></span><span class="p">]],</span> <span class="nb">str</span><span class="p">]</span>:</span></span> + + <label class="view-source-button" for="json_extract_segments-view-source"><span>View Source</span></label> + + </div> + <a class="headerlink" href="#json_extract_segments"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="json_extract_segments-1040"><a href="#json_extract_segments-1040"><span class="linenos">1040</span></a><span class="k">def</span> <span class="nf">json_extract_segments</span><span class="p">(</span> +</span><span id="json_extract_segments-1041"><a href="#json_extract_segments-1041"><span class="linenos">1041</span></a> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">quoted_index</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="json_extract_segments-1042"><a href="#json_extract_segments-1042"><span class="linenos">1042</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">JSON_EXTRACT_TYPE</span><span class="p">],</span> <span class="nb">str</span><span class="p">]:</span> +</span><span id="json_extract_segments-1043"><a href="#json_extract_segments-1043"><span class="linenos">1043</span></a> <span class="k">def</span> <span class="nf">_json_extract_segments</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">JSON_EXTRACT_TYPE</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="json_extract_segments-1044"><a href="#json_extract_segments-1044"><span class="linenos">1044</span></a> <span class="n">path</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expression</span> +</span><span id="json_extract_segments-1045"><a href="#json_extract_segments-1045"><span class="linenos">1045</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONPath</span><span class="p">):</span> +</span><span id="json_extract_segments-1046"><a href="#json_extract_segments-1046"><span class="linenos">1046</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="json_extract_segments-1047"><a href="#json_extract_segments-1047"><span class="linenos">1047</span></a> +</span><span id="json_extract_segments-1048"><a href="#json_extract_segments-1048"><span class="linenos">1048</span></a> <span class="n">segments</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="json_extract_segments-1049"><a href="#json_extract_segments-1049"><span class="linenos">1049</span></a> <span class="k">for</span> <span class="n">segment</span> <span class="ow">in</span> <span class="n">path</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> +</span><span id="json_extract_segments-1050"><a href="#json_extract_segments-1050"><span class="linenos">1050</span></a> <span class="n">path</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">segment</span><span class="p">)</span> +</span><span id="json_extract_segments-1051"><a href="#json_extract_segments-1051"><span class="linenos">1051</span></a> <span class="k">if</span> <span class="n">path</span><span class="p">:</span> +</span><span id="json_extract_segments-1052"><a href="#json_extract_segments-1052"><span class="linenos">1052</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">segment</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONPathPart</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span> +</span><span id="json_extract_segments-1053"><a href="#json_extract_segments-1053"><span class="linenos">1053</span></a> <span class="n">quoted_index</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">segment</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">JSONPathSubscript</span><span class="p">)</span> +</span><span id="json_extract_segments-1054"><a href="#json_extract_segments-1054"><span class="linenos">1054</span></a> <span class="p">):</span> +</span><span id="json_extract_segments-1055"><a href="#json_extract_segments-1055"><span class="linenos">1055</span></a> <span class="n">path</span> <span class="o">=</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">dialect</span><span class="o">.</span><span class="n">QUOTE_START</span><span class="si">}{</span><span class="n">path</span><span class="si">}{</span><span class="bp">self</span><span class="o">.</span><span class="n">dialect</span><span class="o">.</span><span class="n">QUOTE_END</span><span class="si">}</span><span class="s2">"</span> +</span><span id="json_extract_segments-1056"><a href="#json_extract_segments-1056"><span class="linenos">1056</span></a> +</span><span id="json_extract_segments-1057"><a href="#json_extract_segments-1057"><span class="linenos">1057</span></a> <span class="n">segments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> +</span><span id="json_extract_segments-1058"><a href="#json_extract_segments-1058"><span class="linenos">1058</span></a> +</span><span id="json_extract_segments-1059"><a href="#json_extract_segments-1059"><span class="linenos">1059</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="o">*</span><span class="n">segments</span><span class="p">)</span> +</span><span id="json_extract_segments-1060"><a href="#json_extract_segments-1060"><span class="linenos">1060</span></a> +</span><span id="json_extract_segments-1061"><a href="#json_extract_segments-1061"><span class="linenos">1061</span></a> <span class="k">return</span> <span class="n">_json_extract_segments</span> </span></pre></div> </section> - <section id="json_path_segments"> - <input id="json_path_segments-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> + <section id="json_path_key_only_name"> + <input id="json_path_key_only_name-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> <div class="attr function"> <span class="def">def</span> - <span class="name">json_path_segments</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span><span class="p">:</span> <span class="n"><a href="../generator.html#Generator">sqlglot.generator.Generator</a></span>,</span><span class="param"> <span class="n">expression</span><span class="p">:</span> <span class="n"><a href="../expressions.html#JSONPath">sqlglot.expressions.JSONPath</a></span></span><span class="return-annotation">) -> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span>:</span></span> + <span class="name">json_path_key_only_name</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span><span class="p">:</span> <span class="n"><a href="../generator.html#Generator">sqlglot.generator.Generator</a></span>,</span><span class="param"> <span class="n">expression</span><span class="p">:</span> <span class="n"><a href="../expressions.html#JSONPathKey">sqlglot.expressions.JSONPathKey</a></span></span><span class="return-annotation">) -> <span class="nb">str</span>:</span></span> - <label class="view-source-button" for="json_path_segments-view-source"><span>View Source</span></label> + <label class="view-source-button" for="json_path_key_only_name-view-source"><span>View Source</span></label> </div> - <a class="headerlink" href="#json_path_segments"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="json_path_segments-1046"><a href="#json_path_segments-1046"><span class="linenos">1046</span></a><span class="k">def</span> <span class="nf">json_path_segments</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">JSONPath</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="json_path_segments-1047"><a href="#json_path_segments-1047"><span class="linenos">1047</span></a> <span class="n">segments</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="json_path_segments-1048"><a href="#json_path_segments-1048"><span class="linenos">1048</span></a> <span class="k">for</span> <span class="n">segment</span> <span class="ow">in</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span><span class="p">:</span> -</span><span id="json_path_segments-1049"><a href="#json_path_segments-1049"><span class="linenos">1049</span></a> <span class="n">path</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">segment</span><span class="p">)</span> -</span><span id="json_path_segments-1050"><a href="#json_path_segments-1050"><span class="linenos">1050</span></a> <span class="k">if</span> <span class="n">path</span><span class="p">:</span> -</span><span id="json_path_segments-1051"><a href="#json_path_segments-1051"><span class="linenos">1051</span></a> <span class="n">segments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">dialect</span><span class="o">.</span><span class="n">QUOTE_START</span><span class="si">}{</span><span class="n">path</span><span class="si">}{</span><span class="bp">self</span><span class="o">.</span><span class="n">dialect</span><span class="o">.</span><span class="n">QUOTE_END</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="json_path_segments-1052"><a href="#json_path_segments-1052"><span class="linenos">1052</span></a> -</span><span id="json_path_segments-1053"><a href="#json_path_segments-1053"><span class="linenos">1053</span></a> <span class="k">return</span> <span class="n">segments</span> + <a class="headerlink" href="#json_path_key_only_name"></a> + <div class="pdoc-code codehilite"><pre><span></span><span id="json_path_key_only_name-1064"><a href="#json_path_key_only_name-1064"><span class="linenos">1064</span></a><span class="k">def</span> <span class="nf">json_path_key_only_name</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">JSONPathKey</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="json_path_key_only_name-1065"><a href="#json_path_key_only_name-1065"><span class="linenos">1065</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">JSONPathWildcard</span><span class="p">):</span> +</span><span id="json_path_key_only_name-1066"><a href="#json_path_key_only_name-1066"><span class="linenos">1066</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="s2">"Unsupported wildcard in JSONPathKey expression"</span><span class="p">)</span> +</span><span id="json_path_key_only_name-1067"><a href="#json_path_key_only_name-1067"><span class="linenos">1067</span></a> +</span><span id="json_path_key_only_name-1068"><a href="#json_path_key_only_name-1068"><span class="linenos">1068</span></a> <span class="k">return</span> <span class="n">expression</span><span class="o">.</span><span class="n">name</span> </span></pre></div> |