[jOOQ/jOOQ#11485] Support ABSENT ON NULL for JSON_ARRAYAGG in Trino

This commit is contained in:
Lukas Eder 2023-08-18 11:22:52 +02:00
parent 52799064f1
commit 2436f94c42
2 changed files with 17 additions and 3 deletions

View File

@ -53,8 +53,10 @@ import static org.jooq.impl.JSONEntryImpl.jsonCastMapper;
import static org.jooq.impl.JSONEntryImpl.jsonMerge;
import static org.jooq.impl.Keywords.K_AS;
import static org.jooq.impl.Keywords.K_DISTINCT;
import static org.jooq.impl.Keywords.K_IS_NOT_NULL;
import static org.jooq.impl.Names.N_ARRAY_AGG;
import static org.jooq.impl.Names.N_CAST;
import static org.jooq.impl.Names.N_FILTER;
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;
@ -187,8 +189,14 @@ implements
acceptOverClause(ctx);
break;
case TRINO:
case TRINO: {
boolean noAggregateFilter = onNull == JSONOnNull.ABSENT_ON_NULL && !supportsFilter(ctx);
ctx.visit(N_CAST).sql('(');
if (noAggregateFilter)
ctx.visit(N_FILTER).sql('(');
ctx.visit(N_ARRAY_AGG).sql('(');
acceptDistinct(ctx);
ctx.visit(jsonCast(ctx, arguments.get(0)));
@ -201,9 +209,14 @@ implements
acceptFilterClause(ctx);
acceptOverClause(ctx);
if (noAggregateFilter)
ctx.sql(", v -> v ").visit(K_IS_NOT_NULL).sql(')');
ctx.sql(' ').visit(K_AS).sql(' ').visit(JSON);
ctx.sql(')');
break;
}
default:
acceptStandard(ctx);

View File

@ -157,7 +157,8 @@ implements
private final void acceptTrino(Context<?> ctx) {
ctx.visit(N_CAST).sql('(');
if (onNull == JSONOnNull.ABSENT_ON_NULL)
boolean noAggregateFilter = onNull == JSONOnNull.ABSENT_ON_NULL && !supportsFilter(ctx);
if (noAggregateFilter)
ctx.visit(N_MAP_FILTER).sql('(');
ctx.visit(N_MAP).sql('(');
@ -166,7 +167,7 @@ implements
acceptTrinoArrayAgg(ctx, entry.value(), entry.value());
ctx.sql(')');
if (onNull == JSONOnNull.ABSENT_ON_NULL)
if (noAggregateFilter)
ctx.sql(", (k, v) -> v ").visit(K_IS_NOT_NULL).sql(')');
ctx.sql(' ').visit(K_AS).sql(' ').visit(JSON);