[jOOQ/jOOQ#16759] Add support for BigQuery PERCENTILE_CONT, PERCENTILE_DISC window functions

This includes:

- [jOOQ/jOOQ#15906] Add QOM API support for these functions
This commit is contained in:
Lukas Eder 2024-06-04 16:05:32 +02:00
parent 9059d5284f
commit ce60124612
6 changed files with 445 additions and 63 deletions

View File

@ -222,7 +222,7 @@ implements
/**
* Render function arguments and argument modifiers
*/
private final void toSQLArguments(Context<?> ctx) {
final void toSQLArguments(Context<?> ctx) {
acceptFunctionName(ctx);
ctx.sql('(');
acceptArguments0(ctx);

View File

@ -24915,6 +24915,54 @@ public class DSL {
return new Product(field, true);
}
/**
* The <code>PERCENTILE_CONT</code> function.
* <p>
* Calculate the <code>PERCENTILE_CONT</code> inverse distribution aggregate function.
*
* @param percentile is wrapped as {@link DSL#val(Object)}.
*/
@NotNull
@Support({ DUCKDB, H2, MARIADB, POSTGRES, YUGABYTEDB })
public static OrderedAggregateFunction<BigDecimal> percentileCont(Number percentile) {
return new PercentileCont(Tools.field(percentile));
}
/**
* The <code>PERCENTILE_CONT</code> function.
* <p>
* Calculate the <code>PERCENTILE_CONT</code> inverse distribution aggregate function.
*/
@NotNull
@Support({ DUCKDB, H2, MARIADB, POSTGRES, YUGABYTEDB })
public static OrderedAggregateFunction<BigDecimal> percentileCont(Field<? extends Number> percentile) {
return new PercentileCont(percentile);
}
/**
* The <code>PERCENTILE_DISC</code> function.
* <p>
* Calculate the <code>PERCENTILE_DISC</code> inverse distribution aggregate function.
*
* @param percentile is wrapped as {@link DSL#val(Object)}.
*/
@NotNull
@Support({ DUCKDB, H2, MARIADB, POSTGRES, YUGABYTEDB })
public static OrderedAggregateFunction<BigDecimal> percentileDisc(Number percentile) {
return new PercentileDisc(Tools.field(percentile));
}
/**
* The <code>PERCENTILE_DISC</code> function.
* <p>
* Calculate the <code>PERCENTILE_DISC</code> inverse distribution aggregate function.
*/
@NotNull
@Support({ DUCKDB, H2, MARIADB, POSTGRES, YUGABYTEDB })
public static OrderedAggregateFunction<BigDecimal> percentileDisc(Field<? extends Number> percentile) {
return new PercentileDisc(percentile);
}
/**
* The <code>REGR_AVGX</code> function.
* <p>
@ -32330,66 +32378,6 @@ public class DSL {
return new DefaultAggregateFunction<>(N_CUME_DIST, SQLDataType.NUMERIC, fields.toArray(EMPTY_FIELD));
}
/**
* The
* <code>percentile_cont([number]) within group (order by [column])</code>
* function.
* <p>
* While most dialects support this as an aggregate function,
* {@link SQLDialect#BIGQUERY}, {@link SQLDialect#SQLSERVER}, and
* {@link SQLDialect#REDSHIFT} support only its window function variant.
*/
@NotNull
@Support({ DUCKDB, H2, MARIADB, POSTGRES, YUGABYTEDB })
public static OrderedAggregateFunction<BigDecimal> percentileCont(Number number) {
return percentileCont(val(number));
}
/**
* The
* <code>percentile_cont([number]) within group (order by [column])</code>
* function.
* <p>
* While most dialects support this as an aggregate function,
* {@link SQLDialect#BIGQUERY}, {@link SQLDialect#SQLSERVER}, and
* {@link SQLDialect#REDSHIFT} support only its window function variant.
*/
@NotNull
@Support({ DUCKDB, H2, MARIADB, POSTGRES, YUGABYTEDB })
public static OrderedAggregateFunction<BigDecimal> percentileCont(Field<? extends Number> field) {
return new DefaultAggregateFunction<>(N_PERCENTILE_CONT, SQLDataType.NUMERIC, Tools.nullSafe(field));
}
/**
* The
* <code>percentile_disc([number]) within group (order by [column])</code>
* function.
* <p>
* While most dialects support this as an aggregate function,
* {@link SQLDialect#BIGQUERY}, {@link SQLDialect#SQLSERVER}, and
* {@link SQLDialect#REDSHIFT} support only its window function variant.
*/
@NotNull
@Support({ DUCKDB, H2, MARIADB, POSTGRES, YUGABYTEDB })
public static OrderedAggregateFunction<BigDecimal> percentileDisc(Number number) {
return percentileDisc(val(number));
}
/**
* The
* <code>percentile_disc([number]) within group (order by [column])</code>
* function.
* <p>
* While most dialects support this as an aggregate function,
* {@link SQLDialect#BIGQUERY}, {@link SQLDialect#SQLSERVER}, and
* {@link SQLDialect#REDSHIFT} support only its window function variant.
*/
@NotNull
@Support({ DUCKDB, H2, MARIADB, POSTGRES, YUGABYTEDB })
public static OrderedAggregateFunction<BigDecimal> percentileDisc(Field<? extends Number> field) {
return new DefaultAggregateFunction<>(N_PERCENTILE_DISC, SQLDataType.NUMERIC, Tools.nullSafe(field));
}
// -------------------------------------------------------------------------
// XXX Window clauses
// -------------------------------------------------------------------------

View File

@ -234,8 +234,6 @@ final class Names {
static final Name N_ORDINAL = systemName("ordinal");
static final Name N_OREPLACE = systemName("oreplace");
static final Name N_PARSE_JSON = systemName("parse_json");
static final Name N_PERCENTILE_CONT = systemName("percentile_cont");
static final Name N_PERCENTILE_DISC = systemName("percentile_disc");
static final Name N_PERCENT_RANK = systemName("percent_rank");
static final Name N_PIVOT = systemName("pivot");
static final Name N_PLPGSQL = systemName("plpgsql");
@ -546,6 +544,8 @@ final class Names {
static final Name N_OCTET_LENGTH = systemName("octet_length");
static final Name N_OTRANSLATE = systemName("otranslate");
static final Name N_OVERLAY = systemName("overlay");
static final Name N_PERCENTILE_CONT = systemName("percentile_cont");
static final Name N_PERCENTILE_DISC = systemName("percentile_disc");
static final Name N_PI = systemName("pi");
static final Name N_POSITION = systemName("position");
static final Name N_POW = systemName("pow");

View File

@ -0,0 +1,179 @@
/*
* 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
*
* https://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: https://www.jooq.org/legal/licensing
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
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.ExtendedDataKey.*;
import static org.jooq.impl.Tools.SimpleDataKey.*;
import static org.jooq.SQLDialect.*;
import org.jooq.*;
import org.jooq.Function1;
import org.jooq.Record;
import org.jooq.conf.ParamType;
import org.jooq.tools.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.math.BigDecimal;
/**
* The <code>PERCENTILE CONT</code> statement.
*/
@SuppressWarnings({ "rawtypes", "unused" })
final class PercentileCont
extends
AbstractAggregateFunction<BigDecimal>
implements
QOM.PercentileCont
{
PercentileCont(
Field<? extends Number> percentile
) {
super(
false,
N_PERCENTILE_CONT,
NUMERIC,
nullSafeNotNull(percentile, INTEGER)
);
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public final void accept(Context<?> ctx) {
switch (ctx.family()) {
default:
super.accept(ctx);
break;
}
}
// -------------------------------------------------------------------------
// XXX: Query Object Model
// -------------------------------------------------------------------------
@SuppressWarnings("unchecked")
@Override
public final Field<? extends Number> $percentile() {
return (Field<? extends Number>) getArgument(0);
}
@Override
public final QOM.PercentileCont $percentile(Field<? extends Number> newValue) {
return $constructor().apply(newValue);
}
public final Function1<? super Field<? extends Number>, ? extends QOM.PercentileCont> $constructor() {
return (a1) -> new PercentileCont(a1);
}
// -------------------------------------------------------------------------
// XXX: The Object API
// -------------------------------------------------------------------------
@Override
public boolean equals(Object that) {
if (that instanceof QOM.PercentileCont o) {
return
StringUtils.equals($percentile(), o.$percentile())
;
}
else
return super.equals(that);
}
}

View File

@ -0,0 +1,179 @@
/*
* 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
*
* https://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: https://www.jooq.org/legal/licensing
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
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.ExtendedDataKey.*;
import static org.jooq.impl.Tools.SimpleDataKey.*;
import static org.jooq.SQLDialect.*;
import org.jooq.*;
import org.jooq.Function1;
import org.jooq.Record;
import org.jooq.conf.ParamType;
import org.jooq.tools.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.math.BigDecimal;
/**
* The <code>PERCENTILE DISC</code> statement.
*/
@SuppressWarnings({ "rawtypes", "unused" })
final class PercentileDisc
extends
AbstractAggregateFunction<BigDecimal>
implements
QOM.PercentileDisc
{
PercentileDisc(
Field<? extends Number> percentile
) {
super(
false,
N_PERCENTILE_DISC,
NUMERIC,
nullSafeNotNull(percentile, INTEGER)
);
}
// -------------------------------------------------------------------------
// XXX: QueryPart API
// -------------------------------------------------------------------------
@Override
public final void accept(Context<?> ctx) {
switch (ctx.family()) {
default:
super.accept(ctx);
break;
}
}
// -------------------------------------------------------------------------
// XXX: Query Object Model
// -------------------------------------------------------------------------
@SuppressWarnings("unchecked")
@Override
public final Field<? extends Number> $percentile() {
return (Field<? extends Number>) getArgument(0);
}
@Override
public final QOM.PercentileDisc $percentile(Field<? extends Number> newValue) {
return $constructor().apply(newValue);
}
public final Function1<? super Field<? extends Number>, ? extends QOM.PercentileDisc> $constructor() {
return (a1) -> new PercentileDisc(a1);
}
// -------------------------------------------------------------------------
// XXX: The Object API
// -------------------------------------------------------------------------
@Override
public boolean equals(Object that) {
if (that instanceof QOM.PercentileDisc o) {
return
StringUtils.equals($percentile(), o.$percentile())
;
}
else
return super.equals(that);
}
}

View File

@ -8106,6 +8106,7 @@ public final class QOM {
*/
public /*sealed*/ interface MaxBy<T>
extends
QueryPart,
org.jooq.OptionallyOrderedAggregateFunction<T>
//permits
// MaxBy
@ -8172,6 +8173,7 @@ public final class QOM {
*/
public /*sealed*/ interface MinBy<T>
extends
QueryPart,
org.jooq.OptionallyOrderedAggregateFunction<T>
//permits
// MinBy
@ -8229,6 +8231,40 @@ public final class QOM {
@NotNull Product $distinct(boolean distinct);
}
/**
* The <code>PERCENTILE CONT</code> function.
* <p>
* Calculate the <code>PERCENTILE_CONT</code> inverse distribution aggregate function.
*/
public /*sealed*/ interface PercentileCont
extends
QueryPart,
org.jooq.OrderedAggregateFunction<BigDecimal>
//permits
// PercentileCont
{
@NotNull Field<? extends Number> $percentile();
@CheckReturnValue
@NotNull PercentileCont $percentile(Field<? extends Number> percentile);
}
/**
* The <code>PERCENTILE DISC</code> function.
* <p>
* Calculate the <code>PERCENTILE_DISC</code> inverse distribution aggregate function.
*/
public /*sealed*/ interface PercentileDisc
extends
QueryPart,
org.jooq.OrderedAggregateFunction<BigDecimal>
//permits
// PercentileDisc
{
@NotNull Field<? extends Number> $percentile();
@CheckReturnValue
@NotNull PercentileDisc $percentile(Field<? extends Number> percentile);
}
/**
* The <code>REGR AVGX</code> function.
* <p>