diff --git a/jOOQ/src/main/java/org/jooq/WindowExcludeStep.java b/jOOQ/src/main/java/org/jooq/WindowExcludeStep.java new file mode 100644 index 0000000000..21c9fd45c2 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/WindowExcludeStep.java @@ -0,0 +1,96 @@ +/* + * 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; + +// ... +// ... +// ... +import static org.jooq.SQLDialect.MARIADB; +import static org.jooq.SQLDialect.MYSQL_8_0; +// ... +import static org.jooq.SQLDialect.POSTGRES; +import static org.jooq.SQLDialect.POSTGRES_11; +// ... +// ... +// ... +// ... +// ... +// ... + +/** + * This type is used for the window function DSL API. + *

+ * Example:

+ * field.firstValue()
+ *      .ignoreNulls()
+ *      .over()
+ *      .partitionBy(AUTHOR_ID)
+ *      .orderBy(PUBLISHED_IN.asc())
+ *      .rowsBetweenUnboundedPreceding()
+ *      .andUnboundedFollowing()
+ * 
+ * + * @param The function return type + * @author Lukas Eder + */ +public interface WindowExcludeStep extends WindowFinalStep { + + /** + * Add an EXCLUDE CURRENT ROW clause. + */ + @Support({ POSTGRES_11 }) + WindowFinalStep excludeCurrentRow(); + + /** + * Add an EXCLUDE GROUP clause. + */ + @Support({ POSTGRES_11 }) + WindowFinalStep excludeGroup(); + + /** + * Add an EXCLUDE TIES clause. + */ + @Support({ POSTGRES_11 }) + WindowFinalStep excludeTies(); + + /** + * Add an EXCLUDE NO OTHERS clause. + */ + @Support({ MARIADB, MYSQL_8_0, POSTGRES }) + WindowFinalStep excludeNoOthers(); +} diff --git a/jOOQ/src/main/java/org/jooq/WindowRowsAndStep.java b/jOOQ/src/main/java/org/jooq/WindowRowsAndStep.java index fad3adbe34..42b3822f2e 100644 --- a/jOOQ/src/main/java/org/jooq/WindowRowsAndStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowRowsAndStep.java @@ -73,33 +73,33 @@ public interface WindowRowsAndStep { * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep andUnboundedPreceding(); + WindowExcludeStep andUnboundedPreceding(); /** * Add a ... AND [number] PRECEDING frame clause to the window * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep andPreceding(int number); + WindowExcludeStep andPreceding(int number); /** * Add a ... AND CURRENT ROW frame clause to the window * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep andCurrentRow(); + WindowExcludeStep andCurrentRow(); /** * Add a ... AND UNBOUNDED FOLLOWING frame clause to the window * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep andUnboundedFollowing(); + WindowExcludeStep andUnboundedFollowing(); /** * Add a ... AND [number] FOLLOWING frame clause to the window * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep andFollowing(int number); + WindowExcludeStep andFollowing(int number); } diff --git a/jOOQ/src/main/java/org/jooq/WindowRowsStep.java b/jOOQ/src/main/java/org/jooq/WindowRowsStep.java index e56f5e1292..fb2e0d2342 100644 --- a/jOOQ/src/main/java/org/jooq/WindowRowsStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowRowsStep.java @@ -75,34 +75,34 @@ public interface WindowRowsStep extends WindowFinalStep { * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep rowsUnboundedPreceding(); + WindowExcludeStep rowsUnboundedPreceding(); /** * Add a ROWS [number] PRECEDING frame clause to the window * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep rowsPreceding(int number); + WindowExcludeStep rowsPreceding(int number); /** * Add a ROWS CURRENT ROW frame clause to the window function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep rowsCurrentRow(); + WindowExcludeStep rowsCurrentRow(); /** * Add a ROWS UNBOUNDED FOLLOWING frame clause to the window * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep rowsUnboundedFollowing(); + WindowExcludeStep rowsUnboundedFollowing(); /** * Add a ROWS [number] FOLLOWING frame clause to the window * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep rowsFollowing(int number); + WindowExcludeStep rowsFollowing(int number); /** * Add a ROWS BETWEEN UNBOUNDED PRECEDING ... frame clause to @@ -144,34 +144,34 @@ public interface WindowRowsStep extends WindowFinalStep { * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep rangeUnboundedPreceding(); + WindowExcludeStep rangeUnboundedPreceding(); /** * Add a RANGE [number] PRECEDING frame clause to the window * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep rangePreceding(int number); + WindowExcludeStep rangePreceding(int number); /** * Add a RANGE CURRENT ROW frame clause to the window function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep rangeCurrentRow(); + WindowExcludeStep rangeCurrentRow(); /** * Add a RANGE UNBOUNDED FOLLOWING frame clause to the window * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep rangeUnboundedFollowing(); + WindowExcludeStep rangeUnboundedFollowing(); /** * Add a RANGE [number] FOLLOWING frame clause to the window * function. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowFinalStep rangeFollowing(int number); + WindowExcludeStep rangeFollowing(int number); /** * Add a RANGE BETWEEN UNBOUNDED PRECEDING ... frame clause to @@ -213,34 +213,34 @@ public interface WindowRowsStep extends WindowFinalStep { * function. */ @Support({ POSTGRES_11 }) - WindowFinalStep groupsUnboundedPreceding(); + WindowExcludeStep groupsUnboundedPreceding(); /** * Add a GROUPS [number] PRECEDING frame clause to the window * function. */ @Support({ POSTGRES_11 }) - WindowFinalStep groupsPreceding(int number); + WindowExcludeStep groupsPreceding(int number); /** * Add a GROUPS CURRENT ROW frame clause to the window function. */ @Support({ POSTGRES_11 }) - WindowFinalStep groupsCurrentRow(); + WindowExcludeStep groupsCurrentRow(); /** * Add a GROUPS UNBOUNDED FOLLOWING frame clause to the window * function. */ @Support({ POSTGRES_11 }) - WindowFinalStep groupsUnboundedFollowing(); + WindowExcludeStep groupsUnboundedFollowing(); /** * Add a GROUPS [number] FOLLOWING frame clause to the window * function. */ @Support({ POSTGRES_11 }) - WindowFinalStep groupsFollowing(int number); + WindowExcludeStep groupsFollowing(int number); /** * Add a GROUPS BETWEEN UNBOUNDED PRECEDING ... frame clause to diff --git a/jOOQ/src/main/java/org/jooq/WindowSpecificationExcludeStep.java b/jOOQ/src/main/java/org/jooq/WindowSpecificationExcludeStep.java new file mode 100644 index 0000000000..951916743b --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/WindowSpecificationExcludeStep.java @@ -0,0 +1,111 @@ +/* + * 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; + +// ... +// ... +// ... +import static org.jooq.SQLDialect.MARIADB; +import static org.jooq.SQLDialect.MYSQL_8_0; +// ... +import static org.jooq.SQLDialect.POSTGRES; +import static org.jooq.SQLDialect.POSTGRES_11; +// ... +// ... +// ... +// ... +// ... +// ... + +/** + * An intermediate step in the construction of a {@link WindowSpecification}. + *

+ * Example:

+ * WindowSpecification spec =
+ * DSL.partitionBy(BOOK.AUTHOR_ID)
+ *    .orderBy(BOOK.ID)
+ *    .rowsBetweenUnboundedPreceding()
+ *    .andCurrentRow();
+ * 
+ *

+ *

Referencing XYZ*Step types directly from client code

+ *

+ * It is usually not recommended to reference any XYZ*Step types + * directly from client code, or assign them to local variables. When writing + * dynamic SQL, creating a statement's components dynamically, and passing them + * to the DSL API statically is usually a better choice. See the manual's + * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql. + *

+ * Drawbacks of referencing the XYZ*Step types directly: + *

    + *
  • They're operating on mutable implementations (as of jOOQ 3.x)
  • + *
  • They're less composable and not easy to get right when dynamic SQL gets + * complex
  • + *
  • They're less readable
  • + *
  • They might have binary incompatible changes between minor releases
  • + *
+ * + * @author Lukas Eder + */ +public interface WindowSpecificationExcludeStep extends WindowSpecificationFinalStep { + + /** + * Add an EXCLUDE CURRENT ROW clause. + */ + @Support({ POSTGRES_11 }) + WindowSpecificationFinalStep excludeCurrentRow(); + + /** + * Add an EXCLUDE GROUP clause. + */ + @Support({ POSTGRES_11 }) + WindowSpecificationFinalStep excludeGroup(); + + /** + * Add an EXCLUDE TIES clause. + */ + @Support({ POSTGRES_11 }) + WindowSpecificationFinalStep excludeTies(); + + /** + * Add an EXCLUDE NO OTHERS clause. + */ + @Support({ MARIADB, MYSQL_8_0, POSTGRES }) + WindowSpecificationFinalStep excludeNoOthers(); +} diff --git a/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsAndStep.java b/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsAndStep.java index 7ffc2cb343..147528ac0f 100644 --- a/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsAndStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsAndStep.java @@ -89,34 +89,34 @@ public interface WindowSpecificationRowsAndStep { * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep andUnboundedPreceding(); + WindowSpecificationExcludeStep andUnboundedPreceding(); /** * Add a ... AND [number] PRECEDING frame clause to the window * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep andPreceding(int number); + WindowSpecificationExcludeStep andPreceding(int number); /** * Add a ... AND CURRENT ROW frame clause to the window * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep andCurrentRow(); + WindowSpecificationExcludeStep andCurrentRow(); /** * Add a ... AND UNBOUNDED FOLLOWING frame clause to the window * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep andUnboundedFollowing(); + WindowSpecificationExcludeStep andUnboundedFollowing(); /** * Add a ... AND [number] FOLLOWING frame clause to the window * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep andFollowing(int number); + WindowSpecificationExcludeStep andFollowing(int number); } diff --git a/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsStep.java b/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsStep.java index 975db2e779..520166bfc2 100644 --- a/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsStep.java @@ -90,35 +90,35 @@ public interface WindowSpecificationRowsStep extends WindowSpecificationFinalSte * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep rowsUnboundedPreceding(); + WindowSpecificationExcludeStep rowsUnboundedPreceding(); /** * Add a ROWS [number] PRECEDING frame clause to the window * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep rowsPreceding(int number); + WindowSpecificationExcludeStep rowsPreceding(int number); /** * Add a ROWS CURRENT ROW frame clause to the window * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep rowsCurrentRow(); + WindowSpecificationExcludeStep rowsCurrentRow(); /** * Add a ROWS UNBOUNDED FOLLOWING frame clause to the window * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep rowsUnboundedFollowing(); + WindowSpecificationExcludeStep rowsUnboundedFollowing(); /** * Add a ROWS [number] FOLLOWING frame clause to the window * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep rowsFollowing(int number); + WindowSpecificationExcludeStep rowsFollowing(int number); /** * Add a ROWS BETWEEN UNBOUNDED PRECEDING ... frame clause to @@ -160,35 +160,35 @@ public interface WindowSpecificationRowsStep extends WindowSpecificationFinalSte * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep rangeUnboundedPreceding(); + WindowSpecificationExcludeStep rangeUnboundedPreceding(); /** * Add a RANGE [number] PRECEDING frame clause to the window * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep rangePreceding(int number); + WindowSpecificationExcludeStep rangePreceding(int number); /** * Add a RANGE CURRENT ROW frame clause to the window * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep rangeCurrentRow(); + WindowSpecificationExcludeStep rangeCurrentRow(); /** * Add a RANGE UNBOUNDED FOLLOWING frame clause to the window * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep rangeUnboundedFollowing(); + WindowSpecificationExcludeStep rangeUnboundedFollowing(); /** * Add a RANGE [number] FOLLOWING frame clause to the window * specification. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - WindowSpecificationFinalStep rangeFollowing(int number); + WindowSpecificationExcludeStep rangeFollowing(int number); /** * Add a RANGE BETWEEN UNBOUNDED PRECEDING ... frame clause to @@ -230,35 +230,35 @@ public interface WindowSpecificationRowsStep extends WindowSpecificationFinalSte * specification. */ @Support({ POSTGRES_11 }) - WindowSpecificationFinalStep groupsUnboundedPreceding(); + WindowSpecificationExcludeStep groupsUnboundedPreceding(); /** * Add a GROUPS [number] PRECEDING frame clause to the window * specification. */ @Support({ POSTGRES_11 }) - WindowSpecificationFinalStep groupsPreceding(int number); + WindowSpecificationExcludeStep groupsPreceding(int number); /** * Add a GROUPS CURRENT ROW frame clause to the window * specification. */ @Support({ POSTGRES_11 }) - WindowSpecificationFinalStep groupsCurrentRow(); + WindowSpecificationExcludeStep groupsCurrentRow(); /** * Add a GROUPS UNBOUNDED FOLLOWING frame clause to the window * specification. */ @Support({ POSTGRES_11 }) - WindowSpecificationFinalStep groupsUnboundedFollowing(); + WindowSpecificationExcludeStep groupsUnboundedFollowing(); /** * Add a GROUPS [number] FOLLOWING frame clause to the window * specification. */ @Support({ POSTGRES_11 }) - WindowSpecificationFinalStep groupsFollowing(int number); + WindowSpecificationExcludeStep groupsFollowing(int number); /** * Add a GROUPS BETWEEN UNBOUNDED PRECEDING ... frame clause to diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 0768afad0a..55ed1e52de 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -318,7 +318,7 @@ import org.jooq.WindowFromFirstLastStep; import org.jooq.WindowIgnoreNullsStep; import org.jooq.WindowOverStep; import org.jooq.WindowSpecification; -import org.jooq.WindowSpecificationFinalStep; +import org.jooq.WindowSpecificationExcludeStep; import org.jooq.WindowSpecificationOrderByStep; import org.jooq.WindowSpecificationRowsAndStep; import org.jooq.WindowSpecificationRowsStep; @@ -17560,7 +17560,7 @@ public class DSL { * Create a {@link WindowSpecification} with a ROWS clause. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - public static WindowSpecificationFinalStep rowsUnboundedPreceding() { + public static WindowSpecificationExcludeStep rowsUnboundedPreceding() { return new WindowSpecificationImpl().rowsUnboundedPreceding(); } @@ -17568,7 +17568,7 @@ public class DSL { * Create a {@link WindowSpecification} with a ROWS clause. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - public static WindowSpecificationFinalStep rowsPreceding(int number) { + public static WindowSpecificationExcludeStep rowsPreceding(int number) { return new WindowSpecificationImpl().rowsPreceding(number); } @@ -17576,7 +17576,7 @@ public class DSL { * Create a {@link WindowSpecification} with a ROWS clause. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - public static WindowSpecificationFinalStep rowsCurrentRow() { + public static WindowSpecificationExcludeStep rowsCurrentRow() { return new WindowSpecificationImpl().rowsCurrentRow(); } @@ -17584,7 +17584,7 @@ public class DSL { * Create a {@link WindowSpecification} with a ROWS clause. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - public static WindowSpecificationFinalStep rowsUnboundedFollowing() { + public static WindowSpecificationExcludeStep rowsUnboundedFollowing() { return new WindowSpecificationImpl().rowsUnboundedFollowing(); } @@ -17592,7 +17592,7 @@ public class DSL { * Create a {@link WindowSpecification} with a ROWS clause. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - public static WindowSpecificationFinalStep rowsFollowing(int number) { + public static WindowSpecificationExcludeStep rowsFollowing(int number) { return new WindowSpecificationImpl().rowsFollowing(number); } @@ -17640,7 +17640,7 @@ public class DSL { * Create a {@link WindowSpecification} with a RANGE clause. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - public static WindowSpecificationFinalStep rangeUnboundedPreceding() { + public static WindowSpecificationExcludeStep rangeUnboundedPreceding() { return new WindowSpecificationImpl().rangeUnboundedPreceding(); } @@ -17648,7 +17648,7 @@ public class DSL { * Create a {@link WindowSpecification} with a RANGE clause. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - public static WindowSpecificationFinalStep rangePreceding(int number) { + public static WindowSpecificationExcludeStep rangePreceding(int number) { return new WindowSpecificationImpl().rangePreceding(number); } @@ -17656,7 +17656,7 @@ public class DSL { * Create a {@link WindowSpecification} with a RANGE clause. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - public static WindowSpecificationFinalStep rangeCurrentRow() { + public static WindowSpecificationExcludeStep rangeCurrentRow() { return new WindowSpecificationImpl().rangeCurrentRow(); } @@ -17664,7 +17664,7 @@ public class DSL { * Create a {@link WindowSpecification} with a RANGE clause. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - public static WindowSpecificationFinalStep rangeUnboundedFollowing() { + public static WindowSpecificationExcludeStep rangeUnboundedFollowing() { return new WindowSpecificationImpl().rangeUnboundedFollowing(); } @@ -17672,7 +17672,7 @@ public class DSL { * Create a {@link WindowSpecification} with a RANGE clause. */ @Support({ MARIADB, MYSQL_8_0, POSTGRES }) - public static WindowSpecificationFinalStep rangeFollowing(int number) { + public static WindowSpecificationExcludeStep rangeFollowing(int number) { return new WindowSpecificationImpl().rangeFollowing(number); } @@ -17720,7 +17720,7 @@ public class DSL { * Create a {@link WindowSpecification} with a GROUPS clause. */ @Support({ POSTGRES_11 }) - public static WindowSpecificationFinalStep groupsUnboundedPreceding() { + public static WindowSpecificationExcludeStep groupsUnboundedPreceding() { return new WindowSpecificationImpl().groupsUnboundedPreceding(); } @@ -17728,7 +17728,7 @@ public class DSL { * Create a {@link WindowSpecification} with a GROUPS clause. */ @Support({ POSTGRES_11 }) - public static WindowSpecificationFinalStep groupsPreceding(int number) { + public static WindowSpecificationExcludeStep groupsPreceding(int number) { return new WindowSpecificationImpl().groupsPreceding(number); } @@ -17736,7 +17736,7 @@ public class DSL { * Create a {@link WindowSpecification} with a GROUPS clause. */ @Support({ POSTGRES_11 }) - public static WindowSpecificationFinalStep groupsCurrentRow() { + public static WindowSpecificationExcludeStep groupsCurrentRow() { return new WindowSpecificationImpl().groupsCurrentRow(); } @@ -17744,7 +17744,7 @@ public class DSL { * Create a {@link WindowSpecification} with a GROUPS clause. */ @Support({ POSTGRES_11 }) - public static WindowSpecificationFinalStep groupsUnboundedFollowing() { + public static WindowSpecificationExcludeStep groupsUnboundedFollowing() { return new WindowSpecificationImpl().groupsUnboundedFollowing(); } @@ -17752,7 +17752,7 @@ public class DSL { * Create a {@link WindowSpecification} with a GROUPS clause. */ @Support({ POSTGRES_11 }) - public static WindowSpecificationFinalStep groupsFollowing(int number) { + public static WindowSpecificationExcludeStep groupsFollowing(int number) { return new WindowSpecificationImpl().groupsFollowing(number); } diff --git a/jOOQ/src/main/java/org/jooq/impl/Function.java b/jOOQ/src/main/java/org/jooq/impl/Function.java index 11f5634b4b..baa78c9386 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Function.java +++ b/jOOQ/src/main/java/org/jooq/impl/Function.java @@ -98,6 +98,7 @@ import org.jooq.SQL; import org.jooq.SQLDialect; import org.jooq.WindowBeforeOverStep; import org.jooq.WindowDefinition; +import org.jooq.WindowExcludeStep; import org.jooq.WindowFinalStep; import org.jooq.WindowFromFirstLastStep; import org.jooq.WindowIgnoreNullsStep; @@ -125,7 +126,8 @@ class Function extends AbstractField implements WindowFromFirstLastStep, WindowPartitionByStep, WindowRowsStep, - WindowRowsAndStep + WindowRowsAndStep, + WindowExcludeStep { @@ -703,31 +705,31 @@ class Function extends AbstractField implements } @Override - public final WindowFinalStep rowsUnboundedPreceding() { + public final WindowExcludeStep rowsUnboundedPreceding() { windowSpecification.rowsUnboundedPreceding(); return this; } @Override - public final WindowFinalStep rowsPreceding(int number) { + public final WindowExcludeStep rowsPreceding(int number) { windowSpecification.rowsPreceding(number); return this; } @Override - public final WindowFinalStep rowsCurrentRow() { + public final WindowExcludeStep rowsCurrentRow() { windowSpecification.rowsCurrentRow(); return this; } @Override - public final WindowFinalStep rowsUnboundedFollowing() { + public final WindowExcludeStep rowsUnboundedFollowing() { windowSpecification.rowsUnboundedFollowing(); return this; } @Override - public final WindowFinalStep rowsFollowing(int number) { + public final WindowExcludeStep rowsFollowing(int number) { windowSpecification.rowsFollowing(number); return this; } @@ -763,31 +765,31 @@ class Function extends AbstractField implements } @Override - public final WindowFinalStep rangeUnboundedPreceding() { + public final WindowExcludeStep rangeUnboundedPreceding() { windowSpecification.rangeUnboundedPreceding(); return this; } @Override - public final WindowFinalStep rangePreceding(int number) { + public final WindowExcludeStep rangePreceding(int number) { windowSpecification.rangePreceding(number); return this; } @Override - public final WindowFinalStep rangeCurrentRow() { + public final WindowExcludeStep rangeCurrentRow() { windowSpecification.rangeCurrentRow(); return this; } @Override - public final WindowFinalStep rangeUnboundedFollowing() { + public final WindowExcludeStep rangeUnboundedFollowing() { windowSpecification.rangeUnboundedFollowing(); return this; } @Override - public final WindowFinalStep rangeFollowing(int number) { + public final WindowExcludeStep rangeFollowing(int number) { windowSpecification.rangeFollowing(number); return this; } @@ -823,31 +825,31 @@ class Function extends AbstractField implements } @Override - public final WindowFinalStep groupsUnboundedPreceding() { + public final WindowExcludeStep groupsUnboundedPreceding() { windowSpecification.groupsUnboundedPreceding(); return this; } @Override - public final WindowFinalStep groupsPreceding(int number) { + public final WindowExcludeStep groupsPreceding(int number) { windowSpecification.groupsPreceding(number); return this; } @Override - public final WindowFinalStep groupsCurrentRow() { + public final WindowExcludeStep groupsCurrentRow() { windowSpecification.groupsCurrentRow(); return this; } @Override - public final WindowFinalStep groupsUnboundedFollowing() { + public final WindowExcludeStep groupsUnboundedFollowing() { windowSpecification.groupsUnboundedFollowing(); return this; } @Override - public final WindowFinalStep groupsFollowing(int number) { + public final WindowExcludeStep groupsFollowing(int number) { windowSpecification.groupsFollowing(number); return this; } @@ -883,32 +885,56 @@ class Function extends AbstractField implements } @Override - public final WindowFinalStep andUnboundedPreceding() { + public final WindowExcludeStep andUnboundedPreceding() { windowSpecification.andUnboundedPreceding(); return this; } @Override - public final WindowFinalStep andPreceding(int number) { + public final WindowExcludeStep andPreceding(int number) { windowSpecification.andPreceding(number); return this; } @Override - public final WindowFinalStep andCurrentRow() { + public final WindowExcludeStep andCurrentRow() { windowSpecification.andCurrentRow(); return this; } @Override - public final WindowFinalStep andUnboundedFollowing() { + public final WindowExcludeStep andUnboundedFollowing() { windowSpecification.andUnboundedFollowing(); return this; } @Override - public final WindowFinalStep andFollowing(int number) { + public final WindowExcludeStep andFollowing(int number) { windowSpecification.andFollowing(number); return this; } + + @Override + public final WindowFinalStep excludeCurrentRow() { + windowSpecification.excludeCurrentRow(); + return this; + } + + @Override + public final WindowFinalStep excludeGroup() { + windowSpecification.excludeGroup(); + return this; + } + + @Override + public final WindowFinalStep excludeTies() { + windowSpecification.excludeTies(); + return this; + } + + @Override + public final WindowFinalStep excludeNoOthers() { + windowSpecification.excludeNoOthers(); + return this; + } } diff --git a/jOOQ/src/main/java/org/jooq/impl/Keywords.java b/jOOQ/src/main/java/org/jooq/impl/Keywords.java index 00b9e21ed6..cd990fdf06 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Keywords.java +++ b/jOOQ/src/main/java/org/jooq/impl/Keywords.java @@ -123,6 +123,7 @@ final class Keywords { static final Keyword K_ENUM = keyword("enum"); static final Keyword K_ESCAPE = keyword("escape"); static final Keyword K_EXCEPTION = keyword("exception"); + static final Keyword K_EXCLUDE = keyword("exclude"); static final Keyword K_EXEC = keyword("exec"); static final Keyword K_EXECUTE_BLOCK = keyword("execute block"); static final Keyword K_EXECUTE_IMMEDIATE = keyword("execute immediate"); diff --git a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java index b1bc2350d5..7775af03fd 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ParserImpl.java @@ -399,6 +399,7 @@ import org.jooq.WindowFromFirstLastStep; import org.jooq.WindowIgnoreNullsStep; import org.jooq.WindowOverStep; import org.jooq.WindowSpecification; +import org.jooq.WindowSpecificationExcludeStep; import org.jooq.WindowSpecificationOrderByStep; import org.jooq.WindowSpecificationRowsAndStep; import org.jooq.WindowSpecificationRowsStep; @@ -1265,6 +1266,7 @@ final class ParserImpl implements Parser { final WindowSpecificationOrderByStep s1; final WindowSpecificationRowsStep s2; final WindowSpecificationRowsAndStep s3; + final WindowSpecificationExcludeStep s4; s1 = parseKeywordIf(ctx, "PARTITION BY") ? partitionBy(parseFields(ctx)) @@ -1364,18 +1366,18 @@ final class ParserImpl implements Parser { if (parseKeywordIf(ctx, "UNBOUNDED")) if (parseKeywordIf(ctx, "PRECEDING")) - return s3.andUnboundedPreceding(); + s4 = s3.andUnboundedPreceding(); else if (parseKeywordIf(ctx, "FOLLOWING")) - return s3.andUnboundedFollowing(); + s4 = s3.andUnboundedFollowing(); else throw ctx.expected("FOLLOWING", "PRECEDING"); else if (parseKeywordIf(ctx, "CURRENT ROW")) - return s3.andCurrentRow(); + s4 = s3.andCurrentRow(); else if ((n = parseUnsignedInteger(ctx)) != null) if (parseKeywordIf(ctx, "PRECEDING")) - return s3.andPreceding(n.intValue()); + s4 = s3.andPreceding(n.intValue()); else if (parseKeywordIf(ctx, "FOLLOWING")) - return s3.andFollowing(n.intValue()); + s4 = s3.andFollowing(n.intValue()); else throw ctx.expected("FOLLOWING", "PRECEDING"); else @@ -1383,7 +1385,7 @@ final class ParserImpl implements Parser { } else if (parseKeywordIf(ctx, "UNBOUNDED")) if (parseKeywordIf(ctx, "PRECEDING")) - return s2 == null + s4 = s2 == null ? rows ? rowsUnboundedPreceding() : range @@ -1395,7 +1397,7 @@ final class ParserImpl implements Parser { ? s2.rangeUnboundedPreceding() : s2.groupsUnboundedPreceding(); else if (parseKeywordIf(ctx, "FOLLOWING")) - return s2 == null + s4 = s2 == null ? rows ? rowsUnboundedFollowing() : range @@ -1409,7 +1411,7 @@ final class ParserImpl implements Parser { else throw ctx.expected("FOLLOWING", "PRECEDING"); else if (parseKeywordIf(ctx, "CURRENT ROW")) - return s2 == null + s4 = s2 == null ? rows ? rowsCurrentRow() : range @@ -1422,7 +1424,7 @@ final class ParserImpl implements Parser { : s2.groupsCurrentRow(); else if ((n = parseUnsignedInteger(ctx)) != null) if (parseKeywordIf(ctx, "PRECEDING")) - return s2 == null + s4 = s2 == null ? rows ? rowsPreceding(n.intValue()) : range @@ -1434,7 +1436,7 @@ final class ParserImpl implements Parser { ? s2.rangePreceding(n.intValue()) : s2.groupsPreceding(n.intValue()); else if (parseKeywordIf(ctx, "FOLLOWING")) - return s2 == null + s4 = s2 == null ? rows ? rowsFollowing(n.intValue()) : range @@ -1449,6 +1451,20 @@ final class ParserImpl implements Parser { throw ctx.expected("FOLLOWING", "PRECEDING"); else throw ctx.expected("BETWEEN", "CURRENT ROW", "UNBOUNDED", "integer literal"); + + if (parseIf(ctx, "EXCLUDE")) + if (parseIf(ctx, "CURRENT ROW")) + return s4.excludeCurrentRow(); + else if (parseIf(ctx, "TIES")) + return s4.excludeTies(); + else if (parseIf(ctx, "GROUP")) + return s4.excludeGroup(); + else if (parseIf(ctx, "NO OTHERS")) + return s4.excludeNoOthers(); + else + throw ctx.expected("CURRENT ROW", "TIES", "GROUP", "NO OTHERS"); + else + return s4; } else return s2; diff --git a/jOOQ/src/main/java/org/jooq/impl/WindowSpecificationImpl.java b/jOOQ/src/main/java/org/jooq/impl/WindowSpecificationImpl.java index 01dca27fb5..9c8e6e0f5f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/WindowSpecificationImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/WindowSpecificationImpl.java @@ -46,12 +46,17 @@ import static org.jooq.impl.DSL.one; import static org.jooq.impl.Keywords.K_AND; import static org.jooq.impl.Keywords.K_BETWEEN; import static org.jooq.impl.Keywords.K_CURRENT_ROW; +import static org.jooq.impl.Keywords.K_EXCLUDE; import static org.jooq.impl.Keywords.K_FOLLOWING; import static org.jooq.impl.Keywords.K_ORDER_BY; import static org.jooq.impl.Keywords.K_PARTITION_BY; import static org.jooq.impl.Keywords.K_PRECEDING; import static org.jooq.impl.Keywords.K_UNBOUNDED_FOLLOWING; import static org.jooq.impl.Keywords.K_UNBOUNDED_PRECEDING; +import static org.jooq.impl.WindowSpecificationImpl.Exclude.CURRENT_ROW; +import static org.jooq.impl.WindowSpecificationImpl.Exclude.GROUP; +import static org.jooq.impl.WindowSpecificationImpl.Exclude.NO_OTHERS; +import static org.jooq.impl.WindowSpecificationImpl.Exclude.TIES; import static org.jooq.impl.WindowSpecificationImpl.FrameUnits.GROUPS; import static org.jooq.impl.WindowSpecificationImpl.FrameUnits.RANGE; import static org.jooq.impl.WindowSpecificationImpl.FrameUnits.ROWS; @@ -66,6 +71,7 @@ import org.jooq.Field; import org.jooq.Keyword; import org.jooq.OrderField; import org.jooq.SQLDialect; +import org.jooq.WindowSpecificationExcludeStep; import org.jooq.WindowSpecificationFinalStep; import org.jooq.WindowSpecificationOrderByStep; import org.jooq.WindowSpecificationPartitionByStep; @@ -78,7 +84,8 @@ final class WindowSpecificationImpl extends AbstractQueryPart implements // Cascading interface implementations for window specification behaviour WindowSpecificationPartitionByStep, - WindowSpecificationRowsAndStep + WindowSpecificationRowsAndStep, + WindowSpecificationExcludeStep { @@ -93,6 +100,7 @@ final class WindowSpecificationImpl extends AbstractQueryPart implements private Integer frameStart; private Integer frameEnd; private FrameUnits frameUnits; + private Exclude exclude; private boolean partitionByOne; WindowSpecificationImpl() { @@ -144,6 +152,9 @@ final class WindowSpecificationImpl extends AbstractQueryPart implements } glue = " "; + + if (exclude != null) + ctx.sql(glue).visit(K_EXCLUDE).sql(' ').visit(exclude.keyword); } } @@ -181,7 +192,7 @@ final class WindowSpecificationImpl extends AbstractQueryPart implements public final WindowSpecificationOrderByStep partitionByOne() { partitionByOne = true; partitionBy.add(one()); - return null; + return this; } @Override @@ -196,35 +207,35 @@ final class WindowSpecificationImpl extends AbstractQueryPart implements } @Override - public final WindowSpecificationFinalStep rowsUnboundedPreceding() { + public final WindowSpecificationExcludeStep rowsUnboundedPreceding() { frameUnits = ROWS; frameStart = Integer.MIN_VALUE; return this; } @Override - public final WindowSpecificationFinalStep rowsPreceding(int number) { + public final WindowSpecificationExcludeStep rowsPreceding(int number) { frameUnits = ROWS; frameStart = -number; return this; } @Override - public final WindowSpecificationFinalStep rowsCurrentRow() { + public final WindowSpecificationExcludeStep rowsCurrentRow() { frameUnits = ROWS; frameStart = 0; return this; } @Override - public final WindowSpecificationFinalStep rowsUnboundedFollowing() { + public final WindowSpecificationExcludeStep rowsUnboundedFollowing() { frameUnits = ROWS; frameStart = Integer.MAX_VALUE; return this; } @Override - public final WindowSpecificationFinalStep rowsFollowing(int number) { + public final WindowSpecificationExcludeStep rowsFollowing(int number) { frameUnits = ROWS; frameStart = number; return this; @@ -261,35 +272,35 @@ final class WindowSpecificationImpl extends AbstractQueryPart implements } @Override - public final WindowSpecificationFinalStep rangeUnboundedPreceding() { + public final WindowSpecificationExcludeStep rangeUnboundedPreceding() { frameUnits = RANGE; frameStart = Integer.MIN_VALUE; return this; } @Override - public final WindowSpecificationFinalStep rangePreceding(int number) { + public final WindowSpecificationExcludeStep rangePreceding(int number) { frameUnits = RANGE; frameStart = -number; return this; } @Override - public final WindowSpecificationFinalStep rangeCurrentRow() { + public final WindowSpecificationExcludeStep rangeCurrentRow() { frameUnits = RANGE; frameStart = 0; return this; } @Override - public final WindowSpecificationFinalStep rangeUnboundedFollowing() { + public final WindowSpecificationExcludeStep rangeUnboundedFollowing() { frameUnits = RANGE; frameStart = Integer.MAX_VALUE; return this; } @Override - public final WindowSpecificationFinalStep rangeFollowing(int number) { + public final WindowSpecificationExcludeStep rangeFollowing(int number) { frameUnits = RANGE; frameStart = number; return this; @@ -326,35 +337,35 @@ final class WindowSpecificationImpl extends AbstractQueryPart implements } @Override - public final WindowSpecificationFinalStep groupsUnboundedPreceding() { + public final WindowSpecificationExcludeStep groupsUnboundedPreceding() { frameUnits = GROUPS; frameStart = Integer.MIN_VALUE; return this; } @Override - public final WindowSpecificationFinalStep groupsPreceding(int number) { + public final WindowSpecificationExcludeStep groupsPreceding(int number) { frameUnits = GROUPS; frameStart = -number; return this; } @Override - public final WindowSpecificationFinalStep groupsCurrentRow() { + public final WindowSpecificationExcludeStep groupsCurrentRow() { frameUnits = GROUPS; frameStart = 0; return this; } @Override - public final WindowSpecificationFinalStep groupsUnboundedFollowing() { + public final WindowSpecificationExcludeStep groupsUnboundedFollowing() { frameUnits = GROUPS; frameStart = Integer.MAX_VALUE; return this; } @Override - public final WindowSpecificationFinalStep groupsFollowing(int number) { + public final WindowSpecificationExcludeStep groupsFollowing(int number) { frameUnits = GROUPS; frameStart = number; return this; @@ -391,44 +402,81 @@ final class WindowSpecificationImpl extends AbstractQueryPart implements } @Override - public final WindowSpecificationFinalStep andUnboundedPreceding() { + public final WindowSpecificationExcludeStep andUnboundedPreceding() { frameEnd = Integer.MIN_VALUE; return this; } @Override - public final WindowSpecificationFinalStep andPreceding(int number) { + public final WindowSpecificationExcludeStep andPreceding(int number) { frameEnd = -number; return this; } @Override - public final WindowSpecificationFinalStep andCurrentRow() { + public final WindowSpecificationExcludeStep andCurrentRow() { frameEnd = 0; return this; } @Override - public final WindowSpecificationFinalStep andUnboundedFollowing() { + public final WindowSpecificationExcludeStep andUnboundedFollowing() { frameEnd = Integer.MAX_VALUE; return this; } @Override - public final WindowSpecificationFinalStep andFollowing(int number) { + public final WindowSpecificationExcludeStep andFollowing(int number) { frameEnd = number; return this; } + @Override + public WindowSpecificationFinalStep excludeCurrentRow() { + exclude = CURRENT_ROW; + return this; + } + + @Override + public WindowSpecificationFinalStep excludeGroup() { + exclude = GROUP; + return this; + } + + @Override + public WindowSpecificationFinalStep excludeTies() { + exclude = TIES; + return this; + } + + @Override + public WindowSpecificationFinalStep excludeNoOthers() { + exclude = NO_OTHERS; + return this; + } + enum FrameUnits { ROWS("rows"), RANGE("range"), GROUPS("groups"); - private final Keyword keyword; + final Keyword keyword; private FrameUnits(String keyword) { this.keyword = DSL.keyword(keyword); } } + + enum Exclude { + CURRENT_ROW("current row"), + TIES("ties"), + GROUP("group"), + NO_OTHERS("no others"); + + final Keyword keyword; + + private Exclude(String keyword) { + this.keyword = DSL.keyword(keyword); + } + } }