Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve

### Fixed

- `build_scope` now registers the relations inside a parenthesized join FROM
Comment thread
ravenac95 marked this conversation as resolved.
item, such as `(a JOIN b ON ...)`, so their columns resolve and qualify and
schema validation no longer reports them as unknown. An aliased join,
`(a JOIN b) AS j`, registers only `j`. `ScopeVisitor::reference` reports
the items inside the join at `depth + 1`, before the join itself, and
subqueries in an unaliased join's conditions now get subquery scopes.
- `build_scope` now gives a subquery scope to a query in an expression field
the scope walk skipped: an aggregate's `FILTER (WHERE ...)`, `ORDER BY` and
`LIMIT`, a window frame bound, a `CAST` `FORMAT` or `DEFAULT` expression,
Expand Down
26 changes: 26 additions & 0 deletions crates/polyglot-sql/src/optimizer/qualify_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3190,6 +3190,32 @@ mod tests {
}
}

#[test]
fn test_qualify_parenthesized_join_columns() {
let mut schema = MappingSchema::new();
schema
.add_table(
"a",
&[("id".into(), DataType::Text), ("x".into(), DataType::Text)],
None,
)
.unwrap();
schema
.add_table(
"b",
&[("id".into(), DataType::Text), ("y".into(), DataType::Text)],
None,
)
.unwrap();
let sql = "SELECT x, y FROM (a JOIN b ON a.id = b.id) WHERE x = y";
let qualified =
qualify_columns(parse(sql), &schema, &QualifyColumnsOptions::new()).unwrap();
assert_eq!(
gen(&qualified),
"SELECT a.x AS x, b.y AS y FROM (a JOIN b ON a.id = b.id) WHERE a.x = b.y"
);
}

#[test]
fn test_get_scope_columns() {
let expr = parse("SELECT a, b FROM t WHERE c = 1");
Expand Down
Loading
Loading