use of uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters in project Gaffer by gchq.
the class ByteEntityIteratorSettingsFactory method getElementPropertyRangeQueryFilter.
@Override
public IteratorSetting getElementPropertyRangeQueryFilter(final GraphFilters operation) {
final boolean includeEntities = operation.getView().hasEntities();
final boolean includeEdges = operation.getView().hasEdges();
final DirectedType directedType = operation.getDirectedType();
final SeededGraphFilters.IncludeIncomingOutgoingType inOutType;
if (operation instanceof SeededGraphFilters) {
inOutType = ((SeededGraphFilters) operation).getIncludeIncomingOutGoing();
} else {
inOutType = SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING;
}
final boolean deduplicateUndirectedEdges = operation instanceof GetAllElements;
if (includeEdges && DirectedType.isEither(directedType) && (null == inOutType || inOutType == SeededGraphFilters.IncludeIncomingOutgoingType.EITHER) && includeEntities && !deduplicateUndirectedEdges) {
LOGGER.debug("Returning null from getElementPropertyRangeQueryFilter (" + "inOutType = {}, includeEdges = {}, " + "directedType = {}, deduplicateUndirectedEdges = {})", inOutType, includeEdges, directedType, deduplicateUndirectedEdges);
return null;
}
final IteratorSetting is = new IteratorSettingBuilder(AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_PRIORITY, AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_NAME, RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR).all().includeIncomingOutgoing(inOutType).includeEdges(includeEdges).directedType(directedType).includeEntities(includeEntities).deduplicateUndirectedEdges(deduplicateUndirectedEdges).build();
LOGGER.debug("Creating IteratorSetting for iterator class {} with priority = {}, " + " includeIncomingOutgoing = {}, directedType = {}," + " includeEdges = {}, includeEntities = {}, deduplicateUndirectedEdges = {}", RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR, AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_PRIORITY, inOutType, directedType, includeEdges, includeEntities, deduplicateUndirectedEdges);
return is;
}
use of uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters in project Gaffer by gchq.
the class RowRangeFactory method getRowRange.
private List<RowRange> getRowRange(final Object vertex, final GraphFilters operation, final boolean includeEdgesParam) throws SerialisationException {
final IncludeIncomingOutgoingType inOutType = (operation instanceof SeededGraphFilters) ? ((SeededGraphFilters) operation).getIncludeIncomingOutGoing() : IncludeIncomingOutgoingType.OUTGOING;
final DirectedType directedType = operation.getDirectedType();
final boolean includeEdges;
final boolean includeEntities;
final boolean seedEqual = (operation instanceof SeedMatching) && SeedMatchingType.EQUAL.equals(((SeedMatching) operation).getSeedMatching());
if (seedEqual) {
includeEdges = false;
includeEntities = true;
} else {
includeEdges = includeEdgesParam;
includeEntities = operation.getView().hasEntities();
}
byte[] serialisedVertex = serialiser.serialiseVertex(vertex);
if (!includeEntities && !includeEdges) {
throw new IllegalArgumentException("Need to include either Entities or Edges or both when getting RowRange");
}
if (!includeEdges) {
// return only entities
return Collections.singletonList(new RowRange(getEntityRowId(serialisedVertex, false), true, getEntityRowId(serialisedVertex, true), true));
} else {
if (includeEntities) {
if (directedType == DirectedType.DIRECTED) {
// return onlyDirectedEdges and entities
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Arrays.asList(new RowRange(getEntityRowId(serialisedVertex, false), true, getEntityRowId(serialisedVertex, true), true), new RowRange(getDirectedEdgeRowIdDestFirst(serialisedVertex, false), true, getDirectedEdgeRowIdDestFirst(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Collections.singletonList(new RowRange(getEntityRowId(serialisedVertex, false), true, getDirectedEdgeRowIdSourceFirst(serialisedVertex, true), true));
} else {
return Collections.singletonList(new RowRange(getEntityRowId(serialisedVertex, false), true, getDirectedEdgeRowIdDestFirst(serialisedVertex, true), false));
}
} else if (directedType == DirectedType.UNDIRECTED) {
// Entity only range and undirected only range
return Arrays.asList(new RowRange(getUndirectedEdgeRowId(serialisedVertex, false), true, getUndirectedEdgeRowId(serialisedVertex, true), true), new RowRange(getEntityRowId(serialisedVertex, false), true, getEntityRowId(serialisedVertex, true), true));
} else {
// Return everything
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Arrays.asList(new RowRange(getEntityRowId(serialisedVertex, false), true, getEntityRowId(serialisedVertex, true), true), new RowRange(getDirectedEdgeRowIdDestFirst(serialisedVertex, false), true, getUndirectedEdgeRowId(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Arrays.asList(new RowRange(getEntityRowId(serialisedVertex, false), true, getDirectedEdgeRowIdSourceFirst(serialisedVertex, true), true), new RowRange(getUndirectedEdgeRowId(serialisedVertex, false), true, getUndirectedEdgeRowId(serialisedVertex, true), true));
} else {
return Collections.singletonList(new RowRange(getEntityRowId(serialisedVertex, false), true, getUndirectedEdgeRowId(serialisedVertex, true), true));
}
}
} else if (directedType == DirectedType.DIRECTED) {
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Collections.singletonList(new RowRange(getDirectedEdgeRowIdDestFirst(serialisedVertex, false), true, getDirectedEdgeRowIdDestFirst(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Collections.singletonList(new RowRange(getDirectedEdgeRowIdSourceFirst(serialisedVertex, false), true, getDirectedEdgeRowIdSourceFirst(serialisedVertex, true), true));
} else {
return Collections.singletonList(new RowRange(getDirectedEdgeRowIdSourceFirst(serialisedVertex, false), true, getDirectedEdgeRowIdDestFirst(serialisedVertex, true), true));
}
} else if (directedType == DirectedType.UNDIRECTED) {
return Collections.singletonList(new RowRange(getUndirectedEdgeRowId(serialisedVertex, false), true, getUndirectedEdgeRowId(serialisedVertex, true), true));
} else {
// return all edges
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Collections.singletonList(new RowRange(getDirectedEdgeRowIdDestFirst(serialisedVertex, false), true, getUndirectedEdgeRowId(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Arrays.asList(new RowRange(getDirectedEdgeRowIdSourceFirst(serialisedVertex, false), true, getDirectedEdgeRowIdSourceFirst(serialisedVertex, true), true), new RowRange(getUndirectedEdgeRowId(serialisedVertex, false), true, getUndirectedEdgeRowId(serialisedVertex, true), true));
} else {
final Pair<byte[], byte[]> keys = getAllEdgeOnlyRowIds(serialisedVertex);
return Collections.singletonList(new RowRange(keys.getFirst(), false, keys.getSecond(), false));
}
}
}
}
use of uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters in project Gaffer by gchq.
the class ByteEntityRangeFactory method getRange.
@Override
protected List<Range> getRange(final Object vertex, final GraphFilters operation, final boolean includeEdgesParam) throws RangeFactoryException {
final IncludeIncomingOutgoingType inOutType = (operation instanceof SeededGraphFilters) ? ((SeededGraphFilters) operation).getIncludeIncomingOutGoing() : IncludeIncomingOutgoingType.OUTGOING;
final DirectedType directedType = operation.getDirectedType();
final boolean includeEdges;
final boolean includeEntities;
final boolean seedEqual = (operation instanceof SeedMatching) && SeedMatchingType.EQUAL.equals(((SeedMatching) operation).getSeedMatching());
if (seedEqual) {
includeEdges = false;
includeEntities = true;
} else {
includeEdges = includeEdgesParam;
includeEntities = operation.getView().hasEntities();
}
byte[] serialisedVertex;
try {
serialisedVertex = ByteArrayEscapeUtils.escape(((ToBytesSerialiser) schema.getVertexSerialiser()).serialise(vertex));
} catch (final SerialisationException e) {
throw new RangeFactoryException("Failed to serialise identifier", e);
}
if (!includeEntities && !includeEdges) {
throw new IllegalArgumentException("Need to include either Entities or Edges or both when getting Range");
}
if (!includeEdges) {
// return only entities
return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true));
} else {
if (includeEntities) {
if (directedType == DirectedType.DIRECTED) {
// return onlyDirectedEdges and entities
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Arrays.asList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true), new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true));
} else {
return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), false, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), false));
}
} else if (directedType == DirectedType.UNDIRECTED) {
// Entity only range and undirected only range
return Arrays.asList(new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true), new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true));
} else {
// Return everything
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Arrays.asList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true), new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Arrays.asList(new Range(getEntityKey(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true), new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else {
return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
}
}
} else if (directedType == DirectedType.DIRECTED) {
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Collections.singletonList(new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Collections.singletonList(new Range(getDirectedEdgeKeySourceFirst(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true));
} else {
return Collections.singletonList(new Range(getDirectedEdgeKeySourceFirst(serialisedVertex, false), true, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), true));
}
} else if (directedType == DirectedType.UNDIRECTED) {
return Collections.singletonList(new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else {
// return all edges
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
return Collections.singletonList(new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
return Arrays.asList(new Range(getDirectedEdgeKeySourceFirst(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true), new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
} else {
final Pair<Key, Key> keys = getAllEdgeOnlyKeys(serialisedVertex);
return Collections.singletonList(new Range(keys.getFirst(), false, keys.getSecond(), false));
}
}
}
}
use of uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters in project Gaffer by gchq.
the class ClassicIteratorSettingsFactory method getEdgeEntityDirectionFilterIteratorSetting.
@Override
public IteratorSetting getEdgeEntityDirectionFilterIteratorSetting(final GraphFilters operation) {
final boolean includeEntities = operation.getView().hasEntities();
final boolean includeEdges = operation.getView().hasEdges();
final DirectedType directedType = operation.getDirectedType();
final IncludeIncomingOutgoingType inOutType;
if (operation instanceof SeededGraphFilters) {
inOutType = ((SeededGraphFilters) operation).getIncludeIncomingOutGoing();
} else {
inOutType = IncludeIncomingOutgoingType.OUTGOING;
}
final boolean deduplicateUndirectedEdges = operation instanceof GetAllElements;
if ((null == inOutType || inOutType == IncludeIncomingOutgoingType.EITHER) && includeEdges && (DirectedType.isEither(directedType)) && !deduplicateUndirectedEdges) {
LOGGER.debug("Returning null from getEdgeEntityDirectionFilterIteratorSetting (" + "inOutType = {}, includeEdges = {}, directedType = {}, deduplicateUndirectedEdges = {})", inOutType, includeEdges, directedType, deduplicateUndirectedEdges);
return null;
}
final IteratorSetting is = new IteratorSettingBuilder(AccumuloStoreConstants.EDGE_ENTITY_DIRECTED_UNDIRECTED_INCOMING_OUTGOING_FILTER_ITERATOR_PRIORITY, AccumuloStoreConstants.EDGE_ENTITY_DIRECTED_UNDIRECTED_INCOMING_OUTGOING_FILTER_ITERATOR_NAME, EDGE_DIRECTED_UNDIRECTED_FILTER).includeIncomingOutgoing(inOutType).directedType(directedType).includeEdges(includeEdges).includeEntities(includeEntities).deduplicateUndirectedEdges(deduplicateUndirectedEdges).build();
LOGGER.debug("Creating IteratorSetting for iterator class {} with " + "priority = {}, includeIncomingOutgoing = {}, directedType = {}, " + "includeEdges = {}, includeEntities = {}, deduplicateUndirectedEdges = {}", EDGE_DIRECTED_UNDIRECTED_FILTER, AccumuloStoreConstants.EDGE_ENTITY_DIRECTED_UNDIRECTED_INCOMING_OUTGOING_FILTER_ITERATOR_PRIORITY, inOutType, directedType, includeEdges, includeEntities, deduplicateUndirectedEdges);
return is;
}
Aggregations