[jOOQ/jOOQ#16563] Support delimiter expressions in LISTAGG() and GROUP_CONCAT()
This commit is contained in:
parent
01e6a279d7
commit
852da7839c
@ -78,4 +78,11 @@ public interface GroupConcatSeparatorStep extends AggregateFunction<String> {
|
||||
@NotNull
|
||||
@Support({ CUBRID, DUCKDB, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, TRINO })
|
||||
AggregateFunction<String> separator(String separator);
|
||||
|
||||
/**
|
||||
* Specify the separator on the <code>GROUP_CONCAT</code> function.
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, DUCKDB, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE, TRINO })
|
||||
AggregateFunction<String> separator(Field<String> separator);
|
||||
}
|
||||
|
||||
@ -31874,7 +31874,18 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support({ CUBRID, DUCKDB, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, TRINO })
|
||||
public static OrderedAggregateFunction<String> listAgg(Field<?> field, String separator) {
|
||||
return new ListAgg(false, Tools.nullSafe(field), inline(separator));
|
||||
return listAgg(field, inline(separator));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the aggregated concatenation for a field.
|
||||
*
|
||||
* @see #groupConcat(Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, DUCKDB, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, TRINO })
|
||||
public static OrderedAggregateFunction<String> listAgg(Field<?> field, Field<String> separator) {
|
||||
return new ListAgg(false, Tools.nullSafe(field), separator);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31896,7 +31907,18 @@ public class DSL {
|
||||
@NotNull
|
||||
@Support({ CUBRID, DUCKDB, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
public static OrderedAggregateFunction<String> listAggDistinct(Field<?> field, String separator) {
|
||||
return new ListAgg(true, Tools.nullSafe(field), inline(separator));
|
||||
return listAggDistinct(field, inline(separator));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the aggregated concatenation for a field.
|
||||
*
|
||||
* @see #groupConcatDistinct(Field)
|
||||
*/
|
||||
@NotNull
|
||||
@Support({ CUBRID, DUCKDB, H2, HSQLDB, MARIADB, MYSQL, POSTGRES })
|
||||
public static OrderedAggregateFunction<String> listAggDistinct(Field<?> field, Field<String> separator) {
|
||||
return new ListAgg(true, Tools.nullSafe(field), separator);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -68,7 +68,7 @@ implements
|
||||
|
||||
private final Field<?> field;
|
||||
private final SortFieldList orderBy;
|
||||
private String separator;
|
||||
private Field<String> separator;
|
||||
|
||||
GroupConcat(Field<?> field) {
|
||||
this(field, false);
|
||||
@ -88,7 +88,7 @@ implements
|
||||
if (separator == null)
|
||||
result = new ListAgg(distinct, field, inline(","));
|
||||
else
|
||||
result = new ListAgg(distinct, field, inline(separator));
|
||||
result = new ListAgg(distinct, field, separator);
|
||||
|
||||
if (!orderBy.isEmpty())
|
||||
result.withinGroupOrderBy(orderBy);
|
||||
@ -102,6 +102,11 @@ implements
|
||||
|
||||
@Override
|
||||
public final AggregateFunction<String> separator(String s) {
|
||||
return separator(inline(s));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final AggregateFunction<String> separator(Field<String> s) {
|
||||
this.separator = s;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -93,7 +93,13 @@ import org.jooq.impl.QOM.UNotYetImplemented;
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class ListAgg extends AbstractAggregateFunction<String> implements UNotYetImplemented {
|
||||
final class ListAgg
|
||||
extends
|
||||
AbstractAggregateFunction<String>
|
||||
implements
|
||||
UNotYetImplemented
|
||||
{
|
||||
|
||||
private static final Set<SQLDialect> SET_GROUP_CONCAT_MAX_LEN = SQLDialect.supportedBy(MARIADB, MYSQL);
|
||||
private static final Set<SQLDialect> SUPPORT_GROUP_CONCAT = SQLDialect.supportedBy(CUBRID, H2, HSQLDB, MARIADB, MYSQL, SQLITE);
|
||||
private static final Set<SQLDialect> SUPPORT_STRING_AGG = SQLDialect.supportedBy(DUCKDB, POSTGRES);
|
||||
|
||||
@ -12235,7 +12235,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
|
||||
s2 = s1;
|
||||
|
||||
if (parseKeywordIf("SEPARATOR"))
|
||||
s3 = s2.separator(parseStringLiteral());
|
||||
s3 = s2.separator((Field) parseField());
|
||||
else
|
||||
s3 = s2;
|
||||
|
||||
@ -12517,7 +12517,6 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
|
||||
}
|
||||
|
||||
private final AggregateFilterStep<?> parseOrderedSetFunctionIf() {
|
||||
// TODO Listagg set function
|
||||
OrderedAggregateFunction<?> orderedN;
|
||||
OrderedAggregateFunctionOfDeferredType ordered1;
|
||||
boolean optionalWithinGroup = false;
|
||||
@ -12669,7 +12668,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
|
||||
Field<?> field = parseField();
|
||||
|
||||
if (parseIf(','))
|
||||
ordered = distinct ? listAggDistinct(field, parseStringLiteral()) : listAgg(field, parseStringLiteral());
|
||||
ordered = distinct ? listAggDistinct(field, (Field) parseField()) : listAgg(field, (Field) parseField());
|
||||
else
|
||||
ordered = distinct ? listAggDistinct(field) : listAgg(field);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user