From 8f791a3e9e36fac4345ebb75ba1d9fe51b4b1b55 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Thu, 7 Sep 2006 01:12:04 +0000 Subject: Initial tests and fixes for union query analysis. --- src/main/java/com/amazon/carbonado/filter/AndFilter.java | 7 +++++++ src/main/java/com/amazon/carbonado/filter/BinaryOpFilter.java | 3 +++ src/main/java/com/amazon/carbonado/filter/ClosedFilter.java | 4 ++++ src/main/java/com/amazon/carbonado/filter/Filter.java | 9 +++++++++ src/main/java/com/amazon/carbonado/filter/OpenFilter.java | 4 ++++ src/main/java/com/amazon/carbonado/filter/OrFilter.java | 7 +++++++ src/main/java/com/amazon/carbonado/filter/PropertyFilter.java | 8 +++++--- .../java/com/amazon/carbonado/qe/IndexedQueryAnalyzer.java | 10 ++++++++++ src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java | 10 +++++++--- 9 files changed, 56 insertions(+), 6 deletions(-) (limited to 'src/main/java/com/amazon') diff --git a/src/main/java/com/amazon/carbonado/filter/AndFilter.java b/src/main/java/com/amazon/carbonado/filter/AndFilter.java index 92c3937..a5aa61e 100644 --- a/src/main/java/com/amazon/carbonado/filter/AndFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/AndFilter.java @@ -53,6 +53,13 @@ public class AndFilter extends BinaryOpFilter { return visitor.visit(this, param); } + public Filter unbind() { + if (!isBound()) { + return this; + } + return mLeft.unbind().and(mRight.unbind()); + } + Filter buildDisjunctiveNormalForm() { Filter left = mLeft.reduce().dnf(); Filter right = mRight.reduce().dnf(); diff --git a/src/main/java/com/amazon/carbonado/filter/BinaryOpFilter.java b/src/main/java/com/amazon/carbonado/filter/BinaryOpFilter.java index c95f493..462acf4 100644 --- a/src/main/java/com/amazon/carbonado/filter/BinaryOpFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/BinaryOpFilter.java @@ -49,6 +49,9 @@ public abstract class BinaryOpFilter extends Filter { } mLeft = left; mRight = right; + if (left.isBound() && right.isBound()) { + markBound(); + } } public Filter getLeftFilter() { diff --git a/src/main/java/com/amazon/carbonado/filter/ClosedFilter.java b/src/main/java/com/amazon/carbonado/filter/ClosedFilter.java index 4584109..7895a3d 100644 --- a/src/main/java/com/amazon/carbonado/filter/ClosedFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/ClosedFilter.java @@ -66,6 +66,10 @@ public class ClosedFilter extends Filter { return true; } + public Filter unbind() { + return this; + } + void markBound() { } diff --git a/src/main/java/com/amazon/carbonado/filter/Filter.java b/src/main/java/com/amazon/carbonado/filter/Filter.java index 9d55a99..338b768 100644 --- a/src/main/java/com/amazon/carbonado/filter/Filter.java +++ b/src/main/java/com/amazon/carbonado/filter/Filter.java @@ -415,6 +415,15 @@ public abstract class Filter implements Appender { */ public abstract Filter bind(); + /** + * Undoes the effect of a bind operation. The returned filter might still + * report itself as bound if it doesn't make a distinction between these + * states. + * + * @return canonical Filter instance with unbound property filters + */ + public abstract Filter unbind(); + /** * Returns true if all property filters are known to be properly * bound. This is a side effect of calling {@link #bind}, {@link diff --git a/src/main/java/com/amazon/carbonado/filter/OpenFilter.java b/src/main/java/com/amazon/carbonado/filter/OpenFilter.java index 407aed0..6f6e211 100644 --- a/src/main/java/com/amazon/carbonado/filter/OpenFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/OpenFilter.java @@ -62,6 +62,10 @@ public class OpenFilter extends Filter { return this; } + public Filter unbind() { + return this; + } + public boolean isBound() { return true; } diff --git a/src/main/java/com/amazon/carbonado/filter/OrFilter.java b/src/main/java/com/amazon/carbonado/filter/OrFilter.java index 027ea21..1e7bf72 100644 --- a/src/main/java/com/amazon/carbonado/filter/OrFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/OrFilter.java @@ -53,6 +53,13 @@ public class OrFilter extends BinaryOpFilter { return visitor.visit(this, param); } + public Filter unbind() { + if (!isBound()) { + return this; + } + return mLeft.unbind().or(mRight.unbind()); + } + Filter buildDisjunctiveNormalForm() { return mLeft.dnf().or(mRight.dnf()).reduce(); } diff --git a/src/main/java/com/amazon/carbonado/filter/PropertyFilter.java b/src/main/java/com/amazon/carbonado/filter/PropertyFilter.java index 8fe03d6..824d1d1 100644 --- a/src/main/java/com/amazon/carbonado/filter/PropertyFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/PropertyFilter.java @@ -160,6 +160,10 @@ public class PropertyFilter extends Filter { return mBindID == 0 ? getCanonical(this, 1) : this; } + public Filter unbind() { + return mBindID == 0 ? this : getCanonical(this, 0); + } + public boolean isBound() { return mBindID != 0; } @@ -428,11 +432,9 @@ public class PropertyFilter extends Filter { app.append(String.valueOf(mConstant)); } else { app.append('?'); - /* Uncomment for testing - if (mBindID != 0) { + if (mBindID > 1) { app.append('[').append(String.valueOf(mBindID)).append(']'); } - */ } } diff --git a/src/main/java/com/amazon/carbonado/qe/IndexedQueryAnalyzer.java b/src/main/java/com/amazon/carbonado/qe/IndexedQueryAnalyzer.java index 76fb5f5..d0bd63f 100644 --- a/src/main/java/com/amazon/carbonado/qe/IndexedQueryAnalyzer.java +++ b/src/main/java/com/amazon/carbonado/qe/IndexedQueryAnalyzer.java @@ -431,6 +431,16 @@ public class IndexedQueryAnalyzer { return new Result(this, filter, getRemainderOrderings()); } + public String toString() { + return "IndexedQueryAnalyzer.Result {score=" + + getCompositeScore() + ", localIndex=" + + getLocalIndex() + ", foreignIndex=" + + getForeignIndex() + ", foreignProperty=" + + getForeignProperty() + ", remainderFilter=" + + getRemainderFilter() + ", remainderOrderings=" + + getRemainderOrderings() + '}'; + } + private boolean equals(Object a, Object b) { return a == null ? (b == null) : (a.equals(b)); } diff --git a/src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java b/src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java index 9ed94fd..5648d21 100644 --- a/src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java +++ b/src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java @@ -77,9 +77,13 @@ public class UnionQueryAnalyzer { throw new IllegalArgumentException("Filter must be bound"); } + if (orderings == null) { + orderings = Collections.emptyList(); + } + List.Result> subResults = splitIntoSubResults(filter, orderings); - if (subResults.size() < 1) { + if (subResults.size() <= 1) { // Total ordering not required. return new Result(subResults); } @@ -112,7 +116,7 @@ public class UnionQueryAnalyzer { // since one simple change might alter the query plan. subResults = splitIntoSubResults(filter, orderings); - if (subResults.size() < 1) { + if (subResults.size() <= 1) { // Total ordering no longer required. return new Result(subResults); } @@ -183,7 +187,7 @@ public class UnionQueryAnalyzer { orderings.add(OrderedProperty.get(bestProperty, best.getBestDirection())); subResults = splitIntoSubResults(filter, orderings); - if (subResults.size() < 1) { + if (subResults.size() <= 1) { // Total ordering no longer required. break; } -- cgit v1.2.3