diff options
Diffstat (limited to '')
-rw-r--r-- | docs/sqlglot/executor/context.html | 320 |
1 files changed, 157 insertions, 163 deletions
diff --git a/docs/sqlglot/executor/context.html b/docs/sqlglot/executor/context.html index e31fb2e..6356f3a 100644 --- a/docs/sqlglot/executor/context.html +++ b/docs/sqlglot/executor/context.html @@ -107,107 +107,105 @@ <label class="view-source-button" for="mod-context-view-source"><span>View Source</span></label> - <div class="pdoc-code codehilite"><pre><span></span><span id="L-1"><a href="#L-1"><span class="linenos"> 1</span></a><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">annotations</span> -</span><span id="L-2"><a href="#L-2"><span class="linenos"> 2</span></a> -</span><span id="L-3"><a href="#L-3"><span class="linenos"> 3</span></a><span class="kn">import</span> <span class="nn">typing</span> <span class="k">as</span> <span class="nn">t</span> -</span><span id="L-4"><a href="#L-4"><span class="linenos"> 4</span></a> -</span><span id="L-5"><a href="#L-5"><span class="linenos"> 5</span></a><span class="kn">from</span> <span class="nn">sqlglot.executor.env</span> <span class="kn">import</span> <span class="n">ENV</span> -</span><span id="L-6"><a href="#L-6"><span class="linenos"> 6</span></a> -</span><span id="L-7"><a href="#L-7"><span class="linenos"> 7</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-8"><a href="#L-8"><span class="linenos"> 8</span></a> <span class="kn">from</span> <span class="nn">sqlglot.executor.table</span> <span class="kn">import</span> <span class="n">Table</span><span class="p">,</span> <span class="n">TableIter</span> -</span><span id="L-9"><a href="#L-9"><span class="linenos"> 9</span></a> -</span><span id="L-10"><a href="#L-10"><span class="linenos"> 10</span></a> -</span><span id="L-11"><a href="#L-11"><span class="linenos"> 11</span></a><span class="k">class</span> <span class="nc">Context</span><span class="p">:</span> -</span><span id="L-12"><a href="#L-12"><span class="linenos"> 12</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-13"><a href="#L-13"><span class="linenos"> 13</span></a><span class="sd"> Execution context for sql expressions.</span> -</span><span id="L-14"><a href="#L-14"><span class="linenos"> 14</span></a> -</span><span id="L-15"><a href="#L-15"><span class="linenos"> 15</span></a><span class="sd"> Context is used to hold relevant data tables which can then be queried on with eval.</span> -</span><span id="L-16"><a href="#L-16"><span class="linenos"> 16</span></a> -</span><span id="L-17"><a href="#L-17"><span class="linenos"> 17</span></a><span class="sd"> References to columns can either be scalar or vectors. When set_row is used, column references</span> -</span><span id="L-18"><a href="#L-18"><span class="linenos"> 18</span></a><span class="sd"> evaluate to scalars while set_range evaluates to vectors. This allows convenient and efficient</span> -</span><span id="L-19"><a href="#L-19"><span class="linenos"> 19</span></a><span class="sd"> evaluation of aggregation functions.</span> -</span><span id="L-20"><a href="#L-20"><span class="linenos"> 20</span></a><span class="sd"> """</span> -</span><span id="L-21"><a href="#L-21"><span class="linenos"> 21</span></a> -</span><span id="L-22"><a href="#L-22"><span class="linenos"> 22</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="n">tables</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">Table</span><span class="p">],</span> <span class="n">env</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 class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="L-23"><a href="#L-23"><span class="linenos"> 23</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-24"><a href="#L-24"><span class="linenos"> 24</span></a><span class="sd"> Args</span> -</span><span id="L-25"><a href="#L-25"><span class="linenos"> 25</span></a><span class="sd"> tables: representing the scope of the current execution context.</span> -</span><span id="L-26"><a href="#L-26"><span class="linenos"> 26</span></a><span class="sd"> env: dictionary of functions within the execution context.</span> -</span><span id="L-27"><a href="#L-27"><span class="linenos"> 27</span></a><span class="sd"> """</span> -</span><span id="L-28"><a href="#L-28"><span class="linenos"> 28</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span> <span class="o">=</span> <span class="n">tables</span> -</span><span id="L-29"><a href="#L-29"><span class="linenos"> 29</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_table</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">Table</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-30"><a href="#L-30"><span class="linenos"> 30</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span> <span class="o">=</span> <span class="p">{</span><span class="n">name</span><span class="p">:</span> <span class="n">table</span><span class="o">.</span><span class="n">range_reader</span> <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span> -</span><span id="L-31"><a href="#L-31"><span class="linenos"> 31</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> <span class="o">=</span> <span class="p">{</span><span class="n">name</span><span class="p">:</span> <span class="n">table</span><span class="o">.</span><span class="n">reader</span> <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">table</span> <span class="ow">in</span> <span class="n">tables</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span> -</span><span id="L-32"><a href="#L-32"><span class="linenos"> 32</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span> <span class="o">=</span> <span class="p">{</span><span class="o">**</span><span class="n">ENV</span><span class="p">,</span> <span class="o">**</span><span class="p">(</span><span class="n">env</span> <span class="ow">or</span> <span class="p">{}),</span> <span class="s2">"scope"</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span><span class="p">}</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="k">def</span> <span class="nf">eval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">code</span><span class="p">):</span> -</span><span id="L-35"><a href="#L-35"><span class="linenos"> 35</span></a> <span class="k">return</span> <span class="nb">eval</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">)</span> -</span><span id="L-36"><a href="#L-36"><span class="linenos"> 36</span></a> -</span><span id="L-37"><a href="#L-37"><span class="linenos"> 37</span></a> <span class="k">def</span> <span class="nf">eval_tuple</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">codes</span><span class="p">):</span> -</span><span id="L-38"><a href="#L-38"><span class="linenos"> 38</span></a> <span class="k">return</span> <span class="nb">tuple</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval</span><span class="p">(</span><span class="n">code</span><span class="p">)</span> <span class="k">for</span> <span class="n">code</span> <span class="ow">in</span> <span class="n">codes</span><span class="p">)</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="nd">@property</span> -</span><span id="L-41"><a href="#L-41"><span class="linenos"> 41</span></a> <span class="k">def</span> <span class="nf">table</span><span class="p">(</span><span class="bp">self</span><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="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_table</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> -</span><span id="L-43"><a href="#L-43"><span class="linenos"> 43</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_table</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span> -</span><span id="L-44"><a href="#L-44"><span class="linenos"> 44</span></a> <span class="k">for</span> <span class="n">other</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="L-45"><a href="#L-45"><span class="linenos"> 45</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_table</span><span class="o">.</span><span class="n">columns</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span> -</span><span id="L-46"><a href="#L-46"><span class="linenos"> 46</span></a> <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Columns are different."</span><span class="p">)</span> -</span><span id="L-47"><a href="#L-47"><span class="linenos"> 47</span></a> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_table</span><span class="o">.</span><span class="n">rows</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">rows</span><span class="p">):</span> -</span><span id="L-48"><a href="#L-48"><span class="linenos"> 48</span></a> <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Rows are different."</span><span class="p">)</span> -</span><span id="L-49"><a href="#L-49"><span class="linenos"> 49</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_table</span> -</span><span id="L-50"><a href="#L-50"><span class="linenos"> 50</span></a> -</span><span id="L-51"><a href="#L-51"><span class="linenos"> 51</span></a> <span class="k">def</span> <span class="nf">add_columns</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">columns</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="L-52"><a href="#L-52"><span class="linenos"> 52</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="L-53"><a href="#L-53"><span class="linenos"> 53</span></a> <span class="n">table</span><span class="o">.</span><span class="n">add_columns</span><span class="p">(</span><span class="o">*</span><span class="n">columns</span><span class="p">)</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="nd">@property</span> -</span><span id="L-56"><a href="#L-56"><span class="linenos"> 56</span></a> <span class="k">def</span> <span class="nf">columns</span><span class="p">(</span><span class="bp">self</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><span id="L-57"><a href="#L-57"><span class="linenos"> 57</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">columns</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">def</span> <span class="fm">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> -</span><span id="L-60"><a href="#L-60"><span class="linenos"> 60</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> -</span><span id="L-61"><a href="#L-61"><span class="linenos"> 61</span></a> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">rows</span><span class="p">)):</span> -</span><span id="L-62"><a href="#L-62"><span class="linenos"> 62</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="L-63"><a href="#L-63"><span class="linenos"> 63</span></a> <span class="n">reader</span> <span class="o">=</span> <span class="n">table</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> -</span><span id="L-64"><a href="#L-64"><span class="linenos"> 64</span></a> <span class="k">yield</span> <span class="n">reader</span><span class="p">,</span> <span class="bp">self</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="k">def</span> <span class="nf">table_iter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</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">Iterator</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="n">TableIter</span><span class="p">,</span> <span class="n">Context</span><span class="p">]]:</span> -</span><span id="L-67"><a href="#L-67"><span class="linenos"> 67</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</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="k">for</span> <span class="n">reader</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">[</span><span class="n">table</span><span class="p">]:</span> -</span><span id="L-70"><a href="#L-70"><span class="linenos"> 70</span></a> <span class="k">yield</span> <span class="n">reader</span><span class="p">,</span> <span class="bp">self</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="k">def</span> <span class="nf">filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">condition</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="L-73"><a href="#L-73"><span class="linenos"> 73</span></a> <span class="n">rows</span> <span class="o">=</span> <span class="p">[</span><span class="n">reader</span><span class="o">.</span><span class="n">row</span> <span class="k">for</span> <span class="n">reader</span><span class="p">,</span> <span class="n">_</span> <span class="ow">in</span> <span class="bp">self</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval</span><span class="p">(</span><span class="n">condition</span><span class="p">)]</span> -</span><span id="L-74"><a href="#L-74"><span class="linenos"> 74</span></a> -</span><span id="L-75"><a href="#L-75"><span class="linenos"> 75</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="L-76"><a href="#L-76"><span class="linenos"> 76</span></a> <span class="n">table</span><span class="o">.</span><span class="n">rows</span> <span class="o">=</span> <span class="n">rows</span> -</span><span id="L-77"><a href="#L-77"><span class="linenos"> 77</span></a> -</span><span id="L-78"><a href="#L-78"><span class="linenos"> 78</span></a> <span class="k">def</span> <span class="nf">sort</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="L-79"><a href="#L-79"><span class="linenos"> 79</span></a> <span class="k">def</span> <span class="nf">sort_key</span><span class="p">(</span><span class="n">row</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</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><span id="L-80"><a href="#L-80"><span class="linenos"> 80</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">set_row</span><span class="p">(</span><span class="n">row</span><span class="p">)</span> -</span><span id="L-81"><a href="#L-81"><span class="linenos"> 81</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_tuple</span><span class="p">(</span><span class="n">key</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="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">rows</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="n">sort_key</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="k">def</span> <span class="nf">set_row</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">row</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="L-86"><a href="#L-86"><span class="linenos"> 86</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="L-87"><a href="#L-87"><span class="linenos"> 87</span></a> <span class="n">table</span><span class="o">.</span><span class="n">reader</span><span class="o">.</span><span class="n">row</span> <span class="o">=</span> <span class="n">row</span> -</span><span id="L-88"><a href="#L-88"><span class="linenos"> 88</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</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="k">def</span> <span class="nf">set_index</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">index</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="L-91"><a href="#L-91"><span class="linenos"> 91</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="L-92"><a href="#L-92"><span class="linenos"> 92</span></a> <span class="n">table</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> -</span><span id="L-93"><a href="#L-93"><span class="linenos"> 93</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> -</span><span id="L-94"><a href="#L-94"><span class="linenos"> 94</span></a> -</span><span id="L-95"><a href="#L-95"><span class="linenos"> 95</span></a> <span class="k">def</span> <span class="nf">set_range</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">end</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="L-96"><a href="#L-96"><span class="linenos"> 96</span></a> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">:</span> -</span><span id="L-97"><a href="#L-97"><span class="linenos"> 97</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">range</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> -</span><span id="L-98"><a href="#L-98"><span class="linenos"> 98</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span> -</span><span id="L-99"><a href="#L-99"><span class="linenos"> 99</span></a> -</span><span id="L-100"><a href="#L-100"><span class="linenos">100</span></a> <span class="k">def</span> <span class="fm">__contains__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</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-101"><a href="#L-101"><span class="linenos">101</span></a> <span class="k">return</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="L-1"><a href="#L-1"><span class="linenos"> 1</span></a><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">annotations</span> +</span><span id="L-2"><a href="#L-2"><span class="linenos"> 2</span></a> +</span><span id="L-3"><a href="#L-3"><span class="linenos"> 3</span></a><span class="kn">import</span> <span class="nn">typing</span> <span class="k">as</span> <span class="nn">t</span> +</span><span id="L-4"><a href="#L-4"><span class="linenos"> 4</span></a> +</span><span id="L-5"><a href="#L-5"><span class="linenos"> 5</span></a><span class="kn">from</span> <span class="nn">sqlglot.executor.env</span> <span class="kn">import</span> <span class="n">ENV</span> +</span><span id="L-6"><a href="#L-6"><span class="linenos"> 6</span></a> +</span><span id="L-7"><a href="#L-7"><span class="linenos"> 7</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-8"><a href="#L-8"><span class="linenos"> 8</span></a> <span class="kn">from</span> <span class="nn">sqlglot.executor.table</span> <span class="kn">import</span> <span class="n">Table</span><span class="p">,</span> <span class="n">TableIter</span> +</span><span id="L-9"><a href="#L-9"><span class="linenos"> 9</span></a> +</span><span id="L-10"><a href="#L-10"><span class="linenos">10</span></a> +</span><span id="L-11"><a href="#L-11"><span class="linenos">11</span></a><span class="k">class</span> <span class="nc">Context</span><span class="p">:</span> +</span><span id="L-12"><a href="#L-12"><span class="linenos">12</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-13"><a href="#L-13"><span class="linenos">13</span></a><span class="sd"> Execution context for sql expressions.</span> +</span><span id="L-14"><a href="#L-14"><span class="linenos">14</span></a> +</span><span id="L-15"><a href="#L-15"><span class="linenos">15</span></a><span class="sd"> Context is used to hold relevant data tables which can then be queried on with eval.</span> +</span><span id="L-16"><a href="#L-16"><span class="linenos">16</span></a> +</span><span id="L-17"><a href="#L-17"><span class="linenos">17</span></a><span class="sd"> References to columns can either be scalar or vectors. When set_row is used, column references</span> +</span><span id="L-18"><a href="#L-18"><span class="linenos">18</span></a><span class="sd"> evaluate to scalars while set_range evaluates to vectors. This allows convenient and efficient</span> +</span><span id="L-19"><a href="#L-19"><span class="linenos">19</span></a><span class="sd"> evaluation of aggregation functions.</span> +</span><span id="L-20"><a href="#L-20"><span class="linenos">20</span></a><span class="sd"> """</span> +</span><span id="L-21"><a href="#L-21"><span class="linenos">21</span></a> +</span><span id="L-22"><a href="#L-22"><span class="linenos">22</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="n">tables</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">Table</span><span class="p">],</span> <span class="n">env</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 class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="L-23"><a href="#L-23"><span class="linenos">23</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-24"><a href="#L-24"><span class="linenos">24</span></a><span class="sd"> Args</span> +</span><span id="L-25"><a href="#L-25"><span class="linenos">25</span></a><span class="sd"> tables: representing the scope of the current execution context.</span> +</span><span id="L-26"><a href="#L-26"><span class="linenos">26</span></a><span class="sd"> env: dictionary of functions within the execution context.</span> +</span><span id="L-27"><a href="#L-27"><span class="linenos">27</span></a><span class="sd"> """</span> +</span><span id="L-28"><a href="#L-28"><span class="linenos">28</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span> <span class="o">=</span> <span class="n">tables</span> +</span><span id="L-29"><a href="#L-29"><span class="linenos">29</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_table</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">Table</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="L-30"><a href="#L-30"><span class="linenos">30</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span> <span class="o">=</span> <span class="p">{</span><span class="n">name</span><span class="p">:</span> <span class="n">table</span><span class="o">.</span><span class="n">range_reader</span> <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span> +</span><span id="L-31"><a href="#L-31"><span class="linenos">31</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> <span class="o">=</span> <span class="p">{</span><span class="n">name</span><span class="p">:</span> <span class="n">table</span><span class="o">.</span><span class="n">reader</span> <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">table</span> <span class="ow">in</span> <span class="n">tables</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span> +</span><span id="L-32"><a href="#L-32"><span class="linenos">32</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span> <span class="o">=</span> <span class="p">{</span><span class="o">**</span><span class="n">ENV</span><span class="p">,</span> <span class="o">**</span><span class="p">(</span><span class="n">env</span> <span class="ow">or</span> <span class="p">{}),</span> <span class="s2">"scope"</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span><span class="p">}</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="k">def</span> <span class="nf">eval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">code</span><span class="p">):</span> +</span><span id="L-35"><a href="#L-35"><span class="linenos">35</span></a> <span class="k">return</span> <span class="nb">eval</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">)</span> +</span><span id="L-36"><a href="#L-36"><span class="linenos">36</span></a> +</span><span id="L-37"><a href="#L-37"><span class="linenos">37</span></a> <span class="k">def</span> <span class="nf">eval_tuple</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">codes</span><span class="p">):</span> +</span><span id="L-38"><a href="#L-38"><span class="linenos">38</span></a> <span class="k">return</span> <span class="nb">tuple</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval</span><span class="p">(</span><span class="n">code</span><span class="p">)</span> <span class="k">for</span> <span class="n">code</span> <span class="ow">in</span> <span class="n">codes</span><span class="p">)</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="nd">@property</span> +</span><span id="L-41"><a href="#L-41"><span class="linenos">41</span></a> <span class="k">def</span> <span class="nf">table</span><span class="p">(</span><span class="bp">self</span><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="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_table</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> +</span><span id="L-43"><a href="#L-43"><span class="linenos">43</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_table</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span> +</span><span id="L-44"><a href="#L-44"><span class="linenos">44</span></a> <span class="k">for</span> <span class="n">other</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> +</span><span id="L-45"><a href="#L-45"><span class="linenos">45</span></a> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_table</span><span class="o">.</span><span class="n">columns</span> <span class="o">!=</span> <span class="n">other</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span> +</span><span id="L-46"><a href="#L-46"><span class="linenos">46</span></a> <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Columns are different."</span><span class="p">)</span> +</span><span id="L-47"><a href="#L-47"><span class="linenos">47</span></a> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_table</span><span class="o">.</span><span class="n">rows</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">rows</span><span class="p">):</span> +</span><span id="L-48"><a href="#L-48"><span class="linenos">48</span></a> <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Rows are different."</span><span class="p">)</span> +</span><span id="L-49"><a href="#L-49"><span class="linenos">49</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_table</span> +</span><span id="L-50"><a href="#L-50"><span class="linenos">50</span></a> +</span><span id="L-51"><a href="#L-51"><span class="linenos">51</span></a> <span class="k">def</span> <span class="nf">add_columns</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">columns</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="L-52"><a href="#L-52"><span class="linenos">52</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> +</span><span id="L-53"><a href="#L-53"><span class="linenos">53</span></a> <span class="n">table</span><span class="o">.</span><span class="n">add_columns</span><span class="p">(</span><span class="o">*</span><span class="n">columns</span><span class="p">)</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="nd">@property</span> +</span><span id="L-56"><a href="#L-56"><span class="linenos">56</span></a> <span class="k">def</span> <span class="nf">columns</span><span class="p">(</span><span class="bp">self</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><span id="L-57"><a href="#L-57"><span class="linenos">57</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">columns</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">def</span> <span class="fm">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> +</span><span id="L-60"><a href="#L-60"><span class="linenos">60</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> +</span><span id="L-61"><a href="#L-61"><span class="linenos">61</span></a> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">rows</span><span class="p">)):</span> +</span><span id="L-62"><a href="#L-62"><span class="linenos">62</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> +</span><span id="L-63"><a href="#L-63"><span class="linenos">63</span></a> <span class="n">reader</span> <span class="o">=</span> <span class="n">table</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> +</span><span id="L-64"><a href="#L-64"><span class="linenos">64</span></a> <span class="k">yield</span> <span class="n">reader</span><span class="p">,</span> <span class="bp">self</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="k">def</span> <span class="nf">table_iter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">TableIter</span><span class="p">:</span> +</span><span id="L-67"><a href="#L-67"><span class="linenos">67</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> +</span><span id="L-68"><a href="#L-68"><span class="linenos">68</span></a> <span class="k">return</span> <span class="nb">iter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">[</span><span class="n">table</span><span class="p">])</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 class="k">def</span> <span class="nf">filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">condition</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="L-71"><a href="#L-71"><span class="linenos">71</span></a> <span class="n">rows</span> <span class="o">=</span> <span class="p">[</span><span class="n">reader</span><span class="o">.</span><span class="n">row</span> <span class="k">for</span> <span class="n">reader</span><span class="p">,</span> <span class="n">_</span> <span class="ow">in</span> <span class="bp">self</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval</span><span class="p">(</span><span class="n">condition</span><span class="p">)]</span> +</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">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> +</span><span id="L-74"><a href="#L-74"><span class="linenos">74</span></a> <span class="n">table</span><span class="o">.</span><span class="n">rows</span> <span class="o">=</span> <span class="n">rows</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="nf">sort</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="L-77"><a href="#L-77"><span class="linenos">77</span></a> <span class="k">def</span> <span class="nf">sort_key</span><span class="p">(</span><span class="n">row</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</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><span id="L-78"><a href="#L-78"><span class="linenos">78</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">set_row</span><span class="p">(</span><span class="n">row</span><span class="p">)</span> +</span><span id="L-79"><a href="#L-79"><span class="linenos">79</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_tuple</span><span class="p">(</span><span class="n">key</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="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">rows</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="n">sort_key</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="k">def</span> <span class="nf">set_row</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">row</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="L-84"><a href="#L-84"><span class="linenos">84</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> +</span><span id="L-85"><a href="#L-85"><span class="linenos">85</span></a> <span class="n">table</span><span class="o">.</span><span class="n">reader</span><span class="o">.</span><span class="n">row</span> <span class="o">=</span> <span class="n">row</span> +</span><span id="L-86"><a href="#L-86"><span class="linenos">86</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> +</span><span id="L-87"><a href="#L-87"><span class="linenos">87</span></a> +</span><span id="L-88"><a href="#L-88"><span class="linenos">88</span></a> <span class="k">def</span> <span class="nf">set_index</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">index</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="L-89"><a href="#L-89"><span class="linenos">89</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> +</span><span id="L-90"><a href="#L-90"><span class="linenos">90</span></a> <span class="n">table</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> +</span><span id="L-91"><a href="#L-91"><span class="linenos">91</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</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="k">def</span> <span class="nf">set_range</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">end</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="L-94"><a href="#L-94"><span class="linenos">94</span></a> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">:</span> +</span><span id="L-95"><a href="#L-95"><span class="linenos">95</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">range</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> +</span><span id="L-96"><a href="#L-96"><span class="linenos">96</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span> +</span><span id="L-97"><a href="#L-97"><span class="linenos">97</span></a> +</span><span id="L-98"><a href="#L-98"><span class="linenos">98</span></a> <span class="k">def</span> <span class="fm">__contains__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</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-99"><a href="#L-99"><span class="linenos">99</span></a> <span class="k">return</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span> </span></pre></div> @@ -278,42 +276,40 @@ </span><span id="Context-64"><a href="#Context-64"><span class="linenos"> 64</span></a> <span class="n">reader</span> <span class="o">=</span> <span class="n">table</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> </span><span id="Context-65"><a href="#Context-65"><span class="linenos"> 65</span></a> <span class="k">yield</span> <span class="n">reader</span><span class="p">,</span> <span class="bp">self</span> </span><span id="Context-66"><a href="#Context-66"><span class="linenos"> 66</span></a> -</span><span id="Context-67"><a href="#Context-67"><span class="linenos"> 67</span></a> <span class="k">def</span> <span class="nf">table_iter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</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">Iterator</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="n">TableIter</span><span class="p">,</span> <span class="n">Context</span><span class="p">]]:</span> +</span><span id="Context-67"><a href="#Context-67"><span class="linenos"> 67</span></a> <span class="k">def</span> <span class="nf">table_iter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">TableIter</span><span class="p">:</span> </span><span id="Context-68"><a href="#Context-68"><span class="linenos"> 68</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> -</span><span id="Context-69"><a href="#Context-69"><span class="linenos"> 69</span></a> -</span><span id="Context-70"><a href="#Context-70"><span class="linenos"> 70</span></a> <span class="k">for</span> <span class="n">reader</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">[</span><span class="n">table</span><span class="p">]:</span> -</span><span id="Context-71"><a href="#Context-71"><span class="linenos"> 71</span></a> <span class="k">yield</span> <span class="n">reader</span><span class="p">,</span> <span class="bp">self</span> -</span><span id="Context-72"><a href="#Context-72"><span class="linenos"> 72</span></a> -</span><span id="Context-73"><a href="#Context-73"><span class="linenos"> 73</span></a> <span class="k">def</span> <span class="nf">filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">condition</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Context-74"><a href="#Context-74"><span class="linenos"> 74</span></a> <span class="n">rows</span> <span class="o">=</span> <span class="p">[</span><span class="n">reader</span><span class="o">.</span><span class="n">row</span> <span class="k">for</span> <span class="n">reader</span><span class="p">,</span> <span class="n">_</span> <span class="ow">in</span> <span class="bp">self</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval</span><span class="p">(</span><span class="n">condition</span><span class="p">)]</span> -</span><span id="Context-75"><a href="#Context-75"><span class="linenos"> 75</span></a> -</span><span id="Context-76"><a href="#Context-76"><span class="linenos"> 76</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="Context-77"><a href="#Context-77"><span class="linenos"> 77</span></a> <span class="n">table</span><span class="o">.</span><span class="n">rows</span> <span class="o">=</span> <span class="n">rows</span> -</span><span id="Context-78"><a href="#Context-78"><span class="linenos"> 78</span></a> -</span><span id="Context-79"><a href="#Context-79"><span class="linenos"> 79</span></a> <span class="k">def</span> <span class="nf">sort</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Context-80"><a href="#Context-80"><span class="linenos"> 80</span></a> <span class="k">def</span> <span class="nf">sort_key</span><span class="p">(</span><span class="n">row</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</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><span id="Context-81"><a href="#Context-81"><span class="linenos"> 81</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">set_row</span><span class="p">(</span><span class="n">row</span><span class="p">)</span> -</span><span id="Context-82"><a href="#Context-82"><span class="linenos"> 82</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_tuple</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> +</span><span id="Context-69"><a href="#Context-69"><span class="linenos"> 69</span></a> <span class="k">return</span> <span class="nb">iter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">[</span><span class="n">table</span><span class="p">])</span> +</span><span id="Context-70"><a href="#Context-70"><span class="linenos"> 70</span></a> +</span><span id="Context-71"><a href="#Context-71"><span class="linenos"> 71</span></a> <span class="k">def</span> <span class="nf">filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">condition</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Context-72"><a href="#Context-72"><span class="linenos"> 72</span></a> <span class="n">rows</span> <span class="o">=</span> <span class="p">[</span><span class="n">reader</span><span class="o">.</span><span class="n">row</span> <span class="k">for</span> <span class="n">reader</span><span class="p">,</span> <span class="n">_</span> <span class="ow">in</span> <span class="bp">self</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval</span><span class="p">(</span><span class="n">condition</span><span class="p">)]</span> +</span><span id="Context-73"><a href="#Context-73"><span class="linenos"> 73</span></a> +</span><span id="Context-74"><a href="#Context-74"><span class="linenos"> 74</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> +</span><span id="Context-75"><a href="#Context-75"><span class="linenos"> 75</span></a> <span class="n">table</span><span class="o">.</span><span class="n">rows</span> <span class="o">=</span> <span class="n">rows</span> +</span><span id="Context-76"><a href="#Context-76"><span class="linenos"> 76</span></a> +</span><span id="Context-77"><a href="#Context-77"><span class="linenos"> 77</span></a> <span class="k">def</span> <span class="nf">sort</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Context-78"><a href="#Context-78"><span class="linenos"> 78</span></a> <span class="k">def</span> <span class="nf">sort_key</span><span class="p">(</span><span class="n">row</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</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><span id="Context-79"><a href="#Context-79"><span class="linenos"> 79</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">set_row</span><span class="p">(</span><span class="n">row</span><span class="p">)</span> +</span><span id="Context-80"><a href="#Context-80"><span class="linenos"> 80</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_tuple</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> +</span><span id="Context-81"><a href="#Context-81"><span class="linenos"> 81</span></a> +</span><span id="Context-82"><a href="#Context-82"><span class="linenos"> 82</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">rows</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="n">sort_key</span><span class="p">)</span> </span><span id="Context-83"><a href="#Context-83"><span class="linenos"> 83</span></a> -</span><span id="Context-84"><a href="#Context-84"><span class="linenos"> 84</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">rows</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="n">sort_key</span><span class="p">)</span> -</span><span id="Context-85"><a href="#Context-85"><span class="linenos"> 85</span></a> -</span><span id="Context-86"><a href="#Context-86"><span class="linenos"> 86</span></a> <span class="k">def</span> <span class="nf">set_row</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">row</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Context-87"><a href="#Context-87"><span class="linenos"> 87</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="Context-88"><a href="#Context-88"><span class="linenos"> 88</span></a> <span class="n">table</span><span class="o">.</span><span class="n">reader</span><span class="o">.</span><span class="n">row</span> <span class="o">=</span> <span class="n">row</span> -</span><span id="Context-89"><a href="#Context-89"><span class="linenos"> 89</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> -</span><span id="Context-90"><a href="#Context-90"><span class="linenos"> 90</span></a> -</span><span id="Context-91"><a href="#Context-91"><span class="linenos"> 91</span></a> <span class="k">def</span> <span class="nf">set_index</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">index</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Context-92"><a href="#Context-92"><span class="linenos"> 92</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="Context-93"><a href="#Context-93"><span class="linenos"> 93</span></a> <span class="n">table</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> -</span><span id="Context-94"><a href="#Context-94"><span class="linenos"> 94</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> -</span><span id="Context-95"><a href="#Context-95"><span class="linenos"> 95</span></a> -</span><span id="Context-96"><a href="#Context-96"><span class="linenos"> 96</span></a> <span class="k">def</span> <span class="nf">set_range</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">end</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Context-97"><a href="#Context-97"><span class="linenos"> 97</span></a> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">:</span> -</span><span id="Context-98"><a href="#Context-98"><span class="linenos"> 98</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">range</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> -</span><span id="Context-99"><a href="#Context-99"><span class="linenos"> 99</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span> -</span><span id="Context-100"><a href="#Context-100"><span class="linenos">100</span></a> -</span><span id="Context-101"><a href="#Context-101"><span class="linenos">101</span></a> <span class="k">def</span> <span class="fm">__contains__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</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="Context-102"><a href="#Context-102"><span class="linenos">102</span></a> <span class="k">return</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span> +</span><span id="Context-84"><a href="#Context-84"><span class="linenos"> 84</span></a> <span class="k">def</span> <span class="nf">set_row</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">row</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Context-85"><a href="#Context-85"><span class="linenos"> 85</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> +</span><span id="Context-86"><a href="#Context-86"><span class="linenos"> 86</span></a> <span class="n">table</span><span class="o">.</span><span class="n">reader</span><span class="o">.</span><span class="n">row</span> <span class="o">=</span> <span class="n">row</span> +</span><span id="Context-87"><a href="#Context-87"><span class="linenos"> 87</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> +</span><span id="Context-88"><a href="#Context-88"><span class="linenos"> 88</span></a> +</span><span id="Context-89"><a href="#Context-89"><span class="linenos"> 89</span></a> <span class="k">def</span> <span class="nf">set_index</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">index</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Context-90"><a href="#Context-90"><span class="linenos"> 90</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> +</span><span id="Context-91"><a href="#Context-91"><span class="linenos"> 91</span></a> <span class="n">table</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> +</span><span id="Context-92"><a href="#Context-92"><span class="linenos"> 92</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> +</span><span id="Context-93"><a href="#Context-93"><span class="linenos"> 93</span></a> +</span><span id="Context-94"><a href="#Context-94"><span class="linenos"> 94</span></a> <span class="k">def</span> <span class="nf">set_range</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">end</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Context-95"><a href="#Context-95"><span class="linenos"> 95</span></a> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">:</span> +</span><span id="Context-96"><a href="#Context-96"><span class="linenos"> 96</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">range</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> +</span><span id="Context-97"><a href="#Context-97"><span class="linenos"> 97</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span> +</span><span id="Context-98"><a href="#Context-98"><span class="linenos"> 98</span></a> +</span><span id="Context-99"><a href="#Context-99"><span class="linenos"> 99</span></a> <span class="k">def</span> <span class="fm">__contains__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</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="Context-100"><a href="#Context-100"><span class="linenos">100</span></a> <span class="k">return</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span> </span></pre></div> @@ -487,17 +483,15 @@ evaluation of aggregation functions.</p> <div class="attr function"> <span class="def">def</span> - <span class="name">table_iter</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="bp">self</span>,</span><span class="param"> <span class="n">table</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n">Iterator</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="n"><a href="table.html#TableIter">sqlglot.executor.table.TableIter</a></span><span class="p">,</span> <span class="n"><a href="#Context">sqlglot.executor.context.Context</a></span><span class="p">]]</span>:</span></span> + <span class="name">table_iter</span><span class="signature pdoc-code condensed">(<span class="param"><span class="bp">self</span>, </span><span class="param"><span class="n">table</span><span class="p">:</span> <span class="nb">str</span></span><span class="return-annotation">) -> <span class="n"><a href="table.html#TableIter">sqlglot.executor.table.TableIter</a></span>:</span></span> <label class="view-source-button" for="Context.table_iter-view-source"><span>View Source</span></label> </div> <a class="headerlink" href="#Context.table_iter"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Context.table_iter-67"><a href="#Context.table_iter-67"><span class="linenos">67</span></a> <span class="k">def</span> <span class="nf">table_iter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</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">Iterator</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">[</span><span class="n">TableIter</span><span class="p">,</span> <span class="n">Context</span><span class="p">]]:</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Context.table_iter-67"><a href="#Context.table_iter-67"><span class="linenos">67</span></a> <span class="k">def</span> <span class="nf">table_iter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">TableIter</span><span class="p">:</span> </span><span id="Context.table_iter-68"><a href="#Context.table_iter-68"><span class="linenos">68</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> -</span><span id="Context.table_iter-69"><a href="#Context.table_iter-69"><span class="linenos">69</span></a> -</span><span id="Context.table_iter-70"><a href="#Context.table_iter-70"><span class="linenos">70</span></a> <span class="k">for</span> <span class="n">reader</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">[</span><span class="n">table</span><span class="p">]:</span> -</span><span id="Context.table_iter-71"><a href="#Context.table_iter-71"><span class="linenos">71</span></a> <span class="k">yield</span> <span class="n">reader</span><span class="p">,</span> <span class="bp">self</span> +</span><span id="Context.table_iter-69"><a href="#Context.table_iter-69"><span class="linenos">69</span></a> <span class="k">return</span> <span class="nb">iter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">[</span><span class="n">table</span><span class="p">])</span> </span></pre></div> @@ -515,11 +509,11 @@ evaluation of aggregation functions.</p> </div> <a class="headerlink" href="#Context.filter"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Context.filter-73"><a href="#Context.filter-73"><span class="linenos">73</span></a> <span class="k">def</span> <span class="nf">filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">condition</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Context.filter-74"><a href="#Context.filter-74"><span class="linenos">74</span></a> <span class="n">rows</span> <span class="o">=</span> <span class="p">[</span><span class="n">reader</span><span class="o">.</span><span class="n">row</span> <span class="k">for</span> <span class="n">reader</span><span class="p">,</span> <span class="n">_</span> <span class="ow">in</span> <span class="bp">self</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval</span><span class="p">(</span><span class="n">condition</span><span class="p">)]</span> -</span><span id="Context.filter-75"><a href="#Context.filter-75"><span class="linenos">75</span></a> -</span><span id="Context.filter-76"><a href="#Context.filter-76"><span class="linenos">76</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="Context.filter-77"><a href="#Context.filter-77"><span class="linenos">77</span></a> <span class="n">table</span><span class="o">.</span><span class="n">rows</span> <span class="o">=</span> <span class="n">rows</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Context.filter-71"><a href="#Context.filter-71"><span class="linenos">71</span></a> <span class="k">def</span> <span class="nf">filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">condition</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Context.filter-72"><a href="#Context.filter-72"><span class="linenos">72</span></a> <span class="n">rows</span> <span class="o">=</span> <span class="p">[</span><span class="n">reader</span><span class="o">.</span><span class="n">row</span> <span class="k">for</span> <span class="n">reader</span><span class="p">,</span> <span class="n">_</span> <span class="ow">in</span> <span class="bp">self</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval</span><span class="p">(</span><span class="n">condition</span><span class="p">)]</span> +</span><span id="Context.filter-73"><a href="#Context.filter-73"><span class="linenos">73</span></a> +</span><span id="Context.filter-74"><a href="#Context.filter-74"><span class="linenos">74</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> +</span><span id="Context.filter-75"><a href="#Context.filter-75"><span class="linenos">75</span></a> <span class="n">table</span><span class="o">.</span><span class="n">rows</span> <span class="o">=</span> <span class="n">rows</span> </span></pre></div> @@ -537,12 +531,12 @@ evaluation of aggregation functions.</p> </div> <a class="headerlink" href="#Context.sort"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Context.sort-79"><a href="#Context.sort-79"><span class="linenos">79</span></a> <span class="k">def</span> <span class="nf">sort</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Context.sort-80"><a href="#Context.sort-80"><span class="linenos">80</span></a> <span class="k">def</span> <span class="nf">sort_key</span><span class="p">(</span><span class="n">row</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</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><span id="Context.sort-81"><a href="#Context.sort-81"><span class="linenos">81</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">set_row</span><span class="p">(</span><span class="n">row</span><span class="p">)</span> -</span><span id="Context.sort-82"><a href="#Context.sort-82"><span class="linenos">82</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_tuple</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> -</span><span id="Context.sort-83"><a href="#Context.sort-83"><span class="linenos">83</span></a> -</span><span id="Context.sort-84"><a href="#Context.sort-84"><span class="linenos">84</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">rows</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="n">sort_key</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Context.sort-77"><a href="#Context.sort-77"><span class="linenos">77</span></a> <span class="k">def</span> <span class="nf">sort</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Context.sort-78"><a href="#Context.sort-78"><span class="linenos">78</span></a> <span class="k">def</span> <span class="nf">sort_key</span><span class="p">(</span><span class="n">row</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</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><span id="Context.sort-79"><a href="#Context.sort-79"><span class="linenos">79</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">set_row</span><span class="p">(</span><span class="n">row</span><span class="p">)</span> +</span><span id="Context.sort-80"><a href="#Context.sort-80"><span class="linenos">80</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_tuple</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> +</span><span id="Context.sort-81"><a href="#Context.sort-81"><span class="linenos">81</span></a> +</span><span id="Context.sort-82"><a href="#Context.sort-82"><span class="linenos">82</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">rows</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="n">sort_key</span><span class="p">)</span> </span></pre></div> @@ -560,10 +554,10 @@ evaluation of aggregation functions.</p> </div> <a class="headerlink" href="#Context.set_row"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Context.set_row-86"><a href="#Context.set_row-86"><span class="linenos">86</span></a> <span class="k">def</span> <span class="nf">set_row</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">row</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Context.set_row-87"><a href="#Context.set_row-87"><span class="linenos">87</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="Context.set_row-88"><a href="#Context.set_row-88"><span class="linenos">88</span></a> <span class="n">table</span><span class="o">.</span><span class="n">reader</span><span class="o">.</span><span class="n">row</span> <span class="o">=</span> <span class="n">row</span> -</span><span id="Context.set_row-89"><a href="#Context.set_row-89"><span class="linenos">89</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Context.set_row-84"><a href="#Context.set_row-84"><span class="linenos">84</span></a> <span class="k">def</span> <span class="nf">set_row</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">row</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Tuple</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Context.set_row-85"><a href="#Context.set_row-85"><span class="linenos">85</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> +</span><span id="Context.set_row-86"><a href="#Context.set_row-86"><span class="linenos">86</span></a> <span class="n">table</span><span class="o">.</span><span class="n">reader</span><span class="o">.</span><span class="n">row</span> <span class="o">=</span> <span class="n">row</span> +</span><span id="Context.set_row-87"><a href="#Context.set_row-87"><span class="linenos">87</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> </span></pre></div> @@ -581,10 +575,10 @@ evaluation of aggregation functions.</p> </div> <a class="headerlink" href="#Context.set_index"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Context.set_index-91"><a href="#Context.set_index-91"><span class="linenos">91</span></a> <span class="k">def</span> <span class="nf">set_index</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">index</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Context.set_index-92"><a href="#Context.set_index-92"><span class="linenos">92</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> -</span><span id="Context.set_index-93"><a href="#Context.set_index-93"><span class="linenos">93</span></a> <span class="n">table</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> -</span><span id="Context.set_index-94"><a href="#Context.set_index-94"><span class="linenos">94</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Context.set_index-89"><a href="#Context.set_index-89"><span class="linenos">89</span></a> <span class="k">def</span> <span class="nf">set_index</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">index</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Context.set_index-90"><a href="#Context.set_index-90"><span class="linenos">90</span></a> <span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="o">.</span><span class="n">values</span><span class="p">():</span> +</span><span id="Context.set_index-91"><a href="#Context.set_index-91"><span class="linenos">91</span></a> <span class="n">table</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> +</span><span id="Context.set_index-92"><a href="#Context.set_index-92"><span class="linenos">92</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">row_readers</span> </span></pre></div> @@ -602,10 +596,10 @@ evaluation of aggregation functions.</p> </div> <a class="headerlink" href="#Context.set_range"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Context.set_range-96"><a href="#Context.set_range-96"><span class="linenos">96</span></a> <span class="k">def</span> <span class="nf">set_range</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">end</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> -</span><span id="Context.set_range-97"><a href="#Context.set_range-97"><span class="linenos">97</span></a> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">:</span> -</span><span id="Context.set_range-98"><a href="#Context.set_range-98"><span class="linenos">98</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">range</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> -</span><span id="Context.set_range-99"><a href="#Context.set_range-99"><span class="linenos">99</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Context.set_range-94"><a href="#Context.set_range-94"><span class="linenos">94</span></a> <span class="k">def</span> <span class="nf">set_range</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">end</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span> +</span><span id="Context.set_range-95"><a href="#Context.set_range-95"><span class="linenos">95</span></a> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">:</span> +</span><span id="Context.set_range-96"><a href="#Context.set_range-96"><span class="linenos">96</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">range</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> +</span><span id="Context.set_range-97"><a href="#Context.set_range-97"><span class="linenos">97</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">[</span><span class="s2">"scope"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">range_readers</span> </span></pre></div> |