Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joocer committed Nov 4, 2023
1 parent 19b7fe0 commit 54dbae2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 10 additions & 1 deletion opteryx/components/binder/binder_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ def visit_exit(self, node: Node, context: BindingContext) -> Tuple[Node, Binding
)

def name_column(qualifier, column):
for projection_column in node.columns:
if (
projection_column.schema_column
and projection_column.schema_column.identity == column.identity
):
if projection_column.alias:
return projection_column.alias
if len(context.schemas) > 1 or needs_qualifier:
return f"{qualifier}.{column.name}"
return column.name
Expand Down Expand Up @@ -517,6 +524,7 @@ def visit_join(self, node: Node, context: BindingContext) -> Tuple[Node, Binding
)
if node.on:
# All except CROSS JOINs have been mapped to have an ON condition
# The JOIN operator only support ON conditions.
node.on, context = inner_binder(node.on, context, node.identity)
node.left_columns, node.right_columns = extract_join_fields(
node.on, node.left_relation_names, node.right_relation_names
Expand Down Expand Up @@ -554,7 +562,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
# shared columns exist in both schemas in some uses and in neither in others
context.schemas[f"$shared-{random_string()}"] = RelationSchema(
name=f"^{left_relation_name}#^{right_relation_name}#", columns=columns
)
Expand All @@ -567,6 +575,7 @@ def visit_join(self, node: Node, context: BindingContext) -> Tuple[Node, Binding
for schema in node.right_relation_names:
context.schemas.pop(schema)

# If we have an unnest_column, how how it is bound is different to other columns
if node.unnest_column:
if not node.unnest_alias:
node.unnest_alias = f"UNNEST({node.unnest_column.query_column})"
Expand Down
2 changes: 0 additions & 2 deletions opteryx/components/logical_planner_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,6 @@ def try_cast(branch, alias=None, key="TryCast"):

def extract(branch, alias=None, key=None):
# EXTRACT(part FROM timestamp)
if not isinstance(alias, list):
alias = [] if alias is None else [alias]
datepart = Node(NodeType.LITERAL, type=OrsoTypes.VARCHAR, value=branch["field"])
value = build(branch["expr"])

Expand Down
2 changes: 0 additions & 2 deletions tests/sql_battery/test_shapes_and_errors_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,8 +1191,6 @@
# [#561] HASH JOIN with an empty table
("SELECT * FROM $planets LEFT JOIN (SELECT planetId as id FROM $satellites WHERE id < 0) USING (id)", None, None, UnnamedSubqueryError),
("SELECT * FROM $planets LEFT JOIN (SELECT planetId as id FROM $satellites WHERE id < 0) AS S USING (id)", 9, 20, None),
]
A = [
# [#646] Incorrectly placed temporal clauses
("SELECT * FROM $planets WHERE 1 = 1 FOR TODAY;", None, None, InvalidTemporalRangeFilterError),
("SELECT * FROM $planets GROUP BY name FOR TODAY;", 9, 1, InvalidTemporalRangeFilterError),
Expand Down

0 comments on commit 54dbae2

Please sign in to comment.