Search in sources :

Example 26 with SelectorImpl

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

the class SolrQueryIndexTest method testUnion.

@Test
public void testUnion() throws Exception {
    SelectorImpl selector = mock(SelectorImpl.class);
    SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, null, null);
    String sqlQuery = "select [jcr:path], [jcr:score], [rep:excerpt] from [nt:hierarchyNode] as a where" + " isdescendantnode(a, '/content') and contains([jcr:content/*], 'founded') union select [jcr:path]," + " [jcr:score], [rep:excerpt] from [nt:hierarchyNode] as a where isdescendantnode(a, '/content') and " + "contains([jcr:content/jcr:title], 'founded') union select [jcr:path], [jcr:score], [rep:excerpt]" + " from [nt:hierarchyNode] as a where isdescendantnode(a, '/content') and " + "contains([jcr:content/jcr:description], 'founded') order by [jcr:score] desc";
    FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
    List<QueryIndex.OrderEntry> sortOrder = new LinkedList<QueryIndex.OrderEntry>();
    List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, sortOrder, nodeState);
    assertEquals(0, plans.size());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 27 with SelectorImpl

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

the class IndexPathServiceImpl method createFilter.

private FilterImpl createFilter(String nodeTypeName) {
    NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(nodeStore.getRoot());
    NodeTypeInfo type = nodeTypes.getNodeTypeInfo(nodeTypeName);
    SelectorImpl selector = new SelectorImpl(type, nodeTypeName);
    return new FilterImpl(selector, "SELECT * FROM [" + nodeTypeName + "]", settings);
}
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) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)

Example 28 with SelectorImpl

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

the class QueryImpl method getRows.

@Override
public Iterator<ResultRowImpl> getRows() {
    prepare();
    if (explain) {
        String plan = getPlan();
        if (measure) {
            plan += " cost: { " + getIndexCostInfo() + " }";
        }
        columns = new ColumnImpl[] { new ColumnImpl("explain", "plan", "plan") };
        ResultRowImpl r = new ResultRowImpl(this, Tree.EMPTY_ARRAY, new PropertyValue[] { PropertyValues.newString(plan) }, null, null);
        return Arrays.asList(r).iterator();
    }
    if (LOG.isDebugEnabled()) {
        logDebug("query execute " + statement);
        logDebug("query plan " + getPlan());
    }
    final RowIterator rowIt = new RowIterator(context.getBaseState());
    Comparator<ResultRowImpl> orderBy;
    if (isSortedByIndex) {
        orderBy = null;
    } else {
        orderBy = ResultRowImpl.getComparator(orderings);
    }
    Iterator<ResultRowImpl> it = FilterIterators.newCombinedFilter(rowIt, distinct, limit, offset, orderBy, settings);
    if (orderBy != null) {
        // this will force the rows to be read, so that the size is known
        it.hasNext();
        // we need the size, and there is no other way to get it right now
        // but we also have to take limit and offset into account
        long read = rowIt.getReadCount();
        // we will ignore whatever is behind 'limit+offset'
        read = Math.min(saturatedAdd(limit, offset), read);
        // and we will skip 'offset' entries
        read = Math.max(0, read - offset);
        size = read;
    }
    if (measure) {
        // return the measuring iterator delegating the readCounts to the rowIterator
        it = new MeasuringIterator(this, it) {

            @Override
            protected void setColumns(ColumnImpl[] col) {
                columns = col;
            }

            @Override
            protected long getReadCount() {
                return rowIt.getReadCount();
            }

            @Override
            protected Map<String, Long> getSelectorScanCount() {
                Map<String, Long> selectorReadCounts = Maps.newHashMap();
                for (SelectorImpl selector : selectors) {
                    selectorReadCounts.put(selector.getSelectorName(), selector.getScanCount());
                }
                return selectorReadCounts;
            }
        };
    }
    return it;
}
Also used : SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) ColumnImpl(org.apache.jackrabbit.oak.query.ast.ColumnImpl) Map(java.util.Map) HashMap(java.util.HashMap)

Example 29 with SelectorImpl

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

the class ResultImpl method getColumnSelectorNames.

@Override
public String[] getColumnSelectorNames() {
    ArrayList<String> list = new ArrayList<String>();
    for (ColumnImpl c : query.getColumns()) {
        SelectorImpl selector = c.getSelector();
        String name = selector == null ? null : selector.getSelectorName();
        if (!list.contains(name)) {
            list.add(name);
        }
    }
    return list.toArray(new String[list.size()]);
}
Also used : SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) ArrayList(java.util.ArrayList) ColumnImpl(org.apache.jackrabbit.oak.query.ast.ColumnImpl)

Example 30 with SelectorImpl

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

the class SQL2Parser method parseSource.

private SourceImpl parseSource() throws ParseException {
    SelectorImpl selector = parseSelector();
    selectors.put(selector.getSelectorName(), selector);
    SourceImpl source = selector;
    while (true) {
        JoinType joinType;
        if (readIf("RIGHT")) {
            read("OUTER");
            joinType = JoinType.RIGHT_OUTER;
        } else if (readIf("LEFT")) {
            read("OUTER");
            joinType = JoinType.LEFT_OUTER;
        } else if (readIf("INNER")) {
            joinType = JoinType.INNER;
        } else {
            break;
        }
        read("JOIN");
        selector = parseSelector();
        selectors.put(selector.getSelectorName(), selector);
        read("ON");
        JoinConditionImpl on = parseJoinCondition();
        source = factory.join(source, selector, joinType, on);
    }
    return source;
}
Also used : SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) SourceImpl(org.apache.jackrabbit.oak.query.ast.SourceImpl) JoinType(org.apache.jackrabbit.oak.query.ast.JoinType) JoinConditionImpl(org.apache.jackrabbit.oak.query.ast.JoinConditionImpl)

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