You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
deftest_execute_group_by_order_by_count(self):
tables= {
"x": [
{"t": "a", "a": 6, "y": 2019},
{"t": "b", "a": 12, "y": 2019},
{"t": "c", "a": 15, "y": 2019},
{"t": "a", "a": 10, "y": 2018},
{"t": "b", "a": 12, "y": 2018},
{"t": "c", "a": 2, "y": 2018},
{"t": "a", "a": 9, "y": 2017},
],
}
schema= {
"x": {
"t": "text",
"a": "number",
"y": "number"
},
}
gen=SqlGenerator("mysql")
creates=gen.get_sql_tables_schema(schema)
forcincreates:
print(c.sql(pretty=True, dialect="mysql"), ";", sep="")
inserts=gen.get_sql_tables_content(tables)
foriininserts:
print(i.sql(pretty=True, dialect="mysql"), ";", sep="")
forsql, cols, rowsin [
('select t , sum ( a ) from x group by t order by avg(a) asc limit 1;', ["t", "_col_1"], [("a", 25)]), # PASS
('select t , sum ( a ) from x group by t order by count ( * ) asc limit 1;', ["t", "_col_1"], [("b", 24)]), # FAIL
]:
withself.subTest(sql):
result=execute(sql, read="mysql", schema=schema, tables=tables)
self.assertEqual(result.columns, tuple(cols))
self.assertEqual(result.rows, rows)
SubTest error: Traceback (most recent call last):
File "/Users/.../python3.11/site-packages/sqlglot/executor/python.py", line 40, in execute
contexts[node] = self.aggregate(node, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../python3.11/site-packages/sqlglot/executor/python.py", line 288, in aggregate
add_row()
File "/Users/.../python3.11/site-packages/sqlglot/executor/python.py", line 278, in add_row
table.append(group + context.eval_tuple(aggregations))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../python3.11/site-packages/sqlglot/executor/context.py", line 38, in eval_tuple
return tuple(self.eval(code) for code in codes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/./python3.11/site-packages/sqlglot/executor/context.py", line 38, in <genexpr>
return tuple(self.eval(code) for code in codes)
^^^^^^^^^^^^^^^
File "/Users/./python3.11/site-packages/sqlglot/executor/context.py", line 35, in eval
return eval(code, self.env)
^^^^^^^^^^^^^^^^^^^^
File "COUNT(scope[None]["_a_1"])", line 1, in <module>
KeyError: None
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/.../python3.11/unittest/case.py", line 57, in testPartExecutor
yield
File "/usr/.../python3.11/unittest/case.py", line 538, in subTest
yield
File "/Users/.../src/tr/dbtool/test_executor.py", line 237, in test_execute_group_by_order_by_count
result = execute(sql, read="mysql", schema=schema, tables=tables)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/..../python3.11/site-packages/sqlglot/executor/__init__.py", line 82, in execute
result = PythonExecutor(tables=tables_).execute(plan)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../python3.11/site-packages/sqlglot/executor/python.py", line 60, in execute
raise ExecuteError(f"Step '{node.id}' failed: {e}") from e
sqlglot.errors.ExecuteError: Step 'Aggregate: x (4552043856)' failed: None
The text was updated successfully, but these errors were encountered:
sqlglot==16.8.1
The text was updated successfully, but these errors were encountered: