[jOOQ/jOOQ#13769] Emulate GROUP BY <column index> using substitution in dialects where this isn't natively supported

This commit is contained in:
Lukas Eder 2022-07-06 10:44:32 +02:00
parent 7ac2013a51
commit 58d8c3e971
18 changed files with 714 additions and 609 deletions

View File

@ -74,7 +74,7 @@ public final class Constants {
/**
* The current jooq-runtime XSD file name.
*/
public static final String XSD_RUNTIME = "jooq-runtime-3.17.0.xsd";
public static final String XSD_RUNTIME = "jooq-runtime-3.18.0.xsd";
/**
* The current jooq-runtime XML namespace.

View File

@ -74,7 +74,7 @@ public final class Constants {
/**
* The current jooq-runtime XSD file name.
*/
public static final String XSD_RUNTIME = "jooq-runtime-3.17.0.xsd";
public static final String XSD_RUNTIME = "jooq-runtime-3.18.0.xsd";
/**
* The current jooq-runtime XML namespace.

View File

@ -74,7 +74,7 @@ public final class Constants {
/**
* The current jooq-runtime XSD file name.
*/
public static final String XSD_RUNTIME = "jooq-runtime-3.17.0.xsd";
public static final String XSD_RUNTIME = "jooq-runtime-3.18.0.xsd";
/**
* The current jooq-runtime XML namespace.

View File

@ -28,7 +28,7 @@ public class InterpreterSearchSchema
implements Serializable, Cloneable, XMLAppendable
{
private final static long serialVersionUID = 31700L;
private final static long serialVersionUID = 31800L;
protected String catalog;
@XmlElement(required = true)
protected String schema;

View File

@ -34,7 +34,7 @@ public class MappedCatalog
implements Serializable, Cloneable, XMLAppendable
{
private final static long serialVersionUID = 31700L;
private final static long serialVersionUID = 31800L;
protected String input;
@XmlElement(type = String.class)
@XmlJavaTypeAdapter(RegexAdapter.class)

View File

@ -34,7 +34,7 @@ public class MappedSchema
implements Serializable, Cloneable, XMLAppendable
{
private final static long serialVersionUID = 31700L;
private final static long serialVersionUID = 31800L;
protected String input;
@XmlElement(type = String.class)
@XmlJavaTypeAdapter(RegexAdapter.class)

View File

@ -30,7 +30,7 @@ public class MappedTable
implements Serializable, Cloneable, XMLAppendable
{
private final static long serialVersionUID = 31700L;
private final static long serialVersionUID = 31800L;
protected String input;
@XmlElement(type = String.class)
@XmlJavaTypeAdapter(RegexAdapter.class)

View File

@ -28,7 +28,7 @@ public class MigrationSchema
implements Serializable, Cloneable, XMLAppendable
{
private final static long serialVersionUID = 31700L;
private final static long serialVersionUID = 31800L;
protected String catalog;
@XmlElement(required = true)
protected String schema;

View File

@ -24,7 +24,7 @@ import javax.xml.namespace.QName;
@XmlRegistry
public class ObjectFactory {
private final static QName _Settings_QNAME = new QName("http://www.jooq.org/xsd/jooq-runtime-3.17.0.xsd", "settings");
private final static QName _Settings_QNAME = new QName("http://www.jooq.org/xsd/jooq-runtime-3.18.0.xsd", "settings");
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.jooq.conf
@ -113,7 +113,7 @@ public class ObjectFactory {
* @return
* the new instance of {@link JAXBElement }{@code <}{@link Settings }{@code >}
*/
@XmlElementDecl(namespace = "http://www.jooq.org/xsd/jooq-runtime-3.17.0.xsd", name = "settings")
@XmlElementDecl(namespace = "http://www.jooq.org/xsd/jooq-runtime-3.18.0.xsd", name = "settings")
public JAXBElement<Settings> createSettings(Settings value) {
return new JAXBElement<Settings>(_Settings_QNAME, Settings.class, null, value);
}

View File

@ -28,7 +28,7 @@ public class ParseSearchSchema
implements Serializable, Cloneable, XMLAppendable
{
private final static long serialVersionUID = 31700L;
private final static long serialVersionUID = 31800L;
protected String catalog;
@XmlElement(required = true)
protected String schema;

View File

@ -28,7 +28,7 @@ public class RenderFormatting
implements Serializable, Cloneable, XMLAppendable
{
private final static long serialVersionUID = 31700L;
private final static long serialVersionUID = 31800L;
@XmlElement(defaultValue = "\n")
protected String newline = "\n";
@XmlElement(defaultValue = " ")

View File

@ -32,7 +32,7 @@ public class RenderMapping
implements Serializable, Cloneable, XMLAppendable
{
private final static long serialVersionUID = 31700L;
private final static long serialVersionUID = 31800L;
protected String defaultCatalog;
protected String defaultSchema;
@XmlElementWrapper(name = "catalogs")

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +1,2 @@
@jakarta.xml.bind.annotation.XmlSchema(namespace = "http://www.jooq.org/xsd/jooq-runtime-3.17.0.xsd", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
@jakarta.xml.bind.annotation.XmlSchema(namespace = "http://www.jooq.org/xsd/jooq-runtime-3.18.0.xsd", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
package org.jooq.conf;

View File

@ -1668,6 +1668,15 @@ package org.jooq.impl;

View File

@ -223,6 +223,7 @@ import static org.jooq.impl.Tools.SimpleDataKey.DATA_SELECT_ALIASES;
import static org.jooq.impl.Tools.SimpleDataKey.DATA_SELECT_INTO_TABLE;
import static org.jooq.impl.Tools.SimpleDataKey.DATA_TOP_LEVEL_CTE;
import static org.jooq.impl.Tools.SimpleDataKey.DATA_WINDOW_DEFINITIONS;
import static org.jooq.impl.Transformations.transformGroupByColumnIndex;
import static org.jooq.impl.Transformations.transformQualify;
import static org.jooq.impl.Transformations.transformRownum;
@ -2426,8 +2427,26 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
if (groupByDistinct)
context.sql(' ').visit(K_DISTINCT);
context.separatorRequired(true);
context.visit(groupBy);
GroupFieldList g = groupBy;
context.separatorRequired(true).visit(g);
}
context.end(SELECT_GROUP_BY);

View File

@ -91,6 +91,7 @@ final class Transformations {
private static final Set<SQLDialect> SUPPORT_MISSING_TABLE_REFERENCES = SQLDialect.supportedBy();
private static final Set<SQLDialect> EMULATE_QUALIFY = SQLDialect.supportedBy(CUBRID, FIREBIRD, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB);
private static final Set<SQLDialect> EMULATE_ROWNUM = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB);
private static final Set<SQLDialect> EMULATE_GROUP_BY_COLUMN_INDEX = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, IGNITE, SQLITE);
static final SelectQueryImpl<?> subqueryWithLimit(QueryPart source) {
SelectQueryImpl<?> s;
@ -133,6 +134,15 @@ final class Transformations {
);
}
static final boolean transformGroupByColumnIndex(Configuration configuration) {
return transform(
configuration,
"Settings.transformGroupByColumnIndex",
configuration.settings().getTransformGroupByColumnIndex(),
c -> EMULATE_GROUP_BY_COLUMN_INDEX.contains(c.dialect())
);
}
/**
* Check whether a given SQL transformation needs to be applied.
*/

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:jooq-runtime="http://www.jooq.org/xsd/jooq-runtime-3.17.0.xsd"
xmlns:jooq-runtime="http://www.jooq.org/xsd/jooq-runtime-3.18.0.xsd"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:annox="http://annox.dev.java.net"
targetNamespace="http://www.jooq.org/xsd/jooq-runtime-3.17.0.xsd"
targetNamespace="http://www.jooq.org/xsd/jooq-runtime-3.18.0.xsd"
elementFormDefault="qualified"
jxb:extensionBindingPrefixes="annox"
jxb:version="2.1">
@ -664,6 +664,16 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
Arithmetic expressions may be implemented by the user, or arise from emulations from within jOOQ.
Expressions on literals and bind variables could be evaluated in the client prior to generating SQL.
<p>
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="transformGroupByColumnIndex" type="jooq-runtime:Transformation" minOccurs="0" maxOccurs="1" default="WHEN_NEEDED">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Transform <code>GROUP BY [column index]</code> clauses by substituting the column index.
<p>
Not all dialects support grouping by column index, which is a convenient but also a bit confusing feature of
some dialects. jOOQ can transform the syntax into an equivalent syntax where the referenced <code>SELECT</code>
expression is duplicated into the <code>GROUP BY</code> clause.
<p>
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>