use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class MongoEntityStorage method searchHasAllExplicitTypes.
/**
* Searches the Entity storage for all Entities that contain all the
* specified explicit type IDs.
* @param explicitTypeIds the {@link ImmutableList} of {@link RyaURI}s that
* are being searched for.
* @return the {@link List} of {@link Entity}s that have all the specified
* explicit type IDs. If nothing was found an empty {@link List} is
* returned.
* @throws EntityStorageException
*/
private List<Entity> searchHasAllExplicitTypes(final ImmutableList<RyaURI> explicitTypeIds) throws EntityStorageException {
final List<Entity> hasAllExplicitTypesEntities = new ArrayList<>();
if (!explicitTypeIds.isEmpty()) {
// Grab the first type from the explicit type IDs.
final RyaURI firstType = explicitTypeIds.get(0);
// Check if that type exists anywhere in storage.
final List<RyaURI> subjects = new ArrayList<>();
Optional<Type> type;
try {
if (mongoTypeStorage == null) {
mongoTypeStorage = new MongoTypeStorage(mongo, ryaInstanceName);
}
type = mongoTypeStorage.get(firstType);
} catch (final TypeStorageException e) {
throw new EntityStorageException("Unable to get entity type: " + firstType, e);
}
if (type.isPresent()) {
// Grab the subjects for all the types we found matching "firstType"
final ConvertingCursor<TypedEntity> cursor = search(Optional.empty(), type.get(), Collections.emptySet());
while (cursor.hasNext()) {
final TypedEntity typedEntity = cursor.next();
final RyaURI subject = typedEntity.getSubject();
subjects.add(subject);
}
}
// Now grab all the Entities that have the subjects we found.
for (final RyaURI subject : subjects) {
final Optional<Entity> entityFromSubject = get(subject);
if (entityFromSubject.isPresent()) {
final Entity candidateEntity = entityFromSubject.get();
// types they have.
if (candidateEntity.getExplicitTypeIds().containsAll(explicitTypeIds)) {
hasAllExplicitTypesEntities.add(candidateEntity);
}
}
}
}
return hasAllExplicitTypesEntities;
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class RdfCloudTripleStoreConfiguration method getStatementMetadataProperties.
public Set<RyaURI> getStatementMetadataProperties() {
final Set<RyaURI> uriSet = new HashSet<>();
final String[] uriStrings = getStrings(CONF_STATEMENT_METADATA_PROPERTIES);
if (uriStrings != null) {
for (final String s : uriStrings) {
uriSet.add(new RyaURI(s));
}
}
return uriSet;
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class RdfCloudTripleStoreConfiguration method setStatementMetadataProperties.
public void setStatementMetadataProperties(final Set<RyaURI> metadataProperties) {
final String[] propArray = new String[metadataProperties.size()];
int i = 0;
for (final RyaURI uri : metadataProperties) {
propArray[i] = uri.getData();
i++;
}
setStrings(CONF_STATEMENT_METADATA_PROPERTIES, propArray);
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class WholeRowHashedTripleResolver 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 MessageDigest md = MessageDigest.getInstance("MD5");
final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8);
final byte[] subjHashBytes = md.digest(subjBytes);
final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
final byte[] predHashBytes = md.digest(predBytes);
final byte[][] objBytes = RyaContext.getInstance().serializeType(object);
tripleRowMap.put(TABLE_LAYOUT.SPO, new TripleRow(Bytes.concat(Hex.encodeHexString(subjHashBytes).getBytes(StandardCharsets.UTF_8), DELIM_BYTES, subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes[0], objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value));
tripleRowMap.put(TABLE_LAYOUT.PO, new TripleRow(Bytes.concat(Hex.encodeHexString(predHashBytes).getBytes(StandardCharsets.UTF_8), DELIM_BYTES, 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);
} catch (final NoSuchAlgorithmException e) {
throw new TripleRowResolverException(e);
}
}
use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.
the class MongoFreeTextIndexerIT method testRestrictPredicatesSearch.
@Test
public void testRestrictPredicatesSearch() throws Exception {
conf.setStrings(ConfigUtils.FREETEXT_PREDICATES_LIST, "pred:1,pred:2");
try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
f.setConf(conf);
f.init();
// These should not be stored because they are not in the predicate list
f.storeStatement(new RyaStatement(new RyaURI("foo:subj1"), new RyaURI(RDFS.LABEL.toString()), new RyaType("invalid")));
f.storeStatement(new RyaStatement(new RyaURI("foo:subj2"), new RyaURI(RDFS.COMMENT.toString()), new RyaType("invalid")));
final RyaURI pred1 = new RyaURI("pred:1");
final RyaURI pred2 = new RyaURI("pred:2");
// These should be stored because they are in the predicate list
final RyaStatement s3 = new RyaStatement(new RyaURI("foo:subj3"), pred1, new RyaType("valid"));
final RyaStatement s4 = new RyaStatement(new RyaURI("foo:subj4"), pred2, new RyaType("valid"));
f.storeStatement(s3);
f.storeStatement(s4);
// This should not be stored because the object is not a literal
f.storeStatement(new RyaStatement(new RyaURI("foo:subj5"), pred1, new RyaURI("in:validURI")));
f.flush();
assertEquals(Sets.newHashSet(), getSet(f.queryText("invalid", EMPTY_CONSTRAINTS)));
assertEquals(Sets.newHashSet(), getSet(f.queryText("in:validURI", EMPTY_CONSTRAINTS)));
final Set<Statement> actual = getSet(f.queryText("valid", EMPTY_CONSTRAINTS));
assertEquals(2, actual.size());
assertTrue(actual.contains(RyaToRdfConversions.convertStatement(s3)));
assertTrue(actual.contains(RyaToRdfConversions.convertStatement(s4)));
}
}
Aggregations