use of uk.gov.gchq.gaffer.operation.data.ElementSeed in project Gaffer by gchq.
the class GetElementsinRangesHandlerTest method shouldSummarise.
private void shouldSummarise(final AccumuloStore store) throws OperationException {
// Create set to query for
final Set<Pair<ElementSeed>> simpleEntityRanges = new HashSet<>();
//get Everything between 0 and 1 (Note we are using strings and string serialisers, with this ordering 0999 is before 1)
simpleEntityRanges.add(new Pair<ElementSeed>(new EntitySeed("0"), new EntitySeed("1")));
final View view = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
final GetElementsInRanges<Pair<ElementSeed>, Element> operation = new GetElementsInRanges<>(view, simpleEntityRanges);
final GetElementsInRangesHandler handler = new GetElementsInRangesHandler();
final CloseableIterable<Element> elementsInRange = handler.doOperation(operation, user, store);
int count = 0;
for (final Element elm : elementsInRange) {
//Make sure every element has been summarised
assertEquals(9, elm.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER));
count++;
}
assertEquals(1000, count);
elementsInRange.close();
simpleEntityRanges.clear();
//This should get everything between 0 and 0799 (again being string ordering 0800 is more than 08)
simpleEntityRanges.add(new Pair<ElementSeed>(new EntitySeed("0"), new EntitySeed("08")));
final CloseableIterable<Element> elements = handler.doOperation(operation, user, store);
count = 0;
for (final Element elm : elements) {
//Make sure every element has been summarised
assertEquals(9, elm.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER));
count++;
}
assertEquals(800, count);
elements.close();
}
use of uk.gov.gchq.gaffer.operation.data.ElementSeed in project Gaffer by gchq.
the class AccumuloSingleIDRetrieverTest method testEntitySeedQueryEntitiesOnly.
private void testEntitySeedQueryEntitiesOnly(final AccumuloStore store) throws AccumuloException, StoreException {
setupGraph(store, numEntries);
final User user = new User();
// Create set to query for
final Set<ElementSeed> ids = new HashSet<>();
for (int i = 0; i < numEntries; i++) {
ids.add(new EntitySeed("" + i));
}
final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
AccumuloSingleIDRetriever retriever = null;
final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
operation.setIncludeEntities(true);
operation.setIncludeEdges(IncludeEdgeType.NONE);
try {
retriever = new AccumuloSingleIDRetriever(store, operation, user);
} catch (IteratorSettingException e) {
e.printStackTrace();
}
//Should find only the entities i
assertEquals(numEntries, Iterables.size(retriever));
}
use of uk.gov.gchq.gaffer.operation.data.ElementSeed in project Gaffer by gchq.
the class AggregationIT method shouldAggregateIdenticalElements.
@Test
@TraitRequirement(StoreTrait.STORE_AGGREGATION)
public void shouldAggregateIdenticalElements() throws OperationException, UnsupportedEncodingException {
// Given
final GetElements<ElementSeed, Element> getElements = new GetElements.Builder<>().addSeed(new EntitySeed(AGGREGATED_SOURCE)).build();
// When
final List<Element> results = Lists.newArrayList(graph.execute(getElements, getUser()));
// Then
assertNotNull(results);
assertEquals(2, results.size());
final Entity expectedEntity = new Entity(TestGroups.ENTITY, AGGREGATED_SOURCE);
expectedEntity.putProperty(TestPropertyNames.STRING, "3,3");
final Edge expectedEdge = new Edge(TestGroups.EDGE, AGGREGATED_SOURCE, AGGREGATED_DEST, false);
expectedEdge.putProperty(TestPropertyNames.INT, 1);
expectedEdge.putProperty(TestPropertyNames.COUNT, 2L);
assertThat(results, IsCollectionContaining.hasItems(expectedEdge, expectedEntity));
for (final Element result : results) {
if (result instanceof Entity) {
assertEquals(AGGREGATED_ID, result.getProperty(TestPropertyNames.STRING));
} else {
assertEquals(1, result.getProperty(TestPropertyNames.INT));
assertEquals(2L, result.getProperty(TestPropertyNames.COUNT));
}
}
}
use of uk.gov.gchq.gaffer.operation.data.ElementSeed in project Gaffer by gchq.
the class FilteringIT method testPostAggregationFilteringProperties.
@Test
@TraitRequirement({ StoreTrait.POST_AGGREGATION_FILTERING, StoreTrait.STORE_AGGREGATION })
public void testPostAggregationFilteringProperties() throws OperationException {
// Given
final List<ElementSeed> seeds = Arrays.asList(new EntitySeed("A3"), new EdgeSeed("A5", "B5", false));
final GetElements<ElementSeed, Element> getElementsWithoutFiltering = new GetElements.Builder<>().seeds(seeds).build();
final GetElements<ElementSeed, Element> getElementsWithFiltering = new GetElements.Builder<>().seeds(seeds).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A5")).build()).build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build();
// When - without filtering
final List<Element> resultsWithoutFiltering = Lists.newArrayList(graph.execute(getElementsWithoutFiltering, getUser()));
// When - with filtering
final List<Element> resultsWithFiltering = Lists.newArrayList(graph.execute(getElementsWithFiltering, getUser()));
// Then - without filtering
assertNotNull(resultsWithoutFiltering);
assertEquals(8, resultsWithoutFiltering.size());
assertThat(resultsWithoutFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A3", "C3", false), getEdge("A3", "D3", false), getEdge("A5", "B5", false), getEntity("A5"), getEntity("B5")));
// Then - with filtering
assertNotNull(resultsWithFiltering);
assertEquals(6, resultsWithFiltering.size());
assertThat(resultsWithFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A5", "B5", false), getEdge("A3", "D3", false), getEdge("A3", "C3", false), getEntity("A5")));
}
use of uk.gov.gchq.gaffer.operation.data.ElementSeed in project Gaffer by gchq.
the class GetElementsIT method shouldGetRelatedElements.
private void shouldGetRelatedElements(boolean includeEntities, final IncludeEdgeType includeEdgeType, final IncludeIncomingOutgoingType inOutType) throws Exception {
final List<ElementSeed> seedTerms = new LinkedList<>();
final List<Element> expectedElements = new LinkedList<>();
if (includeEntities) {
for (final Object identifier : ALL_SEED_VERTICES) {
final EntitySeed entitySeed = new EntitySeed(identifier);
seedTerms.add(entitySeed);
}
}
if (IncludeEdgeType.ALL == includeEdgeType || IncludeEdgeType.DIRECTED == includeEdgeType) {
final EdgeSeed seed = new EdgeSeed(SOURCE_DIR_1, DEST_DIR_1, true);
seedTerms.add(seed);
if (IncludeIncomingOutgoingType.BOTH == inOutType || IncludeIncomingOutgoingType.OUTGOING == inOutType) {
final EdgeSeed seedSourceDestDir2 = new EdgeSeed(SOURCE_DIR_2, DEST_DIR_2, true);
seedTerms.add(seedSourceDestDir2);
}
if (IncludeIncomingOutgoingType.BOTH == inOutType || IncludeIncomingOutgoingType.INCOMING == inOutType) {
final EdgeSeed seedSourceDestDir3 = new EdgeSeed(SOURCE_DIR_3, DEST_DIR_3, true);
seedTerms.add(seedSourceDestDir3);
}
}
if (IncludeEdgeType.ALL == includeEdgeType || IncludeEdgeType.UNDIRECTED == includeEdgeType) {
final EdgeSeed seedSourceDest1 = new EdgeSeed(SOURCE_1, DEST_1, false);
seedTerms.add(seedSourceDest1);
final EdgeSeed seedSourceDest2 = new EdgeSeed(SOURCE_2, DEST_2, false);
seedTerms.add(seedSourceDest2);
final EdgeSeed seedSourceDest3 = new EdgeSeed(SOURCE_3, DEST_3, false);
seedTerms.add(seedSourceDest3);
}
expectedElements.addAll(getElements(seedTerms));
shouldGetElements(expectedElements, SeedMatchingType.RELATED, includeEdgeType, includeEntities, inOutType, ALL_SEEDS);
}
Aggregations