Search in sources :

Example 1 with IndexPlan

use of org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan in project jackrabbit-oak by apache.

the class AdvancedIndexTest method builder.

@Test
public void builder() {
    IndexPlan.Builder b = new IndexPlan.Builder();
    IndexPlan plan = b.setEstimatedEntryCount(10).build();
    assertEquals(10, plan.getEstimatedEntryCount());
    b.setEstimatedEntryCount(20);
    assertEquals(10, plan.getEstimatedEntryCount());
}
Also used : IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) Test(org.junit.Test)

Example 2 with IndexPlan

use of org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan in project jackrabbit-oak by apache.

the class AdvancedIndexTest method attribute.

@Test
public void attribute() throws Exception {
    IndexPlan plan = new IndexPlan.Builder().setAttribute("foo", "bar").build();
    assertEquals("bar", plan.getAttribute("foo"));
}
Also used : IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) Test(org.junit.Test)

Example 3 with IndexPlan

use of org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan in project jackrabbit-oak by apache.

the class AdvancedIndexTest method copy.

@Test
public void copy() throws Exception {
    Filter f = new FilterImpl(null, "SELECT * FROM [nt:file]", new QueryEngineSettings());
    IndexPlan.Builder b = new IndexPlan.Builder();
    IndexPlan plan1 = b.setEstimatedEntryCount(10).setFilter(f).setDelayed(true).build();
    IndexPlan plan2 = plan1.copy();
    plan2.setFilter(new FilterImpl(null, "SELECT * FROM [oak:Unstructured]", new QueryEngineSettings()));
    assertEquals(plan1.getEstimatedEntryCount(), 10);
    assertEquals(plan2.getEstimatedEntryCount(), 10);
    assertTrue(plan1.isDelayed());
    assertTrue(plan2.isDelayed());
    assertEquals(plan1.getFilter().getQueryStatement(), "SELECT * FROM [nt:file]");
    assertEquals(plan2.getFilter().getQueryStatement(), "SELECT * FROM [oak:Unstructured]");
}
Also used : Filter(org.apache.jackrabbit.oak.spi.query.Filter) IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) Test(org.junit.Test)

Example 4 with IndexPlan

use of org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan in project jackrabbit-oak by apache.

the class AggregateIndexPlan method getPlanName.

@Override
public String getPlanName() {
    StringBuilder name = new StringBuilder();
    boolean first = true;
    for (IndexPlan p : basePlans.values()) {
        if (!first) {
            name.append(",");
        } else {
            first = false;
        }
        name.append(p.getPlanName());
    }
    return name.toString();
}
Also used : IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan)

Example 5 with IndexPlan

use of org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan in project jackrabbit-oak by apache.

the class QueryImpl method canSortByIndex.

private boolean canSortByIndex() {
    boolean canSortByIndex = false;
    // TODO add issue about order by optimization for multiple selectors
    if (orderings != null && selectors.size() == 1) {
        IndexPlan plan = selectors.get(0).getExecutionPlan().getIndexPlan();
        if (plan != null) {
            List<OrderEntry> list = plan.getSortOrder();
            if (list != null && list.size() == orderings.length) {
                canSortByIndex = true;
                for (int i = 0; i < list.size(); i++) {
                    OrderEntry e = list.get(i);
                    OrderingImpl o = orderings[i];
                    DynamicOperandImpl op = o.getOperand();
                    if (!(op instanceof PropertyValueImpl)) {
                        // ordered by a function: currently not supported
                        canSortByIndex = false;
                        break;
                    }
                    // we only have one selector, so no need to check that
                    // TODO support joins
                    String pn = ((PropertyValueImpl) op).getPropertyName();
                    if (!pn.equals(e.getPropertyName())) {
                        // ordered by another property
                        canSortByIndex = false;
                        break;
                    }
                    if (o.isDescending() != (e.getOrder() == Order.DESCENDING)) {
                        // ordered ascending versus descending
                        canSortByIndex = false;
                        break;
                    }
                }
            }
        }
    }
    return canSortByIndex;
}
Also used : DynamicOperandImpl(org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl) OrderEntry(org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry) IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) OrderingImpl(org.apache.jackrabbit.oak.query.ast.OrderingImpl) PropertyValueImpl(org.apache.jackrabbit.oak.query.ast.PropertyValueImpl)

Aggregations

IndexPlan (org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan)20 AdvancedQueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex)12 Test (org.junit.Test)10 Cursor (org.apache.jackrabbit.oak.spi.query.Cursor)9 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)8 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)7 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)7 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)5 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 ArrayList (java.util.ArrayList)2 OrderEntry (org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry)2 Function (com.google.common.base.Function)1 Blob (org.apache.jackrabbit.oak.api.Blob)1 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)1 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)1 ArrayBasedBlob (org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob)1 QueryEngineSettings (org.apache.jackrabbit.oak.query.QueryEngineSettings)1 DynamicOperandImpl (org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl)1 OrderingImpl (org.apache.jackrabbit.oak.query.ast.OrderingImpl)1 PropertyValueImpl (org.apache.jackrabbit.oak.query.ast.PropertyValueImpl)1