Search in sources :

Example 21 with TripleRow

use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.

the class HashedPoWholeRowTriplePatternStrategyTest method testPoRange.

public void testPoRange() throws Exception {
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
    TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, uri, rangeURI, null, null);
    assertContains(entry.getValue(), tripleRow.getRow());
    entry = strategy.defineRange(null, uri, rangeURI2, null, null);
    assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
Also used : TripleRow(org.apache.rya.api.resolver.triple.TripleRow) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaStatement(org.apache.rya.api.domain.RyaStatement) Map(java.util.Map)

Example 22 with TripleRow

use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.

the class HashedPoWholeRowTriplePatternStrategyTest method testPosRange.

public void testPosRange() throws Exception {
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
    TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(rangeURI, uri, uri, null, null);
    assertContains(entry.getValue(), tripleRow.getRow());
    entry = strategy.defineRange(rangeURI2, uri, uri, null, null);
    assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
Also used : TripleRow(org.apache.rya.api.resolver.triple.TripleRow) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaStatement(org.apache.rya.api.domain.RyaStatement) Map(java.util.Map)

Example 23 with TripleRow

use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.

the class HashedPoWholeRowTriplePatternStrategyTest method testPoRangeCustomType.

public void testPoRangeCustomType() throws Exception {
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, customType1, null));
    TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, uri, customTypeRange1, null, null);
    assertContains(entry.getValue(), tripleRow.getRow());
    entry = strategy.defineRange(null, uri, customTypeRange2, null, null);
    assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
Also used : TripleRow(org.apache.rya.api.resolver.triple.TripleRow) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaStatement(org.apache.rya.api.domain.RyaStatement) Map(java.util.Map)

Example 24 with TripleRow

use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.

the class HashedPoWholeRowTriplePatternStrategyTest method testRegex.

public void testRegex() throws Exception {
    RyaURI subj = new RyaURI("urn:test#1234");
    RyaURI pred = new RyaURI("urn:test#pred");
    RyaURI obj = new RyaURI("urn:test#obj");
    RyaStatement ryaStatement = new RyaStatement(subj, pred, obj);
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = new WholeRowHashedTripleResolver().serialize(ryaStatement);
    TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
    String row = new String(tripleRow.getRow());
    TriplePatternStrategy spoStrategy = new HashedSpoWholeRowTriplePatternStrategy();
    TriplePatternStrategy poStrategy = new HashedPoWholeRowTriplePatternStrategy();
    TriplePatternStrategy ospStrategy = new OspWholeRowTriplePatternStrategy();
    // pred
    TripleRowRegex tripleRowRegex = spoStrategy.buildRegex(null, pred.getData(), null, null, null);
    Pattern p = Pattern.compile(tripleRowRegex.getRow());
    Matcher matcher = p.matcher(row);
    assertTrue(matcher.matches());
    // subj
    tripleRowRegex = spoStrategy.buildRegex(subj.getData(), null, null, null, null);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(row);
    assertTrue(matcher.matches());
    // obj
    tripleRowRegex = spoStrategy.buildRegex(null, null, obj.getData(), null, null);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(row);
    assertTrue(matcher.matches());
    // po table
    row = new String(serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO).getRow());
    tripleRowRegex = poStrategy.buildRegex(null, pred.getData(), null, null, null);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(row);
    assertTrue(matcher.matches());
    tripleRowRegex = poStrategy.buildRegex(null, pred.getData(), obj.getData(), null, null);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(row);
    assertTrue(matcher.matches());
    tripleRowRegex = poStrategy.buildRegex(subj.getData(), pred.getData(), obj.getData(), null, null);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(row);
    assertTrue(matcher.matches());
    // various regex
    tripleRowRegex = poStrategy.buildRegex(null, "urn:test#pr[e|d]{2}", null, null, null);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(row);
    assertTrue(matcher.matches());
    // does not match
    tripleRowRegex = poStrategy.buildRegex(null, "hello", null, null, null);
    p = Pattern.compile(tripleRowRegex.getRow());
    matcher = p.matcher(row);
    assertFalse(matcher.matches());
}
Also used : Pattern(java.util.regex.Pattern) TriplePatternStrategy(org.apache.rya.api.query.strategy.TriplePatternStrategy) Matcher(java.util.regex.Matcher) WholeRowHashedTripleResolver(org.apache.rya.api.resolver.triple.impl.WholeRowHashedTripleResolver) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaURI(org.apache.rya.api.domain.RyaURI) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) TripleRowRegex(org.apache.rya.api.resolver.triple.TripleRowRegex)

Example 25 with TripleRow

use of org.apache.rya.api.resolver.triple.TripleRow in project incubator-rya by apache.

the class RyaSubGraphExporter method spoFormat.

/**
 * Converts a triple into a byte[] holding the Rya SPO representation of it.
 *
 * @param triple - The triple to convert. (not null)
 * @return The Rya SPO representation of the triple.
 * @throws TripleRowResolverException The triple could not be converted.
 */
private static Bytes spoFormat(final RyaStatement triple) throws TripleRowResolverException {
    checkNotNull(triple);
    final Map<TABLE_LAYOUT, TripleRow> serialized = TRIPLE_RESOLVER.serialize(triple);
    final TripleRow spoRow = serialized.get(TABLE_LAYOUT.SPO);
    return addTriplePrefixAndConvertToBytes(spoRow.getRow());
}
Also used : TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow)

Aggregations

TripleRow (org.apache.rya.api.resolver.triple.TripleRow)55 RyaStatement (org.apache.rya.api.domain.RyaStatement)42 RyaURI (org.apache.rya.api.domain.RyaURI)21 Map (java.util.Map)19 TABLE_LAYOUT (org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT)17 Key (org.apache.accumulo.core.data.Key)14 Value (org.apache.accumulo.core.data.Value)13 ByteRange (org.apache.rya.api.query.strategy.ByteRange)13 TripleRowResolverException (org.apache.rya.api.resolver.triple.TripleRowResolverException)13 RyaType (org.apache.rya.api.domain.RyaType)11 RdfCloudTripleStoreConstants (org.apache.rya.api.RdfCloudTripleStoreConstants)8 Test (org.junit.Test)8 IOException (java.io.IOException)7 Text (org.apache.hadoop.io.Text)7 Mutation (org.apache.accumulo.core.data.Mutation)6 Scanner (org.apache.accumulo.core.client.Scanner)5 Authorizations (org.apache.accumulo.core.security.Authorizations)5 IntWritable (org.apache.hadoop.io.IntWritable)5 HashMap (java.util.HashMap)4 BatchWriter (org.apache.accumulo.core.client.BatchWriter)4