use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.
the class GetWalksHandler method doOperation.
@Override
public Iterable<Walk> doOperation(final GetWalks getWalks, final Context context, final Store store) throws OperationException {
// Check input
if (null == getWalks.getInput()) {
return null;
}
// Check there are some operations
if (null == getWalks.getOperations()) {
return new EmptyClosableIterable<>();
}
final Integer resultLimit = getWalks.getResultsLimit();
final int hops = getWalks.getNumberOfGetEdgeOperations();
final LimitedCloseableIterable limitedInputItr = new LimitedCloseableIterable<>(getWalks.getInput(), 0, resultLimit, false);
final List<EntityId> originalInput = Lists.newArrayList(limitedInputItr);
// Check hops and maxHops (if set)
if (hops == 0) {
return new EmptyClosableIterable<>();
} else if (maxHops != null && hops > maxHops) {
throw new OperationException("GetWalks operation contains " + hops + " hops. The maximum number of hops is: " + maxHops);
}
final AdjacencyMaps adjacencyMaps = prune && !getWalks.isIncludePartial() ? new PrunedAdjacencyMaps() : new SimpleAdjacencyMaps();
final EntityMaps entityMaps = new SimpleEntityMaps();
List<?> seeds = originalInput;
// Execute the operations
for (final OperationChain<Iterable<Element>> operation : getWalks.getOperations()) {
if (isWhileOperation(operation)) {
seeds = executeWhileOperation(operation, seeds, resultLimit, context, store, hops, adjacencyMaps, entityMaps);
} else {
seeds = executeOperation(operation, seeds, resultLimit, context, store, hops, adjacencyMaps, entityMaps);
}
}
// requested by the user.
if (entityMaps.size() == adjacencyMaps.size()) {
entityMaps.add(new EntityMap());
}
final GraphWindow graphWindow = new GraphWindow(adjacencyMaps, entityMaps);
// Track/recombine the edge objects and convert to return type
final Stream<Walk> walks = Streams.toStream(originalInput).flatMap(seed -> walk(seed.getVertex(), null, graphWindow, new LinkedList<>(), new LinkedList<>(), hops, getWalks.isIncludePartial()).stream());
return applyConditionalFiltering(walks, getWalks, context, store);
}
use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.
the class FullSchemaLoader method createEntities.
@Override
public Map<EntityId, Entity> createEntities() {
final Map<EntityId, Entity> entities = new HashMap<>();
for (int i = 0; i <= 10; i++) {
for (int j = 0; j < VERTEX_PREFIXES.length; j++) {
final FreqMap freqMap = new FreqMap();
freqMap.upsert("key");
final Entity entity = new Entity(TestGroups.ENTITY, VERTEX_PREFIXES[j] + i);
entity.putProperty(TestPropertyNames.COUNT, 1L);
entity.putProperty(TestPropertyNames.PROP_1, 1);
entity.putProperty(TestPropertyNames.PROP_2, 1L);
entity.putProperty(TestPropertyNames.PROP_3, "1");
entity.putProperty(TestPropertyNames.PROP_4, freqMap);
entity.putProperty(TestPropertyNames.PROP_5, "property");
entity.putProperty(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1)));
entity.putProperty(TestPropertyNames.TIMESTAMP, 1L);
entity.putProperty(TestPropertyNames.VISIBILITY, "public");
addToMap(entity, entities);
}
final FreqMap freqMap2 = new FreqMap();
freqMap2.upsert("key");
final Entity secondEntity = new Entity(TestGroups.ENTITY, SOURCE + i);
secondEntity.putProperty(TestPropertyNames.COUNT, 1L);
secondEntity.putProperty(TestPropertyNames.PROP_1, 1);
secondEntity.putProperty(TestPropertyNames.PROP_2, 1L);
secondEntity.putProperty(TestPropertyNames.PROP_3, "1");
secondEntity.putProperty(TestPropertyNames.PROP_4, freqMap2);
secondEntity.putProperty(TestPropertyNames.PROP_5, "property");
secondEntity.putProperty(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1)));
secondEntity.putProperty(TestPropertyNames.TIMESTAMP, 1L);
secondEntity.putProperty(TestPropertyNames.VISIBILITY, "public");
addToMap(secondEntity, entities);
final FreqMap freqMap3 = new FreqMap();
freqMap3.upsert("key");
final Entity thirdEntity = new Entity(TestGroups.ENTITY, DEST + i);
thirdEntity.putProperty(TestPropertyNames.COUNT, 1L);
thirdEntity.putProperty(TestPropertyNames.PROP_1, 1);
thirdEntity.putProperty(TestPropertyNames.PROP_2, 1L);
thirdEntity.putProperty(TestPropertyNames.PROP_3, "1");
thirdEntity.putProperty(TestPropertyNames.PROP_4, freqMap3);
thirdEntity.putProperty(TestPropertyNames.PROP_5, "property");
thirdEntity.putProperty(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1)));
thirdEntity.putProperty(TestPropertyNames.TIMESTAMP, 1L);
thirdEntity.putProperty(TestPropertyNames.VISIBILITY, "private");
addToMap(thirdEntity, entities);
final FreqMap freqMap4 = new FreqMap();
freqMap4.upsert("key");
final Entity fourthEntity = new Entity(TestGroups.ENTITY, SOURCE_DIR + i);
fourthEntity.putProperty(TestPropertyNames.COUNT, 1L);
fourthEntity.putProperty(TestPropertyNames.PROP_1, 1);
fourthEntity.putProperty(TestPropertyNames.PROP_2, 1L);
fourthEntity.putProperty(TestPropertyNames.PROP_3, "1");
fourthEntity.putProperty(TestPropertyNames.PROP_4, freqMap4);
fourthEntity.putProperty(TestPropertyNames.PROP_5, "property");
fourthEntity.putProperty(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1)));
fourthEntity.putProperty(TestPropertyNames.TIMESTAMP, 1L);
fourthEntity.putProperty(TestPropertyNames.VISIBILITY, "public");
addToMap(fourthEntity, entities);
final FreqMap freqMap5 = new FreqMap();
freqMap5.upsert("key");
final Entity fifthEntity = new Entity(TestGroups.ENTITY, DEST_DIR + i);
fifthEntity.putProperty(TestPropertyNames.COUNT, 1L);
fifthEntity.putProperty(TestPropertyNames.PROP_1, 1);
fifthEntity.putProperty(TestPropertyNames.PROP_2, 1L);
fifthEntity.putProperty(TestPropertyNames.PROP_3, "1");
fifthEntity.putProperty(TestPropertyNames.PROP_4, freqMap5);
fifthEntity.putProperty(TestPropertyNames.PROP_5, "property");
fifthEntity.putProperty(TestPropertyNames.DATE, Date.from(Instant.ofEpochMilli(1)));
fifthEntity.putProperty(TestPropertyNames.TIMESTAMP, 1L);
fifthEntity.putProperty(TestPropertyNames.VISIBILITY, "private");
addToMap(fifthEntity, entities);
}
return entities;
}
use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.
the class VisibilitySchemaLoader method createEntities.
@Override
public Map<EntityId, Entity> createEntities() {
final Map<EntityId, Entity> entities = new HashMap<>();
for (int i = 0; i <= 10; i++) {
for (int j = 0; j < VERTEX_PREFIXES.length; j++) {
final Entity entity = new Entity(TestGroups.ENTITY, VERTEX_PREFIXES[j] + i);
entity.putProperty(TestPropertyNames.COUNT, 1L);
entity.putProperty(TestPropertyNames.VISIBILITY, "public");
addToMap(entity, entities);
}
final Entity secondEntity = new Entity(TestGroups.ENTITY, SOURCE + i);
secondEntity.putProperty(TestPropertyNames.COUNT, 1L);
secondEntity.putProperty(TestPropertyNames.VISIBILITY, "private");
addToMap(secondEntity, entities);
final Entity thirdEntity = new Entity(TestGroups.ENTITY, DEST + i);
thirdEntity.putProperty(TestPropertyNames.COUNT, 1L);
thirdEntity.putProperty(TestPropertyNames.VISIBILITY, "public");
addToMap(thirdEntity, entities);
final Entity fourthEntity = new Entity(TestGroups.ENTITY, SOURCE_DIR + i);
fourthEntity.putProperty(TestPropertyNames.COUNT, 1L);
fourthEntity.putProperty(TestPropertyNames.VISIBILITY, "public");
addToMap(fourthEntity, entities);
final Entity fifthEntity = new Entity(TestGroups.ENTITY, DEST_DIR + i);
fifthEntity.putProperty(TestPropertyNames.COUNT, 1L);
fifthEntity.putProperty(TestPropertyNames.VISIBILITY, "private");
addToMap(fifthEntity, entities);
}
return entities;
}
use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.
the class FilterToOperationConverterTest method testSpecifyVertexAndPropertyFilter.
@Test
public void testSpecifyVertexAndPropertyFilter() {
final Schema schema = getSchema();
final SparkSession sparkSession = SparkSessionProvider.getSparkSession();
// Specify vertex and a filter on property1
Filter[] filters = new Filter[2];
filters[0] = new GreaterThan("property1", 5);
filters[1] = new EqualTo(SchemaToStructTypeConverter.VERTEX_COL_NAME, "0");
FiltersToOperationConverter converter = new FiltersToOperationConverter(getViewFromSchema(schema), schema, filters);
Operation operation = converter.getOperation();
assertTrue(operation instanceof GetRDDOfElements);
assertEquals(1, ((GraphFilters) operation).getView().getEntityGroups().size());
assertEquals(0, ((GraphFilters) operation).getView().getEdgeGroups().size());
final Set<EntityId> seeds = new HashSet<>();
for (final Object seed : ((GetRDDOfElements) operation).getInput()) {
seeds.add((EntitySeed) seed);
}
assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
View opView = ((GraphFilters) operation).getView();
List<TupleAdaptedPredicate<String, ?>> entityPostAggFilters = opView.getEntity(ENTITY_GROUP).getPostAggregationFilterFunctions();
assertThat(entityPostAggFilters).hasSize(1);
final ArrayList<String> expectedProperties = new ArrayList<>();
expectedProperties.add("property1");
assertThat(entityPostAggFilters.get(0).getSelection()).hasSize(1);
assertEquals(expectedProperties.get(0), entityPostAggFilters.get(0).getSelection()[0]);
final ArrayList<Predicate> expectedFunctions = new ArrayList<>();
expectedFunctions.add(new IsMoreThan(5, false));
assertEquals(expectedFunctions.get(0), entityPostAggFilters.get(0).getPredicate());
// Specify vertex and filters on properties property1 and property4
filters = new Filter[3];
filters[0] = new GreaterThan("property1", 5);
filters[1] = new EqualTo(SchemaToStructTypeConverter.VERTEX_COL_NAME, "0");
filters[2] = new LessThan("property4", 8);
converter = new FiltersToOperationConverter(getViewFromSchema(schema), schema, filters);
operation = converter.getOperation();
assertTrue(operation instanceof GetRDDOfElements);
assertEquals(1, ((GraphFilters) operation).getView().getEntityGroups().size());
assertEquals(0, ((GraphFilters) operation).getView().getEdgeGroups().size());
seeds.clear();
for (final Object seed : ((GetRDDOfElements) operation).getInput()) {
seeds.add((EntitySeed) seed);
}
assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
opView = ((GraphFilters) operation).getView();
entityPostAggFilters = opView.getEntity(ENTITY_GROUP).getPostAggregationFilterFunctions();
assertThat(entityPostAggFilters).hasSize(2);
expectedProperties.clear();
expectedProperties.add("property1");
expectedProperties.add("property4");
assertThat(entityPostAggFilters.get(0).getSelection()).hasSize(1);
assertEquals(expectedProperties.get(0), entityPostAggFilters.get(0).getSelection()[0]);
assertThat(entityPostAggFilters.get(1).getSelection()).hasSize(1);
assertEquals(expectedProperties.get(1), entityPostAggFilters.get(1).getSelection()[0]);
expectedFunctions.clear();
expectedFunctions.add(new IsMoreThan(5, false));
expectedFunctions.add(new IsLessThan(8, false));
assertEquals(expectedFunctions.get(0), entityPostAggFilters.get(0).getPredicate());
assertEquals(expectedFunctions.get(1), entityPostAggFilters.get(1).getPredicate());
}
use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.
the class FilterToOperationConverterTest method testSpecifyVertex.
@Test
public void testSpecifyVertex() {
final Schema schema = getSchema();
final SparkSession sparkSession = SparkSessionProvider.getSparkSession();
final Filter[] filters = new Filter[1];
filters[0] = new EqualTo(SchemaToStructTypeConverter.VERTEX_COL_NAME, "0");
final FiltersToOperationConverter converter = new FiltersToOperationConverter(getViewFromSchema(schema), schema, filters);
final Operation operation = converter.getOperation();
assertTrue(operation instanceof GetRDDOfElements);
assertEquals(Collections.singleton(ENTITY_GROUP), ((GraphFilters) operation).getView().getEntityGroups());
assertEquals(0, ((GraphFilters) operation).getView().getEdgeGroups().size());
final Set<EntityId> seeds = new HashSet<>();
for (final Object seed : ((GetRDDOfElements) operation).getInput()) {
seeds.add((EntitySeed) seed);
}
assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
}
Aggregations