Search in sources :

Example 16 with Snapshot

use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.

the class PeriodicQueryPruner method pruneBindingSetBin.

/**
 * Prunes BindingSet bins from the Rya Fluo Application in addition to the BindingSet
 * bins created in the PCJ tables associated with the give query id.
 * @param id - QueryResult Id for the Rya Fluo application
 * @param bin - bin id for bins to be deleted
 */
@Override
public void pruneBindingSetBin(final NodeBin nodeBin) {
    final String pcjId = nodeBin.getNodeId();
    final long bin = nodeBin.getBin();
    try (Snapshot sx = client.newSnapshot()) {
        final String queryId = NodeType.generateNewIdForType(NodeType.QUERY, pcjId);
        final Set<String> fluoIds = getNodeIdsFromResultId(sx, queryId);
        accPruner.pruneBindingSetBin(nodeBin);
        for (final String fluoId : fluoIds) {
            fluoPruner.pruneBindingSetBin(new NodeBin(fluoId, bin));
        }
    } catch (final Exception e) {
        log.warn("Could not successfully initialize PeriodicQueryBinPruner.", e);
    }
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) NodeBin(org.apache.rya.periodic.notification.api.NodeBin)

Example 17 with Snapshot

use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.

the class FluoQueryMetadataDAOIT method periodicQueryMetadataTest.

@Test
public void periodicQueryMetadataTest() {
    final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
    // Create the object that will be serialized.
    final PeriodicQueryMetadata originalMetadata = PeriodicQueryMetadata.builder().setNodeId("nodeId").setParentNodeId("parentNodeId").setVarOrder(new VariableOrder("a", "b", "c")).setChildNodeId("childNodeId").setPeriod(10).setWindowSize(20).setUnit(TimeUnit.DAYS).setTemporalVariable("a").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.
        PeriodicQueryMetadata storedMetadata = null;
        try (Snapshot sx = fluoClient.newSnapshot()) {
            storedMetadata = dao.readPeriodicQueryMetadata(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 18 with Snapshot

use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.

the class FluoQueryMetadataDAOIT method fluoNestedQueryTest.

@Test
public void fluoNestedQueryTest() throws MalformedQueryException, UnsupportedQueryException {
    final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
    // Create the object that will be serialized.
    final String sparql = "SELECT ?id ?type ?location ?averagePrice ?vendor {" + "FILTER(?averagePrice > 4) " + "?type <urn:purchasedFrom> ?vendor ." + "{SELECT ?type ?location (avg(?price) as ?averagePrice) {" + "?id <urn:type> ?type . " + "?id <urn:location> ?location ." + "?id <urn:price> ?price ." + "} " + "GROUP BY ?type ?location }}";
    final SparqlFluoQueryBuilder builder = new SparqlFluoQueryBuilder();
    builder.setSparql(sparql);
    builder.setFluoQueryId(NodeType.generateNewFluoIdForType(NodeType.QUERY));
    final FluoQuery originalQuery = builder.build();
    assertEquals(QueryType.PROJECTION, originalQuery.getQueryType());
    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 19 with Snapshot

use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.

the class FluoQueryMetadataDAOIT method aggregationMetadataTest_withGroupByVarOrders.

@Test
public void aggregationMetadataTest_withGroupByVarOrders() {
    final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
    // Create the object that will be serialized.
    final AggregationMetadata originalMetadata = AggregationMetadata.builder("nodeId").setVarOrder(new VariableOrder("totalCount")).setParentNodeId("parentNodeId").setChildNodeId("childNodeId").setGroupByVariableOrder(new VariableOrder("a", "b", "c")).addAggregation(new AggregationElement(AggregationType.COUNT, "count", "totalCount")).addAggregation(new AggregationElement(AggregationType.AVERAGE, "privae", "avgPrice")).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.
        AggregationMetadata storedMetadata = null;
        try (Snapshot sx = fluoClient.newSnapshot()) {
            storedMetadata = dao.readAggregationMetadata(sx, "nodeId");
        }
    }
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) AggregationElement(org.apache.rya.api.function.aggregation.AggregationElement) 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 20 with Snapshot

use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.

the class FluoQueryMetadataDAOIT method statementPatternMetadataTest.

@Test
public void statementPatternMetadataTest() throws RepositoryException {
    final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
    // Create the object that will be serialized.
    final StatementPatternMetadata.Builder builder = StatementPatternMetadata.builder("nodeId");
    builder.setVarOrder(new VariableOrder("a;b;c"));
    builder.setStatementPattern("statementPattern");
    builder.setParentNodeId("parentNodeId");
    final StatementPatternMetadata 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.
        StatementPatternMetadata storedMetadata = null;
        try (Snapshot sx = fluoClient.newSnapshot()) {
            storedMetadata = dao.readStatementPatternMetadata(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)

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