[jOOQ/jOOQ#8353] Correctly emulate RowSubqueryCondition with embeddables

This commit is contained in:
Lukas Eder 2020-08-26 12:40:32 +02:00
parent 425602980e
commit 7837875e12
2 changed files with 36 additions and 4 deletions

View File

@ -61,6 +61,7 @@ import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.notExists;
import static org.jooq.impl.DSL.row;
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.Tools.embeddedFieldsRow;
import static org.jooq.impl.Tools.visitSubquery;
import java.util.Set;
@ -151,9 +152,10 @@ final class RowSubqueryCondition extends AbstractCondition {
// [#2395] All other configurations have to be emulated
else {
String table = render == null ? "t" : render.nextAlias();
Row l = embeddedFieldsRow(left);
String[] names = new String[left.size()];
for (int i = 0; i < left.size(); i++)
String[] names = new String[l.size()];
for (int i = 0; i < l.size(); i++)
names[i] = table + "_" + i;
Field<?>[] fields = new Field[names.length];
@ -166,7 +168,7 @@ final class RowSubqueryCondition extends AbstractCondition {
case GREATER_OR_EQUAL:
case LESS:
case LESS_OR_EQUAL:
condition = new RowCondition(left, row(fields), comparator);
condition = new RowCondition(l, row(fields), comparator);
break;
case IN:
@ -174,7 +176,7 @@ final class RowSubqueryCondition extends AbstractCondition {
case NOT_IN:
case NOT_EQUALS:
default:
condition = new RowCondition(left, row(fields), EQUALS);
condition = new RowCondition(l, row(fields), EQUALS);
break;
}

View File

@ -96,6 +96,7 @@ import static org.jooq.impl.DSL.getDataType;
import static org.jooq.impl.DSL.keyword;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.nullSafeDataType;
import static org.jooq.impl.DSL.row;
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.DSL.val;
import static org.jooq.impl.DefaultExecuteContext.localConnection;
@ -5359,6 +5360,19 @@ final class Tools {
: null;
}
static final Row embeddedFieldsRow(Row row) {
if (hasEmbeddedFields(row.fields())) {
List<Field<?>> fields = new ArrayList<>(row.size());
for (Field<?> f : flattenCollection(Arrays.asList(row.fields()), false))
fields.add(f);
return row(fields);
}
else
return row;
}
static final Field<?>[] embeddedFields(ScalarSubquery<?> field) {
// Split a scalar subquery of degree N into N scalar subqueries of degree 1
@ -5389,6 +5403,22 @@ final class Tools {
}
}
static final boolean hasEmbeddedFields(Field<?>[] fields) {
for (Field<?> f : fields)
if (f.getDataType().isEmbeddable())
return true;
return false;
}
static final boolean hasEmbeddedFields(Iterable<? extends Field<?>> fields) {
for (Field<?> f : fields)
if (f.getDataType().isEmbeddable())
return true;
return false;
}
static final <E> List<E> collect(Iterable<E> iterable) {
if (iterable instanceof List)
return (List<E>) iterable;