[jOOQ/jOOQ#11458] Add support for the ANY_VALUE() aggregate function
This commit is contained in:
parent
192b5dcbaf
commit
4c7fc5e3b5
138
jOOQ/src/main/java/org/jooq/impl/AnyValue.java
Normal file
138
jOOQ/src/main/java/org/jooq/impl/AnyValue.java
Normal file
@ -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 <code>ANY VALUE</code> statement.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
|
||||
final class AnyValue<T>
|
||||
extends
|
||||
DefaultAggregateFunction<T>
|
||||
{
|
||||
|
||||
AnyValue(
|
||||
Field<T> 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -23294,6 +23294,17 @@ public class DSL {
|
||||
// XXX Aggregate functions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The <code>ANY_VALUE</code> function.
|
||||
* <p>
|
||||
* Get any arbitrary value from the group.
|
||||
*/
|
||||
@NotNull
|
||||
@Support
|
||||
public static <T> AggregateFunction<T> anyValue(Field<T> value) {
|
||||
return new AnyValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the count(*) function.
|
||||
*/
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user