Search in sources :

Example 76 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class HashJoinTest method testMergeJoinMultiWay.

@Test
public void testMergeJoinMultiWay() throws Exception {
    // add data
    RyaURI pred = new RyaURI(litdupsNS, "pred1");
    RyaType zero = new RyaType("0");
    RyaType one = new RyaType("1");
    RyaType two = new RyaType("2");
    RyaType three = new RyaType("3");
    RyaType four = new RyaType("4");
    RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
    RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
    RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
    RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
    dao.add(new RyaStatement(subj1, pred, one));
    dao.add(new RyaStatement(subj1, pred, two));
    dao.add(new RyaStatement(subj1, pred, three));
    dao.add(new RyaStatement(subj1, pred, four));
    dao.add(new RyaStatement(subj2, pred, zero));
    dao.add(new RyaStatement(subj2, pred, one));
    dao.add(new RyaStatement(subj2, pred, two));
    dao.add(new RyaStatement(subj2, pred, three));
    dao.add(new RyaStatement(subj2, pred, four));
    dao.add(new RyaStatement(subj3, pred, one));
    dao.add(new RyaStatement(subj3, pred, two));
    dao.add(new RyaStatement(subj3, pred, four));
    dao.add(new RyaStatement(subj4, pred, one));
    dao.add(new RyaStatement(subj4, pred, two));
    dao.add(new RyaStatement(subj4, pred, three));
    dao.add(new RyaStatement(subj4, pred, four));
    // 1 join
    HashJoin hjoin = new HashJoin(dao.getQueryEngine());
    CloseableIteration<RyaURI, RyaDAOException> join = hjoin.join(null, new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, one), new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, two), new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, three), new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, four));
    Set<RyaURI> uris = new HashSet<RyaURI>();
    while (join.hasNext()) {
        uris.add(join.next());
    }
    assertTrue(uris.contains(subj1));
    assertTrue(uris.contains(subj2));
    assertTrue(uris.contains(subj4));
    join.close();
}
Also used : RdfCloudTripleStoreUtils(org.apache.rya.api.RdfCloudTripleStoreUtils) RyaURI(org.apache.rya.api.domain.RyaURI) HashJoin(org.apache.rya.api.persist.query.join.HashJoin) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) RyaType(org.apache.rya.api.domain.RyaType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 77 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class HashJoinTest method testSimpleHashJoinPredicateOnly.

@Test
public void testSimpleHashJoinPredicateOnly() throws Exception {
    // add data
    RyaURI pred1 = new RyaURI(litdupsNS, "pred1");
    RyaURI pred2 = new RyaURI(litdupsNS, "pred2");
    RyaType one = new RyaType("1");
    RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
    RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
    RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
    RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
    dao.add(new RyaStatement(subj1, pred1, one));
    dao.add(new RyaStatement(subj1, pred2, one));
    dao.add(new RyaStatement(subj2, pred1, one));
    dao.add(new RyaStatement(subj2, pred2, one));
    dao.add(new RyaStatement(subj3, pred1, one));
    dao.add(new RyaStatement(subj3, pred2, one));
    dao.add(new RyaStatement(subj4, pred1, one));
    dao.add(new RyaStatement(subj4, pred2, one));
    // 1 join
    HashJoin ijoin = new HashJoin(dao.getQueryEngine());
    CloseableIteration<RyaStatement, RyaDAOException> join = ijoin.join(null, pred1, pred2);
    int count = 0;
    while (join.hasNext()) {
        RyaStatement next = join.next();
        count++;
    }
    assertEquals(4, count);
    join.close();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) HashJoin(org.apache.rya.api.persist.query.join.HashJoin) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

Example 78 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class RdfFileInputToolTest method testInputContext.

@Test
public void testInputContext() throws Exception {
    RdfFileInputTool.main(new String[] { "-Dac.mock=true", "-Dac.instance=" + instance, "-Dac.username=" + user, "-Dac.pwd=" + pwd, "-Dac.auth=" + auths.toString(), "-Dac.cv=" + auths.toString(), "-Drdf.tablePrefix=" + tablePrefix, "-Drdf.format=" + RDFFormat.TRIG.getName(), "src/test/resources/namedgraphs.trig" });
    RyaStatement rs = new RyaStatement(new RyaURI("http://www.example.org/exampleDocument#Monica"), new RyaURI("http://www.example.org/vocabulary#name"), new RyaType("Monica Murphy"), new RyaURI("http://www.example.org/exampleDocument#G1"));
    rs.setColumnVisibility(auths.toString().getBytes());
    AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix(tablePrefix);
    conf.setAuths(auths.toString());
    TestUtils.verify(connector, conf, rs);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) Test(org.junit.Test)

Example 79 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class EntityDocumentConverter method toDocument.

@Override
public Document toDocument(final Entity entity) {
    requireNonNull(entity);
    final Document doc = new Document();
    doc.append(SUBJECT, entity.getSubject().getData());
    doc.append(EXPLICIT_TYPE_IDS, entity.getExplicitTypeIds().stream().map(explicitTypeId -> explicitTypeId.getData()).collect(Collectors.toList()));
    final Document propertiesDoc = new Document();
    for (final RyaURI typeId : entity.getProperties().keySet()) {
        final Document typePropertiesDoc = new Document();
        entity.getProperties().get(typeId).forEach((propertyNameUri, property) -> {
            final String propertyName = property.getName().getData();
            final String encodedPropertyName = MongoDbSafeKey.encodeKey(propertyName);
            final RyaType value = property.getValue();
            typePropertiesDoc.append(encodedPropertyName, ryaTypeConverter.toDocument(value));
        });
        propertiesDoc.append(typeId.getData(), typePropertiesDoc);
    }
    doc.append(PROPERTIES, propertiesDoc);
    doc.append(VERSION, entity.getVersion());
    doc.append(SMART_URI, entity.getSmartUri().stringValue());
    return doc;
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) Document(org.bson.Document) RyaType(org.apache.rya.api.domain.RyaType)

Example 80 with RyaType

use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.

the class BaseEntityIndexer method updateEntity.

/**
 * Updates a {@link Entity} to reflect new {@link RyaStatement}s.
 *
 * @param subject - The Subject of the {@link Entity} the statements are for. (not null)
 * @param statements - Statements that the {@link Entity} will be updated with. (not null)
 * @throws IndexingException
 */
private void updateEntity(final RyaURI subject, final Collection<RyaStatement> statements) throws IndexingException {
    requireNonNull(subject);
    requireNonNull(statements);
    final EntityStorage entities = this.entities.get();
    final TypeStorage types = this.types.get();
    checkState(entities != null, "Must set this indexers configuration before storing statements.");
    checkState(types != null, "Must set this indexers configuration before storing statements.");
    new EntityUpdater(entities).update(subject, old -> {
        // Create a builder with the updated Version.
        final Entity.Builder updated;
        if (!old.isPresent()) {
            updated = Entity.builder().setSubject(subject).setVersion(0);
        } else {
            final int updatedVersion = old.get().getVersion() + 1;
            updated = Entity.builder(old.get()).setVersion(updatedVersion);
        }
        // Update the entity based on the Statements.
        for (final RyaStatement statement : statements) {
            // The Statement is setting an Explicit Type ID for the Entity.
            if (Objects.equal(TYPE_URI, statement.getPredicate())) {
                final RyaURI typeId = new RyaURI(statement.getObject().getData());
                updated.setExplicitType(typeId);
            } else // The Statement is adding a Property to the Entity.
            {
                final RyaURI propertyName = statement.getPredicate();
                final RyaType propertyValue = statement.getObject();
                try (final ConvertingCursor<Type> typesIt = types.search(propertyName)) {
                    // Set the Property for each type that includes the Statement's predicate.
                    while (typesIt.hasNext()) {
                        final RyaURI typeId = typesIt.next().getId();
                        updated.setProperty(typeId, new Property(propertyName, propertyValue));
                    }
                } catch (final TypeStorageException | IOException e) {
                    throw new RuntimeException("Failed to fetch Types that include the property name '" + statement.getPredicate().getData() + "'.", e);
                }
            }
        }
        return Optional.of(updated.build());
    });
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) RyaStatement(org.apache.rya.api.domain.RyaStatement) IOException(java.io.IOException) RyaType(org.apache.rya.api.domain.RyaType) TypeStorageException(org.apache.rya.indexing.entity.storage.TypeStorage.TypeStorageException) TypeStorage(org.apache.rya.indexing.entity.storage.TypeStorage) RyaURI(org.apache.rya.api.domain.RyaURI) RyaType(org.apache.rya.api.domain.RyaType) Type(org.apache.rya.indexing.entity.model.Type) Property(org.apache.rya.indexing.entity.model.Property)

Aggregations

RyaType (org.apache.rya.api.domain.RyaType)178 RyaURI (org.apache.rya.api.domain.RyaURI)146 RyaStatement (org.apache.rya.api.domain.RyaStatement)115 Test (org.junit.Test)109 BindingSet (org.openrdf.query.BindingSet)42 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)42 ArrayList (java.util.ArrayList)35 StatementPattern (org.openrdf.query.algebra.StatementPattern)35 ParsedQuery (org.openrdf.query.parser.ParsedQuery)35 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)35 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)34 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)34 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)28 Property (org.apache.rya.indexing.entity.model.Property)23 URIImpl (org.openrdf.model.impl.URIImpl)23 HashSet (java.util.HashSet)22 Entity (org.apache.rya.indexing.entity.model.Entity)20 Value (org.openrdf.model.Value)19 LiteralImpl (org.openrdf.model.impl.LiteralImpl)19 BatchWriter (org.apache.accumulo.core.client.BatchWriter)18