[jOOQ/jOOQ#8353] Correctly emulate RowSubqueryCondition with embeddables
This commit is contained in:
parent
425602980e
commit
7837875e12
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user