Repository: mabel-dev/opteryx

Issue:
🪲 None appearing in aliases lists
### Thank you for taking the time to report a problem with Opteryx.
_To help us to respond to your request we ask that you try to provide the below detail about the bug._

**Describe the bug** _A clear and specific description of what the bug is. What the error, incorrect or unexpected behaviour was._


**Expected behaviour** _A clear and concise description of what you expected to happen._


**Sample Code/Statement** _If you can, please submit the SQL statement or Python code snippet, or a representative example using the sample datasets._

~~~sql

~~~

**Additional context** _Add any other context about the problem here, for example what you have done to try to diagnose or workaround the problem._



Discussion:

Resolving patch:
diff --git a/opteryx/components/binder/binder.py b/opteryx/components/binder/binder.py
--- a/opteryx/components/binder/binder.py
+++ b/opteryx/components/binder/binder.py
@@ -164,7 +164,7 @@ def create_variable_node(node: Node, context: Dict[str, Any]) -> Node:
         node.source = found_source_relation.name
 
     # if we have an alias for a column not known about in the schema, add it
-    if node.alias not in column.all_names:
+    if node.alias and node.alias not in column.all_names:
         column.aliases.append(node.alias)
 
     # Update node.schema_column with the found column
@@ -233,7 +233,7 @@ def inner_binder(node: Node, context: Dict[str, Any], step: str) -> Tuple[Node,
         column_name = format_expression(node)
         schema_column = ConstantColumn(
             name=column_name,
-            aliases=[node.alias],
+            aliases=[node.alias] if node.alias else [],
             type=node.type,
             value=node.value,
             nullable=False,
@@ -249,7 +249,7 @@ def inner_binder(node: Node, context: Dict[str, Any], step: str) -> Tuple[Node,
         if schema_column:
             schema_column = FlatColumn(
                 name=column_name,
-                aliases=[schema_column.aliases],
+                aliases=[schema_column.aliases] if schema_column.aliases else None,
                 type=0,
                 identity=schema_column.identity,
             )
@@ -286,7 +286,10 @@ def inner_binder(node: Node, context: Dict[str, Any], step: str) -> Tuple[Node,
 
         else:
             schema_column = ExpressionColumn(
-                name=column_name, aliases=[node.alias], type=0, expression=node.value
+                name=column_name,
+                aliases=[node.alias] if node.alias else [],
+                type=0,
+                expression=node.value,
             )
             schemas["$derived"].columns.append(schema_column)
             node.schema_column = schema_column
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
@@ -448,6 +448,8 @@ def visit_join(self, node: Node, context: BindingContext) -> Tuple[Node, Binding
             columns = []
 
             # Loop through all using fields in the node
+            left_relation_name = ""
+            right_relation_name = ""
             for column_name in (n.value for n in node.using):
                 # Try to pop the column from each left relation until found
                 for left_relation_name in node.left_relation_names:
@@ -463,6 +465,7 @@ def visit_join(self, node: Node, context: BindingContext) -> Tuple[Node, Binding
                         columns.append(right_column)
                         break
 
+            # shared columns exist in both schemas in some uses and in neither in other
             context.schemas[f"$shared-{random_string()}"] = RelationSchema(
                 name=f"^{left_relation_name}#^{right_relation_name}#", columns=columns
             )


Test patch: