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