Search in sources :

Example 56 with RyaURI

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

the class CountPlan method map.

@Override
public Collection<Map.Entry<IntermediateProspect, LongWritable>> map(final RyaStatement ryaStatement) {
    final RyaURI subject = ryaStatement.getSubject();
    final RyaURI predicate = ryaStatement.getPredicate();
    final String subjpred = ryaStatement.getSubject().getData() + DELIM + ryaStatement.getPredicate().getData();
    final String predobj = ryaStatement.getPredicate().getData() + DELIM + ryaStatement.getObject().getData();
    final String subjobj = ryaStatement.getSubject().getData() + DELIM + ryaStatement.getObject().getData();
    final RyaType object = ryaStatement.getObject();
    final int localIndex = URIUtil.getLocalNameIndex(subject.getData());
    final String namespace = subject.getData().substring(0, localIndex - 1);
    final String visibility = new String(ryaStatement.getColumnVisibility(), StandardCharsets.UTF_8);
    final List<Map.Entry<IntermediateProspect, LongWritable>> entries = new ArrayList<>(7);
    // Create an entry for each TripleValueType type.
    entries.add(new CustomEntry<IntermediateProspect, LongWritable>(IntermediateProspect.builder().setIndex(COUNT).setData(subject.getData()).setDataType(URITYPE).setTripleValueType(TripleValueType.SUBJECT).setVisibility(visibility).build(), ONE));
    entries.add(new CustomEntry<IntermediateProspect, LongWritable>(IntermediateProspect.builder().setIndex(COUNT).setData(predicate.getData()).setDataType(URITYPE).setTripleValueType(TripleValueType.PREDICATE).setVisibility(visibility).build(), ONE));
    entries.add(new CustomEntry<IntermediateProspect, LongWritable>(IntermediateProspect.builder().setIndex(COUNT).setData(object.getData()).setDataType(object.getDataType().stringValue()).setTripleValueType(TripleValueType.OBJECT).setVisibility(visibility).build(), ONE));
    entries.add(new CustomEntry<IntermediateProspect, LongWritable>(IntermediateProspect.builder().setIndex(COUNT).setData(subjpred).setDataType(XMLSchema.STRING.toString()).setTripleValueType(TripleValueType.SUBJECT_PREDICATE).setVisibility(visibility).build(), ONE));
    entries.add(new CustomEntry<IntermediateProspect, LongWritable>(IntermediateProspect.builder().setIndex(COUNT).setData(subjobj).setDataType(XMLSchema.STRING.toString()).setTripleValueType(TripleValueType.SUBJECT_OBJECT).setVisibility(visibility).build(), ONE));
    entries.add(new CustomEntry<IntermediateProspect, LongWritable>(IntermediateProspect.builder().setIndex(COUNT).setData(predobj).setDataType(XMLSchema.STRING.toString()).setTripleValueType(TripleValueType.PREDICATE_OBJECT).setVisibility(visibility).build(), ONE));
    entries.add(new CustomEntry<IntermediateProspect, LongWritable>(IntermediateProspect.builder().setIndex(COUNT).setData(namespace).setDataType(URITYPE).setTripleValueType(TripleValueType.ENTITY).setVisibility(visibility).build(), ONE));
    return entries;
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) IndexEntry(org.apache.rya.prospector.domain.IndexEntry) CustomEntry(org.apache.rya.prospector.utils.CustomEntry) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) IntermediateProspect(org.apache.rya.prospector.domain.IntermediateProspect) LongWritable(org.apache.hadoop.io.LongWritable) RyaType(org.apache.rya.api.domain.RyaType)

Example 57 with RyaURI

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

the class JoinSelectStatisticsTest method testMap3.

@Test
public void testMap3() throws Exception {
    init();
    System.out.println("*************************Test3**************************** ");
    BatchWriter bw_table1 = c.createBatchWriter("rya_spo", new BatchWriterConfig());
    for (int i = 1; i < 3; i++) {
        for (int j = 1; j < 3; j++) {
            for (int k = 1; k < 3; k++) {
                RyaStatement rs = new RyaStatement(new RyaURI(uri + i), new RyaURI(uri + (j)), new RyaType(uri + k));
                Map<TABLE_LAYOUT, TripleRow> tripleRowMap = ryaContext.serializeTriple(rs);
                TripleRow tripleRow = tripleRowMap.get(TABLE_LAYOUT.SPO);
                Mutation m = JoinSelectStatsUtil.createMutation(tripleRow);
                bw_table1.addMutation(m);
            }
        }
    }
    bw_table1.close();
    BatchWriter bw_table2 = c.createBatchWriter("rya_prospects", new BatchWriterConfig());
    for (int i = 1; i < 3; i++) {
        int k = 1;
        for (String s : cardList) {
            Mutation m = new Mutation(new Text(s + DELIM + uri + i + DELIM + i));
            m.put(new Text(), new Text(), new Value(new IntWritable(i + k).toString().getBytes()));
            bw_table2.addMutation(m);
            k++;
        }
        for (int j = 1; j < 3; j++) {
            k = 1;
            for (String s : aggCardList) {
                Mutation m = new Mutation(new Text(s + DELIM + uri + i + DELIM + uri + j + DELIM + i));
                m.put(new Text(), new Text(), new Value(new IntWritable(i + k + j).toString().getBytes()));
                bw_table2.addMutation(m);
                k++;
            }
        }
    }
    bw_table2.close();
    Assert.assertEquals(0, ToolRunner.run(new JoinSelectTestDriver(), new String[] { "" }));
    Scanner scan = c.createScanner("rya_selectivity", new Authorizations());
    scan.setRange(new Range());
    for (Map.Entry<Key, Value> entry : scan) {
        System.out.println("Key row string is " + entry.getKey().getRow().toString());
        System.out.println("Join type is " + entry.getKey().getColumnFamily().toString());
        System.out.println("Value is " + entry.getKey().getColumnQualifier().toString());
    }
    Scanner scan1 = c.createScanner("rya_selectivity", new Authorizations());
    scan1.setRange(Range.prefix("subject" + DELIM + uri + 1));
    int i = 0;
    for (Map.Entry<Key, Value> entry : scan1) {
        Key key = entry.getKey();
        String s = key.getColumnFamily().toString();
        int val = Integer.parseInt(key.getColumnQualifier().toString());
        if (s.equals("predicatepredicate")) {
            Assert.assertTrue(val == 14);
        }
        if (s.equals("objectobject")) {
            Assert.assertTrue(val == 18);
        }
        if (s.equals("predicateobjectpredicateobject")) {
            Assert.assertTrue(val == 28);
        }
        if (s.equals("predicateobjectsubjectpredicate")) {
            Assert.assertTrue(val == 20);
        }
        if (s.equals("predicateobjectobjectsubject")) {
            Assert.assertTrue(val == 16);
        }
        i++;
    }
    Assert.assertTrue(i == 12);
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) RyaStatement(org.apache.rya.api.domain.RyaStatement) Text(org.apache.hadoop.io.Text) RyaType(org.apache.rya.api.domain.RyaType) Range(org.apache.accumulo.core.data.Range) RyaURI(org.apache.rya.api.domain.RyaURI) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Map(java.util.Map) IntWritable(org.apache.hadoop.io.IntWritable) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 58 with RyaURI

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

the class ProspectorServiceEvalStatsDAOTest method testNoAuthsCount.

@Test
public void testNoAuthsCount() throws Exception {
    // Load some data into a mock Accumulo and run the Prospector MapReduce job.
    final Instance mock = new MockInstance("accumulo");
    final Connector connector = mock.getConnector("user", new PasswordToken("pass"));
    final String outtable = "rya_prospects";
    if (connector.tableOperations().exists(outtable)) {
        connector.tableOperations().delete(outtable);
    }
    connector.tableOperations().create(outtable);
    connector.securityOperations().createUser("user", "pass".getBytes(), new Authorizations("U", "FOUO"));
    final AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO();
    ryaDAO.setConnector(connector);
    ryaDAO.init();
    ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata1")));
    ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata2")));
    ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("12")));
    ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred"), new RyaType(XMLSchema.INTEGER, "12")));
    ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred1"), new RyaType("12")));
    final String confFile = "stats_cluster_config.xml";
    final Path confPath = new Path(getClass().getClassLoader().getResource(confFile).toString());
    final String[] args = { confPath.toString() };
    ToolRunner.run(new Prospector(), args);
    ryaDAO.destroy();
    final Configuration conf = new Configuration();
    conf.addResource(confPath);
    final AccumuloRdfConfiguration rdfConf = new AccumuloRdfConfiguration(conf);
    final ProspectorServiceEvalStatsDAO evalDao = new ProspectorServiceEvalStatsDAO(connector, rdfConf);
    evalDao.init();
    // Get the cardinality of the 'urn:gem#pred' predicate.
    List<Value> values = new ArrayList<Value>();
    values.add(new URIImpl("urn:gem#pred"));
    double count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.PREDICATE, values);
    assertEquals(4.0, count, 0.001);
    // Get the cardinality of the 'mydata1' object.
    values = new ArrayList<Value>();
    values.add(new LiteralImpl("mydata1"));
    count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values);
    assertEquals(1.0, count, 0.001);
    // Get the cardinality of the 'mydata3' object.
    values = new ArrayList<Value>();
    values.add(new LiteralImpl("mydata3"));
    count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values);
    assertEquals(-1.0, count, 0.001);
}
Also used : Path(org.apache.hadoop.fs.Path) Connector(org.apache.accumulo.core.client.Connector) AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) Authorizations(org.apache.accumulo.core.security.Authorizations) Configuration(org.apache.hadoop.conf.Configuration) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Instance(org.apache.accumulo.core.client.Instance) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) URIImpl(org.openrdf.model.impl.URIImpl) RyaType(org.apache.rya.api.domain.RyaType) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) RyaURI(org.apache.rya.api.domain.RyaURI) LiteralImpl(org.openrdf.model.impl.LiteralImpl) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Prospector(org.apache.rya.prospector.mr.Prospector) Value(org.openrdf.model.Value) Test(org.junit.Test)

Example 59 with RyaURI

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

the class ProspectorServiceEvalStatsDAOTest method testCount.

@Test
public void testCount() throws Exception {
    // Load some data into a mock Accumulo and run the Prospector MapReduce job.
    final Instance mock = new MockInstance("accumulo");
    final Connector connector = mock.getConnector("user", new PasswordToken("pass"));
    final String outtable = "rya_prospects";
    if (connector.tableOperations().exists(outtable)) {
        connector.tableOperations().delete(outtable);
    }
    connector.tableOperations().create(outtable);
    final AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO();
    ryaDAO.setConnector(connector);
    ryaDAO.init();
    ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata1")));
    ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("mydata2")));
    ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1234"), new RyaURI("urn:gem#pred"), new RyaType("12")));
    ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred"), new RyaType(XMLSchema.INTEGER, "12")));
    ryaDAO.add(new RyaStatement(new RyaURI("urn:gem:etype#1235"), new RyaURI("urn:gem#pred1"), new RyaType("12")));
    final String confFile = "stats_cluster_config.xml";
    final Path confPath = new Path(getClass().getClassLoader().getResource(confFile).toString());
    final String[] args = { confPath.toString() };
    ToolRunner.run(new Prospector(), args);
    ryaDAO.destroy();
    final Configuration conf = new Configuration();
    conf.addResource(confPath);
    final AccumuloRdfConfiguration rdfConf = new AccumuloRdfConfiguration(conf);
    rdfConf.setAuths("U", "FOUO");
    final ProspectorServiceEvalStatsDAO evalDao = new ProspectorServiceEvalStatsDAO(connector, rdfConf);
    evalDao.init();
    // Get the cardinality of the 'urn:gem#pred' predicate.
    List<Value> values = new ArrayList<Value>();
    values.add(new URIImpl("urn:gem#pred"));
    double count = evalDao.getCardinality(rdfConf, CARDINALITY_OF.PREDICATE, values);
    assertEquals(4.0, count, 0.001);
    // Get the cardinality of the 'mydata1' object.
    values = new ArrayList<Value>();
    values.add(new LiteralImpl("mydata1"));
    count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values);
    assertEquals(1.0, count, 0.001);
    // Get the cardinality of the 'mydata3' object.
    values = new ArrayList<Value>();
    values.add(new LiteralImpl("mydata3"));
    count = evalDao.getCardinality(rdfConf, RdfEvalStatsDAO.CARDINALITY_OF.OBJECT, values);
    assertEquals(-1.0, count, 0.001);
}
Also used : Path(org.apache.hadoop.fs.Path) Connector(org.apache.accumulo.core.client.Connector) AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) Configuration(org.apache.hadoop.conf.Configuration) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Instance(org.apache.accumulo.core.client.Instance) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) URIImpl(org.openrdf.model.impl.URIImpl) RyaType(org.apache.rya.api.domain.RyaType) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) RyaURI(org.apache.rya.api.domain.RyaURI) LiteralImpl(org.openrdf.model.impl.LiteralImpl) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Prospector(org.apache.rya.prospector.mr.Prospector) Value(org.openrdf.model.Value) Test(org.junit.Test)

Example 60 with RyaURI

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

the class MongoDBRyaDAOIT method buildVisibilityTestRyaStatement.

private static RyaStatement buildVisibilityTestRyaStatement(final String documentVisibility) {
    final RyaStatementBuilder builder = new RyaStatementBuilder();
    builder.setPredicate(new RyaURI("http://temp.com"));
    builder.setSubject(new RyaURI("http://subject.com"));
    builder.setObject(new RyaURI("http://object.com"));
    builder.setContext(new RyaURI("http://context.com"));
    builder.setColumnVisibility(documentVisibility != null ? documentVisibility.getBytes() : null);
    final RyaStatement statement = builder.build();
    return statement;
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) RyaStatement(org.apache.rya.api.domain.RyaStatement)

Aggregations

RyaURI (org.apache.rya.api.domain.RyaURI)287 Test (org.junit.Test)190 RyaStatement (org.apache.rya.api.domain.RyaStatement)183 RyaType (org.apache.rya.api.domain.RyaType)146 BindingSet (org.openrdf.query.BindingSet)56 ArrayList (java.util.ArrayList)52 StatementPattern (org.openrdf.query.algebra.StatementPattern)50 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)49 HashSet (java.util.HashSet)43 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)43 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)42 ParsedQuery (org.openrdf.query.parser.ParsedQuery)42 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)42 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)35 Entity (org.apache.rya.indexing.entity.model.Entity)30 Property (org.apache.rya.indexing.entity.model.Property)28 URIImpl (org.openrdf.model.impl.URIImpl)25 EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)22 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)21 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)21