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());
}
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());
}
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);
}
}
}
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++]);
}
}
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();
}
};
}
Aggregations