Search in sources :

Example 16 with Transaction

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

the class IncUpdateDAO method addRow.

/**
 * Add a row, creating and closing a transaction.
 *
 * @param fluoClient - Creates connections to the Fluo table that will be written to. (not null)
 * @param row - The Row ID.
 * @param col - The Column.
 * @param val - The value.
 */
public static void addRow(final FluoClient fluoClient, final String row, final Column col, final String val) {
    checkNotNull(fluoClient);
    try (Transaction tx = fluoClient.newTransaction()) {
        addRow(tx, row, col, val);
        tx.commit();
    }
}
Also used : Transaction(org.apache.fluo.api.client.Transaction)

Example 17 with Transaction

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

the class StatementPatternIdCacheTest method testCache.

@Test
public void testCache() {
    Transaction mockTx = Mockito.mock(Transaction.class);
    String nodeId = NodeType.generateNewFluoIdForType(NodeType.STATEMENT_PATTERN);
    when(mockTx.get(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS)).thenReturn(Bytes.of(nodeId));
    when(mockTx.get(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS_HASH)).thenReturn(Bytes.of("123"));
    StatementPatternIdCache cache = new StatementPatternIdCache();
    Set<String> ids1 = cache.getStatementPatternIds(mockTx);
    Set<String> ids2 = cache.getStatementPatternIds(mockTx);
    Assert.assertEquals(ids1, ids2);
    Assert.assertEquals(Sets.newHashSet(nodeId), ids1);
    Mockito.verify(mockTx, Mockito.times(1)).get(Bytes.of(STATEMENT_PATTERN_ID), STATEMENT_PATTERN_IDS);
}
Also used : Transaction(org.apache.fluo.api.client.Transaction) Test(org.junit.Test)

Example 18 with Transaction

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

the class ListQueryIdsIT method getQueryIds.

/**
 * This test ensures that when there are PCJ tables in Accumulo as well as
 * the Fluo table's export destinations column, the command for fetching the
 * list of queries only includes queries that appear in both places.
 */
@Test
public void getQueryIds() throws AccumuloException, AccumuloSecurityException, TableExistsException {
    try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
        // Store a few SPARQL/Query ID pairs in the Fluo table.
        try (Transaction tx = fluoClient.newTransaction()) {
            tx.set("SPARQL_3", QUERY_NODE_ID, "ID_3");
            tx.set("SPARQL_1", QUERY_NODE_ID, "ID_1");
            tx.set("SPARQL_4", QUERY_NODE_ID, "ID_4");
            tx.set("SPARQL_2", QUERY_NODE_ID, "ID_2");
            tx.commit();
        }
        // Ensure the correct list of Query IDs is retured.
        final List<String> expected = Lists.newArrayList("ID_1", "ID_2", "ID_3", "ID_4");
        final List<String> queryIds = new ListQueryIds().listQueryIds(fluoClient);
        assertEquals(expected, queryIds);
    }
}
Also used : FluoClient(org.apache.fluo.api.client.FluoClient) Transaction(org.apache.fluo.api.client.Transaction) Test(org.junit.Test)

Example 19 with Transaction

use of org.apache.fluo.api.client.Transaction 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 20 with Transaction

use of org.apache.fluo.api.client.Transaction 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)

Aggregations

Transaction (org.apache.fluo.api.client.Transaction)28 Test (org.junit.Test)17 FluoClient (org.apache.fluo.api.client.FluoClient)15 Snapshot (org.apache.fluo.api.client.Snapshot)13 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)11 NodeType (org.apache.rya.indexing.pcj.fluo.app.NodeType)5 Bytes (org.apache.fluo.api.data.Bytes)4 SpanBatchDeleteInformation (org.apache.rya.indexing.pcj.fluo.app.batch.SpanBatchDeleteInformation)3 HashSet (java.util.HashSet)2 Column (org.apache.fluo.api.data.Column)2 RyaStatement (org.apache.rya.api.domain.RyaStatement)2 AggregationElement (org.apache.rya.api.function.aggregation.AggregationElement)2 TripleRowResolverException (org.apache.rya.api.resolver.triple.TripleRowResolverException)2 FluoQueryMetadataDAO (org.apache.rya.indexing.pcj.fluo.app.query.FluoQueryMetadataDAO)2 ColumnScanner (org.apache.fluo.api.client.scanner.ColumnScanner)1 RowScanner (org.apache.fluo.api.client.scanner.RowScanner)1 ColumnValue (org.apache.fluo.api.data.ColumnValue)1 RyaURI (org.apache.rya.api.domain.RyaURI)1 FluoQueryStringBuilder (org.apache.rya.indexing.pcj.fluo.api.ListFluoQueries.FluoQueryStringBuilder)1 BindingSetRow (org.apache.rya.indexing.pcj.fluo.app.BindingSetRow)1