Search in sources :

Example 1 with WholeRowTripleResolver

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

the class JoinSelectMapperTest method testOutput.

@Test
public void testOutput() throws TripleRowResolverException, IOException {
    RyaStatement rya = new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata1"));
    Text s = new Text(rya.getSubject().getData());
    Text p = new Text(rya.getPredicate().getData());
    Text o = new Text(rya.getObject().getData());
    Text sp = new Text(rya.getSubject().getData() + DELIM + rya.getPredicate().getData());
    Text so = new Text(rya.getSubject().getData() + DELIM + rya.getObject().getData());
    Text po = new Text(rya.getPredicate().getData() + DELIM + rya.getObject().getData());
    Text ps = new Text(rya.getPredicate().getData() + DELIM + rya.getSubject().getData());
    Text op = new Text(rya.getObject().getData() + DELIM + rya.getPredicate().getData());
    Text os = new Text(rya.getObject().getData() + DELIM + rya.getSubject().getData());
    TripleEntry t1 = new TripleEntry(s, p, new Text("subject"), new Text("predicate"), new Text("object"));
    TripleEntry t2 = new TripleEntry(p, o, new Text("predicate"), new Text("object"), new Text("subject"));
    TripleEntry t3 = new TripleEntry(o, s, new Text("object"), new Text("subject"), new Text("predicate"));
    TripleEntry t4 = new TripleEntry(o, new Text(""), new Text("object"), new Text(""), new Text("subjectpredicate"));
    TripleEntry t5 = new TripleEntry(p, new Text(""), new Text("predicate"), new Text(""), new Text("objectsubject"));
    TripleEntry t6 = new TripleEntry(s, new Text(""), new Text("subject"), new Text(""), new Text("predicateobject"));
    TripleEntry t7 = new TripleEntry(s, new Text(""), new Text("subject"), new Text(""), new Text("objectpredicate"));
    TripleEntry t8 = new TripleEntry(p, new Text(""), new Text("predicate"), new Text(""), new Text("subjectobject"));
    TripleEntry t9 = new TripleEntry(o, new Text(""), new Text("object"), new Text(""), new Text("predicatesubject"));
    TripleRowResolver trr = new WholeRowTripleResolver();
    Map<TABLE_LAYOUT, TripleRow> map = trr.serialize(rya);
    System.out.println(map);
    TripleRow tr = map.get(TABLE_LAYOUT.SPO);
    System.out.println("Triple row is" + tr);
    System.out.println("ColumnV is " + tr.getTimestamp());
    byte[] b = new byte[0];
    Key key = new Key(tr.getRow(), tr.getColumnFamily(), tr.getColumnQualifier(), b, 1);
    Value val = new Value(b);
    new MapDriver<Key, Value, CompositeType, TripleCard>().withMapper(new JoinSelectSpoTableOutput.JoinSelectMapper()).withInput(key, val).withOutput(new CompositeType(o, new IntWritable(2)), new TripleCard(t1)).withOutput(new CompositeType(s, new IntWritable(2)), new TripleCard(t2)).withOutput(new CompositeType(p, new IntWritable(2)), new TripleCard(t3)).withOutput(new CompositeType(po, new IntWritable(2)), new TripleCard(t6)).withOutput(new CompositeType(so, new IntWritable(2)), new TripleCard(t5)).withOutput(new CompositeType(sp, new IntWritable(2)), new TripleCard(t4)).withOutput(new CompositeType(op, new IntWritable(2)), new TripleCard(t7)).withOutput(new CompositeType(os, new IntWritable(2)), new TripleCard(t8)).withOutput(new CompositeType(ps, new IntWritable(2)), new TripleCard(t9)).runTest();
}
Also used : TripleRowResolver(org.apache.rya.api.resolver.triple.TripleRowResolver) MapDriver(org.apache.hadoop.mrunit.mapreduce.MapDriver) RyaStatement(org.apache.rya.api.domain.RyaStatement) Text(org.apache.hadoop.io.Text) RyaType(org.apache.rya.api.domain.RyaType) TripleCard(org.apache.rya.joinselect.mr.utils.TripleCard) RyaURI(org.apache.rya.api.domain.RyaURI) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) WholeRowTripleResolver(org.apache.rya.api.resolver.triple.impl.WholeRowTripleResolver) Value(org.apache.accumulo.core.data.Value) TripleEntry(org.apache.rya.joinselect.mr.utils.TripleEntry) Key(org.apache.accumulo.core.data.Key) IntWritable(org.apache.hadoop.io.IntWritable) CompositeType(org.apache.rya.joinselect.mr.utils.CompositeType) Test(org.junit.Test)

Example 2 with WholeRowTripleResolver

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

the class AbstractTriplePatternStrategyTest 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 WholeRowTripleResolver().serialize(ryaStatement);
    TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
    String row = new String(tripleRow.getRow());
    TriplePatternStrategy spoStrategy = new SpoWholeRowTriplePatternStrategy();
    TriplePatternStrategy poStrategy = new PoWholeRowTriplePatternStrategy();
    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 : 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) 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) WholeRowTripleResolver(org.apache.rya.api.resolver.triple.impl.WholeRowTripleResolver)

Example 3 with WholeRowTripleResolver

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

the class AccumuloLoadStatementsFileIT method loadTurtleFile.

@Test
public void loadTurtleFile() throws Exception {
    // Install an instance of Rya.
    final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(false).setEnableEntityCentricIndex(false).setEnableFreeTextIndex(false).setEnableTemporalIndex(false).setEnablePcjIndex(false).setEnableGeoIndex(false).setFluoPcjAppName("fluo_app_name").build();
    final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(getUsername(), getPassword().toCharArray(), getInstanceName(), getZookeepers());
    final RyaClient ryaClient = AccumuloRyaClientFactory.build(connectionDetails, getConnector());
    final Install install = ryaClient.getInstall();
    install.install(getRyaInstanceName(), installConfig);
    // Load the test statement file.
    ryaClient.getLoadStatementsFile().loadStatements(getRyaInstanceName(), Paths.get("src/test/resources/example.ttl"), RDFFormat.TURTLE);
    // Verify that the statements were loaded.
    final ValueFactory vf = new ValueFactoryImpl();
    final List<Statement> expected = new ArrayList<>();
    expected.add(vf.createStatement(vf.createURI("http://example#alice"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#bob")));
    expected.add(vf.createStatement(vf.createURI("http://example#bob"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#charlie")));
    expected.add(vf.createStatement(vf.createURI("http://example#charlie"), vf.createURI("http://example#likes"), vf.createURI("http://example#icecream")));
    final List<Statement> statements = new ArrayList<>();
    final WholeRowTripleResolver tripleResolver = new WholeRowTripleResolver();
    final Scanner scanner = getConnector().createScanner(getRyaInstanceName() + "spo", new Authorizations());
    final Iterator<Entry<Key, Value>> it = scanner.iterator();
    while (it.hasNext()) {
        final Entry<Key, Value> next = it.next();
        final Key key = next.getKey();
        final byte[] row = key.getRow().getBytes();
        final byte[] columnFamily = key.getColumnFamily().getBytes();
        final byte[] columnQualifier = key.getColumnQualifier().getBytes();
        final TripleRow tripleRow = new TripleRow(row, columnFamily, columnQualifier);
        final RyaStatement ryaStatement = tripleResolver.deserialize(TABLE_LAYOUT.SPO, tripleRow);
        final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
        // Filter out the rya version statement if it is present.
        if (!isRyaMetadataStatement(vf, statement)) {
            statements.add(statement);
        }
    }
    assertEquals(expected, statements);
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) Entry(java.util.Map.Entry) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) WholeRowTripleResolver(org.apache.rya.api.resolver.triple.impl.WholeRowTripleResolver) Value(org.apache.accumulo.core.data.Value) Install(org.apache.rya.api.client.Install) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 4 with WholeRowTripleResolver

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

the class DuplicateEliminationTest method testTableMapperOutput.

@Test
public void testTableMapperOutput() throws Exception {
    RyaStatement rya = TestUtils.ryaStatement("x", "subOrganizationOf", "y");
    TripleRowResolver trr = new WholeRowTripleResolver();
    Map<TABLE_LAYOUT, TripleRow> map = trr.serialize(rya);
    TripleRow tr = map.get(TABLE_LAYOUT.SPO);
    byte[] b = new byte[0];
    Key key = new Key(tr.getRow(), tr.getColumnFamily(), tr.getColumnQualifier(), b, 1);
    Value val = new Value(b);
    new MapDriver<Key, Value, Fact, Derivation>().withMapper(new DuplicateElimination.DuplicateTableMapper()).withInput(key, val).withOutput(X_SUB_Y, X_SUB_Y.getDerivation()).runTest();
}
Also used : TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRowResolver(org.apache.rya.api.resolver.triple.TripleRowResolver) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) MapDriver(org.apache.hadoop.mrunit.mapreduce.MapDriver) WholeRowTripleResolver(org.apache.rya.api.resolver.triple.impl.WholeRowTripleResolver) Value(org.apache.accumulo.core.data.Value) RyaStatement(org.apache.rya.api.domain.RyaStatement) Key(org.apache.accumulo.core.data.Key) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with WholeRowTripleResolver

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

the class ForwardChainTest method testTableMapperOutput.

@Test
public void testTableMapperOutput() throws Exception {
    RyaStatement rya = TestUtils.ryaStatement("x", "subOrganizationOf", "y");
    TripleRowResolver trr = new WholeRowTripleResolver();
    Map<TABLE_LAYOUT, TripleRow> map = trr.serialize(rya);
    TripleRow tr = map.get(TABLE_LAYOUT.SPO);
    byte[] b = new byte[0];
    Key key = new Key(tr.getRow(), tr.getColumnFamily(), tr.getColumnQualifier(), b, 1);
    Value val = new Value(b);
    ResourceWritable rw1 = new ResourceWritable();
    ResourceWritable rw2 = new ResourceWritable();
    rw1.set(TestUtils.uri("x"));
    rw2.set(TestUtils.uri("y"));
    new MapDriver<Key, Value, ResourceWritable, Fact>().withMapper(new ForwardChain.TableMapper(schema)).withInput(key, val).withOutput(rw1, X_SUB_Y).withOutput(rw2, X_SUB_Y).runTest();
}
Also used : TripleRowResolver(org.apache.rya.api.resolver.triple.TripleRowResolver) RyaStatement(org.apache.rya.api.domain.RyaStatement) Fact(org.apache.rya.reasoning.Fact) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) WholeRowTripleResolver(org.apache.rya.api.resolver.triple.impl.WholeRowTripleResolver) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

RyaStatement (org.apache.rya.api.domain.RyaStatement)5 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)5 WholeRowTripleResolver (org.apache.rya.api.resolver.triple.impl.WholeRowTripleResolver)5 Key (org.apache.accumulo.core.data.Key)4 Value (org.apache.accumulo.core.data.Value)4 Test (org.junit.Test)4 TABLE_LAYOUT (org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT)3 TripleRowResolver (org.apache.rya.api.resolver.triple.TripleRowResolver)3 MapDriver (org.apache.hadoop.mrunit.mapreduce.MapDriver)2 RyaURI (org.apache.rya.api.domain.RyaURI)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Scanner (org.apache.accumulo.core.client.Scanner)1 Authorizations (org.apache.accumulo.core.security.Authorizations)1 IntWritable (org.apache.hadoop.io.IntWritable)1 Text (org.apache.hadoop.io.Text)1 Install (org.apache.rya.api.client.Install)1