Search in sources :

Example 1 with IncludeIncomingOutgoingType

use of uk.gov.gchq.gaffer.operation.GetOperation.IncludeIncomingOutgoingType in project Gaffer by gchq.

the class ClassicIteratorSettingsFactory method getEdgeEntityDirectionFilterIteratorSetting.

@Override
public IteratorSetting getEdgeEntityDirectionFilterIteratorSetting(final GetElementsOperation<?, ?> operation) {
    final boolean includeEntities = operation.isIncludeEntities();
    final IncludeEdgeType includeEdgeType = operation.getIncludeEdges();
    final IncludeIncomingOutgoingType includeIncomingOutgoingType = operation.getIncludeIncomingOutGoing();
    final boolean deduplicateUndirectedEdges = operation instanceof GetAllElements;
    if (includeIncomingOutgoingType == IncludeIncomingOutgoingType.BOTH && includeEdgeType == IncludeEdgeType.ALL && !deduplicateUndirectedEdges) {
        return null;
    }
    return 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(includeIncomingOutgoingType).includeEdges(includeEdgeType).includeEntities(includeEntities).deduplicateUndirectedEdges(deduplicateUndirectedEdges).build();
}
Also used : IncludeEdgeType(uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType) IncludeIncomingOutgoingType(uk.gov.gchq.gaffer.operation.GetOperation.IncludeIncomingOutgoingType) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) IteratorSettingBuilder(uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder)

Example 2 with IncludeIncomingOutgoingType

use of uk.gov.gchq.gaffer.operation.GetOperation.IncludeIncomingOutgoingType in project Gaffer by gchq.

the class GetElementsHandler method isSeedRelated.

private boolean isSeedRelated(final GetElements<ElementSeed, Element> operation, final Edge edge) {
    final Matches seedMatches = isSeedRelated(ElementSeed.createSeed(edge), operation.getSeeds());
    final IncludeEdgeType includeEdgeType = operation.getIncludeEdges();
    final IncludeIncomingOutgoingType inOutType = operation.getIncludeIncomingOutGoing();
    if (IncludeEdgeType.ALL == includeEdgeType) {
        if (IncludeIncomingOutgoingType.BOTH == inOutType) {
            return seedMatches.isMatch();
        }
        if (IncludeIncomingOutgoingType.INCOMING == inOutType) {
            if (edge.isDirected()) {
                return seedMatches.isDestination();
            }
            return seedMatches.isMatch();
        }
        if (IncludeIncomingOutgoingType.OUTGOING == inOutType) {
            if (edge.isDirected()) {
                return seedMatches.isSource();
            }
            return seedMatches.isMatch();
        }
    }
    if (IncludeEdgeType.DIRECTED == includeEdgeType) {
        if (!edge.isDirected()) {
            return false;
        }
        if (IncludeIncomingOutgoingType.BOTH == inOutType) {
            return seedMatches.isMatch();
        }
        if (IncludeIncomingOutgoingType.INCOMING == inOutType) {
            return seedMatches.isDestination();
        }
        if (IncludeIncomingOutgoingType.OUTGOING == inOutType) {
            return seedMatches.isSource();
        }
    }
    if (IncludeEdgeType.UNDIRECTED == includeEdgeType) {
        if (edge.isDirected()) {
            return false;
        }
        if (IncludeIncomingOutgoingType.BOTH == inOutType) {
            return seedMatches.isMatch();
        }
        if (IncludeIncomingOutgoingType.INCOMING == inOutType) {
            return seedMatches.isMatch();
        }
        if (IncludeIncomingOutgoingType.OUTGOING == inOutType) {
            return seedMatches.isMatch();
        }
    }
    return false;
}
Also used : Matches(uk.gov.gchq.gaffer.operation.data.ElementSeed.Matches) IncludeEdgeType(uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType) IncludeIncomingOutgoingType(uk.gov.gchq.gaffer.operation.GetOperation.IncludeIncomingOutgoingType)

Example 3 with IncludeIncomingOutgoingType

use of uk.gov.gchq.gaffer.operation.GetOperation.IncludeIncomingOutgoingType in project Gaffer by gchq.

the class ByteEntityIteratorSettingsFactory method getElementPropertyRangeQueryFilter.

@Override
public IteratorSetting getElementPropertyRangeQueryFilter(final GetElementsOperation<?, ?> operation) {
    final boolean includeEntities = operation.isIncludeEntities();
    final IncludeEdgeType includeEdgeType = operation.getIncludeEdges();
    final IncludeIncomingOutgoingType includeIncomingOutgoingType = operation.getIncludeIncomingOutGoing();
    final boolean deduplicateUndirectedEdges = operation instanceof GetAllElements;
    if (includeEdgeType == IncludeEdgeType.ALL && includeIncomingOutgoingType == IncludeIncomingOutgoingType.BOTH && includeEntities && !deduplicateUndirectedEdges) {
        return null;
    }
    return new IteratorSettingBuilder(AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_PRIORITY, AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_NAME, RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR).all().includeIncomingOutgoing(includeIncomingOutgoingType).includeEdges(includeEdgeType).includeEntities(includeEntities).deduplicateUndirectedEdges(deduplicateUndirectedEdges).build();
}
Also used : IncludeEdgeType(uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType) IncludeIncomingOutgoingType(uk.gov.gchq.gaffer.operation.GetOperation.IncludeIncomingOutgoingType) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) IteratorSettingBuilder(uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder)

Example 4 with IncludeIncomingOutgoingType

use of uk.gov.gchq.gaffer.operation.GetOperation.IncludeIncomingOutgoingType in project Gaffer by gchq.

the class ByteEntityRangeFactory method getRange.

@Override
protected <T extends GetElementsOperation<?, ?>> List<Range> getRange(final Object vertex, final T operation, final IncludeEdgeType includeEdgesParam) throws RangeFactoryException {
    final IncludeIncomingOutgoingType inOutType = operation.getIncludeIncomingOutGoing();
    final IncludeEdgeType includeEdges;
    final boolean includeEntities;
    if (SeedMatchingType.EQUAL.equals(operation.getSeedMatching())) {
        includeEdges = IncludeEdgeType.NONE;
        includeEntities = true;
    } else {
        includeEdges = includeEdgesParam;
        includeEntities = operation.isIncludeEntities();
    }
    byte[] serialisedVertex;
    try {
        serialisedVertex = ByteArrayEscapeUtils.escape(schema.getVertexSerialiser().serialise(vertex));
    } catch (final SerialisationException e) {
        throw new RangeFactoryException("Failed to serialise identifier", e);
    }
    if (!includeEntities && includeEdges == IncludeEdgeType.NONE) {
        throw new IllegalArgumentException("Need to include either Entities or Edges or both when getting Range");
    }
    if (includeEdges == IncludeEdgeType.NONE) {
        // return only entities
        return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true));
    } else {
        if (includeEntities) {
            if (includeEdges == IncludeEdgeType.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 (includeEdges == IncludeEdgeType.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 (includeEdges == IncludeEdgeType.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 (includeEdges == IncludeEdgeType.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> keys = getAllEdgeOnlyKeys(serialisedVertex);
                return Collections.singletonList(new Range(keys.getFirst(), false, keys.getSecond(), false));
            }
        }
    }
}
Also used : IncludeEdgeType(uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) IncludeIncomingOutgoingType(uk.gov.gchq.gaffer.operation.GetOperation.IncludeIncomingOutgoingType) Range(org.apache.accumulo.core.data.Range) RangeFactoryException(uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException) Pair(uk.gov.gchq.gaffer.accumulostore.utils.Pair)

Aggregations

IncludeEdgeType (uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType)4 IncludeIncomingOutgoingType (uk.gov.gchq.gaffer.operation.GetOperation.IncludeIncomingOutgoingType)4 IteratorSettingBuilder (uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder)2 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)2 Range (org.apache.accumulo.core.data.Range)1 RangeFactoryException (uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)1 Pair (uk.gov.gchq.gaffer.accumulostore.utils.Pair)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1 Matches (uk.gov.gchq.gaffer.operation.data.ElementSeed.Matches)1