use of org.apache.fluo.api.client.Transaction 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");
}
}
}
use of org.apache.fluo.api.client.Transaction 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);
}
}
use of org.apache.fluo.api.client.Transaction in project incubator-rya by apache.
the class FluoQueryMetadataDAOIT method fluoConstructQueryTest.
@Test
public void fluoConstructQueryTest() throws MalformedQueryException, UnsupportedQueryException {
final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
// Create the object that will be serialized.
final String sparql = "CONSTRUCT { ?customer <http://travelsTo> <http://England> . ?customer <http://friendsWith> ?worker }" + "WHERE { " + "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.CONSTRUCT, originalQuery.getQueryType());
assertEquals(true, 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 queryMetadataTest.
@Test
public void queryMetadataTest() {
final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
// Create the object that will be serialized.
final String queryId = NodeType.generateNewFluoIdForType(NodeType.QUERY);
final QueryMetadata.Builder builder = QueryMetadata.builder(queryId);
builder.setQueryType(QueryType.PROJECTION);
builder.setVarOrder(new VariableOrder("y;s;d"));
builder.setSparql("sparql string");
builder.setChildNodeId("childNodeId");
builder.setExportStrategies(new HashSet<>(Arrays.asList(ExportStrategy.KAFKA)));
final QueryMetadata 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.
QueryMetadata storedMetdata = null;
try (Snapshot sx = fluoClient.newSnapshot()) {
storedMetdata = dao.readQueryMetadata(sx, queryId);
}
// 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 ListFluoQueriesIT method queryMetadataTest.
@Test
public void queryMetadataTest() throws Exception {
final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
String sparql1 = "select ?x ?y ?z where {?x <uri:p1> ?y; <uri:p2> 'literal1'. ?y <uri:p3> ?z }";
String sparql2 = "select ?x ?y ?z where {{select ?x ?y ?z {?x <uri:p1> ?y; <uri:p2> ?z. ?y <uri:p3> ?z }}}";
// Create the object that will be serialized.
String queryId1 = NodeType.generateNewFluoIdForType(NodeType.QUERY);
final QueryMetadata.Builder builder = QueryMetadata.builder(queryId1);
builder.setQueryType(QueryType.PROJECTION);
builder.setVarOrder(new VariableOrder("y;s;d"));
builder.setSparql(sparql1);
builder.setChildNodeId("childNodeId");
builder.setExportStrategies(new HashSet<>(Arrays.asList(ExportStrategy.KAFKA)));
final QueryMetadata meta1 = builder.build();
String queryId2 = NodeType.generateNewFluoIdForType(NodeType.QUERY);
final QueryMetadata.Builder builder2 = QueryMetadata.builder(queryId2);
builder2.setQueryType(QueryType.PROJECTION);
builder2.setVarOrder(new VariableOrder("y;s;d"));
builder2.setSparql(sparql2);
builder2.setChildNodeId("childNodeId");
builder2.setExportStrategies(new HashSet<>(Arrays.asList(ExportStrategy.RYA)));
final QueryMetadata meta2 = builder2.build();
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
// Write it to the Fluo table.
try (Transaction tx = fluoClient.newTransaction()) {
dao.write(tx, meta1);
dao.write(tx, meta2);
tx.commit();
}
ListFluoQueries listFluoQueries = new ListFluoQueries();
List<String> queries = listFluoQueries.listFluoQueries(fluoClient);
FluoQueryStringBuilder queryBuilder1 = new FluoQueryStringBuilder();
String expected1 = queryBuilder1.setQueryId(queryId1).setQueryType(QueryType.PROJECTION).setQuery(sparql1).setExportStrategies(Sets.newHashSet(ExportStrategy.KAFKA)).build();
FluoQueryStringBuilder queryBuilder2 = new FluoQueryStringBuilder();
String expected2 = queryBuilder2.setQueryId(queryId2).setQueryType(QueryType.PROJECTION).setQuery(sparql2).setExportStrategies(Sets.newHashSet(ExportStrategy.RYA)).build();
Set<String> expected = new HashSet<>();
expected.add(expected1);
expected.add(expected2);
Assert.assertEquals(expected, Sets.newHashSet(queries));
}
}
Aggregations