Search in sources :

Example 1 with Snapshot

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();
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) StatementPatternMetadata(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata) FilterMetadata(org.apache.rya.indexing.pcj.fluo.app.query.FilterMetadata) BigInteger(java.math.BigInteger) JoinMetadata(org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata) FluoQuery(org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)

Example 2 with Snapshot

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;
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) ArrayList(java.util.ArrayList)

Example 3 with Snapshot

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);
    }
}
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 4 with Snapshot

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);
    }
}
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 5 with Snapshot

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);
    }
}
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)

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