use of org.apache.fluo.api.client.FluoClient 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.FluoClient 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);
}
}
use of org.apache.fluo.api.client.FluoClient 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.FluoClient 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.FluoClient 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);
}
}
Aggregations