[jOOQ/jOOQ#14074] Add support for passing a list of bind values to DSL.unnest(Collection)
This commit is contained in:
parent
6349b4ff57
commit
1b3b100d26
@ -116,15 +116,6 @@ final class ArrayTable extends AbstractTable<Record> implements UNotYetImplement
|
||||
this.field = init(arrayType, this.alias, this.fieldAliases[0]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
static final DataType<?> componentDataType(Object[] array) {
|
||||
if (!isEmpty(array) && array[0] instanceof Field<?> f) {
|
||||
return f.getDataType();
|
||||
}
|
||||
else
|
||||
return DSL.getDataType(array.getClass().getComponentType());
|
||||
}
|
||||
|
||||
static final FieldsImpl<Record> init(Class<?> arrayType, Name alias, Name fieldAlias) {
|
||||
|
||||
// [#1114] [#7863] VARRAY/TABLE of OBJECT have more than one field
|
||||
|
||||
@ -43,6 +43,7 @@ import static org.jooq.impl.DSL.one;
|
||||
import static org.jooq.impl.DSL.using;
|
||||
import static org.jooq.impl.Names.N_ARRAY_TABLE;
|
||||
import static org.jooq.impl.Names.N_COLUMN_VALUE;
|
||||
import static org.jooq.impl.Tools.componentDataType;
|
||||
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Context;
|
||||
@ -83,7 +84,7 @@ final class ArrayTableEmulation extends AbstractTable<Record> implements UTransi
|
||||
this.array = array;
|
||||
this.alias = alias;
|
||||
this.fieldAlias = fieldAlias == null ? N_COLUMN_VALUE : fieldAlias;
|
||||
this.field = new FieldsImpl<>(DSL.field(name(alias.last(), this.fieldAlias.last()), ArrayTable.componentDataType(array)));
|
||||
this.field = new FieldsImpl<>(DSL.field(name(alias.last(), this.fieldAlias.last()), componentDataType(array)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -125,6 +125,7 @@ import static org.jooq.impl.Tools.combine;
|
||||
import static org.jooq.impl.Tools.configuration;
|
||||
import static org.jooq.impl.Tools.isEmpty;
|
||||
import static org.jooq.impl.Tools.map;
|
||||
import static org.jooq.impl.Tools.mostSpecificArray;
|
||||
import static org.jooq.tools.StringUtils.isEmpty;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -11261,8 +11262,12 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support
|
||||
public static Table<?> unnest(Object[] array) {
|
||||
if (!isEmpty(array) && array[0] instanceof Field)
|
||||
boolean notEmpty = !isEmpty(array);
|
||||
|
||||
if (notEmpty && array[0] instanceof Field)
|
||||
return new ArrayOfValues(Tools.fieldsArray(array));
|
||||
else if (notEmpty && array.getClass() == Object[].class)
|
||||
return unnest0(val(mostSpecificArray(array)));
|
||||
else
|
||||
return unnest0(val(array));
|
||||
}
|
||||
|
||||
@ -7262,4 +7262,31 @@ final class Tools {
|
||||
return !FALSE.equals(ctx.settings().isRenderVariablesInDerivedTablesForEmulations())
|
||||
&& !NO_SUPPORT_CORRELATED_DERIVED_TABLE.contains(ctx.dialect());
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
static final DataType<?> componentDataType(Object[] array) {
|
||||
if (!isEmpty(array) && array[0] instanceof Field<?> f) {
|
||||
return f.getDataType();
|
||||
}
|
||||
else
|
||||
return DSL.getDataType(array.getClass().getComponentType());
|
||||
}
|
||||
|
||||
static final Object[] mostSpecificArray(Object[] array) {
|
||||
if (isEmpty(array))
|
||||
return array;
|
||||
|
||||
Class<?> type = null;
|
||||
for (Object o : array)
|
||||
if (o != null)
|
||||
if (type == null)
|
||||
type = o.getClass();
|
||||
else if (type != o.getClass())
|
||||
return array;
|
||||
|
||||
if (type == null)
|
||||
return array;
|
||||
else
|
||||
return Convert.convertArray(array, type);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user