Search in sources :

Example 81 with RyaType

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

the class RyaSubGraphKafkaSerDeTest method serializationTestWithLiteral.

@Test
public void serializationTestWithLiteral() {
    RyaSubGraph bundle = new RyaSubGraph(UUID.randomUUID().toString());
    bundle.addStatement(new RyaStatement(new RyaURI("uri:123"), new RyaURI("uri:234"), new RyaType(XMLSchema.INTEGER, "345")));
    bundle.addStatement(new RyaStatement(new RyaURI("uri:345"), new RyaURI("uri:567"), new RyaType(XMLSchema.INTEGER, "789")));
    byte[] bundleBytes = serializer.toBytes(bundle);
    RyaSubGraph deserializedBundle = serializer.fromBytes(bundleBytes);
    assertEquals(bundle, deserializedBundle);
}
Also used : RyaSubGraph(org.apache.rya.api.domain.RyaSubGraph) RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

Example 82 with RyaType

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

the class FluoAndHistoricPcjsDemo method prettyFormat.

private static String prettyFormat(final RyaStatement statement) {
    final RyaURI s = statement.getSubject();
    final RyaURI p = statement.getPredicate();
    final RyaType o = statement.getObject();
    return "<" + s.getData() + "> <" + p.getData() + "> <" + o.getData() + ">";
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaType(org.apache.rya.api.domain.RyaType)

Example 83 with RyaType

use of org.apache.rya.api.domain.RyaType 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);
    }
}
Also used : TableLayoutStrategy(org.apache.rya.api.layout.TableLayoutStrategy) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) TriplePatternStrategy(org.apache.rya.api.query.strategy.TriplePatternStrategy) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaStatement(org.apache.rya.api.domain.RyaStatement) Text(org.apache.hadoop.io.Text) RyaRange(org.apache.rya.api.domain.RyaRange) RyaRange(org.apache.rya.api.domain.RyaRange) Range(org.apache.accumulo.core.data.Range) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaType(org.apache.rya.api.domain.RyaType) IOException(java.io.IOException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) RyaURI(org.apache.rya.api.domain.RyaURI) TripleRowRegex(org.apache.rya.api.resolver.triple.TripleRowRegex) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 84 with RyaType

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

the class AbstractTriplePatternStrategyTest method testObjectTypeInfo.

public void testObjectTypeInfo() throws Exception {
    RyaURI subj = new RyaURI("urn:test#1234");
    RyaURI pred = new RyaURI("urn:test#pred");
    RyaType obj = new RyaType(XMLSchema.LONG, "10");
    RyaStatement ryaStatement = new RyaStatement(subj, pred, obj);
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = RyaTripleContext.getInstance(new MockRdfConfiguration()).serializeTriple(ryaStatement);
    TripleRow tripleRow = serialize.get(SPO);
    String row = new String(tripleRow.getRow());
    TriplePatternStrategy spoStrategy = new SpoWholeRowTriplePatternStrategy();
    // obj
    byte[][] bytes = RyaContext.getInstance().serializeType(obj);
    String objStr = new String(bytes[0]);
    byte[] objectTypeInfo = bytes[1];
    TripleRowRegex tripleRowRegex = spoStrategy.buildRegex(null, null, objStr, null, objectTypeInfo);
    Pattern p = Pattern.compile(tripleRowRegex.getRow());
    Matcher matcher = p.matcher(row);
    assertTrue(matcher.matches());
    // build row with same object str data
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> dupTriple_str = RyaTripleContext.getInstance(new MockRdfConfiguration()).serializeTriple(new RyaStatement(subj, pred, new RyaType(XMLSchema.STRING, objStr)));
    TripleRow tripleRow_dup_str = dupTriple_str.get(SPO);
    row = new String(tripleRow_dup_str.getRow());
    spoStrategy = new SpoWholeRowTriplePatternStrategy();
    tripleRowRegex = spoStrategy.buildRegex(null, null, objStr, null, objectTypeInfo);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(row);
    assertFalse(matcher.matches());
    // po table
    TriplePatternStrategy poStrategy = new PoWholeRowTriplePatternStrategy();
    tripleRowRegex = poStrategy.buildRegex(null, null, objStr, null, objectTypeInfo);
    p = Pattern.compile(tripleRowRegex.getRow());
    String po_row = new String(serialize.get(PO).getRow());
    matcher = p.matcher(po_row);
    assertTrue(matcher.matches());
    tripleRowRegex = poStrategy.buildRegex(null, null, objStr, null, objectTypeInfo);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(new String(dupTriple_str.get(PO).getRow()));
    assertFalse(matcher.matches());
    // osp table
    TriplePatternStrategy ospStrategy = new OspWholeRowTriplePatternStrategy();
    tripleRowRegex = ospStrategy.buildRegex(null, null, objStr, null, objectTypeInfo);
    p = Pattern.compile(tripleRowRegex.getRow());
    String osp_row = new String(serialize.get(OSP).getRow());
    matcher = p.matcher(osp_row);
    assertTrue(matcher.matches());
    tripleRowRegex = ospStrategy.buildRegex(null, null, objStr, null, objectTypeInfo);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(new String(dupTriple_str.get(OSP).getRow()));
    assertFalse(matcher.matches());
}
Also used : PoWholeRowTriplePatternStrategy(org.apache.rya.api.query.strategy.wholerow.PoWholeRowTriplePatternStrategy) Pattern(java.util.regex.Pattern) SpoWholeRowTriplePatternStrategy(org.apache.rya.api.query.strategy.wholerow.SpoWholeRowTriplePatternStrategy) PoWholeRowTriplePatternStrategy(org.apache.rya.api.query.strategy.wholerow.PoWholeRowTriplePatternStrategy) OspWholeRowTriplePatternStrategy(org.apache.rya.api.query.strategy.wholerow.OspWholeRowTriplePatternStrategy) Matcher(java.util.regex.Matcher) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) RyaURI(org.apache.rya.api.domain.RyaURI) SpoWholeRowTriplePatternStrategy(org.apache.rya.api.query.strategy.wholerow.SpoWholeRowTriplePatternStrategy) OspWholeRowTriplePatternStrategy(org.apache.rya.api.query.strategy.wholerow.OspWholeRowTriplePatternStrategy) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) TripleRowRegex(org.apache.rya.api.resolver.triple.TripleRowRegex)

Example 85 with RyaType

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

the class AccumuloRyaDAOTest method testLiteralTypes.

@Test
public void testLiteralTypes() throws Exception {
    RyaURI cpu = new RyaURI(litdupsNS + "cpu");
    RyaURI loadPerc = new RyaURI(litdupsNS + "loadPerc");
    RyaType longLit = new RyaType(XMLSchema.LONG, "3");
    dao.add(new RyaStatement(cpu, loadPerc, longLit));
    AccumuloRyaQueryEngine queryEngine = dao.getQueryEngine();
    CloseableIteration<RyaStatement, RyaDAOException> query = queryEngine.query(new RyaStatement(cpu, null, null), conf);
    assertTrue(query.hasNext());
    RyaStatement next = query.next();
    assertEquals(new Long(longLit.getData()), new Long(next.getObject().getData()));
    query.close();
    RyaType doubleLit = new RyaType(XMLSchema.DOUBLE, "2.0");
    dao.add(new RyaStatement(cpu, loadPerc, doubleLit));
    query = queryEngine.query(new RyaStatement(cpu, loadPerc, doubleLit), conf);
    assertTrue(query.hasNext());
    next = query.next();
    assertEquals(Double.parseDouble(doubleLit.getData()), Double.parseDouble(next.getObject().getData()), 0.001);
    query.close();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

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