use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.
the class AccumuloRyaQueryEngine method query.
@Override
public CloseableIterable<RyaStatement> query(RyaQuery ryaQuery) throws RyaDAOException {
Preconditions.checkNotNull(ryaQuery);
RyaStatement stmt = ryaQuery.getQuery();
Preconditions.checkNotNull(stmt);
// query configuration
String[] auths = ryaQuery.getAuths();
Authorizations authorizations = auths != null ? new Authorizations(auths) : configuration.getAuthorizations();
Long ttl = ryaQuery.getTtl();
Long currentTime = ryaQuery.getCurrentTime();
Long maxResults = ryaQuery.getMaxResults();
Integer batchSize = ryaQuery.getBatchSize();
String regexSubject = ryaQuery.getRegexSubject();
String regexPredicate = ryaQuery.getRegexPredicate();
String regexObject = ryaQuery.getRegexObject();
TableLayoutStrategy tableLayoutStrategy = configuration.getTableLayoutStrategy();
try {
// find triple pattern range
TriplePatternStrategy strategy = ryaContext.retrieveStrategy(stmt);
TABLE_LAYOUT layout;
Range range;
RyaURI subject = stmt.getSubject();
RyaURI predicate = stmt.getPredicate();
RyaType object = stmt.getObject();
RyaURI context = stmt.getContext();
String qualifier = stmt.getQualifer();
TripleRowRegex tripleRowRegex = null;
if (strategy != null) {
// otherwise, full table scan is supported
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(subject, predicate, object, context, null);
layout = entry.getKey();
ByteRange byteRange = entry.getValue();
range = new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd()));
} else {
range = new Range();
layout = TABLE_LAYOUT.SPO;
strategy = ryaContext.retrieveStrategy(layout);
}
byte[] objectTypeInfo = null;
if (object != null) {
// TODO: Not good to serialize this twice
if (object instanceof RyaRange) {
objectTypeInfo = RyaContext.getInstance().serializeType(((RyaRange) object).getStart())[1];
} else {
objectTypeInfo = RyaContext.getInstance().serializeType(object)[1];
}
}
tripleRowRegex = strategy.buildRegex(regexSubject, regexPredicate, regexObject, null, objectTypeInfo);
// use range to set scanner
// populate scanner based on authorizations, ttl
String table = layoutToTable(layout, tableLayoutStrategy);
Scanner scanner = connector.createScanner(table, authorizations);
scanner.setRange(range);
if (batchSize != null) {
scanner.setBatchSize(batchSize);
}
fillScanner(scanner, context, qualifier, ttl, currentTime, tripleRowRegex, ryaQuery.getConf());
FluentCloseableIterable<RyaStatement> results = FluentCloseableIterable.from(new ScannerBaseCloseableIterable(scanner)).transform(keyValueToRyaStatementFunctionMap.get(layout));
if (maxResults != null) {
results = results.limit(maxResults.intValue());
}
return results;
} catch (Exception e) {
throw new RyaDAOException(e);
}
}
use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.
the class HashedSpoWholeRowTriplePatternStrategyTest method testSpoRange.
public void testSpoRange() throws Exception {
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, uri, rangeURI, null, null);
assertContains(entry.getValue(), tripleRow.getRow());
entry = strategy.defineRange(uri, uri, rangeURI2, null, null);
assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.
the class HashedSpoWholeRowTriplePatternStrategyTest method testSpRange.
public void testSpRange() throws Exception {
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, rangeURI, null, null, null);
assertContains(entry.getValue(), tripleRow.getRow());
entry = strategy.defineRange(uri, rangeURI2, null, null, null);
assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.
the class HashedSpoWholeRowTriplePatternStrategyTest method testSpoCustomType.
public void testSpoCustomType() throws Exception {
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, customType1, null));
TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, uri, customType1, null, null);
assertContains(entry.getValue(), tripleRow.getRow());
entry = strategy.defineRange(uri, uri, customType2, null, null);
assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.
the class NullRowTriplePatternStrategyTest method testDefineRange.
/**
* Test of defineRange method, of class NullRowTriplePatternStrategy.
* @throws java.lang.Exception
*/
@Test
public void testDefineRange() throws Exception {
RyaURI subject = null;
RyaURI predicate = null;
RyaType object = null;
RyaURI context = null;
RdfCloudTripleStoreConfiguration conf = new MockRdfConfiguration();
NullRowTriplePatternStrategy instance = new NullRowTriplePatternStrategy();
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> expResult = new RdfCloudTripleStoreUtils.CustomEntry<>(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, new ByteRange(new byte[] {}, LAST_BYTES));
Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> result = instance.defineRange(subject, predicate, object, context, conf);
assertEquals(expResult.getKey(), result.getKey());
assertTrue(Arrays.equals(expResult.getValue().getStart(), result.getValue().getStart()));
assertTrue(Arrays.equals(expResult.getValue().getEnd(), result.getValue().getEnd()));
}
Aggregations