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);
}
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);
}
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);
;
}
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);
}
}
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);
}
Aggregations