From 5bed0b0e886ce8ad84795ae53e447ac36fa0eb13 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Thu, 27 Oct 2022 08:39:34 +0200 Subject: [PATCH] [jOOQ/jOOQ#7527] Added consecutiveAggregation() --- .../java/org/jooq/DiagnosticsContext.java | 22 +++++++-- .../java/org/jooq/DiagnosticsListener.java | 41 ++++++++++++++++ .../src/main/java/org/jooq/conf/Settings.java | 47 +++++++++++++++++++ .../org/jooq/impl/DiagnosticsConnection.java | 42 +++++++++++++---- .../org/jooq/impl/DiagnosticsListeners.java | 7 +++ .../org/jooq/xsd/jooq-runtime-3.18.0.xsd | 9 ++++ 6 files changed, 155 insertions(+), 13 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/DiagnosticsContext.java b/jOOQ/src/main/java/org/jooq/DiagnosticsContext.java index 5077d3546b..fd56bce13b 100644 --- a/jOOQ/src/main/java/org/jooq/DiagnosticsContext.java +++ b/jOOQ/src/main/java/org/jooq/DiagnosticsContext.java @@ -53,7 +53,8 @@ import org.jetbrains.annotations.Nullable; public interface DiagnosticsContext extends Scope { /** - * The object that was diagnosed if available, or null, if there was no specific {@link QueryPart} to attach the diagnostic to. + * The object that was diagnosed if available, or null, if + * there was no specific {@link QueryPart} to attach the diagnostic to. */ @Nullable QueryPart part(); @@ -94,8 +95,8 @@ public interface DiagnosticsContext extends Scope { int resultSetFetchedRows(); /** - * The number of columns that were consumed from the {@link #resultSet()}, or - * -1 if there was no result set. + * The number of columns that were consumed from the {@link #resultSet()}, + * or -1 if there was no result set. *

* If the result set is still being consumed (i.e. prior to the * {@link ResultSet#close()} call), then this will return the number of @@ -111,8 +112,8 @@ public interface DiagnosticsContext extends Scope { int resultSetFetchedColumnCount(); /** - * The number of columns that were consumed from the {@link #resultSet()}, or - * -1 if there was no result set. + * The number of columns that were consumed from the {@link #resultSet()}, + * or -1 if there was no result set. *

* If the result set is still being consumed (i.e. prior to the * {@link ResultSet#close()} call), then this will return the number of @@ -174,6 +175,11 @@ public interface DiagnosticsContext extends Scope { /** * The duplicate statements that all correspond to a single normalised * statement. + *

+ * This set is used by at least: + *

*/ @NotNull Set duplicateStatements(); @@ -181,6 +187,12 @@ public interface DiagnosticsContext extends Scope { /** * The repeated statements that all correspond to a single normalised * statement. + *

+ * This set is used by at least: + *

*/ @NotNull List repeatedStatements(); diff --git a/jOOQ/src/main/java/org/jooq/DiagnosticsListener.java b/jOOQ/src/main/java/org/jooq/DiagnosticsListener.java index 2d393bfba3..78572297f2 100644 --- a/jOOQ/src/main/java/org/jooq/DiagnosticsListener.java +++ b/jOOQ/src/main/java/org/jooq/DiagnosticsListener.java @@ -222,6 +222,47 @@ public interface DiagnosticsListener { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java index 632c681c01..c88e7787e0 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -125,6 +125,8 @@ public class Settings @XmlElement(defaultValue = "true") protected Boolean diagnosticsRepeatedStatements = true; @XmlElement(defaultValue = "true") + protected Boolean diagnosticsConsecutiveAggregation = true; + @XmlElement(defaultValue = "true") protected Boolean diagnosticsTooManyColumnsFetched = true; @XmlElement(defaultValue = "true") protected Boolean diagnosticsTooManyRowsFetched = true; @@ -1362,6 +1364,35 @@ public class Settings this.diagnosticsRepeatedStatements = value; } + /** + * Whether to run the {@link org.jooq.DiagnosticsListener#consecutiveAggregation(org.jooq.DiagnosticsContext) diagnostic. + *

+ * Diagnostics are turned off if no {@link org.jooq.Configuration#diagnosticsListenerProviders()} are configured. + * Once configured, this diagnostic is turned on by default. + *

+ * This feature is available in the commercial distribution only. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isDiagnosticsConsecutiveAggregation() { + return diagnosticsConsecutiveAggregation; + } + + /** + * Sets the value of the diagnosticsConsecutiveAggregation property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setDiagnosticsConsecutiveAggregation(Boolean value) { + this.diagnosticsConsecutiveAggregation = value; + } + /** * Whether to run the {@link org.jooq.DiagnosticsListener#tooManyColumnsFetched(org.jooq.DiagnosticsContext) diagnostic. *

@@ -4869,6 +4900,11 @@ public class Settings return this; } + public Settings withDiagnosticsConsecutiveAggregation(Boolean value) { + setDiagnosticsConsecutiveAggregation(value); + return this; + } + public Settings withDiagnosticsTooManyColumnsFetched(Boolean value) { setDiagnosticsTooManyColumnsFetched(value); return this; @@ -5927,6 +5963,7 @@ public class Settings builder.append("diagnosticsDuplicateStatementsUsingTransformPatterns", diagnosticsDuplicateStatementsUsingTransformPatterns); builder.append("diagnosticsMissingWasNullCall", diagnosticsMissingWasNullCall); builder.append("diagnosticsRepeatedStatements", diagnosticsRepeatedStatements); + builder.append("diagnosticsConsecutiveAggregation", diagnosticsConsecutiveAggregation); builder.append("diagnosticsTooManyColumnsFetched", diagnosticsTooManyColumnsFetched); builder.append("diagnosticsTooManyRowsFetched", diagnosticsTooManyRowsFetched); builder.append("diagnosticsUnnecessaryWasNullCall", diagnosticsUnnecessaryWasNullCall); @@ -6418,6 +6455,15 @@ public class Settings return false; } } + if (diagnosticsConsecutiveAggregation == null) { + if (other.diagnosticsConsecutiveAggregation!= null) { + return false; + } + } else { + if (!diagnosticsConsecutiveAggregation.equals(other.diagnosticsConsecutiveAggregation)) { + return false; + } + } if (diagnosticsTooManyColumnsFetched == null) { if (other.diagnosticsTooManyColumnsFetched!= null) { return false; @@ -7695,6 +7741,7 @@ public class Settings result = ((prime*result)+((diagnosticsDuplicateStatementsUsingTransformPatterns == null)? 0 :diagnosticsDuplicateStatementsUsingTransformPatterns.hashCode())); result = ((prime*result)+((diagnosticsMissingWasNullCall == null)? 0 :diagnosticsMissingWasNullCall.hashCode())); result = ((prime*result)+((diagnosticsRepeatedStatements == null)? 0 :diagnosticsRepeatedStatements.hashCode())); + result = ((prime*result)+((diagnosticsConsecutiveAggregation == null)? 0 :diagnosticsConsecutiveAggregation.hashCode())); result = ((prime*result)+((diagnosticsTooManyColumnsFetched == null)? 0 :diagnosticsTooManyColumnsFetched.hashCode())); result = ((prime*result)+((diagnosticsTooManyRowsFetched == null)? 0 :diagnosticsTooManyRowsFetched.hashCode())); result = ((prime*result)+((diagnosticsUnnecessaryWasNullCall == null)? 0 :diagnosticsUnnecessaryWasNullCall.hashCode())); diff --git a/jOOQ/src/main/java/org/jooq/impl/DiagnosticsConnection.java b/jOOQ/src/main/java/org/jooq/impl/DiagnosticsConnection.java index 0a006fd6a4..6eb8d7f037 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DiagnosticsConnection.java +++ b/jOOQ/src/main/java/org/jooq/impl/DiagnosticsConnection.java @@ -38,15 +38,20 @@ package org.jooq.impl; import static java.lang.Boolean.FALSE; +import static java.util.Arrays.asList; import static java.util.Collections.synchronizedMap; // ... +// ... import static org.jooq.conf.ParamType.FORCE_INDEXED; +import static org.jooq.impl.DSL.count; +import static org.jooq.impl.DSL.noCondition; import java.sql.CallableStatement; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -55,14 +60,17 @@ import java.util.Map.Entry; import java.util.Set; import java.util.function.Predicate; +import org.jooq.AggregateFunction; import org.jooq.Condition; import org.jooq.Configuration; import org.jooq.Parser; // ... import org.jooq.Queries; +import org.jooq.Query; import org.jooq.QueryPart; import org.jooq.RenderContext; // ... +import org.jooq.Select; import org.jooq.conf.Settings; import org.jooq.impl.QOM.Eq; import org.jooq.tools.jdbc.DefaultConnection; @@ -73,15 +81,16 @@ import org.jooq.tools.jdbc.DefaultConnection; final class DiagnosticsConnection extends DefaultConnection { // TODO: Make these configurable - static final int LRU_SIZE_GLOBAL = 50000; - static final int LRU_SIZE_LOCAL = 500; - static final int DUP_SIZE = 500; + static final int LRU_SIZE_GLOBAL = 50000; + static final int LRU_SIZE_LOCAL = 500; + static final int DUP_SIZE = 500; - final Map> repeatedSQL = new LRU<>(LRU_SIZE_LOCAL); - final Configuration configuration; - final RenderContext normalisingRenderer; - final Parser parser; - final DiagnosticsListeners listeners; + final Map> repeatedSQL = new LRU<>(LRU_SIZE_LOCAL); + final Map> consecutiveAgg = new LRU<>(LRU_SIZE_LOCAL); + final Configuration configuration; + final RenderContext normalisingRenderer; + final Parser parser; + final DiagnosticsListeners listeners; DiagnosticsConnection(Configuration configuration) { super(configuration.connectionProvider().acquire()); @@ -223,6 +232,7 @@ final class DiagnosticsConnection extends DefaultConnection { )); } + if (queries != null) { @@ -248,6 +258,22 @@ final class DiagnosticsConnection extends DefaultConnection { + + + + + + + + + + + + + + + + } } catch (Error e) { throw e; diff --git a/jOOQ/src/main/java/org/jooq/impl/DiagnosticsListeners.java b/jOOQ/src/main/java/org/jooq/impl/DiagnosticsListeners.java index 648f5ea96c..f9ff5dc682 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DiagnosticsListeners.java +++ b/jOOQ/src/main/java/org/jooq/impl/DiagnosticsListeners.java @@ -121,6 +121,13 @@ final class DiagnosticsListeners implements DiagnosticsListener { + + + + + + + diff --git a/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.18.0.xsd b/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.18.0.xsd index 32a92cb2e7..289a5d7046 100644 --- a/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.18.0.xsd +++ b/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.18.0.xsd @@ -313,6 +313,15 @@ Diagnostics are turned off if no {@link org.jooq.Configuration#diagnosticsListen Once configured, this diagnostic is turned on by default.]]> + + +Diagnostics are turned off if no {@link org.jooq.Configuration#diagnosticsListenerProviders()} are configured. +Once configured, this diagnostic is turned on by default. +

+This feature is available in the commercial distribution only.]]> + +