From 4c7fc5e3b56ec40e343a02fc7f8fb1532b666fad Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 12 May 2021 10:34:27 +0200 Subject: [PATCH] [jOOQ/jOOQ#11458] Add support for the ANY_VALUE() aggregate function --- .../src/main/java/org/jooq/impl/AnyValue.java | 138 ++++++++++++++++++ jOOQ/src/main/java/org/jooq/impl/DSL.java | 11 ++ jOOQ/src/main/java/org/jooq/impl/Names.java | 1 + .../main/java/org/jooq/impl/ParserImpl.java | 5 + 4 files changed, 155 insertions(+) create mode 100644 jOOQ/src/main/java/org/jooq/impl/AnyValue.java diff --git a/jOOQ/src/main/java/org/jooq/impl/AnyValue.java b/jOOQ/src/main/java/org/jooq/impl/AnyValue.java new file mode 100644 index 0000000000..dbb39b40a9 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/AnyValue.java @@ -0,0 +1,138 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import static org.jooq.impl.DSL.*; +import static org.jooq.impl.Internal.*; +import static org.jooq.impl.Keywords.*; +import static org.jooq.impl.Names.*; +import static org.jooq.impl.SQLDataType.*; +import static org.jooq.impl.Tools.*; +import static org.jooq.impl.Tools.BooleanDataKey.*; +import static org.jooq.impl.Tools.DataExtendedKey.*; +import static org.jooq.impl.Tools.DataKey.*; +import static org.jooq.SQLDialect.*; + +import org.jooq.*; +import org.jooq.Record; +import org.jooq.conf.*; +import org.jooq.impl.*; +import org.jooq.tools.*; + +import java.util.*; + + +/** + * The ANY VALUE statement. + */ +@SuppressWarnings({ "rawtypes", "unchecked", "unused" }) +final class AnyValue +extends + DefaultAggregateFunction +{ + + AnyValue( + Field value + ) { + super( + false, + N_ANY_VALUE, + Tools.nullSafeDataType(value), + nullSafeNotNull(value, OTHER) + ); + } + + // ------------------------------------------------------------------------- + // XXX: QueryPart API + // ------------------------------------------------------------------------- + + + + @Override + void acceptFunctionName(Context ctx) { + switch (ctx.family()) { + + + + + + + + + + + + + + case CUBRID: + case DERBY: + case FIREBIRD: + case H2: + case HSQLDB: + case IGNITE: + case MARIADB: + case POSTGRES: + case SQLITE: + ctx.visit(N_MIN); + break; + + + + + + + + + + + + default: + super.acceptFunctionName(ctx); + break; + } + } + + @Override + public void accept(Context ctx) { + super.accept(ctx); + } + + + + +} diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 9702e6a86c..093f12129e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -23294,6 +23294,17 @@ public class DSL { // XXX Aggregate functions // ------------------------------------------------------------------------- + /** + * The ANY_VALUE function. + *

+ * Get any arbitrary value from the group. + */ + @NotNull + @Support + public static AggregateFunction anyValue(Field value) { + return new AnyValue(value); + } + /** * Get the count(*) function. */ diff --git a/jOOQ/src/main/java/org/jooq/impl/Names.java b/jOOQ/src/main/java/org/jooq/impl/Names.java index f67388fcf6..225cb2bad0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Names.java +++ b/jOOQ/src/main/java/org/jooq/impl/Names.java @@ -62,6 +62,7 @@ final class Names { static final Name N_ADD_SECONDS = unquotedName("add_seconds"); static final Name N_ADD_YEARS = unquotedName("add_years"); static final Name N_ANY = unquotedName("any"); + static final Name N_ANY_VALUE = unquotedName("any_value"); static final Name N_ARRAY = unquotedName("array"); static final Name N_ARRAY_AGG = unquotedName("array_agg"); static final Name N_ARRAY_GET = unquotedName("array_get"); diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java index 6408f2ee20..83a0d59ea3 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java @@ -10809,6 +10809,8 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { parse(')'); switch (operation) { + case ANY_VALUE: + return anyValue(arg); case AVG: return distinct ? avgDistinct(arg) : avg(arg); case MAX: @@ -12310,6 +12312,8 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { case 'A': if (parseFunctionNameIf("ANY")) return ComputationalOperation.ANY; + else if (parseFunctionNameIf("ANY_VALUE")) + return ComputationalOperation.ANY_VALUE; else if (parseFunctionNameIf("AVG")) return ComputationalOperation.AVG; @@ -12965,6 +12969,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext { } private static enum ComputationalOperation { + ANY_VALUE, AVG, MAX, MIN,