Search in sources :

Example 31 with SelectorImpl

use of org.apache.jackrabbit.oak.query.ast.SelectorImpl in project jackrabbit-oak by apache.

the class AsyncPropertyIndexTest method createFilter.

private static FilterImpl createFilter(NodeState root, String nodeTypeName) {
    NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(root);
    NodeTypeInfo type = nodeTypes.getNodeTypeInfo(nodeTypeName);
    SelectorImpl selector = new SelectorImpl(type, nodeTypeName);
    return new FilterImpl(selector, "SELECT * FROM [" + nodeTypeName + "]", new QueryEngineSettings());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeTypeInfo(org.apache.jackrabbit.oak.query.ast.NodeTypeInfo) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)

Example 32 with SelectorImpl

use of org.apache.jackrabbit.oak.query.ast.SelectorImpl in project jackrabbit-oak by apache.

the class PropertyIndexLookupTest method createFilter.

private static FilterImpl createFilter(NodeState root, String nodeTypeName) {
    NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(root);
    NodeTypeInfo type = nodeTypes.getNodeTypeInfo(nodeTypeName);
    SelectorImpl selector = new SelectorImpl(type, nodeTypeName);
    return new FilterImpl(selector, "SELECT * FROM [" + nodeTypeName + "]", new QueryEngineSettings());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeTypeInfo(org.apache.jackrabbit.oak.query.ast.NodeTypeInfo) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)

Example 33 with SelectorImpl

use of org.apache.jackrabbit.oak.query.ast.SelectorImpl in project jackrabbit-oak by apache.

the class PropertyIndexTest method createFilter.

private static FilterImpl createFilter(NodeState root, String nodeTypeName) {
    NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(root);
    NodeTypeInfo type = nodeTypes.getNodeTypeInfo(nodeTypeName);
    SelectorImpl selector = new SelectorImpl(type, nodeTypeName);
    return new FilterImpl(selector, "SELECT * FROM [" + nodeTypeName + "]", new QueryEngineSettings());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeTypeInfo(org.apache.jackrabbit.oak.query.ast.NodeTypeInfo) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)

Example 34 with SelectorImpl

use of org.apache.jackrabbit.oak.query.ast.SelectorImpl in project jackrabbit-oak by apache.

the class SolrQueryIndexTest method testNoNegativeCost.

@Test
public void testNoNegativeCost() throws Exception {
    NodeState root = InitialContent.INITIAL_CONTENT;
    NodeBuilder builder = root.builder();
    builder.child("oak:index").child("solr").setProperty("usedProperties", Collections.singleton("name"), Type.STRINGS).setProperty("propertyRestrictions", true).setProperty("type", "solr");
    nodeState = builder.getNodeState();
    SelectorImpl selector = newSelector(root, "a");
    String query = "select * from [nt:base] as a where native('solr','select?q=searchKeywords:\"foo\"^20 text:\"foo\"^1 " + "description:\"foo\"^8 something:\"foo\"^3 headline:\"foo\"^5 title:\"foo\"^10 &q.op=OR'";
    String sqlQuery = "select * from [nt:base] a where native('solr','" + query + "'";
    SolrClient solrServer = mock(SolrClient.class);
    SolrServerProvider solrServerProvider = mock(SolrServerProvider.class);
    when(solrServerProvider.getSearchingSolrServer()).thenReturn(solrServer);
    OakSolrConfigurationProvider configurationProvider = mock(OakSolrConfigurationProvider.class);
    OakSolrConfiguration configuration = new DefaultSolrConfiguration() {

        @Override
        public boolean useForPropertyRestrictions() {
            return true;
        }

        @Override
        public int getRows() {
            return 10;
        }
    };
    when(configurationProvider.getConfiguration()).thenReturn(configuration);
    SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, configurationProvider, solrServerProvider);
    FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
    filter.restrictProperty("native*solr", Operator.EQUAL, PropertyValues.newString(query));
    CountingResponse response = new CountingResponse(0);
    when(solrServer.query(any(SolrParams.class))).thenReturn(response);
    List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, null, nodeState);
    for (QueryIndex.IndexPlan p : plans) {
        double costPerEntry = p.getCostPerEntry();
        assertTrue(costPerEntry >= 0);
        double costPerExecution = p.getCostPerExecution();
        assertTrue(costPerExecution >= 0);
        long estimatedEntryCount = p.getEstimatedEntryCount();
        assertTrue(estimatedEntryCount >= 0);
        double c = p.getCostPerExecution() + estimatedEntryCount * p.getCostPerEntry();
        assertTrue(c >= 0);
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) OakSolrConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider) SolrClient(org.apache.solr.client.solrj.SolrClient) SolrServerProvider(org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) DefaultSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration) SolrParams(org.apache.solr.common.params.SolrParams) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) Test(org.junit.Test)

Example 35 with SelectorImpl

use of org.apache.jackrabbit.oak.query.ast.SelectorImpl in project jackrabbit-oak by apache.

the class QueryImpl method init.

@Override
public void init() {
    final QueryImpl query = this;
    if (constraint != null) {
        // need to do this *before* the visitation below, as the
        // simplify() method does not always keep the query reference
        // passed in setQuery(). TODO: avoid that mutability concern
        constraint = constraint.simplify();
    }
    new AstVisitorBase() {

        @Override
        public boolean visit(BindVariableValueImpl node) {
            node.setQuery(query);
            bindVariableMap.put(node.getBindVariableName(), null);
            return true;
        }

        @Override
        public boolean visit(ChildNodeImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(ChildNodeJoinConditionImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(CoalesceImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(ColumnImpl node) {
            node.setQuery(query);
            return true;
        }

        @Override
        public boolean visit(DescendantNodeImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(DescendantNodeJoinConditionImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(EquiJoinConditionImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(FullTextSearchImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return super.visit(node);
        }

        @Override
        public boolean visit(NativeFunctionImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return super.visit(node);
        }

        @Override
        public boolean visit(SimilarImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return super.visit(node);
        }

        @Override
        public boolean visit(SpellcheckImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return super.visit(node);
        }

        @Override
        public boolean visit(SuggestImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return super.visit(node);
        }

        @Override
        public boolean visit(FullTextSearchScoreImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(LiteralImpl node) {
            node.setQuery(query);
            return true;
        }

        @Override
        public boolean visit(NodeLocalNameImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(NodeNameImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(PropertyExistenceImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(PropertyInexistenceImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(PropertyValueImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(SameNodeImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(SameNodeJoinConditionImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(SelectorImpl node) {
            String name = node.getSelectorName();
            if (selectorIndexes.put(name, selectors.size()) != null) {
                throw new IllegalArgumentException("Two selectors with the same name: " + name);
            }
            selectors.add(node);
            node.setQuery(query);
            return true;
        }

        @Override
        public boolean visit(LengthImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(UpperCaseImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(LowerCaseImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(ComparisonImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(InImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(AndImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(OrImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(NotImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }
    }.visit(this);
    source.setQueryConstraint(constraint);
    for (ColumnImpl column : columns) {
        column.bindSelector(source);
    }
    distinctColumns = new boolean[columns.length];
    for (int i = 0; i < columns.length; i++) {
        ColumnImpl c = columns[i];
        boolean distinct = true;
        if (QueryConstants.JCR_SCORE.equals(c.getPropertyName())) {
            distinct = false;
        }
        distinctColumns[i] = distinct;
    }
    init = true;
}
Also used : SpellcheckImpl(org.apache.jackrabbit.oak.query.ast.SpellcheckImpl) NodeLocalNameImpl(org.apache.jackrabbit.oak.query.ast.NodeLocalNameImpl) AstVisitorBase(org.apache.jackrabbit.oak.query.ast.AstVisitorBase) FullTextSearchScoreImpl(org.apache.jackrabbit.oak.query.ast.FullTextSearchScoreImpl) PropertyInexistenceImpl(org.apache.jackrabbit.oak.query.ast.PropertyInexistenceImpl) UpperCaseImpl(org.apache.jackrabbit.oak.query.ast.UpperCaseImpl) InImpl(org.apache.jackrabbit.oak.query.ast.InImpl) DescendantNodeJoinConditionImpl(org.apache.jackrabbit.oak.query.ast.DescendantNodeJoinConditionImpl) NodeNameImpl(org.apache.jackrabbit.oak.query.ast.NodeNameImpl) BindVariableValueImpl(org.apache.jackrabbit.oak.query.ast.BindVariableValueImpl) SuggestImpl(org.apache.jackrabbit.oak.query.ast.SuggestImpl) ComparisonImpl(org.apache.jackrabbit.oak.query.ast.ComparisonImpl) PropertyExistenceImpl(org.apache.jackrabbit.oak.query.ast.PropertyExistenceImpl) SameNodeJoinConditionImpl(org.apache.jackrabbit.oak.query.ast.SameNodeJoinConditionImpl) ChildNodeImpl(org.apache.jackrabbit.oak.query.ast.ChildNodeImpl) SimilarImpl(org.apache.jackrabbit.oak.query.ast.SimilarImpl) PropertyValueImpl(org.apache.jackrabbit.oak.query.ast.PropertyValueImpl) SameNodeImpl(org.apache.jackrabbit.oak.query.ast.SameNodeImpl) NotImpl(org.apache.jackrabbit.oak.query.ast.NotImpl) DescendantNodeImpl(org.apache.jackrabbit.oak.query.ast.DescendantNodeImpl) NativeFunctionImpl(org.apache.jackrabbit.oak.query.ast.NativeFunctionImpl) ChildNodeJoinConditionImpl(org.apache.jackrabbit.oak.query.ast.ChildNodeJoinConditionImpl) LiteralImpl(org.apache.jackrabbit.oak.query.ast.LiteralImpl) FullTextSearchImpl(org.apache.jackrabbit.oak.query.ast.FullTextSearchImpl) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) CoalesceImpl(org.apache.jackrabbit.oak.query.ast.CoalesceImpl) LowerCaseImpl(org.apache.jackrabbit.oak.query.ast.LowerCaseImpl) LengthImpl(org.apache.jackrabbit.oak.query.ast.LengthImpl) AndImpl(org.apache.jackrabbit.oak.query.ast.AndImpl) ColumnImpl(org.apache.jackrabbit.oak.query.ast.ColumnImpl) OrImpl(org.apache.jackrabbit.oak.query.ast.OrImpl) EquiJoinConditionImpl(org.apache.jackrabbit.oak.query.ast.EquiJoinConditionImpl)

Aggregations

SelectorImpl (org.apache.jackrabbit.oak.query.ast.SelectorImpl)36 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)30 QueryEngineSettings (org.apache.jackrabbit.oak.query.QueryEngineSettings)29 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)17 Test (org.junit.Test)17 LinkedList (java.util.LinkedList)14 NodeStateNodeTypeInfoProvider (org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)14 NodeTypeInfo (org.apache.jackrabbit.oak.query.ast.NodeTypeInfo)14 NodeTypeInfoProvider (org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider)14 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)10 ColumnImpl (org.apache.jackrabbit.oak.query.ast.ColumnImpl)4 DefaultSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration)3 OakSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration)3 OakSolrConfigurationProvider (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider)3 SolrServerProvider (org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PropertyValue (org.apache.jackrabbit.oak.api.PropertyValue)1