Skip to content

Commit

Permalink
[#11061] [#11070] [#11091] Fix regression
Browse files Browse the repository at this point in the history
There needs to be a mechanism to identify the data type of a function based on its default type and/or arguments. So far, there's a weak correlation of the behaviour and whether we're calling Tools::anyNotNull or Tools::allNotNull. Further refactorings will probably invalidate this correlation
  • Loading branch information
lukaseder committed Dec 8, 2020
1 parent c9dca0b commit 7b65972
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion jOOQ/src/main/java/org/jooq/impl/Nvl.java
Expand Up @@ -42,6 +42,7 @@
import static org.jooq.impl.Names.N_IFNULL;
import static org.jooq.impl.Names.N_IIF;
import static org.jooq.impl.Names.N_NVL;
import static org.jooq.impl.Tools.anyNotNull;

import org.jooq.Context;
import org.jooq.Field;
Expand All @@ -60,7 +61,7 @@ final class Nvl<T> extends AbstractField<T> {
private final Field<T> arg2;

Nvl(Field<T> arg1, Field<T> arg2) {
super(N_NVL, Tools.anyNotNull(arg1.getDataType(), arg1, arg2));
super(N_NVL, anyNotNull(arg1.getDataType(), arg1, arg2));

this.arg1 = arg1;
this.arg2 = arg2;
Expand Down
22 changes: 11 additions & 11 deletions jOOQ/src/main/java/org/jooq/impl/Tools.java
Expand Up @@ -5900,24 +5900,24 @@ private static final ParseNameCase parseNameCase(Configuration configuration) {
}

private static final DataType<?> dataType(Field<?> field) {
return dataType(OTHER, field);
return dataType(OTHER, field, false);
}

@SuppressWarnings("unchecked")
private static final <T> DataType<T> dataType(DataType<T> defaultType, Field<?> field) {
private static final <T> DataType<T> dataType(DataType<T> defaultType, Field<?> field, boolean preferDefault) {
return field == null
? defaultType
: field.getType() != defaultType.getType()
: preferDefault && field.getType() != defaultType.getType()
? defaultType.nullable(field.getDataType().nullable())
: (DataType<T>) field.getDataType();
}

static final <T> DataType<T> allNotNull(DataType<T> defaultType, Field<?> f1) {
return dataType(defaultType, f1);
return dataType(defaultType, f1, true);
}

static final <T> DataType<T> allNotNull(DataType<T> defaultType, Field<?> f1, Field<?> f2) {
DataType<T> result = dataType(defaultType, f1);
DataType<T> result = dataType(defaultType, f1, true);

if (result.nullable())
return result;
Expand All @@ -5928,7 +5928,7 @@ else if (dataType(f2).nullable())
}

static final <T> DataType<T> allNotNull(DataType<T> defaultType, Field<?> f1, Field<?> f2, Field<?> f3) {
DataType<T> result = dataType(defaultType, f1);
DataType<T> result = dataType(defaultType, f1, true);

if (result.nullable())
return result;
Expand All @@ -5941,7 +5941,7 @@ else if (dataType(f3).nullable())
}

static final <T> DataType<T> allNotNull(DataType<T> defaultType, Field<?>... fields) {
DataType<T> result = dataType(defaultType, isEmpty(fields) ? null : fields[0]);
DataType<T> result = dataType(defaultType, isEmpty(fields) ? null : fields[0], true);

if (result.nullable())
return result;
Expand All @@ -5954,11 +5954,11 @@ static final <T> DataType<T> allNotNull(DataType<T> defaultType, Field<?>... fie
}

static final <T> DataType<T> anyNotNull(DataType<T> defaultType, Field<?> f1) {
return dataType(defaultType, f1);
return dataType(defaultType, f1, false);
}

static final <T> DataType<T> anyNotNull(DataType<T> defaultType, Field<?> f1, Field<?> f2) {
DataType<T> result = dataType(defaultType, f1);
DataType<T> result = dataType(defaultType, f1, false);

if (!result.nullable())
return result;
Expand All @@ -5969,7 +5969,7 @@ else if (!dataType(f2).nullable())
}

static final <T> DataType<T> anyNotNull(DataType<T> defaultType, Field<?> f1, Field<?> f2, Field<?> f3) {
DataType<T> result = dataType(defaultType, f1);
DataType<T> result = dataType(defaultType, f1, false);

if (!result.nullable())
return result;
Expand All @@ -5982,7 +5982,7 @@ else if (!dataType(f3).nullable())
}

static final <T> DataType<T> anyNotNull(DataType<T> defaultType, Field<?>... fields) {
DataType<T> result = dataType(defaultType, isEmpty(fields) ? null : fields[0]);
DataType<T> result = dataType(defaultType, isEmpty(fields) ? null : fields[0], false);

if (!result.nullable())
return result;
Expand Down

0 comments on commit 7b65972

Please sign in to comment.