use of org.apache.rya.api.resolver.triple.TripleRowResolverException in project incubator-rya by apache.
the class WholeRowTripleResolver method deserialize.
@Override
public RyaStatement deserialize(final TABLE_LAYOUT table_layout, final TripleRow tripleRow) throws TripleRowResolverException {
try {
assert tripleRow != null && table_layout != null;
final byte[] row = tripleRow.getRow();
final int firstIndex = Bytes.indexOf(row, DELIM_BYTE);
final int secondIndex = Bytes.lastIndexOf(row, DELIM_BYTE);
final int typeIndex = Bytes.indexOf(row, TYPE_DELIM_BYTE);
final byte[] first = Arrays.copyOf(row, firstIndex);
final byte[] second = Arrays.copyOfRange(row, firstIndex + 1, secondIndex);
final byte[] third = Arrays.copyOfRange(row, secondIndex + 1, typeIndex);
final byte[] type = Arrays.copyOfRange(row, typeIndex, row.length);
final byte[] columnFamily = tripleRow.getColumnFamily();
final boolean contextExists = columnFamily != null && columnFamily.length > 0;
final RyaURI context = (contextExists) ? (new RyaURI(new String(columnFamily, StandardCharsets.UTF_8))) : null;
final byte[] columnQualifier = tripleRow.getColumnQualifier();
final String qualifier = columnQualifier != null && columnQualifier.length > 0 ? new String(columnQualifier, StandardCharsets.UTF_8) : null;
final Long timestamp = tripleRow.getTimestamp();
final byte[] columnVisibility = tripleRow.getColumnVisibility();
final byte[] value = tripleRow.getValue();
switch(table_layout) {
case SPO:
{
final byte[] obj = Bytes.concat(third, type);
return new RyaStatement(new RyaURI(new String(first, StandardCharsets.UTF_8)), new RyaURI(new String(second, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp);
}
case PO:
{
final byte[] obj = Bytes.concat(second, type);
return new RyaStatement(new RyaURI(new String(third, StandardCharsets.UTF_8)), new RyaURI(new String(first, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp);
}
case OSP:
{
final byte[] obj = Bytes.concat(first, type);
return new RyaStatement(new RyaURI(new String(second, StandardCharsets.UTF_8)), new RyaURI(new String(third, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp);
}
}
} catch (final RyaTypeResolverException e) {
throw new TripleRowResolverException(e);
}
throw new TripleRowResolverException("TripleRow[" + tripleRow + "] with Table layout[" + table_layout + "] is not deserializable");
}
use of org.apache.rya.api.resolver.triple.TripleRowResolverException in project incubator-rya by apache.
the class AccumuloRyaStatementStore method fetchStatements.
@Override
public Iterator<RyaStatement> fetchStatements() throws FetchStatementException {
try {
final RyaTripleContext ryaTripleContext = RyaTripleContext.getInstance(accumuloRyaDao.getConf());
Scanner scanner = null;
try {
scanner = AccumuloRyaUtils.getScanner(tablePrefix + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, accumuloRyaDao.getConf());
for (final IteratorSetting iteratorSetting : iteratorSettings) {
scanner.addScanIterator(iteratorSetting);
}
} catch (final IOException e) {
throw new FetchStatementException("Unable to get scanner to fetch Rya Statements", e);
}
// Convert Entry iterator to RyaStatement iterator
final Iterator<Entry<Key, Value>> entryIter = scanner.iterator();
final Iterator<RyaStatement> ryaStatementIter = Iterators.transform(entryIter, new Function<Entry<Key, Value>, RyaStatement>() {
@Override
public RyaStatement apply(final Entry<Key, Value> entry) {
final Key key = entry.getKey();
final Value value = entry.getValue();
RyaStatement ryaStatement = null;
try {
ryaStatement = AccumuloRyaUtils.createRyaStatement(key, value, ryaTripleContext);
} catch (final TripleRowResolverException e) {
log.error("Unable to convert the key/value pair into a Rya Statement", e);
}
return ryaStatement;
}
});
return ryaStatementIter;
} catch (final Exception e) {
throw new FetchStatementException("Failed to fetch statements.", e);
}
}
use of org.apache.rya.api.resolver.triple.TripleRowResolverException in project incubator-rya by apache.
the class RyaStatementWritable method write.
/**
* Serializes this RyaStatementWritable.
* @param dataOutput An output stream for serialized statement data.
* @throws IOException if the RyaStatement is null or otherwise can't be
* serialized.
*/
@Override
public void write(DataOutput dataOutput) throws IOException {
if (ryaStatement == null) {
throw new IOException("Rya Statement is null");
}
try {
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> map = ryaContext.serializeTriple(ryaStatement);
TripleRow tripleRow = map.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
byte[] row = tripleRow.getRow();
byte[] columnFamily = tripleRow.getColumnFamily();
byte[] columnQualifier = tripleRow.getColumnQualifier();
write(dataOutput, row);
write(dataOutput, columnFamily);
write(dataOutput, columnQualifier);
write(dataOutput, ryaStatement.getColumnVisibility());
write(dataOutput, ryaStatement.getValue());
Long timestamp = ryaStatement.getTimestamp();
boolean b = timestamp != null;
dataOutput.writeBoolean(b);
if (b) {
dataOutput.writeLong(timestamp);
}
} catch (TripleRowResolverException e) {
throw new IOException(e);
}
}
use of org.apache.rya.api.resolver.triple.TripleRowResolverException in project incubator-rya by apache.
the class WholeRowTripleResolver method serialize.
@Override
public Map<TABLE_LAYOUT, TripleRow> serialize(final RyaStatement stmt) throws TripleRowResolverException {
try {
final RyaURI subject = stmt.getSubject();
final RyaURI predicate = stmt.getPredicate();
final RyaType object = stmt.getObject();
final RyaURI context = stmt.getContext();
final Long timestamp = stmt.getTimestamp();
final byte[] columnVisibility = stmt.getColumnVisibility();
final String qualifer = stmt.getQualifer();
final byte[] qualBytes = qualifer == null ? EMPTY_BYTES : qualifer.getBytes(StandardCharsets.UTF_8);
final byte[] value = stmt.getValue();
assert subject != null && predicate != null && object != null;
final byte[] cf = (context == null) ? EMPTY_BYTES : context.getData().getBytes(StandardCharsets.UTF_8);
final Map<TABLE_LAYOUT, TripleRow> tripleRowMap = new HashMap<TABLE_LAYOUT, TripleRow>();
final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8);
final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
final byte[][] objBytes = RyaContext.getInstance().serializeType(object);
tripleRowMap.put(TABLE_LAYOUT.SPO, new TripleRow(Bytes.concat(subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes[0], objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
tripleRowMap.put(TABLE_LAYOUT.PO, new TripleRow(Bytes.concat(predBytes, DELIM_BYTES, objBytes[0], DELIM_BYTES, subjBytes, objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
tripleRowMap.put(TABLE_LAYOUT.OSP, new TripleRow(Bytes.concat(objBytes[0], DELIM_BYTES, subjBytes, DELIM_BYTES, predBytes, objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
return tripleRowMap;
} catch (final RyaTypeResolverException e) {
throw new TripleRowResolverException(e);
}
}
use of org.apache.rya.api.resolver.triple.TripleRowResolverException in project incubator-rya by apache.
the class WholeRowHashedTripleResolver method deserialize.
@Override
public RyaStatement deserialize(final TABLE_LAYOUT table_layout, final TripleRow tripleRow) throws TripleRowResolverException {
try {
assert tripleRow != null && table_layout != null;
byte[] row = tripleRow.getRow();
// if it is a hashed row, ony keep the row after the hash
if ((table_layout == TABLE_LAYOUT.SPO) || (table_layout == TABLE_LAYOUT.PO)) {
final int hashStart = Bytes.indexOf(row, DELIM_BYTE);
row = Arrays.copyOfRange(row, hashStart + 1, row.length);
}
final int firstIndex = Bytes.indexOf(row, DELIM_BYTE);
final byte[] first = Arrays.copyOf(row, firstIndex);
final int secondIndex = Bytes.lastIndexOf(row, DELIM_BYTE);
final int typeIndex = Bytes.indexOf(row, TYPE_DELIM_BYTE);
final byte[] second = Arrays.copyOfRange(row, firstIndex + 1, secondIndex);
final byte[] third = Arrays.copyOfRange(row, secondIndex + 1, typeIndex);
final byte[] type = Arrays.copyOfRange(row, typeIndex, row.length);
final byte[] columnFamily = tripleRow.getColumnFamily();
final boolean contextExists = columnFamily != null && columnFamily.length > 0;
final RyaURI context = (contextExists) ? (new RyaURI(new String(columnFamily, StandardCharsets.UTF_8))) : null;
final byte[] columnQualifier = tripleRow.getColumnQualifier();
final String qualifier = columnQualifier != null && columnQualifier.length > 0 ? new String(columnQualifier, StandardCharsets.UTF_8) : null;
final Long timestamp = tripleRow.getTimestamp();
final byte[] columnVisibility = tripleRow.getColumnVisibility();
final byte[] value = tripleRow.getValue();
switch(table_layout) {
case SPO:
{
final byte[] obj = Bytes.concat(third, type);
return new RyaStatement(new RyaURI(new String(first, StandardCharsets.UTF_8)), new RyaURI(new String(second, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp);
}
case PO:
{
final byte[] obj = Bytes.concat(second, type);
return new RyaStatement(new RyaURI(new String(third, StandardCharsets.UTF_8)), new RyaURI(new String(first, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp);
}
case OSP:
{
final byte[] obj = Bytes.concat(first, type);
return new RyaStatement(new RyaURI(new String(second, StandardCharsets.UTF_8)), new RyaURI(new String(third, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp);
}
}
} catch (final RyaTypeResolverException e) {
throw new TripleRowResolverException(e);
}
throw new TripleRowResolverException("TripleRow[" + tripleRow + "] with Table layout[" + table_layout + "] is not deserializable");
}
Aggregations