[jOOQ/jOOQ#13013] Interpreter does not correctly interpret CREATE INDEX

.. WHERE

This includes:

- [jOOQ/jOOQ#12428] DDL export no longer exports INDEX WHERE clause
This commit is contained in:
Lukas Eder 2022-02-08 13:48:13 +01:00
parent 1d5c8c2ccf
commit 496faf7489
5 changed files with 25 additions and 26 deletions

View File

@ -81,14 +81,6 @@ package org.jooq;

View File

@ -66,6 +66,7 @@ import org.jooq.ConstraintEnforcementStep;
import org.jooq.CreateDomainAsStep;
import org.jooq.CreateDomainConstraintStep;
import org.jooq.CreateDomainDefaultStep;
import org.jooq.CreateIndexIncludeStep;
import org.jooq.CreateSequenceFlagsStep;
import org.jooq.CreateTableOnCommitStep;
import org.jooq.CreateViewAsStep;
@ -236,14 +237,17 @@ final class DDL {
}
final Query createIndex(Index i) {
return (configuration.createIndexIfNotExists()
? i.getUnique()
? ctx.createUniqueIndexIfNotExists(i)
: ctx.createIndexIfNotExists(i)
: i.getUnique()
? ctx.createUniqueIndex(i)
: ctx.createIndex(i))
.on(i.getTable(), i.getFields());
CreateIndexIncludeStep s1 =
(configuration.createIndexIfNotExists()
? i.getUnique()
? ctx.createUniqueIndexIfNotExists(i)
: ctx.createIndexIfNotExists(i)
: i.getUnique()
? ctx.createUniqueIndex(i)
: ctx.createIndex(i))
.on(i.getTable(), i.getFields());
return i.getWhere() != null ? s1.where(i.getWhere()) : s1;
}
final List<Query> alterTableAddConstraints(Table<?> table) {

View File

@ -66,8 +66,6 @@ import org.jooq.SortField;
import org.jooq.Table;
import org.jooq.impl.QOM.UNotYetImplemented;
import org.jetbrains.annotations.NotNull;
/**
* @author Lukas Eder
*/
@ -92,8 +90,9 @@ class IndexImpl extends AbstractNamed implements Index, UNotYetImplemented {
this.unique = unique;
}
final SortField<?>[] $fields() { return fields; }
final boolean $unique() { return unique; }
final SortField<?>[] $fields() { return fields; }
final boolean $unique() { return unique; }
final Condition $where() { return where; }
@Override
public final void accept(Context<?> ctx) {

View File

@ -335,7 +335,7 @@ final class Interpreter {
for (Index index : query.$indexes()) {
IndexImpl impl = (IndexImpl) index;
mt.indexes.add(new MutableIndex((UnqualifiedName) impl.getUnqualifiedName(), mt, mt.sortFields(asList(impl.$fields())), impl.$unique()));
mt.indexes.add(new MutableIndex((UnqualifiedName) impl.getUnqualifiedName(), mt, mt.sortFields(asList(impl.$fields())), impl.$unique(), impl.$where()));
}
}
@ -964,7 +964,7 @@ final class Interpreter {
return;
}
mt.indexes.add(new MutableIndex((UnqualifiedName) index.getUnqualifiedName(), mt, mtf, query.$unique()));
mt.indexes.add(new MutableIndex((UnqualifiedName) index.getUnqualifiedName(), mt, mtf, query.$unique(), query.$where()));
}
private final void accept0(AlterIndexImpl query) {
@ -2012,13 +2012,15 @@ final class Interpreter {
MutableTable table;
List<MutableSortField> fields;
boolean unique;
Condition where;
MutableIndex(UnqualifiedName name, MutableTable table, List<MutableSortField> fields, boolean unique) {
MutableIndex(UnqualifiedName name, MutableTable table, List<MutableSortField> fields, boolean unique, Condition where) {
super(name);
this.table = table;
this.fields = fields;
this.unique = unique;
this.where = where;
}
@Override
@ -2046,7 +2048,7 @@ final class Interpreter {
name(),
t,
map(fields, msf -> t.field(msf.name()).sort(msf.sort), SortField[]::new),
null,
where,
unique
));
}

View File

@ -172,8 +172,9 @@ final class Snapshot extends AbstractMeta {
for (Field<?> field : table.fields())
createField(field.getUnqualifiedName(), field.getDataType(), this, field.getComment());
indexes = map(table.getIndexes(), index -> Internal.createIndex(
index.getQualifiedName(), this,
indexes = map(table.getIndexes(), index -> new IndexImpl(
index.getQualifiedName(),
this,
map(index.getFields(), field -> {
// [#10804] Use this table's field reference if possible.
@ -183,6 +184,7 @@ final class Snapshot extends AbstractMeta {
// [#9009] TODO NULLS FIRST / NULLS LAST
}, SortField[]::new),
index.getWhere(),
index.getUnique()
));