use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.
the class FluoQueryMetadataDAOIT method fluoConstructQueryTest.
@Test
public void fluoConstructQueryTest() throws MalformedQueryException, UnsupportedQueryException {
final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
// Create the object that will be serialized.
final String sparql = "CONSTRUCT { ?customer <http://travelsTo> <http://England> . ?customer <http://friendsWith> ?worker }" + "WHERE { " + "FILTER(?customer = <http://Alice>) " + "FILTER(?city = <http://London>) " + "?customer <http://talksTo> ?worker. " + "?worker <http://livesIn> ?city. " + "?worker <http://worksAt> <http://Chipotle>. " + "}";
final SparqlFluoQueryBuilder builder = new SparqlFluoQueryBuilder();
builder.setSparql(sparql);
builder.setFluoQueryId(NodeType.generateNewFluoIdForType(NodeType.QUERY));
final FluoQuery originalQuery = builder.build();
assertEquals(QueryType.CONSTRUCT, originalQuery.getQueryType());
assertEquals(true, originalQuery.getConstructQueryMetadata().isPresent());
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
// Write it to the Fluo table.
try (Transaction tx = fluoClient.newTransaction()) {
dao.write(tx, originalQuery);
tx.commit();
}
// Read it from the Fluo table.
FluoQuery storedQuery = null;
try (Snapshot sx = fluoClient.newSnapshot()) {
storedQuery = dao.readFluoQuery(sx, originalQuery.getQueryMetadata().getNodeId());
}
// Ensure the deserialized object is the same as the serialized one.
assertEquals(originalQuery, storedQuery);
}
}
use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.
the class FluoQueryMetadataDAOIT method queryMetadataTest.
@Test
public void queryMetadataTest() {
final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
// Create the object that will be serialized.
final String queryId = NodeType.generateNewFluoIdForType(NodeType.QUERY);
final QueryMetadata.Builder builder = QueryMetadata.builder(queryId);
builder.setQueryType(QueryType.PROJECTION);
builder.setVarOrder(new VariableOrder("y;s;d"));
builder.setSparql("sparql string");
builder.setChildNodeId("childNodeId");
builder.setExportStrategies(new HashSet<>(Arrays.asList(ExportStrategy.KAFKA)));
final QueryMetadata originalMetadata = builder.build();
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
// Write it to the Fluo table.
try (Transaction tx = fluoClient.newTransaction()) {
dao.write(tx, originalMetadata);
tx.commit();
}
// Read it from the Fluo table.
QueryMetadata storedMetdata = null;
try (Snapshot sx = fluoClient.newSnapshot()) {
storedMetdata = dao.readQueryMetadata(sx, queryId);
}
// Ensure the deserialized object is the same as the serialized one.
assertEquals(originalMetadata, storedMetdata);
}
}
use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.
the class CountStatements method countStatements.
/**
* Get the number of RDF Statements that have been loaded into the Fluo app
* that have not been processed yet.
*
* @param fluo - The connection to Fluo that will be used to fetch the metadata. (not null)
* @return The number of RDF Statements that have been loaded into the Fluo
* app that have not been processed yet.
*/
public BigInteger countStatements(final FluoClient fluo) {
checkNotNull(fluo);
try (Snapshot sx = fluo.newSnapshot()) {
// Limit the scan to the Triples binding set column.
final Iterator<ColumnScanner> rows = sx.scanner().fetch(FluoQueryColumns.TRIPLES).byRow().build().iterator();
BigInteger count = BigInteger.valueOf(0L);
while (rows.hasNext()) {
rows.next();
count = count.add(BigInteger.ONE);
}
return count;
}
}
Aggregations