Search in sources :

Example 1 with ConstructGraph

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);
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) FluoClient(org.apache.fluo.api.client.FluoClient) ParsedQuery(org.openrdf.query.parser.ParsedQuery) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) ConstructGraph(org.apache.rya.indexing.pcj.fluo.app.ConstructGraph) StatementPattern(org.openrdf.query.algebra.StatementPattern) Snapshot(org.apache.fluo.api.client.Snapshot) Transaction(org.apache.fluo.api.client.Transaction) Test(org.junit.Test)

Example 2 with ConstructGraph

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);
}
Also used : Column(org.apache.fluo.api.data.Column) ConstructGraph(org.apache.rya.indexing.pcj.fluo.app.ConstructGraph) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)

Aggregations

ConstructGraph (org.apache.rya.indexing.pcj.fluo.app.ConstructGraph)2 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)2 FluoClient (org.apache.fluo.api.client.FluoClient)1 Snapshot (org.apache.fluo.api.client.Snapshot)1 Transaction (org.apache.fluo.api.client.Transaction)1 Column (org.apache.fluo.api.data.Column)1 Test (org.junit.Test)1 StatementPattern (org.openrdf.query.algebra.StatementPattern)1 ParsedQuery (org.openrdf.query.parser.ParsedQuery)1 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)1