use of org.apache.fluo.api.client.Transaction in project incubator-rya by apache.
the class FluoBinPruner method pruneBindingSetBin.
/**
* This method deletes BindingSets in the specified bin from the BindingSet
* Column of the indicated Fluo nodeId
*
* @param id
* - Fluo nodeId
* @param bin
* - bin id
*/
@Override
public void pruneBindingSetBin(final NodeBin nodeBin) {
final String id = nodeBin.getNodeId();
final long bin = nodeBin.getBin();
try (Transaction tx = client.newTransaction()) {
final Optional<NodeType> type = NodeType.fromNodeId(id);
if (!type.isPresent()) {
log.trace("Unable to determine NodeType from id: " + id);
throw new RuntimeException();
}
final Column batchInfoColumn = type.get().getResultColumn();
final Bytes batchInfoSpanPrefix = BindingHashShardingFunction.getShardedScanPrefix(id, vf.createLiteral(bin));
final SpanBatchDeleteInformation batchInfo = SpanBatchDeleteInformation.builder().setColumn(batchInfoColumn).setSpan(Span.prefix(batchInfoSpanPrefix)).build();
BatchInformationDAO.addBatch(tx, id, batchInfo);
tx.commit();
}
}
use of org.apache.fluo.api.client.Transaction 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);
}
}
use of org.apache.fluo.api.client.Transaction 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);
}
}
use of org.apache.fluo.api.client.Transaction 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);
}
}
use of org.apache.fluo.api.client.Transaction 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);
}
}
Aggregations