Search in sources :

Example 21 with Snapshot

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);
    }
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) FluoClient(org.apache.fluo.api.client.FluoClient) Transaction(org.apache.fluo.api.client.Transaction) Test(org.junit.Test)

Example 22 with Snapshot

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);
    }
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) FluoClient(org.apache.fluo.api.client.FluoClient) Transaction(org.apache.fluo.api.client.Transaction) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) Test(org.junit.Test)

Example 23 with Snapshot

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;
    }
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) ColumnScanner(org.apache.fluo.api.client.scanner.ColumnScanner) BigInteger(java.math.BigInteger)

Aggregations

Snapshot (org.apache.fluo.api.client.Snapshot)23 FluoClient (org.apache.fluo.api.client.FluoClient)13 Transaction (org.apache.fluo.api.client.Transaction)13 Test (org.junit.Test)13 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)10 ArrayList (java.util.ArrayList)4 ColumnScanner (org.apache.fluo.api.client.scanner.ColumnScanner)4 RowScanner (org.apache.fluo.api.client.scanner.RowScanner)3 Bytes (org.apache.fluo.api.data.Bytes)3 BigInteger (java.math.BigInteger)2 AggregationElement (org.apache.rya.api.function.aggregation.AggregationElement)2 FluoQuery (org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)2 HashSet (java.util.HashSet)1 CellScanner (org.apache.fluo.api.client.scanner.CellScanner)1 ColumnValue (org.apache.fluo.api.data.ColumnValue)1 RowColumnValue (org.apache.fluo.api.data.RowColumnValue)1 ConstructGraph (org.apache.rya.indexing.pcj.fluo.app.ConstructGraph)1 NodeType (org.apache.rya.indexing.pcj.fluo.app.NodeType)1 FilterMetadata (org.apache.rya.indexing.pcj.fluo.app.query.FilterMetadata)1 JoinMetadata (org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata)1