[mssql] Parse CROSS/OUTER APPLY

T-SQL (and Oracle) support non-standard syntax, which is similar in
functionality to LATERAL joins in ANSI and PostgreSQL
<https://blog.jooq.org/tag/lateral-derived-table/>: it allows to use
the columns from the tables defined to the left of `APPLY` in the
"derived tables" (subqueries) to the right of `APPLY`. Unlike ANSI
LATERAL (but like Postgres' implementation), APPLY is also used with
table-valued function calls.

Despite them being similar, we represent "APPLY" joins with
`JoinOperator`s of its own (`CrossApply` and `OuterApply`). Doing
otherwise seemed like it would cause unnecessary confusion, as those
interested in dialect-specific parsing would probably not expect APPLY
being parsed as LATERAL, and those wanting to forbid non-standard SQL
would not be helped by this either.

This also renames existing JoinOperator::Cross -> CrossJoin to avoid
confusion with CrossApply.
This commit is contained in:
Nickolay Ponomarev 2019-06-19 02:26:51 +03:00
parent 0f6bf15258
commit 4294581ded
5 changed files with 44 additions and 10 deletions

View file

@ -1560,7 +1560,7 @@ fn parse_cross_join() {
args: vec![],
with_hints: vec![],
},
join_operator: JoinOperator::Cross
join_operator: JoinOperator::CrossJoin
},
only(only(select.from).joins),
);
@ -1804,7 +1804,7 @@ fn parse_join_syntax_variants() {
let res = parse_sql_statements("SELECT * FROM a OUTER JOIN b ON 1");
assert_eq!(
ParserError::ParserError("Expected LEFT, RIGHT, or FULL, found: OUTER".to_string()),
ParserError::ParserError("Expected APPLY, found: JOIN".to_string()),
res.unwrap_err()
);
}