use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class GetAdjacentIdsDeletedElementsIT method assertElements.
@Override
protected void assertElements(final Iterable<ElementId> expected, final CloseableIterable<? extends EntityId> actual) {
final List<ElementId> expectedIds = new ArrayList<>();
for (final ElementId element : expected) {
if (element instanceof EdgeId) {
expectedIds.add(new EntitySeed(((EdgeId) element).getDestination()));
}
}
super.assertElements(expectedIds, actual);
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldDeserialiseEdgeIdWithQueriedDestVertex.
@Test
public void shouldDeserialiseEdgeIdWithQueriedDestVertex() {
// Given
final EdgeId expectedElementId = new EdgeSeed("vertex1", "vertex2", true, EdgeId.MatchedVertex.DESTINATION);
final Edge edge = new Edge.Builder().source("vertex1").dest("vertex2").directed(true).group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, new FreqMap()).property(TestPropertyNames.PROP_2, new FreqMap()).build();
final Key key = converter.getKeysFromEdge(edge).getSecond();
// When
final ElementId elementId = converter.getElementId(key, false);
// Then
assertEquals(expectedElementId, elementId);
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldDeserialiseEdgeIdWithQueriedSourceVertex.
@Test
public void shouldDeserialiseEdgeIdWithQueriedSourceVertex() {
// Given
final EdgeId expectedElementId = new EdgeSeed("source1", "dest1", true);
final Edge edge = new Edge.Builder().source("source1").dest("dest1").directed(true).group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, new FreqMap()).property(TestPropertyNames.PROP_2, new FreqMap()).build();
final Key key = converter.getKeysFromEdge(edge).getSecond();
// When
final ElementId elementId = converter.getElementId(key, false);
// Then
assertEquals(expectedElementId, elementId);
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class QueryGenerator method seedToPredicate.
private FilterPredicate seedToPredicate(final ParquetElementSeed seed, final SeededGraphFilters.IncludeIncomingOutgoingType includeIncomingOutgoingType, final SeedMatching.SeedMatchingType seedMatchingType, final String group, final boolean reversed) {
final boolean isEntityGroup = schemaUtils.getEntityGroups().contains(group);
FilterPredicate filter = null;
final ElementId elementId = seed.getElementId();
// Is it an entity group?
if (isEntityGroup) {
// EntityId case
if (elementId instanceof EntityId) {
filter = getIsEqualFilter(ParquetStore.VERTEX, ((ParquetEntitySeed) seed).getSeed(), group);
} else {
// EdgeId case
// Does the seed type need to match the group type?
final ParquetEdgeSeed edgeSeed = (ParquetEdgeSeed) seed;
if (seedMatchingType != SeedMatching.SeedMatchingType.EQUAL) {
// Vertex = source of edge seed or Vertex = destination of edge seed
// look in partition 0 with filter src = A and partition 1 with filter src = B
filter = getIsEqualFilter(ParquetStore.VERTEX, edgeSeed.getSource(), group);
if (null != ((ParquetEdgeSeed) seed).getDestination()) {
filter = FilterPredicateUtils.or(filter, getIsEqualFilter(ParquetStore.VERTEX, edgeSeed.getDestination(), group));
}
}
}
} else {
// EntityId case
if (elementId instanceof EntityId) {
// If seedMatchingType is EQUAL then we can't find anything in an edge group
if (seedMatchingType != SeedMatching.SeedMatchingType.EQUAL) {
if (includeIncomingOutgoingType == SeededGraphFilters.IncludeIncomingOutgoingType.INCOMING) {
if (reversed) {
// Dst is seed
filter = getIsEqualFilter(ParquetStore.DESTINATION, ((ParquetEntitySeed) seed).getSeed(), group);
} else {
// Src is seed and edge is undirected
filter = getIsEqualFilter(ParquetStore.SOURCE, ((ParquetEntitySeed) seed).getSeed(), group);
filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DIRECTED, new Object[] { false }, group));
}
} else if (includeIncomingOutgoingType == SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING) {
if (reversed) {
// Dst is seed and edge is undirected
filter = getIsEqualFilter(ParquetStore.DESTINATION, ((ParquetEntitySeed) seed).getSeed(), group);
filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DIRECTED, new Object[] { false }, group));
} else {
// Src is seed
filter = getIsEqualFilter(ParquetStore.SOURCE, ((ParquetEntitySeed) seed).getSeed(), group);
}
} else {
if (reversed) {
// Dst is seed
filter = getIsEqualFilter(ParquetStore.DESTINATION, ((ParquetEntitySeed) seed).getSeed(), group);
} else {
// Src is seed
filter = getIsEqualFilter(ParquetStore.SOURCE, ((ParquetEntitySeed) seed).getSeed(), group);
}
}
}
} else {
// EdgeId case
final ParquetEdgeSeed edgeSeed = (ParquetEdgeSeed) seed;
if (!reversed) {
// Src is source of edge seed and destination is destination of edge seed
filter = getIsEqualFilter(ParquetStore.SOURCE, edgeSeed.getSource(), group);
// WRONG seed is already serialised source and dest - now fixed?
filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DESTINATION, edgeSeed.getDestination(), group));
final DirectedType directedType = edgeSeed.getDirectedType();
if (directedType == DirectedType.DIRECTED) {
filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DIRECTED, new Object[] { true }, group));
} else if (directedType == DirectedType.UNDIRECTED) {
filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DIRECTED, new Object[] { false }, group));
}
} else {
// TODO Optimise this - there are times this is unnecessary
filter = getIsEqualFilter(ParquetStore.DESTINATION, edgeSeed.getSource(), group);
filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.SOURCE, edgeSeed.getDestination(), group));
final DirectedType directedType = edgeSeed.getDirectedType();
if (directedType == DirectedType.DIRECTED) {
filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DIRECTED, new Object[] { true }, group));
} else if (directedType == DirectedType.UNDIRECTED) {
filter = FilterPredicateUtils.and(filter, getIsEqualFilter(ParquetStore.DIRECTED, new Object[] { false }, group));
}
}
}
}
LOGGER.debug("Returning {} from seedToPredicate", filter);
return filter;
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class GetElementsTest method shouldSetSeedMatchingTypeToEquals.
@Test
public void shouldSetSeedMatchingTypeToEquals() {
// Given
final ElementId elementId1 = new EntitySeed("identifier");
// When
final GetElements op = new GetElements.Builder().input(elementId1).seedMatching(SeedMatchingType.EQUAL).build();
// Then
assertEquals(SeedMatchingType.EQUAL, op.getSeedMatching());
}
Aggregations