Search in sources :

Example 6 with Snapshot

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

the class FluoQueryMetadataDAOIT method fluoNestedConstructQueryTest.

@Test
public void fluoNestedConstructQueryTest() throws MalformedQueryException, UnsupportedQueryException {
    final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
    // Create the object that will be serialized.
    final String sparql = "CONSTRUCT { " + "_:b a <urn:highSpeedTrafficArea> . " + "_:b <urn:hasCount> ?obsCount . " + "_:b <urn:hasLocation> ?location ." + "_:b <urn:hasAverageVelocity> ?avgVelocity ." + "} WHERE { " + "FILTER(?obsCount > 1) " + "{ " + "SELECT ?location (count(?obs) AS ?obsCount) (avg(?velocity) AS ?avgVelocity) " + "WHERE { " + "FILTER(?velocity > 75) " + "?obs <urn:hasVelocity> ?velocity. " + "?obs <urn:hasLocation> ?location. " + "}GROUP BY ?location }}";
    final SparqlFluoQueryBuilder builder = new SparqlFluoQueryBuilder();
    builder.setSparql(sparql);
    builder.setFluoQueryId(NodeType.generateNewFluoIdForType(NodeType.QUERY));
    final FluoQuery originalQuery = builder.build();
    assertEquals(QueryType.CONSTRUCT, 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 7 with Snapshot

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

the class FluoQueryMetadataDAOIT method projectionMetadataTest.

@Test
public void projectionMetadataTest() {
    final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
    // Create the object that will be serialized.
    final ProjectionMetadata.Builder builder = ProjectionMetadata.builder("nodeId");
    builder.setVarOrder(new VariableOrder("y;s;d"));
    builder.setProjectedVars(new VariableOrder("x;y;z"));
    builder.setChildNodeId("childNodeId");
    builder.setParentNodeId("parentNodeId");
    final ProjectionMetadata 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.
        ProjectionMetadata storedMetdata = null;
        try (Snapshot sx = fluoClient.newSnapshot()) {
            storedMetdata = dao.readProjectionMetadata(sx, "nodeId");
        }
        // 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 8 with Snapshot

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

the class FluoQueryMetadataDAOIT method aggregationMetadataTest_noGroupByVarOrders.

@Test
public void aggregationMetadataTest_noGroupByVarOrders() {
    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").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");
        }
        // Ensure the deserialized object is the same as the serialized one.
        assertEquals(originalMetadata, storedMetadata);
    }
}
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 9 with Snapshot

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

the class FluoQueryMetadataDAOIT method filterMetadataTest.

@Test
public void filterMetadataTest() {
    final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
    // Create the object that will be serialized.
    final FilterMetadata.Builder builder = FilterMetadata.builder("nodeId");
    builder.setVarOrder(new VariableOrder("e;f"));
    builder.setParentNodeId("parentNodeId");
    builder.setChildNodeId("childNodeId");
    builder.setFilterSparql("originalSparql");
    final FilterMetadata 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.
        FilterMetadata storedMetadata = null;
        try (Snapshot sx = fluoClient.newSnapshot()) {
            storedMetadata = dao.readFilterMetadata(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 10 with Snapshot

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

the class CreateDeleteIT method getFluoTableEntries.

private List<Bytes> getFluoTableEntries(final FluoClient fluoClient) {
    try (Snapshot snapshot = fluoClient.newSnapshot()) {
        final List<Bytes> rows = new ArrayList<>();
        final RowScanner rscanner = snapshot.scanner().over(Span.prefix("")).byRow().build();
        for (final ColumnScanner cscanner : rscanner) {
            rows.add(cscanner.getRow());
        }
        return rows;
    }
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) Bytes(org.apache.fluo.api.data.Bytes) ArrayList(java.util.ArrayList) RowScanner(org.apache.fluo.api.client.scanner.RowScanner) ColumnScanner(org.apache.fluo.api.client.scanner.ColumnScanner)

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