Repository: mabel-dev/opteryx

Issue:
🪲 GENERATE_SERIES formatting incorrectly



Discussion:

Resolving patch:
diff --git a/opteryx/components/binder/binder_visitor.py b/opteryx/components/binder/binder_visitor.py
--- a/opteryx/components/binder/binder_visitor.py
+++ b/opteryx/components/binder/binder_visitor.py
@@ -375,15 +375,24 @@ def visit_function_dataset(
             context.schemas[relation_name] = schema
             node.columns = columns
         elif node.function == "GENERATE_SERIES":
+            node.alias = node.alias or "generate_series"
+            node.relation_name = node.alias
+            columns = [
+                LogicalColumn(
+                    node_type=NodeType.IDENTIFIER,
+                    source_column=node.alias,
+                    source=node.relation_name,
+                    schema_column=FlatColumn(name=node.alias, type=0),
+                )
+            ]
             schema = RelationSchema(
-                name=node.alias,
-                columns=[FlatColumn(name=node.alias or "generate_series", type=0)],
+                name=node.relation_name,
+                columns=[c.schema_column for c in columns],
             )
-            context.schemas[node.alias] = schema
-            node.columns = [schema.columns[0].identity]
-            node.relation_name = node.alias
+            context.schemas[node.relation_name] = schema
+            node.columns = columns
         else:
-            raise NotImplementedError(f"{node.function} binding isn't written yet")
+            raise NotImplementedError(f"{node.function} does not exist")
         return node, context
 
     def visit_join(self, node: Node, context: BindingContext) -> Tuple[Node, BindingContext]:
diff --git a/opteryx/components/logical_planner.py b/opteryx/components/logical_planner.py
--- a/opteryx/components/logical_planner.py
+++ b/opteryx/components/logical_planner.py
@@ -706,6 +706,7 @@ def plan_show_columns(statement):
         previous_step_id, step_id = step_id, random_string()
         plan.add_node(step_id, filter_node)
         plan.add_edge(previous_step_id, step_id)
+        raise UnsupportedSyntaxError("Unable to filter colmns in SHOW COLUMNS")
 
     return plan
 
diff --git a/opteryx/operators/function_dataset_node.py b/opteryx/operators/function_dataset_node.py
--- a/opteryx/operators/function_dataset_node.py
+++ b/opteryx/operators/function_dataset_node.py
@@ -32,7 +32,7 @@
 
 def _generate_series(**kwargs):
     value_array = series.generate_series(*kwargs["args"])
-    return [{kwargs["columns"][0]: value} for value in value_array]
+    return [{kwargs["columns"][0].schema_column.identity: value} for value in value_array]
 
 
 def _unnest(**kwargs):


Test patch:
diff --git a/tests/sql_battery/test_shapes_and_errors_battery.py b/tests/sql_battery/test_shapes_and_errors_battery.py
--- a/tests/sql_battery/test_shapes_and_errors_battery.py
+++ b/tests/sql_battery/test_shapes_and_errors_battery.py
@@ -561,8 +561,7 @@
         ("SELECT * FROM UNNEST(('foo', 'bar', 'baz', 'qux', 'corge', 'garply', 'waldo', 'fred')) AS element WHERE element LIKE '%e%'", 2, 1, None),
         ("SELECT * FROM UNNEST(('foo', 'bar', 'baz', 'qux', 'corge', 'garply', 'waldo', 'fred')) AS UN", 8, 1, None),
         ("SELECT * FROM UNNEST(('foo', 'bar', 'baz', 'qux', 'corge', 'garply', 'waldo', 'fred')) AS UN WHERE UN LIKE '%e%'", 2, 1, None),
-]
-A = [
+
         ("SELECT * FROM generate_series(1, 10)", 10, 1, UnnamedColumnError),
         ("SELECT * FROM generate_series(1, 10) AS GS", 10, 1, None),
         ("SELECT * FROM generate_series(-10,10) AS GS", 21, 1, None),
@@ -699,7 +698,7 @@
         ("SHOW EXTENDED COLUMNS FROM $satellites", 8, 10, None),
         ("SHOW EXTENDED COLUMNS FROM $planets", 20, 10, None),
         ("SHOW EXTENDED COLUMNS FROM $astronauts", 19, 10, None),
-# temp        ("SHOW COLUMNS FROM $satellites LIKE '%d'", 2, 4, None),
+        ("SHOW COLUMNS FROM $satellites LIKE '%d'", 2, 4, UnsupportedSyntaxError),
         ("SHOW COLUMNS FROM testdata.partitioned.dated FOR '2020-02-03'", 8, 4, None),
 
         ("SELECT * FROM $satellites CROSS JOIN $astronauts", 63189, 27, None),
@@ -723,6 +722,7 @@
         ("SELECT * FROM $planets LEFT JOIN $planets FOR TODAY USING(id)", 9, 40, AmbiguousDatasetError),
         ("SELECT * FROM $planets LEFT JOIN $planets USING(id, name)", 9, 40, AmbiguousDatasetError),
         ("SELECT * FROM $planets INNER JOIN $planets ON id = id AND name = name", None, None, AmbiguousDatasetError),
+
         ("SELECT P_1.* FROM $planets AS P_1 INNER JOIN $planets AS P_2 ON P_1.id = P_2.id", 9, 20, None),
         ("SELECT P_2.* FROM $planets AS P_1 INNER JOIN $planets AS P_2 ON P_1.id = P_2.id", 9, 20, None),
         ("SELECT P_1.* FROM $planets AS P_1 INNER JOIN $planets AS P_2 ON P_2.id = P_1.id", 9, 20, None),
@@ -752,7 +752,8 @@
 #        ("SELECT P_1.* FROM $planets AS P_1 INNER JOIN $planets AS P_2 ON P_1.id = P_2.id AND P_1.id > 2", 7, 20, None),
 #        ("SELECT P_1.* FROM $planets AS P_1 INNER JOIN $satellites AS P_2 ON P_1.id = P_2.planet_id AND P_2.id != 5", 9, 20, None),
         ("SELECT P_1.* FROM $planets AS P_1 INNER JOIN $planets AS P_2 ON P_1.id = P_2.id AND P_1.name = P_2.name AND P_1.mass = P_2.mass", 9, 20, None),
-
+]
+A = [
         ("SELECT * FROM $planets AS P_1 INNER JOIN $planets AS P_2 ON P_1.id = P_2.id AND P_2.name = P_1.name", 9, 40, None),
         ("SELECT * FROM $planets NATURAL JOIN generate_series(1, 5) as id", 5, 20, None),
         ("SELECT * FROM $planets AS P1 NATURAL JOIN $planets AS P2", 5, 20, None),