use of uk.gov.gchq.gaffer.operation.impl.get.GetEdges in project Gaffer by gchq.
the class LoadAndQuery2 method run.
public CloseableIterable<Edge> run() throws OperationException {
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [generate] Create some edges from the data file using our data generator class
// ---------------------------------------------------------
final List<Element> elements = new ArrayList<>();
final DataGenerator2 dataGenerator = new DataGenerator2();
for (final String s : DataUtils.loadData(getData())) {
elements.add(dataGenerator.getElement(s));
}
// ---------------------------------------------------------
log("Elements generated from the data file.");
for (final Element element : elements) {
log("GENERATED_EDGES", element.toString());
}
log("");
// [graph] Create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
// ---------------------------------------------------------
// [add] Add the edges to the graph
// ---------------------------------------------------------
final AddElements addElements = new AddElements.Builder().elements(elements).build();
graph.execute(addElements, user);
// ---------------------------------------------------------
log("The elements have been added.\n");
// [get simple] Get all the edges related to vertex 1
// ---------------------------------------------------------
final GetEdges<EntitySeed> getRelatedEdges = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build();
final CloseableIterable<Edge> allColoursResults = graph.execute(getRelatedEdges, user);
// ---------------------------------------------------------
log("\nAll edges containing vertex 1");
log("\nNotice that the edges are aggregated within their groups");
for (final Element e : allColoursResults) {
log("GET_RELATED_EDGES_RESULT", e.toString());
}
// [get] Rerun the previous query with a View to specify which subset of results we want
// ---------------------------------------------------------
final View view = new View.Builder().edge("red").build();
final GetEdges<EntitySeed> getRelatedRedEdges = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).view(view).build();
final CloseableIterable<Edge> redResults = graph.execute(getRelatedRedEdges, user);
// ---------------------------------------------------------
log("\nAll red edges containing vertex 1\n");
for (final Element e : redResults) {
log("GET_RELATED_RED_EDGES_RESULT", e.toString());
}
return redResults;
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetEdges in project Gaffer by gchq.
the class LoadAndQuery3 method run.
public CloseableIterable<Edge> run() throws OperationException {
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [generate] create some edges from the data file using our data generator class
// ---------------------------------------------------------
final List<Element> elements = new ArrayList<>();
final DataGenerator3 dataGenerator = new DataGenerator3();
for (final String s : DataUtils.loadData(getData())) {
elements.add(dataGenerator.getElement(s));
}
// ---------------------------------------------------------
log("Elements generated from the data file.");
for (final Element element : elements) {
log("GENERATED_EDGES", element.toString());
}
log("");
// [graph] create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
// ---------------------------------------------------------
// [add] add the edges to the graph
// ---------------------------------------------------------
final AddElements addElements = new AddElements.Builder().elements(elements).build();
graph.execute(addElements, user);
// ---------------------------------------------------------
log("The elements have been added.\n");
log("\nAll edges containing the vertex 1. The counts have been aggregated\n");
// [get simple] get all the edges that contain the vertex "1"
// ---------------------------------------------------------
final GetEdges<EntitySeed> getRelatedEdges = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build();
final CloseableIterable<Edge> results = graph.execute(getRelatedEdges, user);
// ---------------------------------------------------------
for (final Element e : results) {
log("GET_RELATED_EDGES_RESULT", e.toString());
}
// [get] rerun previous query with a filter to return only edges with a count more than 3
// ---------------------------------------------------------
final View view = new View.Builder().edge("data", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(3)).build()).build()).build();
final GetEdges<EntitySeed> getRelatedEdgesWithCountMoreThan3 = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).view(view).build();
final CloseableIterable<Edge> filteredResults = graph.execute(getRelatedEdgesWithCountMoreThan3, user);
// ---------------------------------------------------------
log("\nAll edges containing the vertex 1 with an aggregated count more than than 3\n");
for (final Element e : filteredResults) {
log("GET_RELATED_ELEMENTS_WITH_COUNT_MORE_THAN_3_RESULT", e.toString());
}
return filteredResults;
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetEdges in project Gaffer by gchq.
the class LoadAndQuery4 method run.
public CloseableIterable<Edge> run() throws OperationException {
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [generate] Create some edges from the data file using our data generator class
// ---------------------------------------------------------
final List<Element> elements = new ArrayList<>();
final DataGenerator4 dataGenerator = new DataGenerator4();
for (final String s : DataUtils.loadData(getData())) {
elements.add(dataGenerator.getElement(s));
}
// ---------------------------------------------------------
log("Elements generated from the data file.");
for (final Element element : elements) {
log("GENERATED_EDGES", element.toString());
}
log("");
// [graph] create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
// ---------------------------------------------------------
// [add] add the edges to the graph
final AddElements addElements = new AddElements.Builder().elements(elements).build();
graph.execute(addElements, user);
// ---------------------------------------------------------
log("The elements have been added.\n");
// [get simple] get all the edges that contain the vertex "1"
// ---------------------------------------------------------
final GetEdges<EntitySeed> getRelatedEdges = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build();
final CloseableIterable<Edge> results = graph.execute(getRelatedEdges, user);
// ---------------------------------------------------------
log("\nAll edges containing the vertex 1. The counts and 'things' have been aggregated\n");
for (final Element e : results) {
log("GET_RELATED_EDGES_RESULT", e.toString());
}
// rerun previous query but calculate a mean
// [transform] Create a mean transient property using an element transformer
// ---------------------------------------------------------
final ElementTransformer mean = new ElementTransformer.Builder().select("thing", "count").project("mean").execute(new MeanTransform()).build();
// ---------------------------------------------------------
// [get] Add the element transformer to the view and run the query
// ---------------------------------------------------------
final View view = new View.Builder().edge("data", new ViewElementDefinition.Builder().transientProperty("mean", Float.class).transformer(mean).build()).build();
final GetEdges<EntitySeed> getRelatedEdgesWithMean = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).view(view).build();
final CloseableIterable<Edge> transientResults = graph.execute(getRelatedEdgesWithMean, user);
// ---------------------------------------------------------
log("\nWe can add a new property to the edges that is calculated from the aggregated values of other properties\n");
for (final Element e : transientResults) {
log("GET_RELATED_ELEMENTS_WITH_MEAN_RESULT", e.toString());
}
return transientResults;
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetEdges in project Gaffer by gchq.
the class ExportIT method shouldExportResultsInSet.
@Test
public void shouldExportResultsInSet() throws OperationException, IOException {
// Given
final OperationChain<CloseableIterable<?>> exportOpChain = new Builder().first(new GetEdges.Builder<>().addSeed(new EntitySeed(SOURCE_DIR_0)).build()).then(new ExportToSet()).then(new GenerateObjects.Builder<Edge, EntitySeed>().generator(new EntitySeedExtractor()).build()).then(new GetEdges<>()).then(new ExportToSet()).then(new GetSetExport()).build();
// When
final CloseableIterable<?> export = graph.execute(exportOpChain, getUser());
// Then
assertEquals(2, Lists.newArrayList(export).size());
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetEdges in project Gaffer by gchq.
the class TransformationIT method shouldCreateTransientEdgeProperty.
@Test
@TraitRequirement(StoreTrait.TRANSFORMATION)
public void shouldCreateTransientEdgeProperty() throws OperationException {
// Given
final GetEdges<EdgeSeed> getEdges = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed(SOURCE_1, DEST_1, false)).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.TRANSIENT_1, String.class).transformer(new ElementTransformer.Builder().select(IdentifierType.SOURCE.name(), TestPropertyNames.INT).execute(new Concat()).project(TestPropertyNames.TRANSIENT_1).build()).build()).build()).build();
// When
final List<Edge> results = Lists.newArrayList(graph.execute(getEdges, getUser()));
assertNotNull(results);
for (final Edge result : results) {
assertEquals(SOURCE_1 + "," + result.getProperty(TestPropertyNames.INT), result.getProperty(TestPropertyNames.TRANSIENT_1));
}
}
Aggregations