use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class DiffCollectorTest method testDeepChange.
@Test
public void testDeepChange() throws Exception {
NodeState root = EMPTY_NODE;
NodeBuilder builder = root.builder();
NodeBuilder b1 = builder.child("rep:security").child("rep:authorizables");
b1.child("rep:groups").child("t").child("te").child("testGroup_1c22a39f");
NodeBuilder b2 = b1.child("rep:users");
b2.child("t").child("te").child("testUser_008e00d9");
NodeBuilder b3 = b2.child("a");
b3.child("an").child("anonymous");
b3.child("ad").child("admin");
NodeState before = builder.getNodeState();
builder = before.builder();
NodeBuilder a1 = builder.child("rep:security").child("rep:authorizables").child("rep:groups").child("t").child("te");
a1.child("testGroup_1c22a39f").setProperty("jcr:uuid", "c6195630-e956-3d4b-8912-479c303bf15a");
a1.child("testPrincipal_4e6b704e").setProperty("jcr:uuid", "ee59b554-76b7-3e27-9fc6-15bda1388894");
NodeState after = builder.getNodeState();
UUIDDiffCollector collector = new UUIDDiffCollector(before, after);
FilterImpl f = FilterImpl.newTestInstance();
f.restrictProperty("jcr:uuid", Operator.EQUAL, PropertyValues.newString("ee59b554-76b7-3e27-9fc6-15bda1388894"));
Set<String> result = collector.getResults(f);
Iterator<String> iterator = result.iterator();
assertTrue(iterator.hasNext());
assertEquals("rep:security/rep:authorizables/rep:groups/t/te/testPrincipal_4e6b704e", iterator.next());
assertFalse(iterator.hasNext());
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class PropertyIndexTest method testCustomConfigNodeType.
/**
* @see <a href="https://issues.apache.org/jira/browse/OAK-666">OAK-666:
* Property2Index: node type is used when indexing, but ignored when
* querying</a>
*/
@Test
public void testCustomConfigNodeType() throws Exception {
NodeState root = INITIAL_CONTENT;
// Add index definitions
NodeBuilder builder = root.builder();
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
createIndexDefinition(index, "fooIndex", true, false, ImmutableSet.of("foo", "extrafoo"), ImmutableSet.of(NT_UNSTRUCTURED));
createIndexDefinition(index, "fooIndexFile", true, false, ImmutableSet.of("foo"), ImmutableSet.of(NT_FILE));
NodeState before = builder.getNodeState();
// Add some content and process it through the property index hook
builder.child("a").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "abc");
builder.child("b").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", Arrays.asList("abc", "def"), Type.STRINGS);
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
FilterImpl f = createFilter(indexed, NT_UNSTRUCTURED);
// Query the index
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
assertEquals(ImmutableSet.of("a", "b"), find(lookup, "foo", "abc", f));
assertEquals(ImmutableSet.of("b"), find(lookup, "foo", "def", f));
assertEquals(ImmutableSet.of(), find(lookup, "foo", "ghi", f));
try {
assertEquals(ImmutableSet.of(), find(lookup, "pqr", "foo", f));
fail();
} catch (IllegalArgumentException e) {
// expected: no index for "pqr"
}
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class PropertyIndexTest method pathBasedCostEstimation.
/**
* This is essentially same test as {@link #costEstimation()} with one difference that it uses
* path constraint in query and creates similar trees under 2 branches {@code path1} and {@code path2}.
* The cost estimation is then verified to be same as that in {@code costEstimation} for query under {@code path1}
* @throws Exception
*/
@Test
public void pathBasedCostEstimation() throws Exception {
NodeState root = INITIAL_CONTENT;
// Add index definition
NodeBuilder builder = root.builder();
NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("foo"), null);
// disable the estimation
index.setProperty("entryCount", -1);
builder.setProperty(COUNT_PROPERTY_NAME, (long) MANY * 2, Type.LONG);
NodeState before = builder.getNodeState();
NodeBuilder path1 = builder.child("path1");
NodeBuilder path2 = builder.child("path2");
// Add some content and process it through the property index hook
for (int i = 0; i < MANY; i++) {
path1.child("n" + i).setProperty("foo", "x" + i % 20);
path2.child("n" + i).setProperty("foo", "x" + i % 20);
}
path1.setProperty(COUNT_PROPERTY_NAME, (long) MANY, Type.LONG);
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
FilterImpl f = createFilter(indexed, NT_BASE);
f.restrictPath("/path1", Filter.PathRestriction.ALL_CHILDREN);
// Query the index
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
double cost;
cost = lookup.getCost(f, "foo", PropertyValues.newString("x1"));
assertTrue("cost: " + cost, cost >= 10 && cost <= 14);
cost = lookup.getCost(f, "foo", PropertyValues.newString(Arrays.asList("x1", "x2")));
assertTrue("cost: " + cost, cost >= 20 && cost <= 24);
cost = lookup.getCost(f, "foo", PropertyValues.newString(Arrays.asList("x1", "x2", "x3", "x4", "x5")));
assertTrue("cost: " + cost, cost >= 50 && cost <= 54);
cost = lookup.getCost(f, "foo", PropertyValues.newString(Arrays.asList("x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x0")));
assertTrue("cost: " + cost, cost >= 120 && cost <= 124);
cost = lookup.getCost(f, "foo", null);
assertTrue("cost: " + cost, cost >= MANY);
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class PropertyIndexTest method testCustomConfigPropertyLookup.
@Test
public void testCustomConfigPropertyLookup() throws Exception {
NodeState root = INITIAL_CONTENT;
// Add index definition
NodeBuilder builder = root.builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, false, ImmutableSet.of("foo", "extrafoo"), null);
NodeState before = builder.getNodeState();
// Add some content and process it through the property index hook
builder.child("a").setProperty("foo", "abc").setProperty("extrafoo", "pqr");
builder.child("b").setProperty("foo", Arrays.asList("abc", "def"), Type.STRINGS);
// plus lots of dummy content to highlight the benefit of indexing
for (int i = 0; i < MANY; i++) {
builder.child("n" + i).setProperty("foo", "xyz");
}
NodeState after = builder.getNodeState();
// Add an index
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
FilterImpl f = createFilter(indexed, NT_BASE);
// Query the index
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
assertEquals(ImmutableSet.of("a", "b"), find(lookup, "foo", "abc", f));
assertEquals(ImmutableSet.of("b"), find(lookup, "foo", "def", f));
assertEquals(ImmutableSet.of(), find(lookup, "foo", "ghi", f));
assertEquals(MANY, find(lookup, "foo", "xyz", f).size());
assertEquals(ImmutableSet.of("a"), find(lookup, "extrafoo", "pqr", f));
try {
assertEquals(ImmutableSet.of(), find(lookup, "pqr", "foo", f));
fail();
} catch (IllegalArgumentException e) {
// expected: no index for "pqr"
}
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class PropertyIndexTest method testPathExclude.
@Test
public void testPathExclude() throws Exception {
NodeState root = INITIAL_CONTENT;
// Add index definition
NodeBuilder builder = root.builder();
NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("foo"), null);
index.setProperty(createProperty(PROP_EXCLUDED_PATHS, of("/test/a"), Type.STRINGS));
NodeState before = builder.getNodeState();
// Add some content and process it through the property index hook
builder.child("test").child("a").setProperty("foo", "abc");
builder.child("test").child("b").setProperty("foo", "abc");
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
FilterImpl f = createFilter(indexed, NT_BASE);
f.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("abc"));
// Query the index
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
assertEquals(ImmutableSet.of("test/b"), find(lookup, "foo", "abc", f));
//no path restriction, opt out
PropertyIndexPlan plan = new PropertyIndexPlan("plan", root, index.getNodeState(), f);
assertTrue(Double.POSITIVE_INFINITY == plan.getCost());
//path restriction is not an ancestor of excluded path, index may be used
f.setPath("/test2");
plan = new PropertyIndexPlan("plan", root, index.getNodeState(), f);
assertTrue(Double.POSITIVE_INFINITY != plan.getCost());
//path restriction is an ancestor of excluded path, opt out
f.setPath("/test");
plan = new PropertyIndexPlan("plan", root, index.getNodeState(), f);
assertTrue(Double.POSITIVE_INFINITY == plan.getCost());
}
Aggregations