use of org.apache.rya.indexing.pcj.fluo.app.ConstructGraph 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.rya.indexing.pcj.fluo.app.ConstructGraph in project incubator-rya by apache.
the class FluoQueryMetadataDAO method readConstructQueryMetadataBuilder.
private ConstructQueryMetadata.Builder readConstructQueryMetadataBuilder(final SnapshotBase sx, final String nodeId) {
requireNonNull(sx);
requireNonNull(nodeId);
// Fetch the values from the Fluo table.
final String rowId = nodeId;
final Map<Column, String> values = sx.gets(rowId, FluoQueryColumns.CONSTRUCT_GRAPH, FluoQueryColumns.CONSTRUCT_CHILD_NODE_ID, FluoQueryColumns.CONSTRUCT_PARENT_NODE_ID, FluoQueryColumns.CONSTRUCT_VARIABLE_ORDER);
final String graphString = values.get(FluoQueryColumns.CONSTRUCT_GRAPH);
final ConstructGraph graph = ConstructGraphSerializer.toConstructGraph(graphString);
final String childNodeId = values.get(FluoQueryColumns.CONSTRUCT_CHILD_NODE_ID);
final String parentNodeId = values.get(FluoQueryColumns.CONSTRUCT_PARENT_NODE_ID);
final String varOrderString = values.get(FluoQueryColumns.CONSTRUCT_VARIABLE_ORDER);
return ConstructQueryMetadata.builder().setNodeId(nodeId).setParentNodeId(parentNodeId).setConstructGraph(graph).setVarOrder(new VariableOrder(varOrderString)).setChildNodeId(childNodeId);
}
Aggregations