[jOOQ/jOOQ#14985] Allow for specifying explicit path joins

- Implement this for INNER JOIN and LEFT JOIN
This commit is contained in:
Lukas Eder 2023-04-26 17:04:48 +02:00
parent 49b48887c7
commit cab5e0d78b
2 changed files with 23 additions and 7 deletions

View File

@ -227,9 +227,19 @@ class DefaultRenderContext extends AbstractContext<RenderContext> implements Ren
Table<?> child = root;
List<Table<?>> tables = new ArrayList<>();
while (root instanceof TableImpl && (child = ((TableImpl<?>) root).child) != null) {
tables.add(root);
root = child;
// [#14985] Traverse paths only when referencing paths (!forceNew),
// not when declaring them in FROM (forceNew)
if (!forceNew) {
while (root instanceof TableImpl && (child = ((TableImpl<?>) root).child) != null) {
// [#14985] If a subpath has been declared in FROM, join
// to that, instead of the root.
if (scopeStack.get(root) != null)
break;
tables.add(root);
root = child;
}
}
e = forceNew

View File

@ -566,14 +566,20 @@ implements
emulateNaturalLeftOuterJoin(ctx) ||
emulateNaturalRightOuterJoin(ctx) ||
emulateNaturalFullOuterJoin(ctx)) {
toSQLJoinCondition(ctx, naturalCondition());
}
// Regular JOIN condition
else {
toSQLJoinCondition(ctx, condition);
// [#14985] Path joins additional conditions
else if (rhs instanceof TableImpl && ((TableImpl<?>) rhs).child != null) {
toSQLJoinCondition(ctx, new Join(((TableImpl<?>) rhs).child, rhs)
.onKey(((TableImpl<?>) rhs).childPath)
.condition.getWhere().and(condition.getWhere())
);
}
// Regular JOIN condition
else
toSQLJoinCondition(ctx, condition);
}
@SuppressWarnings({ "rawtypes", "unchecked" })