Search in sources :

Example 41 with RyaType

use of org.apache.rya.api.domain.RyaType 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 42 with RyaType

use of org.apache.rya.api.domain.RyaType 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 43 with RyaType

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

the class KafkaRyaSubGraphExportIT method nestedConstructQuery.

@Test
public void nestedConstructQuery() throws Exception {
    // A query that groups what is aggregated by one of the keys.
    final String sparql = "CONSTRUCT { " + "_:b a <urn:highSpeedTrafficArea> . " + "_:b <urn:hasCount> ?obsCount . " + "_:b <urn:hasLocation> ?location ." + "_:b <urn:hasAverageVelocity> ?avgVelocity ." + "} WHERE { " + "FILTER(?obsCount > 1) " + "{ " + "SELECT ?location (count(?obs) AS ?obsCount) (avg(?velocity) AS ?avgVelocity) " + "WHERE { " + "FILTER(?velocity > 75) " + "?obs <urn:hasVelocity> ?velocity. " + "?obs <urn:hasLocation> ?location. " + "}GROUP BY ?location }}";
    // Create the Statements that will be loaded into Rya.
    final ValueFactory vf = new ValueFactoryImpl();
    final Collection<Statement> statements = Sets.newHashSet(vf.createStatement(vf.createURI("urn:obs1"), vf.createURI("urn:hasVelocity"), vf.createLiteral(77)), vf.createStatement(vf.createURI("urn:obs1"), vf.createURI("urn:hasLocation"), vf.createLiteral("OldTown")), vf.createStatement(vf.createURI("urn:obs2"), vf.createURI("urn:hasVelocity"), vf.createLiteral(81)), vf.createStatement(vf.createURI("urn:obs2"), vf.createURI("urn:hasLocation"), vf.createLiteral("OldTown")), vf.createStatement(vf.createURI("urn:obs3"), vf.createURI("urn:hasVelocity"), vf.createLiteral(70)), vf.createStatement(vf.createURI("urn:obs3"), vf.createURI("urn:hasLocation"), vf.createLiteral("OldTown")), vf.createStatement(vf.createURI("urn:obs5"), vf.createURI("urn:hasVelocity"), vf.createLiteral(87)), vf.createStatement(vf.createURI("urn:obs5"), vf.createURI("urn:hasLocation"), vf.createLiteral("Rosslyn")), vf.createStatement(vf.createURI("urn:obs6"), vf.createURI("urn:hasVelocity"), vf.createLiteral(81)), vf.createStatement(vf.createURI("urn:obs6"), vf.createURI("urn:hasLocation"), vf.createLiteral("Rosslyn")), vf.createStatement(vf.createURI("urn:obs7"), vf.createURI("urn:hasVelocity"), vf.createLiteral(67)), vf.createStatement(vf.createURI("urn:obs7"), vf.createURI("urn:hasLocation"), vf.createLiteral("Clarendon")), vf.createStatement(vf.createURI("urn:obs8"), vf.createURI("urn:hasVelocity"), vf.createLiteral(77)), vf.createStatement(vf.createURI("urn:obs8"), vf.createURI("urn:hasLocation"), vf.createLiteral("Ballston")), vf.createStatement(vf.createURI("urn:obs9"), vf.createURI("urn:hasVelocity"), vf.createLiteral(87)), vf.createStatement(vf.createURI("urn:obs9"), vf.createURI("urn:hasLocation"), vf.createLiteral("FallsChurch")));
    // Create the PCJ in Fluo and load the statements into Rya.
    final String pcjId = loadStatements(sparql, statements);
    // Verify the end results of the query match the expected results.
    final Set<RyaSubGraph> results = readAllResults(pcjId);
    RyaStatement statement1 = new RyaStatement(new RyaURI("urn:obs1"), new RyaURI("urn:hasCount"), new RyaType(XMLSchema.INTEGER, "2"));
    RyaStatement statement2 = new RyaStatement(new RyaURI("urn:obs1"), new RyaURI("urn:hasAverageVelocity"), new RyaType(XMLSchema.DECIMAL, "84"));
    RyaStatement statement3 = new RyaStatement(new RyaURI("urn:obs1"), new RyaURI("urn:hasLocation"), new RyaType("Rosslyn"));
    RyaStatement statement4 = new RyaStatement(new RyaURI("urn:obs1"), new RyaURI(RDF.TYPE.toString()), new RyaURI("urn:highSpeedTrafficArea"));
    RyaStatement statement5 = new RyaStatement(new RyaURI("urn:obs2"), new RyaURI("urn:hasCount"), new RyaType(XMLSchema.INTEGER, "2"));
    RyaStatement statement6 = new RyaStatement(new RyaURI("urn:obs2"), new RyaURI("urn:hasAverageVelocity"), new RyaType(XMLSchema.DECIMAL, "79"));
    RyaStatement statement7 = new RyaStatement(new RyaURI("urn:obs2"), new RyaURI("urn:hasLocation"), new RyaType("OldTown"));
    RyaStatement statement8 = new RyaStatement(new RyaURI("urn:obs2"), new RyaURI(RDF.TYPE.toString()), new RyaURI("urn:highSpeedTrafficArea"));
    final Set<RyaSubGraph> expectedResults = new HashSet<>();
    RyaSubGraph subGraph1 = new RyaSubGraph(pcjId);
    Set<RyaStatement> stmnts1 = new HashSet<>(Arrays.asList(statement1, statement2, statement3, statement4));
    subGraph1.setStatements(stmnts1);
    expectedResults.add(subGraph1);
    RyaSubGraph subGraph2 = new RyaSubGraph(pcjId);
    Set<RyaStatement> stmnts2 = new HashSet<>(Arrays.asList(statement5, statement6, statement7, statement8));
    subGraph2.setStatements(stmnts2);
    expectedResults.add(subGraph2);
    Assert.assertEquals(expectedResults.size(), results.size());
    ConstructGraphTestUtils.subGraphsEqualIgnoresBlankNode(expectedResults, results);
    ;
}
Also used : RyaSubGraph(org.apache.rya.api.domain.RyaSubGraph) RyaURI(org.apache.rya.api.domain.RyaURI) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactory(org.openrdf.model.ValueFactory) RyaType(org.apache.rya.api.domain.RyaType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 44 with RyaType

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

the class AccumuloPcjSerializer method convert.

@Override
public byte[] convert(BindingSet bindingSet, VariableOrder varOrder) throws BindingSetConversionException {
    checkNotNull(bindingSet);
    checkNotNull(varOrder);
    // A list that holds all of the byte segments that will be concatenated at the end.
    // This minimizes byte[] construction.
    final List<byte[]> byteSegments = new LinkedList<>();
    try {
        for (final String varName : varOrder) {
            // Only write information for a variable name if the binding set contains it.
            if (bindingSet.hasBinding(varName)) {
                final RyaType rt = RdfToRyaConversions.convertValue(bindingSet.getBinding(varName).getValue());
                final byte[][] serializedVal = RyaContext.getInstance().serializeType(rt);
                byteSegments.add(serializedVal[0]);
                byteSegments.add(serializedVal[1]);
            }
            // But always write the value delimiter. If a value is missing, you'll see two delimiters next to each-other.
            byteSegments.add(DELIM_BYTES);
        }
        return concat(byteSegments);
    } catch (RyaTypeResolverException e) {
        throw new BindingSetConversionException("Could not convert the BindingSet into a byte[].", e);
    }
}
Also used : RyaTypeResolverException(org.apache.rya.api.resolver.RyaTypeResolverException) RyaType(org.apache.rya.api.domain.RyaType) LinkedList(java.util.LinkedList)

Example 45 with RyaType

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

the class AccumuloPcjSerializer method deserializeValue.

private static Value deserializeValue(byte[] byteVal) throws RyaTypeResolverException {
    final int typeIndex = Bytes.indexOf(byteVal, TYPE_DELIM_BYTE);
    checkArgument(typeIndex >= 0);
    final byte[] data = Arrays.copyOf(byteVal, typeIndex);
    final byte[] type = Arrays.copyOfRange(byteVal, typeIndex, byteVal.length);
    final RyaType rt = RyaContext.getInstance().deserialize(Bytes.concat(data, type));
    return RyaToRdfConversions.convertValue(rt);
}
Also used : RyaType(org.apache.rya.api.domain.RyaType)

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