use of org.apache.rya.api.domain.RyaRange in project incubator-rya by apache.
the class SpoWholeRowTriplePatternStrategy method defineRange.
@Override
public Map.Entry<TABLE_LAYOUT, ByteRange> defineRange(final RyaURI subject, final RyaURI predicate, final RyaType object, final RyaURI context, final RdfCloudTripleStoreConfiguration conf) throws IOException {
try {
// s_r(p)(ng)
if (!handles(subject, predicate, object, context)) {
return null;
}
final RyaContext ryaContext = RyaContext.getInstance();
final TABLE_LAYOUT table_layout = TABLE_LAYOUT.SPO;
byte[] start;
byte[] stop;
if (predicate != null) {
if (object != null) {
if (object instanceof RyaRange) {
// sp_r(o)
// range = sp_r(o.s)->sp_r(o.e) (remove last byte to remove type info)
RyaRange rv = (RyaRange) object;
rv = ryaContext.transformRange(rv);
final byte[] objStartBytes = ryaContext.serializeType(rv.getStart())[0];
final byte[] objEndBytes = ryaContext.serializeType(rv.getStop())[0];
final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8);
final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
start = Bytes.concat(subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objStartBytes);
stop = Bytes.concat(subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objEndBytes, DELIM_BYTES, LAST_BYTES);
} else {
// spo
// range = spo->spo (remove last byte to remove type info)
// TODO: There must be a better way than creating multiple byte[]
final byte[] objBytes = ryaContext.serializeType(object)[0];
start = Bytes.concat(subject.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, predicate.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, objBytes, TYPE_DELIM_BYTES);
stop = Bytes.concat(start, LAST_BYTES);
}
} else if (predicate instanceof RyaRange) {
// s_r(p)
// range = s_r(p.s)->s_r(p.e)
RyaRange rv = (RyaRange) predicate;
rv = ryaContext.transformRange(rv);
final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8);
final byte[] predStartBytes = rv.getStart().getData().getBytes(StandardCharsets.UTF_8);
final byte[] predStopBytes = rv.getStop().getData().getBytes(StandardCharsets.UTF_8);
start = Bytes.concat(subjBytes, DELIM_BYTES, predStartBytes);
stop = Bytes.concat(subjBytes, DELIM_BYTES, predStopBytes, DELIM_BYTES, LAST_BYTES);
} else {
// sp
// range = sp
start = Bytes.concat(subject.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, predicate.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES);
stop = Bytes.concat(start, LAST_BYTES);
}
} else if (subject instanceof RyaRange) {
// r(s)
// range = r(s.s) -> r(s.e)
RyaRange ru = (RyaRange) subject;
ru = ryaContext.transformRange(ru);
start = ru.getStart().getData().getBytes(StandardCharsets.UTF_8);
stop = Bytes.concat(ru.getStop().getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, LAST_BYTES);
} else {
// s
// range = s
start = Bytes.concat(subject.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES);
stop = Bytes.concat(start, LAST_BYTES);
}
return new RdfCloudTripleStoreUtils.CustomEntry<TABLE_LAYOUT, ByteRange>(table_layout, new ByteRange(start, stop));
} catch (final RyaTypeResolverException e) {
throw new IOException(e);
}
}
Aggregations