[jOOQ/jOOQ#10730] Add support for JSON_ARRAYAGG(DISTINCT)
This includes: - [jOOQ/jOOQ#13986] Add support for Db2 11.1 LISTAGG(DISTINCT)
This commit is contained in:
parent
d0cef8f285
commit
e913ce8d76
@ -26126,7 +26126,7 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support({ H2, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
|
||||
public static JSONArrayAggOrderByStep<JSON> jsonArrayAgg(Field<?> value) {
|
||||
return new JSONArrayAgg<>(JSON, value);
|
||||
return new JSONArrayAgg<>(JSON, value, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -26135,7 +26135,25 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support({ H2, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
|
||||
public static JSONArrayAggOrderByStep<JSONB> jsonbArrayAgg(Field<?> value) {
|
||||
return new JSONArrayAgg<>(JSONB, value);
|
||||
return new JSONArrayAgg<>(JSONB, value, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* The JSON array aggregate function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ H2, MARIADB, MYSQL, SQLITE })
|
||||
public static JSONArrayAggOrderByStep<JSON> jsonArrayAggDistinct(Field<?> value) {
|
||||
return new JSONArrayAgg<>(JSON, value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The JSON array aggregate function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ H2, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB })
|
||||
public static JSONArrayAggOrderByStep<JSONB> jsonbArrayAggDistinct(Field<?> value) {
|
||||
return new JSONArrayAgg<>(JSONB, value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -44,10 +44,11 @@ import static org.jooq.SQLDialect.MYSQL;
|
||||
// ...
|
||||
import static org.jooq.impl.DSL.function;
|
||||
import static org.jooq.impl.DSL.groupConcat;
|
||||
import static org.jooq.impl.DSL.groupConcatDistinct;
|
||||
import static org.jooq.impl.DSL.inline;
|
||||
import static org.jooq.impl.DSL.noCondition;
|
||||
import static org.jooq.impl.JSONEntryImpl.jsonCastMapper;
|
||||
import static org.jooq.impl.JSONEntryImpl.jsonMerge;
|
||||
import static org.jooq.impl.Keywords.K_DISTINCT;
|
||||
import static org.jooq.impl.Names.N_GROUP_CONCAT;
|
||||
import static org.jooq.impl.Names.N_JSONB_AGG;
|
||||
import static org.jooq.impl.Names.N_JSON_AGG;
|
||||
@ -101,8 +102,8 @@ implements
|
||||
private JSONOnNull onNull;
|
||||
private DataType<?> returning;
|
||||
|
||||
JSONArrayAgg(DataType<J> type, Field<?> arg) {
|
||||
super(false, N_JSON_ARRAYAGG, type, arg);
|
||||
JSONArrayAgg(DataType<J> type, Field<?> arg, boolean distinct) {
|
||||
super(distinct, N_JSON_ARRAYAGG, type, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -134,6 +135,7 @@ implements
|
||||
case POSTGRES:
|
||||
case YUGABYTEDB:
|
||||
ctx.visit(getDataType() == JSON ? N_JSON_AGG : N_JSONB_AGG).sql('(');
|
||||
acceptDistinct(ctx);
|
||||
ctx.visit(arguments.get(0));
|
||||
acceptOrderBy(ctx);
|
||||
ctx.sql(')');
|
||||
@ -148,6 +150,7 @@ implements
|
||||
|
||||
case SQLITE:
|
||||
ctx.visit(N_JSON_GROUP_ARRAY).sql('(');
|
||||
acceptDistinct(ctx);
|
||||
ctx.visit(arguments.get(0));
|
||||
acceptOrderBy(ctx);
|
||||
ctx.sql(')');
|
||||
@ -190,6 +193,7 @@ implements
|
||||
inline('['),
|
||||
CustomField.of(N_GROUP_CONCAT, VARCHAR, c1 -> {
|
||||
c1.visit(groupConcatEmulationWithoutArrayWrappers(
|
||||
distinct,
|
||||
CustomField.of(Names.N_FIELD, VARCHAR, c2 -> acceptArguments2(c2, QueryPartListView.wrap(arg2))),
|
||||
withinGroupOrderBy
|
||||
));
|
||||
@ -200,10 +204,11 @@ implements
|
||||
);
|
||||
}
|
||||
|
||||
static final Field<?> groupConcatEmulationWithoutArrayWrappers(Field<?> field, SortFieldList orderBy) {
|
||||
return Tools.isEmpty(orderBy)
|
||||
? groupConcat(field)
|
||||
: groupConcat(field).orderBy(orderBy);
|
||||
static final Field<?> groupConcatEmulationWithoutArrayWrappers(boolean distinct, Field<?> field, SortFieldList orderBy) {
|
||||
return Tools.apply(
|
||||
distinct ? groupConcatDistinct(field) : groupConcat(field),
|
||||
agg -> Tools.isEmpty(orderBy) ? agg : agg.orderBy(orderBy)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -226,6 +231,7 @@ implements
|
||||
|
||||
private final void acceptStandard(Context<?> ctx) {
|
||||
ctx.visit(N_JSON_ARRAYAGG).sql('(');
|
||||
acceptDistinct(ctx);
|
||||
|
||||
|
||||
|
||||
@ -249,6 +255,11 @@ implements
|
||||
acceptOverClause(ctx);
|
||||
}
|
||||
|
||||
private void acceptDistinct(Context<?> ctx) {
|
||||
if (distinct)
|
||||
ctx.visit(K_DISTINCT).sql(' ');
|
||||
}
|
||||
|
||||
@Override
|
||||
public final JSONArrayAgg<J> nullOnNull() {
|
||||
onNull = NULL_ON_NULL;
|
||||
@ -310,7 +321,7 @@ implements
|
||||
@Override
|
||||
public final Function1<? super Field<?>, ? extends AggregateFunction<J>> $constructor() {
|
||||
return f -> {
|
||||
JSONArrayAgg<J> r = new JSONArrayAgg<J>(getDataType(), f);
|
||||
JSONArrayAgg<J> r = new JSONArrayAgg<J>(getDataType(), f, distinct);
|
||||
r.onNull = onNull;
|
||||
r.returning = returning;
|
||||
return r;
|
||||
|
||||
@ -653,6 +653,7 @@ public final class QOM {
|
||||
JSONArrayAgg*/
|
||||
{
|
||||
@NotNull default Field<?> $field() { return $arg1(); }
|
||||
boolean $distinct();
|
||||
@Nullable JSONOnNull $onNull();
|
||||
@Nullable DataType<?> $returning();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user