use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.
the class GetQueryReport method getReport.
/**
* Get a report that indicates how many biniding sets have been emitted for
* a query that is being managed by the fluo application.
*
* @param fluo - The connection to Fluo that will be used to fetch the metadata. (not null)
* @param queryId - The ID of the query to fetch. (not null)
* @return A report that was built for the query.
* @throws UnsupportedQueryException
*/
public QueryReport getReport(final FluoClient fluo, final String queryId) throws UnsupportedQueryException {
checkNotNull(fluo);
checkNotNull(queryId);
final QueryReport.Builder reportBuilder = QueryReport.builder();
try (Snapshot sx = fluo.newSnapshot()) {
final FluoQuery fluoQuery = metadataDao.readFluoQuery(sx, queryId);
reportBuilder.setFluoQuery(fluoQuery);
// Query results.
BigInteger count = countBindingSets(sx, queryId, FluoQueryColumns.QUERY_BINDING_SET);
reportBuilder.setCount(queryId, count);
// Filter results.
for (final FilterMetadata filter : fluoQuery.getFilterMetadata()) {
final String filterId = filter.getNodeId();
count = countBindingSets(sx, filterId, FluoQueryColumns.FILTER_BINDING_SET);
reportBuilder.setCount(filterId, count);
}
// Join results.
for (final JoinMetadata join : fluoQuery.getJoinMetadata()) {
final String joinId = join.getNodeId();
count = countBindingSets(sx, joinId, FluoQueryColumns.JOIN_BINDING_SET);
reportBuilder.setCount(joinId, count);
}
// Statement Pattern results.
for (final StatementPatternMetadata statementPattern : fluoQuery.getStatementPatternMetadata()) {
final String patternId = statementPattern.getNodeId();
count = countBindingSets(sx, patternId, FluoQueryColumns.STATEMENT_PATTERN_BINDING_SET);
reportBuilder.setCount(patternId, count);
}
}
return reportBuilder.build();
}
use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.
the class ListFluoQueries method listFluoQueries.
/**
* Retrieve a list of String representations of each query maintained by Fluo
*
* @param fluo - FluoClient for interacting with Fluo
* @return - List of String representations of queries maintained by Fluo.
* @throws Exception
*/
public List<String> listFluoQueries(FluoClient fluo) throws Exception {
List<String> queryStrings = new ArrayList<>();
Snapshot sx = fluo.newSnapshot();
List<String> ids = new ListQueryIds().listQueryIds(fluo);
for (String id : ids) {
queryStrings.add(extractString(dao.readQueryMetadata(sx, id)));
}
return queryStrings;
}
use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.
the class FluoQueryMetadataDAOIT method joinMetadataTest.
@Test
public void joinMetadataTest() {
final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
// Create the object that will be serialized.
final JoinMetadata.Builder builder = JoinMetadata.builder("nodeId");
builder.setVarOrder(new VariableOrder("g;y;s"));
builder.setJoinType(JoinType.NATURAL_JOIN);
builder.setParentNodeId("parentNodeId");
builder.setLeftChildNodeId("leftChildNodeId");
builder.setRightChildNodeId("rightChildNodeId");
final JoinMetadata 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.
JoinMetadata storedMetadata = null;
try (Snapshot sx = fluoClient.newSnapshot()) {
storedMetadata = dao.readJoinMetadata(sx, "nodeId");
}
// Ensure the deserialized object is the same as the serialized one.
assertEquals(originalMetadata, storedMetadata);
}
}
use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.
the class FluoQueryMetadataDAOIT method constructQueryMetadataTest.
@Test
public void constructQueryMetadataTest() throws MalformedQueryException {
final String query = "select ?x ?y where {?x <uri:p1> ?y. ?y <uri:p2> <uri:o1> }";
final SPARQLParser parser = new SPARQLParser();
final ParsedQuery pq = parser.parseQuery(query, null);
final List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
// Create the object that will be serialized.
final ConstructQueryMetadata.Builder builder = ConstructQueryMetadata.builder();
builder.setNodeId("nodeId");
builder.setChildNodeId("childNodeId");
builder.setParentNodeId("parentNodeId");
builder.setVarOrder(new VariableOrder("a;b;c"));
builder.setConstructGraph(new ConstructGraph(patterns));
final ConstructQueryMetadata 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.
ConstructQueryMetadata storedMetdata = null;
try (Snapshot sx = fluoClient.newSnapshot()) {
storedMetdata = dao.readConstructQueryMetadata(sx, "nodeId");
}
// 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 FluoQueryMetadataDAOIT method fluoQueryTest.
@Test
public void fluoQueryTest() throws MalformedQueryException, UnsupportedQueryException {
final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
// Create the object that will be serialized.
final String sparql = "SELECT ?customer ?worker ?city " + "{ " + "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.PROJECTION, originalQuery.getQueryType());
assertEquals(false, 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);
}
}
Aggregations