diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2006-09-07 01:12:04 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2006-09-07 01:12:04 +0000 |
commit | 8f791a3e9e36fac4345ebb75ba1d9fe51b4b1b55 (patch) | |
tree | 71895833e72e2f17240743e7b6fde0b3b25f6c57 /src/main/java/com/amazon | |
parent | 9c29c1190a6e70e5a1c200ca1ed1f403b7c56ead (diff) |
Initial tests and fixes for union query analysis.
Diffstat (limited to 'src/main/java/com/amazon')
9 files changed, 56 insertions, 6 deletions
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<S extends Storable> extends BinaryOpFilter<S> { return visitor.visit(this, param);
}
+ public Filter<S> unbind() {
+ if (!isBound()) {
+ return this;
+ }
+ return mLeft.unbind().and(mRight.unbind());
+ }
+
Filter<S> buildDisjunctiveNormalForm() {
Filter<S> left = mLeft.reduce().dnf();
Filter<S> 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<S extends Storable> extends Filter<S> { }
mLeft = left;
mRight = right;
+ if (left.isBound() && right.isBound()) {
+ markBound();
+ }
}
public Filter<S> 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<S extends Storable> extends Filter<S> { return true;
}
+ public Filter<S> 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 @@ -416,6 +416,15 @@ public abstract class Filter<S extends Storable> implements Appender { public abstract Filter<S> 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<S> unbind();
+
+ /**
* Returns true if all property filters are known to be properly
* bound. This is a side effect of calling {@link #bind}, {@link
* #initialFilterValues}, {@link #disjunctiveNormalForm} or {@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<S extends Storable> extends Filter<S> { return this;
}
+ public Filter<S> 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<S extends Storable> extends BinaryOpFilter<S> { return visitor.visit(this, param);
}
+ public Filter<S> unbind() {
+ if (!isBound()) {
+ return this;
+ }
+ return mLeft.unbind().or(mRight.unbind());
+ }
+
Filter<S> 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<S extends Storable> extends Filter<S> { return mBindID == 0 ? getCanonical(this, 1) : this;
}
+ public Filter<S> unbind() {
+ return mBindID == 0 ? this : getCanonical(this, 0);
+ }
+
public boolean isBound() {
return mBindID != 0;
}
@@ -428,11 +432,9 @@ public class PropertyFilter<S extends Storable> extends Filter<S> { 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<S extends Storable> { 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<S extends Storable> { throw new IllegalArgumentException("Filter must be bound");
}
+ if (orderings == null) {
+ orderings = Collections.emptyList();
+ }
+
List<IndexedQueryAnalyzer<S>.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<S extends Storable> { // 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<S extends Storable> { 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;
}
|