[jOOQ/jOOQ#15093] Add API support for ( UNION | INTERSECT | EXCEPT ) DISTINCT

This commit is contained in:
Lukas Eder 2023-05-22 09:32:48 +02:00
parent 4dcec71dfa
commit 9ffabd11a6
4 changed files with 158 additions and 0 deletions

View File

@ -110,6 +110,12 @@ extends
/**
* Apply the <code>UNION</code> set operation.
* <p>
* In SQL, a <code>UNION</code> is <code>DISTINCT</code> by default,
* meaning, duplicates are removed from the result set. So, this is the same
* as {@link #unionDistinct(Select)}. If duplicate removal isn't required,
* or already guaranteed by the data model, it is recommended to use
* {@link #unionAll(Select)}, instead.
*
* @throws IllegalArgumentException If the argument select has the same
* identity as this select. The jOOQ 3.x API is mutable, which
@ -121,6 +127,23 @@ extends
@Support
Select<R> union(Select<? extends R> select);
/**
* Apply the <code>UNION DISTINCT</code> set operation.
* <p>
* In SQL, a <code>UNION</code> is <code>DISTINCT</code> by default.
* However, it is often useful to make this explicit to express intent when
* distinct removal is really desired.
*
* @throws IllegalArgumentException If the argument select has the same
* identity as this select. The jOOQ 3.x API is mutable, which
* means that calls to the DSL API mutate this instance. Adding
* this instance as an set operation argument would lead to a
* {@link StackOverflowError} when generating the SQL.
*/
@NotNull @CheckReturnValue
@Support
Select<R> unionDistinct(Select<? extends R> select);
/**
* Apply the <code>UNION ALL</code> set operation.
*
@ -136,6 +159,12 @@ extends
/**
* Apply the <code>EXCEPT</code> (or <code>MINUS</code>) set operation.
* <p>
* In SQL, an <code>EXCEPT</code> is <code>DISTINCT</code> by default,
* meaning, duplicates are removed from the result set. So, this is the same
* as {@link #exceptDistinct(Select)}. If duplicate removal isn't required,
* or already guaranteed by the data model, it is recommended to use
* {@link #exceptAll(Select)}, instead, if the underlying RDBMS supports it.
*
* @throws IllegalArgumentException If the argument select has the same
* identity as this select. The jOOQ 3.x API is mutable, which
@ -147,6 +176,23 @@ extends
@Support({ CUBRID, DERBY, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, TRINO, YUGABYTEDB })
Select<R> except(Select<? extends R> select);
/**
* Apply the <code>EXCEPT</code> (or <code>MINUS</code>) set operation.
* <p>
* In SQL, an <code>EXCEPT</code> is <code>DISTINCT</code> by default.
* However, it is often useful to make this explicit to express intent when
* distinct removal is really desired.
*
* @throws IllegalArgumentException If the argument select has the same
* identity as this select. The jOOQ 3.x API is mutable, which
* means that calls to the DSL API mutate this instance. Adding
* this instance as an set operation argument would lead to a
* {@link StackOverflowError} when generating the SQL.
*/
@NotNull @CheckReturnValue
@Support({ CUBRID, DERBY, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, TRINO, YUGABYTEDB })
Select<R> exceptDistinct(Select<? extends R> select);
/**
* Apply the <code>EXCEPT ALL</code> set operation.
*
@ -162,6 +208,13 @@ extends
/**
* Apply the <code>INTERSECT</code> set operation.
* <p>
* In SQL, an <code>INTERSECT</code> is <code>DISTINCT</code> by default,
* meaning, duplicates are removed from the result set. So, this is the same
* as {@link #intersectDistinct(Select)}. If duplicate removal isn't
* required, or already guaranteed by the data model, it is recommended to
* use {@link #intersectAll(Select)}, instead, if the underlying RDBMS
* supports it. Apply the <code>INTERSECT</code> set operation.
*
* @throws IllegalArgumentException If the argument select has the same
* identity as this select. The jOOQ 3.x API is mutable, which
@ -173,6 +226,23 @@ extends
@Support({ CUBRID, DERBY, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, TRINO, YUGABYTEDB })
Select<R> intersect(Select<? extends R> select);
/**
* Apply the <code>INTERSECT</code> set operation.
* <p>
* In SQL, a <code>INTERSECT</code> is <code>DISTINCT</code> by default.
* However, it is often useful to make this explicit to express intent when
* distinct removal is really desired.
*
* @throws IllegalArgumentException If the argument select has the same
* identity as this select. The jOOQ 3.x API is mutable, which
* means that calls to the DSL API mutate this instance. Adding
* this instance as an set operation argument would lead to a
* {@link StackOverflowError} when generating the SQL.
*/
@NotNull @CheckReturnValue
@Support({ CUBRID, DERBY, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, TRINO, YUGABYTEDB })
Select<R> intersectDistinct(Select<? extends R> select);
/**
* Apply the <code>INTERSECT ALL</code> set operation.
*

View File

@ -135,12 +135,30 @@ public interface SelectUnionStep<R extends Record> extends SelectCorrelatedSubqu
/**
* Apply the <code>UNION</code> set operation.
* <p>
* In SQL, a <code>UNION</code> is <code>DISTINCT</code> by default,
* meaning, duplicates are removed from the result set. So, this is the same
* as {@link #unionDistinct(Select)}. If duplicate removal isn't required,
* or already guaranteed by the data model, it is recommended to use
* {@link #unionAll(Select)}, instead.
*/
@Override
@NotNull @CheckReturnValue
@Support
SelectOrderByStep<R> union(Select<? extends R> select);
/**
* Apply the <code>UNION DISTINCT</code> set operation.
* <p>
* In SQL, a <code>UNION</code> is <code>DISTINCT</code> by default.
* However, it is often useful to make this explicit to express intent when
* distinct removal is really desired.
*/
@Override
@NotNull @CheckReturnValue
@Support
SelectOrderByStep<R> unionDistinct(Select<? extends R> select);
/**
* Apply the <code>UNION ALL</code> set operation.
*/
@ -151,12 +169,30 @@ public interface SelectUnionStep<R extends Record> extends SelectCorrelatedSubqu
/**
* Apply the <code>EXCEPT</code> (or <code>MINUS</code>) set operation.
* <p>
* In SQL, an <code>EXCEPT</code> is <code>DISTINCT</code> by default,
* meaning, duplicates are removed from the result set. So, this is the same
* as {@link #exceptDistinct(Select)}. If duplicate removal isn't required,
* or already guaranteed by the data model, it is recommended to use
* {@link #exceptAll(Select)}, instead, if the underlying RDBMS supports it.
*/
@Override
@NotNull @CheckReturnValue
@Support({ CUBRID, DERBY, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, TRINO, YUGABYTEDB })
SelectOrderByStep<R> except(Select<? extends R> select);
/**
* Apply the <code>EXCEPT</code> (or <code>MINUS</code>) set operation.
* <p>
* In SQL, an <code>EXCEPT</code> is <code>DISTINCT</code> by default.
* However, it is often useful to make this explicit to express intent when
* distinct removal is really desired.
*/
@Override
@NotNull @CheckReturnValue
@Support({ CUBRID, DERBY, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, TRINO, YUGABYTEDB })
SelectOrderByStep<R> exceptDistinct(Select<? extends R> select);
/**
* Apply the <code>EXCEPT ALL</code> set operation.
*/
@ -167,12 +203,34 @@ public interface SelectUnionStep<R extends Record> extends SelectCorrelatedSubqu
/**
* Apply the <code>INTERSECT</code> set operation.
* <p>
* In SQL, an <code>INTERSECT</code> is <code>DISTINCT</code> by default,
* meaning, duplicates are removed from the result set. So, this is the same
* as {@link #intersectDistinct(Select)}. If duplicate removal isn't
* required, or already guaranteed by the data model, it is recommended to
* use {@link #intersectAll(Select)}, instead, if the underlying RDBMS
* supports it. Apply the <code>INTERSECT</code> set operation.
*/
@Override
@NotNull @CheckReturnValue
@Support({ CUBRID, DERBY, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, TRINO, YUGABYTEDB })
SelectOrderByStep<R> intersect(Select<? extends R> select);
/**
* Apply the <code>INTERSECT</code> set operation.
* <p>
* In SQL, an <code>INTERSECT</code> is <code>DISTINCT</code> by default,
* meaning, duplicates are removed from the result set. So, this is the same
* as {@link #intersectDistinct(Select)}. If duplicate removal isn't
* required, or already guaranteed by the data model, it is recommended to
* use {@link #intersectAll(Select)}, instead, if the underlying RDBMS
* supports it. Apply the <code>INTERSECT</code> set operation.
*/
@Override
@NotNull @CheckReturnValue
@Support({ CUBRID, DERBY, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, TRINO, YUGABYTEDB })
SelectOrderByStep<R> intersectDistinct(Select<? extends R> select);
/**
* Apply the <code>INTERSECT ALL</code> set operation.
*/

View File

@ -1995,6 +1995,11 @@ implements
return new SelectImpl(getDelegate().union(select));
}
@Override
public final SelectImpl unionDistinct(Select<? extends R> select) {
return new SelectImpl(getDelegate().unionDistinct(select));
}
@Override
public final SelectImpl unionAll(Select<? extends R> select) {
return new SelectImpl(getDelegate().unionAll(select));
@ -2005,6 +2010,11 @@ implements
return new SelectImpl(getDelegate().except(select));
}
@Override
public final SelectImpl exceptDistinct(Select<? extends R> select) {
return new SelectImpl(getDelegate().exceptDistinct(select));
}
@Override
public final SelectImpl exceptAll(Select<? extends R> select) {
return new SelectImpl(getDelegate().exceptAll(select));
@ -2015,6 +2025,11 @@ implements
return new SelectImpl(getDelegate().intersect(select));
}
@Override
public final SelectImpl intersectDistinct(Select<? extends R> select) {
return new SelectImpl(getDelegate().intersectDistinct(select));
}
@Override
public final SelectImpl intersectAll(Select<? extends R> select) {
return new SelectImpl(getDelegate().intersectAll(select));

View File

@ -4665,6 +4665,11 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
return combine(UNION, other);
}
@Override
public final SelectQueryImpl<R> unionDistinct(Select<? extends R> other) {
return combine(UNION, other);
}
@Override
public final SelectQueryImpl<R> unionAll(Select<? extends R> other) {
return combine(UNION_ALL, other);
@ -4675,6 +4680,11 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
return combine(EXCEPT, other);
}
@Override
public final SelectQueryImpl<R> exceptDistinct(Select<? extends R> other) {
return combine(EXCEPT, other);
}
@Override
public final SelectQueryImpl<R> exceptAll(Select<? extends R> other) {
return combine(EXCEPT_ALL, other);
@ -4685,6 +4695,11 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
return combine(INTERSECT, other);
}
@Override
public final SelectQueryImpl<R> intersectDistinct(Select<? extends R> other) {
return combine(INTERSECT, other);
}
@Override
public final SelectQueryImpl<R> intersectAll(Select<? extends R> other) {
return combine(INTERSECT_ALL, other);