Search in sources :

Example 36 with ResultRow

use of org.apache.jackrabbit.oak.api.ResultRow in project jackrabbit-oak by apache.

the class ContentRemoteResultTest method testMultiBinaryColumn.

@Test
public void testMultiBinaryColumn() {
    Blob first = mock(Blob.class);
    Blob second = mock(Blob.class);
    ContentRemoteBinaries binaries = mock(ContentRemoteBinaries.class);
    doReturn("first").when(binaries).put(first);
    doReturn("second").when(binaries).put(second);
    PropertyValue value = mock(PropertyValue.class);
    doReturn(Type.BINARIES).when(value).getType();
    doReturn(asList(first, second)).when(value).getValue(Type.BINARIES);
    ResultRow row = mock(ResultRow.class);
    doReturn(value).when(row).getValue("column");
    ContentRemoteResult result = createResult(binaries, row);
    RemoteValue remoteValue = result.getColumnValue("column");
    assertEquals(asList("first", "second"), remoteValue.asMultiBinaryId());
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) Blob(org.apache.jackrabbit.oak.api.Blob) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) RemoteValue(org.apache.jackrabbit.oak.remote.RemoteValue) Test(org.junit.Test)

Example 37 with ResultRow

use of org.apache.jackrabbit.oak.api.ResultRow in project jackrabbit-oak by apache.

the class ContentRemoteResultTest method testBooleanColumn.

@Test
public void testBooleanColumn() {
    PropertyValue value = mock(PropertyValue.class);
    doReturn(Type.BOOLEAN).when(value).getType();
    doReturn(true).when(value).getValue(Type.BOOLEAN);
    ResultRow row = mock(ResultRow.class);
    doReturn(value).when(row).getValue("column");
    ContentRemoteResult result = createResult(row);
    RemoteValue remoteValue = result.getColumnValue("column");
    assertEquals(true, remoteValue.asBoolean());
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) RemoteValue(org.apache.jackrabbit.oak.remote.RemoteValue) Test(org.junit.Test)

Example 38 with ResultRow

use of org.apache.jackrabbit.oak.api.ResultRow in project jackrabbit-oak by apache.

the class NativeQueryTest method assertDontTraverseFor.

private void assertDontTraverseFor(String sql) throws ParseException {
    QueryImpl query = (QueryImpl) p.parse(sql);
    query.setExecutionContext(QUERY_ENGINE.getExecutionContext());
    Result result = query.executeQuery();
    Iterator<? extends ResultRow> it = result.getRows().iterator();
    assertFalse("Zero results expected", it.hasNext());
    query = (QueryImpl) p.parse("measure " + sql);
    query.setExecutionContext(QUERY_ENGINE.getExecutionContext());
    result = query.executeQuery();
    it = result.getRows().iterator();
    while (it.hasNext()) {
        ResultRow row = it.next();
        String selector = row.getValue("selector").getValue(Type.STRING);
        if ("nt:base".equals(selector)) {
            long scanCount = row.getValue("scanCount").getValue(Type.LONG);
            // we expect that no was scanned that's it
            // - no traversal of the whole respository
            assertEquals("Repository's scan count doesn't match", 0, scanCount);
        }
    }
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) Result(org.apache.jackrabbit.oak.api.Result)

Example 39 with ResultRow

use of org.apache.jackrabbit.oak.api.ResultRow in project jackrabbit-oak by apache.

the class UnionQueryTest method testOrderLimitOffset.

@Test
public void testOrderLimitOffset() throws Exception {
    String left = "SELECT [jcr:path] FROM [nt:base] AS a WHERE ISDESCENDANTNODE(a, '/UnionQueryTest')";
    String right = "SELECT [jcr:path] FROM [nt:base] AS a WHERE ISDESCENDANTNODE(a, '/UnionQueryTest')";
    String order = "ORDER BY [jcr:path]";
    String union = String.format("%s UNION %s %s", left, right, order);
    final int limit = 3;
    final int offset = 2;
    String[] expected = { "/UnionQueryTest/a/b/c", "/UnionQueryTest/a/b/c/d", "/UnionQueryTest/a/b/c/d/e" };
    Result result = qe.executeQuery(union, QueryEngineImpl.SQL2, limit, offset, QueryEngine.NO_BINDINGS, QueryEngine.NO_MAPPINGS);
    List<ResultRow> rows = Lists.newArrayList(result.getRows());
    assertEquals(expected.length, rows.size());
    int i = 0;
    for (ResultRow rr : result.getRows()) {
        assertEquals(rr.getPath(), expected[i++]);
    }
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) Result(org.apache.jackrabbit.oak.api.Result) Test(org.junit.Test)

Example 40 with ResultRow

use of org.apache.jackrabbit.oak.api.ResultRow in project jackrabbit-oak by apache.

the class QueryResultImpl method getRows.

@Override
public RowIterator getRows() throws RepositoryException {
    Iterator<RowImpl> rowIterator = new Iterator<RowImpl>() {

        private final Iterator<? extends ResultRow> it = result.getRows().iterator();

        private final String pathSelector;

        private RowImpl current;

        private int rowCount;

        //Avoid log check for every row access
        private final boolean debugEnabled = queryOpsLogger.isDebugEnabled();

        {
            String[] columnSelectorNames = result.getColumnSelectorNames();
            if (columnSelectorNames.length == 1) {
                pathSelector = columnSelectorNames[0];
            } else {
                pathSelector = null;
            }
            fetch();
        }

        private void fetch() {
            if (it.hasNext()) {
                current = new RowImpl(QueryResultImpl.this, it.next(), pathSelector);
                if (debugEnabled) {
                    rowCount++;
                    if (rowCount % 100 == 0) {
                        queryOpsLogger.debug("Iterated over [{}] results so far", rowCount);
                    }
                }
            } else {
                current = null;
            }
        }

        @Override
        public boolean hasNext() {
            return current != null;
        }

        @Override
        public RowImpl next() {
            if (current == null) {
                throw new NoSuchElementException();
            }
            RowImpl r = current;
            fetch();
            return r;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    final PrefetchIterator<RowImpl> prefIt = new PrefetchIterator<RowImpl>(sessionDelegate.sync(rowIterator), new PrefetchOptions() {

        {
            size = result.getSize();
            fastSize = sessionContext.getFastQueryResultSize();
            fastSizeCallback = result;
        }
    });
    return new RowIteratorAdapter(prefIt) {

        @Override
        public long getSize() {
            return prefIt.size();
        }
    };
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) RowIteratorAdapter(org.apache.jackrabbit.commons.iterator.RowIteratorAdapter) PrefetchOptions(org.apache.jackrabbit.oak.jcr.query.PrefetchIterator.PrefetchOptions) Iterator(java.util.Iterator) RowIterator(javax.jcr.query.RowIterator) NodeIterator(javax.jcr.NodeIterator) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

ResultRow (org.apache.jackrabbit.oak.api.ResultRow)41 Test (org.junit.Test)29 PropertyValue (org.apache.jackrabbit.oak.api.PropertyValue)26 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)24 Result (org.apache.jackrabbit.oak.api.Result)12 Tree (org.apache.jackrabbit.oak.api.Tree)4 ParseException (java.text.ParseException)3 Root (org.apache.jackrabbit.oak.api.Root)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Iterator (java.util.Iterator)2 NoSuchElementException (java.util.NoSuchElementException)2 Nonnull (javax.annotation.Nonnull)2 NodeIterator (javax.jcr.NodeIterator)2 RowIterator (javax.jcr.query.RowIterator)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 PrefetchOptions (org.apache.jackrabbit.oak.jcr.query.PrefetchIterator.PrefetchOptions)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1