diff options
Diffstat (limited to 'docs/sqlglot/executor.html')
-rw-r--r-- | docs/sqlglot/executor.html | 230 |
1 files changed, 126 insertions, 104 deletions
diff --git a/docs/sqlglot/executor.html b/docs/sqlglot/executor.html index 22f17f0..64bd241 100644 --- a/docs/sqlglot/executor.html +++ b/docs/sqlglot/executor.html @@ -59,6 +59,9 @@ <a class="variable" href="#logger">logger</a> </li> <li> + <a class="variable" href="#PYTHON_TYPE_TO_SQLGLOT">PYTHON_TYPE_TO_SQLGLOT</a> + </li> + <li> <a class="function" href="#execute">execute</a> </li> </ul> @@ -362,62 +365,68 @@ </span><span id="L-28"><a href="#L-28"><span class="linenos">28</span></a> <span class="kn">from</span> <span class="nn">sqlglot.schema</span> <span class="kn">import</span> <span class="n">Schema</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><span id="L-31"><a href="#L-31"><span class="linenos">31</span></a><span class="k">def</span> <span class="nf">execute</span><span class="p">(</span> -</span><span id="L-32"><a href="#L-32"><span class="linenos">32</span></a> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">Expression</span><span class="p">,</span> -</span><span id="L-33"><a href="#L-33"><span class="linenos">33</span></a> <span class="n">schema</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">|</span> <span class="n">Schema</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> -</span><span id="L-34"><a href="#L-34"><span class="linenos">34</span></a> <span class="n">read</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> -</span><span id="L-35"><a href="#L-35"><span class="linenos">35</span></a> <span class="n">tables</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> -</span><span id="L-36"><a href="#L-36"><span class="linenos">36</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">Table</span><span class="p">:</span> -</span><span id="L-37"><a href="#L-37"><span class="linenos">37</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-38"><a href="#L-38"><span class="linenos">38</span></a><span class="sd"> Run a sql query against data.</span> -</span><span id="L-39"><a href="#L-39"><span class="linenos">39</span></a> -</span><span id="L-40"><a href="#L-40"><span class="linenos">40</span></a><span class="sd"> Args:</span> -</span><span id="L-41"><a href="#L-41"><span class="linenos">41</span></a><span class="sd"> sql: a sql statement.</span> -</span><span id="L-42"><a href="#L-42"><span class="linenos">42</span></a><span class="sd"> schema: database schema.</span> -</span><span id="L-43"><a href="#L-43"><span class="linenos">43</span></a><span class="sd"> This can either be an instance of `Schema` or a mapping in one of the following forms:</span> -</span><span id="L-44"><a href="#L-44"><span class="linenos">44</span></a><span class="sd"> 1. {table: {col: type}}</span> -</span><span id="L-45"><a href="#L-45"><span class="linenos">45</span></a><span class="sd"> 2. {db: {table: {col: type}}}</span> -</span><span id="L-46"><a href="#L-46"><span class="linenos">46</span></a><span class="sd"> 3. {catalog: {db: {table: {col: type}}}}</span> -</span><span id="L-47"><a href="#L-47"><span class="linenos">47</span></a><span class="sd"> read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").</span> -</span><span id="L-48"><a href="#L-48"><span class="linenos">48</span></a><span class="sd"> tables: additional tables to register.</span> -</span><span id="L-49"><a href="#L-49"><span class="linenos">49</span></a> -</span><span id="L-50"><a href="#L-50"><span class="linenos">50</span></a><span class="sd"> Returns:</span> -</span><span id="L-51"><a href="#L-51"><span class="linenos">51</span></a><span class="sd"> Simple columnar data structure.</span> -</span><span id="L-52"><a href="#L-52"><span class="linenos">52</span></a><span class="sd"> """</span> -</span><span id="L-53"><a href="#L-53"><span class="linenos">53</span></a> <span class="n">tables_</span> <span class="o">=</span> <span class="n">ensure_tables</span><span class="p">(</span><span class="n">tables</span><span class="p">)</span> +</span><span id="L-31"><a href="#L-31"><span class="linenos">31</span></a><span class="n">PYTHON_TYPE_TO_SQLGLOT</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="L-32"><a href="#L-32"><span class="linenos">32</span></a> <span class="s2">"dict"</span><span class="p">:</span> <span class="s2">"MAP"</span><span class="p">,</span> +</span><span id="L-33"><a href="#L-33"><span class="linenos">33</span></a><span class="p">}</span> +</span><span id="L-34"><a href="#L-34"><span class="linenos">34</span></a> +</span><span id="L-35"><a href="#L-35"><span class="linenos">35</span></a> +</span><span id="L-36"><a href="#L-36"><span class="linenos">36</span></a><span class="k">def</span> <span class="nf">execute</span><span class="p">(</span> +</span><span id="L-37"><a href="#L-37"><span class="linenos">37</span></a> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">Expression</span><span class="p">,</span> +</span><span id="L-38"><a href="#L-38"><span class="linenos">38</span></a> <span class="n">schema</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">|</span> <span class="n">Schema</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="L-39"><a href="#L-39"><span class="linenos">39</span></a> <span class="n">read</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="L-40"><a href="#L-40"><span class="linenos">40</span></a> <span class="n">tables</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="L-41"><a href="#L-41"><span class="linenos">41</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">Table</span><span class="p">:</span> +</span><span id="L-42"><a href="#L-42"><span class="linenos">42</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-43"><a href="#L-43"><span class="linenos">43</span></a><span class="sd"> Run a sql query against data.</span> +</span><span id="L-44"><a href="#L-44"><span class="linenos">44</span></a> +</span><span id="L-45"><a href="#L-45"><span class="linenos">45</span></a><span class="sd"> Args:</span> +</span><span id="L-46"><a href="#L-46"><span class="linenos">46</span></a><span class="sd"> sql: a sql statement.</span> +</span><span id="L-47"><a href="#L-47"><span class="linenos">47</span></a><span class="sd"> schema: database schema.</span> +</span><span id="L-48"><a href="#L-48"><span class="linenos">48</span></a><span class="sd"> This can either be an instance of `Schema` or a mapping in one of the following forms:</span> +</span><span id="L-49"><a href="#L-49"><span class="linenos">49</span></a><span class="sd"> 1. {table: {col: type}}</span> +</span><span id="L-50"><a href="#L-50"><span class="linenos">50</span></a><span class="sd"> 2. {db: {table: {col: type}}}</span> +</span><span id="L-51"><a href="#L-51"><span class="linenos">51</span></a><span class="sd"> 3. {catalog: {db: {table: {col: type}}}}</span> +</span><span id="L-52"><a href="#L-52"><span class="linenos">52</span></a><span class="sd"> read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").</span> +</span><span id="L-53"><a href="#L-53"><span class="linenos">53</span></a><span class="sd"> tables: additional tables to register.</span> </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">if</span> <span class="ow">not</span> <span class="n">schema</span><span class="p">:</span> -</span><span id="L-56"><a href="#L-56"><span class="linenos">56</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="L-57"><a href="#L-57"><span class="linenos">57</span></a> <span class="n">flattened_tables</span> <span class="o">=</span> <span class="n">flatten_schema</span><span class="p">(</span><span class="n">tables_</span><span class="o">.</span><span class="n">mapping</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="n">dict_depth</span><span class="p">(</span><span class="n">tables_</span><span class="o">.</span><span class="n">mapping</span><span class="p">))</span> -</span><span id="L-58"><a href="#L-58"><span class="linenos">58</span></a> -</span><span id="L-59"><a href="#L-59"><span class="linenos">59</span></a> <span class="k">for</span> <span class="n">keys</span> <span class="ow">in</span> <span class="n">flattened_tables</span><span class="p">:</span> -</span><span id="L-60"><a href="#L-60"><span class="linenos">60</span></a> <span class="n">table</span> <span class="o">=</span> <span class="n">nested_get</span><span class="p">(</span><span class="n">tables_</span><span class="o">.</span><span class="n">mapping</span><span class="p">,</span> <span class="o">*</span><span class="nb">zip</span><span class="p">(</span><span class="n">keys</span><span class="p">,</span> <span class="n">keys</span><span class="p">))</span> -</span><span id="L-61"><a href="#L-61"><span class="linenos">61</span></a> <span class="k">assert</span> <span class="n">table</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</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="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">table</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span> -</span><span id="L-64"><a href="#L-64"><span class="linenos">64</span></a> <span class="n">nested_set</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="p">[</span><span class="o">*</span><span class="n">keys</span><span class="p">,</span> <span class="n">column</span><span class="p">],</span> <span class="nb">type</span><span class="p">(</span><span class="n">table</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">column</span><span class="p">])</span><span class="o">.</span><span class="vm">__name__</span><span class="p">)</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">schema</span> <span class="o">=</span> <span class="n">ensure_schema</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">read</span><span class="p">)</span> +</span><span id="L-55"><a href="#L-55"><span class="linenos">55</span></a><span class="sd"> Returns:</span> +</span><span id="L-56"><a href="#L-56"><span class="linenos">56</span></a><span class="sd"> Simple columnar data structure.</span> +</span><span id="L-57"><a href="#L-57"><span class="linenos">57</span></a><span class="sd"> """</span> +</span><span id="L-58"><a href="#L-58"><span class="linenos">58</span></a> <span class="n">tables_</span> <span class="o">=</span> <span class="n">ensure_tables</span><span class="p">(</span><span class="n">tables</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">read</span><span class="p">)</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="k">if</span> <span class="ow">not</span> <span class="n">schema</span><span class="p">:</span> +</span><span id="L-61"><a href="#L-61"><span class="linenos">61</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="L-62"><a href="#L-62"><span class="linenos">62</span></a> <span class="n">flattened_tables</span> <span class="o">=</span> <span class="n">flatten_schema</span><span class="p">(</span><span class="n">tables_</span><span class="o">.</span><span class="n">mapping</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="n">dict_depth</span><span class="p">(</span><span class="n">tables_</span><span class="o">.</span><span class="n">mapping</span><span class="p">))</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="k">for</span> <span class="n">keys</span> <span class="ow">in</span> <span class="n">flattened_tables</span><span class="p">:</span> +</span><span id="L-65"><a href="#L-65"><span class="linenos">65</span></a> <span class="n">table</span> <span class="o">=</span> <span class="n">nested_get</span><span class="p">(</span><span class="n">tables_</span><span class="o">.</span><span class="n">mapping</span><span class="p">,</span> <span class="o">*</span><span class="nb">zip</span><span class="p">(</span><span class="n">keys</span><span class="p">,</span> <span class="n">keys</span><span class="p">))</span> +</span><span id="L-66"><a href="#L-66"><span class="linenos">66</span></a> <span class="k">assert</span> <span class="n">table</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> </span><span id="L-67"><a href="#L-67"><span class="linenos">67</span></a> -</span><span id="L-68"><a href="#L-68"><span class="linenos">68</span></a> <span class="k">if</span> <span class="n">tables_</span><span class="o">.</span><span class="n">supported_table_args</span> <span class="ow">and</span> <span class="n">tables_</span><span class="o">.</span><span class="n">supported_table_args</span> <span class="o">!=</span> <span class="n">schema</span><span class="o">.</span><span class="n">supported_table_args</span><span class="p">:</span> -</span><span id="L-69"><a href="#L-69"><span class="linenos">69</span></a> <span class="k">raise</span> <span class="n">ExecuteError</span><span class="p">(</span><span class="s2">"Tables must support the same table args as schema"</span><span class="p">)</span> -</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="n">now</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> -</span><span id="L-72"><a href="#L-72"><span class="linenos">72</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">optimize</span><span class="p">(</span><span class="n">sql</span><span class="p">,</span> <span class="n">schema</span><span class="p">,</span> <span class="n">leave_tables_isolated</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">read</span><span class="p">)</span> +</span><span id="L-68"><a href="#L-68"><span class="linenos">68</span></a> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">table</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span> +</span><span id="L-69"><a href="#L-69"><span class="linenos">69</span></a> <span class="n">py_type</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="n">table</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">column</span><span class="p">])</span><span class="o">.</span><span class="vm">__name__</span> +</span><span id="L-70"><a href="#L-70"><span class="linenos">70</span></a> <span class="n">nested_set</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="p">[</span><span class="o">*</span><span class="n">keys</span><span class="p">,</span> <span class="n">column</span><span class="p">],</span> <span class="n">PYTHON_TYPE_TO_SQLGLOT</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">py_type</span><span class="p">)</span> <span class="ow">or</span> <span class="n">py_type</span><span class="p">)</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 class="n">schema</span> <span class="o">=</span> <span class="n">ensure_schema</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">read</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="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Optimization finished: </span><span class="si">%f</span><span class="s2">"</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">now</span><span class="p">)</span> -</span><span id="L-75"><a href="#L-75"><span class="linenos">75</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Optimized SQL: </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span> +</span><span id="L-74"><a href="#L-74"><span class="linenos">74</span></a> <span class="k">if</span> <span class="n">tables_</span><span class="o">.</span><span class="n">supported_table_args</span> <span class="ow">and</span> <span class="n">tables_</span><span class="o">.</span><span class="n">supported_table_args</span> <span class="o">!=</span> <span class="n">schema</span><span class="o">.</span><span class="n">supported_table_args</span><span class="p">:</span> +</span><span id="L-75"><a href="#L-75"><span class="linenos">75</span></a> <span class="k">raise</span> <span class="n">ExecuteError</span><span class="p">(</span><span class="s2">"Tables must support the same table args as schema"</span><span class="p">)</span> </span><span id="L-76"><a href="#L-76"><span class="linenos">76</span></a> -</span><span id="L-77"><a href="#L-77"><span class="linenos">77</span></a> <span class="n">plan</span> <span class="o">=</span> <span class="n">Plan</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="L-78"><a href="#L-78"><span class="linenos">78</span></a> -</span><span id="L-79"><a href="#L-79"><span class="linenos">79</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Logical Plan: </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">plan</span><span class="p">)</span> -</span><span id="L-80"><a href="#L-80"><span class="linenos">80</span></a> -</span><span id="L-81"><a href="#L-81"><span class="linenos">81</span></a> <span class="n">now</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> -</span><span id="L-82"><a href="#L-82"><span class="linenos">82</span></a> <span class="n">result</span> <span class="o">=</span> <span class="n">PythonExecutor</span><span class="p">(</span><span class="n">tables</span><span class="o">=</span><span class="n">tables_</span><span class="p">)</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">plan</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="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Query finished: </span><span class="si">%f</span><span class="s2">"</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">now</span><span class="p">)</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">return</span> <span class="n">result</span> +</span><span id="L-77"><a href="#L-77"><span class="linenos">77</span></a> <span class="n">now</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> +</span><span id="L-78"><a href="#L-78"><span class="linenos">78</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">optimize</span><span class="p">(</span><span class="n">sql</span><span class="p">,</span> <span class="n">schema</span><span class="p">,</span> <span class="n">leave_tables_isolated</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">read</span><span class="p">)</span> +</span><span id="L-79"><a href="#L-79"><span class="linenos">79</span></a> +</span><span id="L-80"><a href="#L-80"><span class="linenos">80</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Optimization finished: </span><span class="si">%f</span><span class="s2">"</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">now</span><span class="p">)</span> +</span><span id="L-81"><a href="#L-81"><span class="linenos">81</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Optimized SQL: </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span> +</span><span id="L-82"><a href="#L-82"><span class="linenos">82</span></a> +</span><span id="L-83"><a href="#L-83"><span class="linenos">83</span></a> <span class="n">plan</span> <span class="o">=</span> <span class="n">Plan</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-84"><a href="#L-84"><span class="linenos">84</span></a> +</span><span id="L-85"><a href="#L-85"><span class="linenos">85</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Logical Plan: </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">plan</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="n">now</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> +</span><span id="L-88"><a href="#L-88"><span class="linenos">88</span></a> <span class="n">result</span> <span class="o">=</span> <span class="n">PythonExecutor</span><span class="p">(</span><span class="n">tables</span><span class="o">=</span><span class="n">tables_</span><span class="p">)</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">plan</span><span class="p">)</span> +</span><span id="L-89"><a href="#L-89"><span class="linenos">89</span></a> +</span><span id="L-90"><a href="#L-90"><span class="linenos">90</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Query finished: </span><span class="si">%f</span><span class="s2">"</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">now</span><span class="p">)</span> +</span><span id="L-91"><a href="#L-91"><span class="linenos">91</span></a> +</span><span id="L-92"><a href="#L-92"><span class="linenos">92</span></a> <span class="k">return</span> <span class="n">result</span> </span></pre></div> @@ -434,6 +443,18 @@ </section> + <section id="PYTHON_TYPE_TO_SQLGLOT"> + <div class="attr variable"> + <span class="name">PYTHON_TYPE_TO_SQLGLOT</span> = +<span class="default_value">{'dict': 'MAP'}</span> + + + </div> + <a class="headerlink" href="#PYTHON_TYPE_TO_SQLGLOT"></a> + + + + </section> <section id="execute"> <input id="execute-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> <div class="attr function"> @@ -445,62 +466,63 @@ </div> <a class="headerlink" href="#execute"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="execute-32"><a href="#execute-32"><span class="linenos">32</span></a><span class="k">def</span> <span class="nf">execute</span><span class="p">(</span> -</span><span id="execute-33"><a href="#execute-33"><span class="linenos">33</span></a> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">Expression</span><span class="p">,</span> -</span><span id="execute-34"><a href="#execute-34"><span class="linenos">34</span></a> <span class="n">schema</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">|</span> <span class="n">Schema</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> -</span><span id="execute-35"><a href="#execute-35"><span class="linenos">35</span></a> <span class="n">read</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> -</span><span id="execute-36"><a href="#execute-36"><span class="linenos">36</span></a> <span class="n">tables</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> -</span><span id="execute-37"><a href="#execute-37"><span class="linenos">37</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">Table</span><span class="p">:</span> -</span><span id="execute-38"><a href="#execute-38"><span class="linenos">38</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="execute-39"><a href="#execute-39"><span class="linenos">39</span></a><span class="sd"> Run a sql query against data.</span> -</span><span id="execute-40"><a href="#execute-40"><span class="linenos">40</span></a> -</span><span id="execute-41"><a href="#execute-41"><span class="linenos">41</span></a><span class="sd"> Args:</span> -</span><span id="execute-42"><a href="#execute-42"><span class="linenos">42</span></a><span class="sd"> sql: a sql statement.</span> -</span><span id="execute-43"><a href="#execute-43"><span class="linenos">43</span></a><span class="sd"> schema: database schema.</span> -</span><span id="execute-44"><a href="#execute-44"><span class="linenos">44</span></a><span class="sd"> This can either be an instance of `Schema` or a mapping in one of the following forms:</span> -</span><span id="execute-45"><a href="#execute-45"><span class="linenos">45</span></a><span class="sd"> 1. {table: {col: type}}</span> -</span><span id="execute-46"><a href="#execute-46"><span class="linenos">46</span></a><span class="sd"> 2. {db: {table: {col: type}}}</span> -</span><span id="execute-47"><a href="#execute-47"><span class="linenos">47</span></a><span class="sd"> 3. {catalog: {db: {table: {col: type}}}}</span> -</span><span id="execute-48"><a href="#execute-48"><span class="linenos">48</span></a><span class="sd"> read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").</span> -</span><span id="execute-49"><a href="#execute-49"><span class="linenos">49</span></a><span class="sd"> tables: additional tables to register.</span> -</span><span id="execute-50"><a href="#execute-50"><span class="linenos">50</span></a> -</span><span id="execute-51"><a href="#execute-51"><span class="linenos">51</span></a><span class="sd"> Returns:</span> -</span><span id="execute-52"><a href="#execute-52"><span class="linenos">52</span></a><span class="sd"> Simple columnar data structure.</span> -</span><span id="execute-53"><a href="#execute-53"><span class="linenos">53</span></a><span class="sd"> """</span> -</span><span id="execute-54"><a href="#execute-54"><span class="linenos">54</span></a> <span class="n">tables_</span> <span class="o">=</span> <span class="n">ensure_tables</span><span class="p">(</span><span class="n">tables</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="execute-37"><a href="#execute-37"><span class="linenos">37</span></a><span class="k">def</span> <span class="nf">execute</span><span class="p">(</span> +</span><span id="execute-38"><a href="#execute-38"><span class="linenos">38</span></a> <span class="n">sql</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="n">Expression</span><span class="p">,</span> +</span><span id="execute-39"><a href="#execute-39"><span class="linenos">39</span></a> <span class="n">schema</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span> <span class="o">|</span> <span class="n">Schema</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="execute-40"><a href="#execute-40"><span class="linenos">40</span></a> <span class="n">read</span><span class="p">:</span> <span class="n">DialectType</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="execute-41"><a href="#execute-41"><span class="linenos">41</span></a> <span class="n">tables</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Dict</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> +</span><span id="execute-42"><a href="#execute-42"><span class="linenos">42</span></a><span class="p">)</span> <span class="o">-></span> <span class="n">Table</span><span class="p">:</span> +</span><span id="execute-43"><a href="#execute-43"><span class="linenos">43</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="execute-44"><a href="#execute-44"><span class="linenos">44</span></a><span class="sd"> Run a sql query against data.</span> +</span><span id="execute-45"><a href="#execute-45"><span class="linenos">45</span></a> +</span><span id="execute-46"><a href="#execute-46"><span class="linenos">46</span></a><span class="sd"> Args:</span> +</span><span id="execute-47"><a href="#execute-47"><span class="linenos">47</span></a><span class="sd"> sql: a sql statement.</span> +</span><span id="execute-48"><a href="#execute-48"><span class="linenos">48</span></a><span class="sd"> schema: database schema.</span> +</span><span id="execute-49"><a href="#execute-49"><span class="linenos">49</span></a><span class="sd"> This can either be an instance of `Schema` or a mapping in one of the following forms:</span> +</span><span id="execute-50"><a href="#execute-50"><span class="linenos">50</span></a><span class="sd"> 1. {table: {col: type}}</span> +</span><span id="execute-51"><a href="#execute-51"><span class="linenos">51</span></a><span class="sd"> 2. {db: {table: {col: type}}}</span> +</span><span id="execute-52"><a href="#execute-52"><span class="linenos">52</span></a><span class="sd"> 3. {catalog: {db: {table: {col: type}}}}</span> +</span><span id="execute-53"><a href="#execute-53"><span class="linenos">53</span></a><span class="sd"> read: the SQL dialect to apply during parsing (eg. "spark", "hive", "presto", "mysql").</span> +</span><span id="execute-54"><a href="#execute-54"><span class="linenos">54</span></a><span class="sd"> tables: additional tables to register.</span> </span><span id="execute-55"><a href="#execute-55"><span class="linenos">55</span></a> -</span><span id="execute-56"><a href="#execute-56"><span class="linenos">56</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">schema</span><span class="p">:</span> -</span><span id="execute-57"><a href="#execute-57"><span class="linenos">57</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="p">{}</span> -</span><span id="execute-58"><a href="#execute-58"><span class="linenos">58</span></a> <span class="n">flattened_tables</span> <span class="o">=</span> <span class="n">flatten_schema</span><span class="p">(</span><span class="n">tables_</span><span class="o">.</span><span class="n">mapping</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="n">dict_depth</span><span class="p">(</span><span class="n">tables_</span><span class="o">.</span><span class="n">mapping</span><span class="p">))</span> -</span><span id="execute-59"><a href="#execute-59"><span class="linenos">59</span></a> -</span><span id="execute-60"><a href="#execute-60"><span class="linenos">60</span></a> <span class="k">for</span> <span class="n">keys</span> <span class="ow">in</span> <span class="n">flattened_tables</span><span class="p">:</span> -</span><span id="execute-61"><a href="#execute-61"><span class="linenos">61</span></a> <span class="n">table</span> <span class="o">=</span> <span class="n">nested_get</span><span class="p">(</span><span class="n">tables_</span><span class="o">.</span><span class="n">mapping</span><span class="p">,</span> <span class="o">*</span><span class="nb">zip</span><span class="p">(</span><span class="n">keys</span><span class="p">,</span> <span class="n">keys</span><span class="p">))</span> -</span><span id="execute-62"><a href="#execute-62"><span class="linenos">62</span></a> <span class="k">assert</span> <span class="n">table</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> -</span><span id="execute-63"><a href="#execute-63"><span class="linenos">63</span></a> -</span><span id="execute-64"><a href="#execute-64"><span class="linenos">64</span></a> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">table</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span> -</span><span id="execute-65"><a href="#execute-65"><span class="linenos">65</span></a> <span class="n">nested_set</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="p">[</span><span class="o">*</span><span class="n">keys</span><span class="p">,</span> <span class="n">column</span><span class="p">],</span> <span class="nb">type</span><span class="p">(</span><span class="n">table</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">column</span><span class="p">])</span><span class="o">.</span><span class="vm">__name__</span><span class="p">)</span> -</span><span id="execute-66"><a href="#execute-66"><span class="linenos">66</span></a> -</span><span id="execute-67"><a href="#execute-67"><span class="linenos">67</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="n">ensure_schema</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">read</span><span class="p">)</span> +</span><span id="execute-56"><a href="#execute-56"><span class="linenos">56</span></a><span class="sd"> Returns:</span> +</span><span id="execute-57"><a href="#execute-57"><span class="linenos">57</span></a><span class="sd"> Simple columnar data structure.</span> +</span><span id="execute-58"><a href="#execute-58"><span class="linenos">58</span></a><span class="sd"> """</span> +</span><span id="execute-59"><a href="#execute-59"><span class="linenos">59</span></a> <span class="n">tables_</span> <span class="o">=</span> <span class="n">ensure_tables</span><span class="p">(</span><span class="n">tables</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">read</span><span class="p">)</span> +</span><span id="execute-60"><a href="#execute-60"><span class="linenos">60</span></a> +</span><span id="execute-61"><a href="#execute-61"><span class="linenos">61</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">schema</span><span class="p">:</span> +</span><span id="execute-62"><a href="#execute-62"><span class="linenos">62</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="p">{}</span> +</span><span id="execute-63"><a href="#execute-63"><span class="linenos">63</span></a> <span class="n">flattened_tables</span> <span class="o">=</span> <span class="n">flatten_schema</span><span class="p">(</span><span class="n">tables_</span><span class="o">.</span><span class="n">mapping</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="n">dict_depth</span><span class="p">(</span><span class="n">tables_</span><span class="o">.</span><span class="n">mapping</span><span class="p">))</span> +</span><span id="execute-64"><a href="#execute-64"><span class="linenos">64</span></a> +</span><span id="execute-65"><a href="#execute-65"><span class="linenos">65</span></a> <span class="k">for</span> <span class="n">keys</span> <span class="ow">in</span> <span class="n">flattened_tables</span><span class="p">:</span> +</span><span id="execute-66"><a href="#execute-66"><span class="linenos">66</span></a> <span class="n">table</span> <span class="o">=</span> <span class="n">nested_get</span><span class="p">(</span><span class="n">tables_</span><span class="o">.</span><span class="n">mapping</span><span class="p">,</span> <span class="o">*</span><span class="nb">zip</span><span class="p">(</span><span class="n">keys</span><span class="p">,</span> <span class="n">keys</span><span class="p">))</span> +</span><span id="execute-67"><a href="#execute-67"><span class="linenos">67</span></a> <span class="k">assert</span> <span class="n">table</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> </span><span id="execute-68"><a href="#execute-68"><span class="linenos">68</span></a> -</span><span id="execute-69"><a href="#execute-69"><span class="linenos">69</span></a> <span class="k">if</span> <span class="n">tables_</span><span class="o">.</span><span class="n">supported_table_args</span> <span class="ow">and</span> <span class="n">tables_</span><span class="o">.</span><span class="n">supported_table_args</span> <span class="o">!=</span> <span class="n">schema</span><span class="o">.</span><span class="n">supported_table_args</span><span class="p">:</span> -</span><span id="execute-70"><a href="#execute-70"><span class="linenos">70</span></a> <span class="k">raise</span> <span class="n">ExecuteError</span><span class="p">(</span><span class="s2">"Tables must support the same table args as schema"</span><span class="p">)</span> -</span><span id="execute-71"><a href="#execute-71"><span class="linenos">71</span></a> -</span><span id="execute-72"><a href="#execute-72"><span class="linenos">72</span></a> <span class="n">now</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> -</span><span id="execute-73"><a href="#execute-73"><span class="linenos">73</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">optimize</span><span class="p">(</span><span class="n">sql</span><span class="p">,</span> <span class="n">schema</span><span class="p">,</span> <span class="n">leave_tables_isolated</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">read</span><span class="p">)</span> +</span><span id="execute-69"><a href="#execute-69"><span class="linenos">69</span></a> <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">table</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span> +</span><span id="execute-70"><a href="#execute-70"><span class="linenos">70</span></a> <span class="n">py_type</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="n">table</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">column</span><span class="p">])</span><span class="o">.</span><span class="vm">__name__</span> +</span><span id="execute-71"><a href="#execute-71"><span class="linenos">71</span></a> <span class="n">nested_set</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="p">[</span><span class="o">*</span><span class="n">keys</span><span class="p">,</span> <span class="n">column</span><span class="p">],</span> <span class="n">PYTHON_TYPE_TO_SQLGLOT</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">py_type</span><span class="p">)</span> <span class="ow">or</span> <span class="n">py_type</span><span class="p">)</span> +</span><span id="execute-72"><a href="#execute-72"><span class="linenos">72</span></a> +</span><span id="execute-73"><a href="#execute-73"><span class="linenos">73</span></a> <span class="n">schema</span> <span class="o">=</span> <span class="n">ensure_schema</span><span class="p">(</span><span class="n">schema</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">read</span><span class="p">)</span> </span><span id="execute-74"><a href="#execute-74"><span class="linenos">74</span></a> -</span><span id="execute-75"><a href="#execute-75"><span class="linenos">75</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Optimization finished: </span><span class="si">%f</span><span class="s2">"</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">now</span><span class="p">)</span> -</span><span id="execute-76"><a href="#execute-76"><span class="linenos">76</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Optimized SQL: </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span> +</span><span id="execute-75"><a href="#execute-75"><span class="linenos">75</span></a> <span class="k">if</span> <span class="n">tables_</span><span class="o">.</span><span class="n">supported_table_args</span> <span class="ow">and</span> <span class="n">tables_</span><span class="o">.</span><span class="n">supported_table_args</span> <span class="o">!=</span> <span class="n">schema</span><span class="o">.</span><span class="n">supported_table_args</span><span class="p">:</span> +</span><span id="execute-76"><a href="#execute-76"><span class="linenos">76</span></a> <span class="k">raise</span> <span class="n">ExecuteError</span><span class="p">(</span><span class="s2">"Tables must support the same table args as schema"</span><span class="p">)</span> </span><span id="execute-77"><a href="#execute-77"><span class="linenos">77</span></a> -</span><span id="execute-78"><a href="#execute-78"><span class="linenos">78</span></a> <span class="n">plan</span> <span class="o">=</span> <span class="n">Plan</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> -</span><span id="execute-79"><a href="#execute-79"><span class="linenos">79</span></a> -</span><span id="execute-80"><a href="#execute-80"><span class="linenos">80</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Logical Plan: </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">plan</span><span class="p">)</span> -</span><span id="execute-81"><a href="#execute-81"><span class="linenos">81</span></a> -</span><span id="execute-82"><a href="#execute-82"><span class="linenos">82</span></a> <span class="n">now</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> -</span><span id="execute-83"><a href="#execute-83"><span class="linenos">83</span></a> <span class="n">result</span> <span class="o">=</span> <span class="n">PythonExecutor</span><span class="p">(</span><span class="n">tables</span><span class="o">=</span><span class="n">tables_</span><span class="p">)</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">plan</span><span class="p">)</span> -</span><span id="execute-84"><a href="#execute-84"><span class="linenos">84</span></a> -</span><span id="execute-85"><a href="#execute-85"><span class="linenos">85</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Query finished: </span><span class="si">%f</span><span class="s2">"</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">now</span><span class="p">)</span> -</span><span id="execute-86"><a href="#execute-86"><span class="linenos">86</span></a> -</span><span id="execute-87"><a href="#execute-87"><span class="linenos">87</span></a> <span class="k">return</span> <span class="n">result</span> +</span><span id="execute-78"><a href="#execute-78"><span class="linenos">78</span></a> <span class="n">now</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> +</span><span id="execute-79"><a href="#execute-79"><span class="linenos">79</span></a> <span class="n">expression</span> <span class="o">=</span> <span class="n">optimize</span><span class="p">(</span><span class="n">sql</span><span class="p">,</span> <span class="n">schema</span><span class="p">,</span> <span class="n">leave_tables_isolated</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dialect</span><span class="o">=</span><span class="n">read</span><span class="p">)</span> +</span><span id="execute-80"><a href="#execute-80"><span class="linenos">80</span></a> +</span><span id="execute-81"><a href="#execute-81"><span class="linenos">81</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Optimization finished: </span><span class="si">%f</span><span class="s2">"</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">now</span><span class="p">)</span> +</span><span id="execute-82"><a href="#execute-82"><span class="linenos">82</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Optimized SQL: </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">expression</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">pretty</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span> +</span><span id="execute-83"><a href="#execute-83"><span class="linenos">83</span></a> +</span><span id="execute-84"><a href="#execute-84"><span class="linenos">84</span></a> <span class="n">plan</span> <span class="o">=</span> <span class="n">Plan</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="execute-85"><a href="#execute-85"><span class="linenos">85</span></a> +</span><span id="execute-86"><a href="#execute-86"><span class="linenos">86</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Logical Plan: </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">plan</span><span class="p">)</span> +</span><span id="execute-87"><a href="#execute-87"><span class="linenos">87</span></a> +</span><span id="execute-88"><a href="#execute-88"><span class="linenos">88</span></a> <span class="n">now</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> +</span><span id="execute-89"><a href="#execute-89"><span class="linenos">89</span></a> <span class="n">result</span> <span class="o">=</span> <span class="n">PythonExecutor</span><span class="p">(</span><span class="n">tables</span><span class="o">=</span><span class="n">tables_</span><span class="p">)</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">plan</span><span class="p">)</span> +</span><span id="execute-90"><a href="#execute-90"><span class="linenos">90</span></a> +</span><span id="execute-91"><a href="#execute-91"><span class="linenos">91</span></a> <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">"Query finished: </span><span class="si">%f</span><span class="s2">"</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">now</span><span class="p">)</span> +</span><span id="execute-92"><a href="#execute-92"><span class="linenos">92</span></a> +</span><span id="execute-93"><a href="#execute-93"><span class="linenos">93</span></a> <span class="k">return</span> <span class="n">result</span> </span></pre></div> |