[jOOQ/jOOQ#11485] Support ABSENT ON NULL for JSON_ARRAYAGG in Trino
This commit is contained in:
parent
52799064f1
commit
2436f94c42
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user