From adbd2f4d38aa6e83f26d94aa165f2a4822993175 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Wed, 6 May 2015 19:10:47 +0200 Subject: [PATCH] [#2728] Add support for Amazon Redshift --- jOOQ/src/main/java/org/jooq/Field.java | 1 + .../java/org/jooq/WindowIgnoreNullsStep.java | 5 +- .../main/java/org/jooq/WindowOrderByStep.java | 1 + .../main/java/org/jooq/WindowOverStep.java | 43 +++---- .../java/org/jooq/WindowPartitionByStep.java | 1 + .../main/java/org/jooq/WindowRowsAndStep.java | 1 + .../main/java/org/jooq/WindowRowsStep.java | 1 + .../jooq/WindowSpecificationOrderByStep.java | 1 + .../WindowSpecificationPartitionByStep.java | 1 + .../jooq/WindowSpecificationRowsAndStep.java | 1 + .../org/jooq/WindowSpecificationRowsStep.java | 1 + jOOQ/src/main/java/org/jooq/impl/Cosh.java | 1 + jOOQ/src/main/java/org/jooq/impl/DSL.java | 60 +-------- jOOQ/src/main/java/org/jooq/impl/LeadLag.java | 118 ++++++++++++++++++ jOOQ/src/main/java/org/jooq/impl/Sinh.java | 1 + jOOQ/src/main/java/org/jooq/impl/Tanh.java | 1 + 16 files changed, 159 insertions(+), 79 deletions(-) create mode 100644 jOOQ/src/main/java/org/jooq/impl/LeadLag.java diff --git a/jOOQ/src/main/java/org/jooq/Field.java b/jOOQ/src/main/java/org/jooq/Field.java index 9378ea95b5..9f55ee7dee 100644 --- a/jOOQ/src/main/java/org/jooq/Field.java +++ b/jOOQ/src/main/java/org/jooq/Field.java @@ -56,6 +56,7 @@ import static org.jooq.SQLDialect.MARIADB; import static org.jooq.SQLDialect.MYSQL; // ... import static org.jooq.SQLDialect.POSTGRES; +// ... import static org.jooq.SQLDialect.SQLITE; // ... // ... diff --git a/jOOQ/src/main/java/org/jooq/WindowIgnoreNullsStep.java b/jOOQ/src/main/java/org/jooq/WindowIgnoreNullsStep.java index 78b9613b6a..3de541d3fd 100644 --- a/jOOQ/src/main/java/org/jooq/WindowIgnoreNullsStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowIgnoreNullsStep.java @@ -44,6 +44,7 @@ package org.jooq; // ... // ... // ... +// ... /** * This type is used for the window function DSL API. @@ -68,14 +69,14 @@ public interface WindowIgnoreNullsStep extends WindowOverStep { x xxx xx xxxxxxxxxxxx xxxxxxxxxxxx xxxxxx xx xxx xxxxxx xxxxxxxxx xxxx x xxxxx xxx xx xxxxxxxxx xx xxx xxxxxxxxx xx - xxxxxxxxxx xxxx xxxxxxxxx xxxxxxx xxxxxx xx + xxxxxxxxxx xxxx xxxxxxxxx xxxxxxx xxxxxxxxx xxxxxx xx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx xxx x xxx x xxxxxxxxxxxxx xxxxxxxxxxxx xxxxxx xx xxx xxxxxx xxxxxxxxx xxxx x xxxxx xxx xx xxxxxxxxx xx xxx xxxxxxxxx xx - xxxxxxxxxx xxxx xxxxxxxxx xxxxxxx xxxxxx xx + xxxxxxxxxx xxxx xxxxxxxxx xxxxxxx xxxxxxxxx xxxxxx xx xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xx [/pro] */ } diff --git a/jOOQ/src/main/java/org/jooq/WindowOrderByStep.java b/jOOQ/src/main/java/org/jooq/WindowOrderByStep.java index 1a8c74a904..fee9dda375 100644 --- a/jOOQ/src/main/java/org/jooq/WindowOrderByStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowOrderByStep.java @@ -48,6 +48,7 @@ import static org.jooq.SQLDialect.CUBRID; import static org.jooq.SQLDialect.POSTGRES; // ... // ... +// ... import java.util.Collection; diff --git a/jOOQ/src/main/java/org/jooq/WindowOverStep.java b/jOOQ/src/main/java/org/jooq/WindowOverStep.java index cce237cf16..2d0b25236f 100644 --- a/jOOQ/src/main/java/org/jooq/WindowOverStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowOverStep.java @@ -51,6 +51,7 @@ import static org.jooq.SQLDialect.HSQLDB; import static org.jooq.SQLDialect.POSTGRES; // ... // ... +// ... /** * This type is used for the window function DSL API. @@ -78,10 +79,8 @@ public interface WindowOverStep { *

* An example:

      * MAX(id) OVER (PARTITION BY 1)
-     * 
- *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. + * + * */ @Support({ CUBRID, DERBY, H2, HSQLDB, POSTGRES }) WindowPartitionByStep over(); @@ -92,12 +91,12 @@ public interface WindowOverStep { *

* An example:

      * MAX(id) OVER my_window
-     * 
+ * + * *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. If the WINDOW clause is not supported - * (see {@link SelectWindowStep#window(WindowDefinition...)}, then - * referenced windows will be inlined. + * If the WINDOW clause is not supported (see + * {@link SelectWindowStep#window(WindowDefinition...)}, then referenced + * windows will be inlined. */ @Support({ CUBRID, POSTGRES }) WindowFinalStep over(Name name); @@ -108,12 +107,12 @@ public interface WindowOverStep { *

* An example:

      * MAX(id) OVER my_window
-     * 
+ * + * *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. If the WINDOW clause is not supported - * (see {@link SelectWindowStep#window(WindowDefinition...)}, then - * referenced windows will be inlined. + * If the WINDOW clause is not supported (see + * {@link SelectWindowStep#window(WindowDefinition...)}, then referenced + * windows will be inlined. */ @Support({ CUBRID, POSTGRES }) WindowFinalStep over(String name); @@ -123,10 +122,8 @@ public interface WindowOverStep { *

* An example:

      * MAX(id) OVER (PARTITION BY 1)
-     * 
- *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. + * + * */ @Support({ CUBRID, POSTGRES }) WindowFinalStep over(WindowSpecification specification); @@ -137,12 +134,12 @@ public interface WindowOverStep { *

* An example:

      * MAX(id) OVER my_window
-     * 
+ * + * *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. If the WINDOW clause is not supported - * (see {@link SelectWindowStep#window(WindowDefinition...)}, then - * referenced windows will be inlined. + * If the WINDOW clause is not supported (see + * {@link SelectWindowStep#window(WindowDefinition...)}, then referenced + * windows will be inlined. */ @Support({ CUBRID, POSTGRES }) WindowFinalStep over(WindowDefinition definition); diff --git a/jOOQ/src/main/java/org/jooq/WindowPartitionByStep.java b/jOOQ/src/main/java/org/jooq/WindowPartitionByStep.java index 493bffaa7d..9700f0cac9 100644 --- a/jOOQ/src/main/java/org/jooq/WindowPartitionByStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowPartitionByStep.java @@ -48,6 +48,7 @@ import static org.jooq.SQLDialect.CUBRID; import static org.jooq.SQLDialect.POSTGRES; // ... // ... +// ... /** * This type is used for the window function DSL API. diff --git a/jOOQ/src/main/java/org/jooq/WindowRowsAndStep.java b/jOOQ/src/main/java/org/jooq/WindowRowsAndStep.java index 5bfab020b8..6d5151fc64 100644 --- a/jOOQ/src/main/java/org/jooq/WindowRowsAndStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowRowsAndStep.java @@ -46,6 +46,7 @@ package org.jooq; import static org.jooq.SQLDialect.POSTGRES; // ... // ... +// ... /** * This type is used for the window function DSL API. diff --git a/jOOQ/src/main/java/org/jooq/WindowRowsStep.java b/jOOQ/src/main/java/org/jooq/WindowRowsStep.java index eb00b6bca9..2fa4e2a6e6 100644 --- a/jOOQ/src/main/java/org/jooq/WindowRowsStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowRowsStep.java @@ -46,6 +46,7 @@ package org.jooq; import static org.jooq.SQLDialect.POSTGRES; // ... // ... +// ... /** * This type is used for the window function DSL API. diff --git a/jOOQ/src/main/java/org/jooq/WindowSpecificationOrderByStep.java b/jOOQ/src/main/java/org/jooq/WindowSpecificationOrderByStep.java index 5ddaf72738..4842888801 100644 --- a/jOOQ/src/main/java/org/jooq/WindowSpecificationOrderByStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowSpecificationOrderByStep.java @@ -48,6 +48,7 @@ import static org.jooq.SQLDialect.CUBRID; import static org.jooq.SQLDialect.POSTGRES; // ... // ... +// ... import java.util.Collection; diff --git a/jOOQ/src/main/java/org/jooq/WindowSpecificationPartitionByStep.java b/jOOQ/src/main/java/org/jooq/WindowSpecificationPartitionByStep.java index b3ff2ffb2e..323b897a2e 100644 --- a/jOOQ/src/main/java/org/jooq/WindowSpecificationPartitionByStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowSpecificationPartitionByStep.java @@ -48,6 +48,7 @@ import static org.jooq.SQLDialect.CUBRID; import static org.jooq.SQLDialect.POSTGRES; // ... // ... +// ... import java.util.Collection; diff --git a/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsAndStep.java b/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsAndStep.java index d9436fdbd4..34715a7e9a 100644 --- a/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsAndStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsAndStep.java @@ -46,6 +46,7 @@ package org.jooq; import static org.jooq.SQLDialect.POSTGRES; // ... // ... +// ... /** * An intermediate step in the construction of a {@link WindowSpecification}. diff --git a/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsStep.java b/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsStep.java index 77528fbb4e..1acf677657 100644 --- a/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsStep.java +++ b/jOOQ/src/main/java/org/jooq/WindowSpecificationRowsStep.java @@ -46,6 +46,7 @@ package org.jooq; import static org.jooq.SQLDialect.POSTGRES; // ... // ... +// ... /** * An intermediate step in the construction of a {@link WindowSpecification}. diff --git a/jOOQ/src/main/java/org/jooq/impl/Cosh.java b/jOOQ/src/main/java/org/jooq/impl/Cosh.java index c2b8487eb6..a59d2400c4 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Cosh.java +++ b/jOOQ/src/main/java/org/jooq/impl/Cosh.java @@ -74,6 +74,7 @@ class Cosh extends AbstractFunction { xxxx xxxxxxx xxxx xxxx xxxx xxxxxxx + xxxx xxxxxxxxx xxxx xxxxxxxxxx xxxx xxxxxxx xx [/pro] */ diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index f0e54ccc7d..f030404dbf 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -11375,9 +11375,6 @@ public class DSL { /** * The row_number() over ([analytic clause]) function. *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. - *

* Newer versions of {@link SQLDialect#DERBY} and {@link SQLDialect#H2} also * support the ROW_NUMBER() OVER() window function without any * window clause. See the respective docs for details. @@ -11391,9 +11388,6 @@ public class DSL { /** * The rank() over ([analytic clause]) function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowOverStep rank() { @@ -11411,9 +11405,6 @@ public class DSL { /** * The dense_rank() over ([analytic clause]) function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowOverStep denseRank() { @@ -11431,9 +11422,6 @@ public class DSL { /** * The precent_rank() over ([analytic clause]) function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowOverStep percentRank() { @@ -11451,9 +11439,6 @@ public class DSL { /** * The cume_dist() over ([analytic clause]) function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowOverStep cumeDist() { @@ -11471,9 +11456,6 @@ public class DSL { /** * The ntile([number]) over ([analytic clause]) function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowOverStep ntile(int number) { @@ -11522,9 +11504,6 @@ public class DSL { /** * The first_value(field) over ([analytic clause]) function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowIgnoreNullsStep firstValue(Field field) { @@ -11533,9 +11512,6 @@ public class DSL { /** * The last_value(field) over ([analytic clause]) function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowIgnoreNullsStep lastValue(Field field) { @@ -11544,33 +11520,24 @@ public class DSL { /** * The lead(field) over ([analytic clause]) function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowIgnoreNullsStep lead(Field field) { - return new Function("lead", nullSafeDataType(field), nullSafe(field)); + return new LeadLag("lead", nullSafe(field)); } /** * The lead(field, offset) over ([analytic clause]) function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowIgnoreNullsStep lead(Field field, int offset) { - return new Function("lead", nullSafeDataType(field), nullSafe(field), inline(offset)); + return new LeadLag("lead", nullSafe(field), offset); } /** * The * lead(field, offset, defaultValue) over ([analytic clause]) * function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowIgnoreNullsStep lead(Field field, int offset, T defaultValue) { @@ -11581,44 +11548,32 @@ public class DSL { * The * lead(field, offset, defaultValue) over ([analytic clause]) * function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowIgnoreNullsStep lead(Field field, int offset, Field defaultValue) { - return new Function("lead", nullSafeDataType(field), nullSafe(field), inline(offset), nullSafe(defaultValue)); + return new LeadLag("lead", nullSafe(field), offset, nullSafe(defaultValue)); } /** * The lag(field) over ([analytic clause]) function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowIgnoreNullsStep lag(Field field) { - return new Function("lag", nullSafeDataType(field), nullSafe(field)); + return new LeadLag("lag", nullSafe(field)); } /** * The lag(field, offset) over ([analytic clause]) function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowIgnoreNullsStep lag(Field field, int offset) { - return new Function("lag", nullSafeDataType(field), nullSafe(field), inline(offset)); + return new LeadLag("lag", nullSafe(field), offset); } /** * The * lag(field, offset, defaultValue) over ([analytic clause]) * function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowIgnoreNullsStep lag(Field field, int offset, T defaultValue) { @@ -11629,13 +11584,10 @@ public class DSL { * The * lag(field, offset, defaultValue) over ([analytic clause]) * function. - *

- * Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL - * Server and Sybase. */ @Support({ CUBRID, POSTGRES }) public static WindowIgnoreNullsStep lag(Field field, int offset, Field defaultValue) { - return new Function("lag", nullSafeDataType(field), nullSafe(field), inline(offset), nullSafe(defaultValue)); + return new LeadLag("lag", nullSafe(field), offset, nullSafe(defaultValue)); } // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/LeadLag.java b/jOOQ/src/main/java/org/jooq/impl/LeadLag.java new file mode 100644 index 0000000000..f5e1e8b6ad --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/LeadLag.java @@ -0,0 +1,118 @@ +/** + * Copyright (c) 2009-2015, Data Geekery GmbH (http://www.datageekery.com) + * All rights reserved. + * + * This work is dual-licensed + * - under the Apache Software License 2.0 (the "ASL") + * - under the jOOQ License and Maintenance Agreement (the "jOOQ License") + * ============================================================================= + * You may choose which license applies to you: + * + * - If you're using this work with Open Source databases, you may choose + * either ASL or jOOQ License. + * - If you're using this work with at least one commercial database, you must + * choose jOOQ License + * + * For more information, please visit http://www.jooq.org/licenses + * + * Apache Software License 2.0: + * ----------------------------------------------------------------------------- + * 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. + * + * jOOQ License and Maintenance Agreement: + * ----------------------------------------------------------------------------- + * Data Geekery grants the Customer the non-exclusive, timely limited and + * non-transferable license to install and use the Software under the terms of + * the jOOQ License and Maintenance Agreement. + * + * This library is distributed with a LIMITED WARRANTY. See the jOOQ License + * and Maintenance Agreement for more details: http://www.jooq.org/licensing + */ +package org.jooq.impl; + +import static org.jooq.impl.DSL.inline; +import static org.jooq.impl.DSL.keyword; + +import org.jooq.Context; +import org.jooq.Field; + +/** + * @author Lukas Eder + */ +class LeadLag extends Function { + + /** + * Generated UID + */ + private static final long serialVersionUID = 7292087943334025737L; + + private final String function; + private final Field field; + private final int offset; + private final Field defaultValue; + + LeadLag(String function, Field field) { + super(function, field.getDataType(), field); + + this.function = function; + this.field = field; + this.offset = 0; + this.defaultValue = null; + } + + LeadLag(String function, Field field, int offset) { + super(function, field.getDataType(), field, inline(offset)); + + this.function = function; + this.field = field; + this.offset = offset; + this.defaultValue = null; + } + + LeadLag(String function, Field field, int offset, Field defaultValue) { + super(function, field.getDataType(), field, inline(offset), defaultValue); + + this.function = function; + this.field = field; + this.offset = offset; + this.defaultValue = defaultValue; + } + + @Override + public final void accept(Context ctx) { + if (defaultValue == null) { + super.accept(ctx); + } + else { + switch (ctx.family()) { + /* [pro] xx + xxxx xxxxxxxxx + xxxxxxxxxxxxxxxxxxxxxxx + xxxxxxxxxx + + xxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxx + xxxxxxxxxxxxxxxxxxxxx + + xxxxxxxxxx xx + xxxxxxxxxxxxxxxxxxxx + xxxxxxxxxx + xxxxxx + xx [/pro] */ + + default: + super.accept(ctx); + break; + } + } + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/Sinh.java b/jOOQ/src/main/java/org/jooq/impl/Sinh.java index afd2b89a67..6e38e2227d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Sinh.java +++ b/jOOQ/src/main/java/org/jooq/impl/Sinh.java @@ -74,6 +74,7 @@ class Sinh extends AbstractFunction { xxxx xxxxxxx xxxx xxxx xxxx xxxxxxx + xxxx xxxxxxxxx xxxx xxxxxxxxxx xxxx xxxxxxx xx [/pro] */ diff --git a/jOOQ/src/main/java/org/jooq/impl/Tanh.java b/jOOQ/src/main/java/org/jooq/impl/Tanh.java index 8e5d5a7821..69da557eb2 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Tanh.java +++ b/jOOQ/src/main/java/org/jooq/impl/Tanh.java @@ -74,6 +74,7 @@ class Tanh extends AbstractFunction { xxxx xxxxxxx xxxx xxxx xxxx xxxxxxx + xxxx xxxxxxxxx xxxx xxxxxxxxxx xxxx xxxxxxx xx [/pro] */