From 5a818e4f61e7c015fd669c96fc199fce238c6bb4 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Tue, 18 Jan 2022 17:26:04 +0100 Subject: [PATCH] [jOOQ/jOOQ#7284] Implement a few new patterns: - transformPatternsNormaliseAssociativeOps (WIP) - transformPatternsNormaliseFieldCompareValue - transformPatternsOrEqToIn (WIP) --- .../src/main/java/org/jooq/conf/Settings.java | 145 ++++++++++++++++++ .../java/org/jooq/impl/TransformPatterns.java | 88 +++++++++++ .../org/jooq/xsd/jooq-runtime-3.17.0.xsd | 31 ++++ 3 files changed, 264 insertions(+) diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java index 700d08efd4..4d9cf9cf13 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -122,6 +122,12 @@ public class Settings @XmlElement(defaultValue = "true") protected Boolean transformPatternsNotNotDistinct = true; @XmlElement(defaultValue = "true") + protected Boolean transformPatternsNormaliseAssociativeOps = true; + @XmlElement(defaultValue = "true") + protected Boolean transformPatternsNormaliseFieldCompareValue = true; + @XmlElement(defaultValue = "true") + protected Boolean transformPatternsOrEqToIn = true; + @XmlElement(defaultValue = "true") protected Boolean transformPatternsTrivialPredicates = true; @XmlElement(defaultValue = "true") protected Boolean transformPatternsEmptyScalarSubquery = true; @@ -1280,6 +1286,97 @@ public class Settings this.transformPatternsNotNotDistinct = value; } + /** + * Transform (a + b) + (c + d) to ((a + b) + c) + d. + *

+ * This transformation turns trees into lists, which greatly simplifies other tree traversal transformations. + * Some of those other transformations currently rely on this flag to be active. + *

+ * To enable this feature, {@link #transformPatterns} must be enabled as well. + *

+ * This feature is available in the commercial distribution only. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isTransformPatternsNormaliseAssociativeOps() { + return transformPatternsNormaliseAssociativeOps; + } + + /** + * Sets the value of the transformPatternsNormaliseAssociativeOps property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setTransformPatternsNormaliseAssociativeOps(Boolean value) { + this.transformPatternsNormaliseAssociativeOps = value; + } + + /** + * Transform 1 = a to a = 1. + *

+ * This transformation inverses {@link TableField} [op] {@link org.jooq.impl.QOM.Val} comparisons, if they're not in that order. + *

+ * To enable this feature, {@link #transformPatterns} must be enabled as well. + *

+ * This feature is available in the commercial distribution only. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isTransformPatternsNormaliseFieldCompareValue() { + return transformPatternsNormaliseFieldCompareValue; + } + + /** + * Sets the value of the transformPatternsNormaliseFieldCompareValue property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setTransformPatternsNormaliseFieldCompareValue(Boolean value) { + this.transformPatternsNormaliseFieldCompareValue = value; + } + + /** + * Transform x = c1 OR x = c2 to x IN (c1, c2). + *

+ * This transformation simplifies verbose OR predicates into simpler IN predicates. + *

+ * To enable this feature, {@link #transformPatterns} must be enabled as well. + *

+ * This feature is available in the commercial distribution only. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isTransformPatternsOrEqToIn() { + return transformPatternsOrEqToIn; + } + + /** + * Sets the value of the transformPatternsOrEqToIn property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setTransformPatternsOrEqToIn(Boolean value) { + this.transformPatternsOrEqToIn = value; + } + /** * Transform trivial predicates like 1 = 1 to TRUE. *

@@ -3697,6 +3794,21 @@ public class Settings return this; } + public Settings withTransformPatternsNormaliseAssociativeOps(Boolean value) { + setTransformPatternsNormaliseAssociativeOps(value); + return this; + } + + public Settings withTransformPatternsNormaliseFieldCompareValue(Boolean value) { + setTransformPatternsNormaliseFieldCompareValue(value); + return this; + } + + public Settings withTransformPatternsOrEqToIn(Boolean value) { + setTransformPatternsOrEqToIn(value); + return this; + } + public Settings withTransformPatternsTrivialPredicates(Boolean value) { setTransformPatternsTrivialPredicates(value); return this; @@ -4550,6 +4662,9 @@ public class Settings builder.append("transformPatternsNotNot", transformPatternsNotNot); builder.append("transformPatternsNotComparison", transformPatternsNotComparison); builder.append("transformPatternsNotNotDistinct", transformPatternsNotNotDistinct); + builder.append("transformPatternsNormaliseAssociativeOps", transformPatternsNormaliseAssociativeOps); + builder.append("transformPatternsNormaliseFieldCompareValue", transformPatternsNormaliseFieldCompareValue); + builder.append("transformPatternsOrEqToIn", transformPatternsOrEqToIn); builder.append("transformPatternsTrivialPredicates", transformPatternsTrivialPredicates); builder.append("transformPatternsEmptyScalarSubquery", transformPatternsEmptyScalarSubquery); builder.append("transformPatternsNegNeg", transformPatternsNegNeg); @@ -4995,6 +5110,33 @@ public class Settings return false; } } + if (transformPatternsNormaliseAssociativeOps == null) { + if (other.transformPatternsNormaliseAssociativeOps!= null) { + return false; + } + } else { + if (!transformPatternsNormaliseAssociativeOps.equals(other.transformPatternsNormaliseAssociativeOps)) { + return false; + } + } + if (transformPatternsNormaliseFieldCompareValue == null) { + if (other.transformPatternsNormaliseFieldCompareValue!= null) { + return false; + } + } else { + if (!transformPatternsNormaliseFieldCompareValue.equals(other.transformPatternsNormaliseFieldCompareValue)) { + return false; + } + } + if (transformPatternsOrEqToIn == null) { + if (other.transformPatternsOrEqToIn!= null) { + return false; + } + } else { + if (!transformPatternsOrEqToIn.equals(other.transformPatternsOrEqToIn)) { + return false; + } + } if (transformPatternsTrivialPredicates == null) { if (other.transformPatternsTrivialPredicates!= null) { return false; @@ -5938,6 +6080,9 @@ public class Settings result = ((prime*result)+((transformPatternsNotNot == null)? 0 :transformPatternsNotNot.hashCode())); result = ((prime*result)+((transformPatternsNotComparison == null)? 0 :transformPatternsNotComparison.hashCode())); result = ((prime*result)+((transformPatternsNotNotDistinct == null)? 0 :transformPatternsNotNotDistinct.hashCode())); + result = ((prime*result)+((transformPatternsNormaliseAssociativeOps == null)? 0 :transformPatternsNormaliseAssociativeOps.hashCode())); + result = ((prime*result)+((transformPatternsNormaliseFieldCompareValue == null)? 0 :transformPatternsNormaliseFieldCompareValue.hashCode())); + result = ((prime*result)+((transformPatternsOrEqToIn == null)? 0 :transformPatternsOrEqToIn.hashCode())); result = ((prime*result)+((transformPatternsTrivialPredicates == null)? 0 :transformPatternsTrivialPredicates.hashCode())); result = ((prime*result)+((transformPatternsEmptyScalarSubquery == null)? 0 :transformPatternsEmptyScalarSubquery.hashCode())); result = ((prime*result)+((transformPatternsNegNeg == null)? 0 :transformPatternsNegNeg.hashCode())); diff --git a/jOOQ/src/main/java/org/jooq/impl/TransformPatterns.java b/jOOQ/src/main/java/org/jooq/impl/TransformPatterns.java index 8b1f935596..b456b4eacd 100644 --- a/jOOQ/src/main/java/org/jooq/impl/TransformPatterns.java +++ b/jOOQ/src/main/java/org/jooq/impl/TransformPatterns.java @@ -453,6 +453,94 @@ package org.jooq.impl; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.17.0.xsd b/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.17.0.xsd index edea9baca5..6ac4f021e0 100644 --- a/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.17.0.xsd +++ b/jOOQ/src/main/resources/org/jooq/xsd/jooq-runtime-3.17.0.xsd @@ -322,6 +322,37 @@ To enable this feature, {@link #transformPatterns} must be enabled as well. This feature is available in the commercial distribution only.]]> + + (a + b) + (c + d) to ((a + b) + c) + d. +

+This transformation turns trees into lists, which greatly simplifies other tree traversal transformations. +Some of those other transformations currently rely on this flag to be active. +

+To enable this feature, {@link #transformPatterns} must be enabled as well. +

+This feature is available in the commercial distribution only.]]> + + + + 1 = a to a = 1. +

+This transformation inverses {@link TableField} [op] {@link org.jooq.impl.QOM.Val} comparisons, if they're not in that order. +

+To enable this feature, {@link #transformPatterns} must be enabled as well. +

+This feature is available in the commercial distribution only.]]> + + + + x = c1 OR x = c2 to x IN (c1, c2). +

+This transformation simplifies verbose OR predicates into simpler IN predicates. +

+To enable this feature, {@link #transformPatterns} must be enabled as well. +

+This feature is available in the commercial distribution only.]]> + + 1 = 1 to TRUE.