Search in sources :

Example 1 with SeedMatching

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

the class AbstractCoreKeyRangeFactory method getRange.

private List<Range> getRange(final ElementId elementId, final GraphFilters operation, final SeededGraphFilters.IncludeIncomingOutgoingType inOutType) throws RangeFactoryException {
    if (elementId instanceof EntityId) {
        return getRange(((EntityId) elementId).getVertex(), operation, operation.getView().hasEdges());
    } else {
        final EdgeId edgeId = (EdgeId) elementId;
        final List<Range> ranges = new ArrayList<>();
        if (operation.getView().hasEdges() && DirectedType.areCompatible(operation.getDirectedType(), edgeId.getDirectedType())) {
            // EQUALS and RELATED seed matching.
            final DirectedType directed = DirectedType.and(operation.getDirectedType(), edgeId.getDirectedType());
            ranges.addAll(getRange(edgeId.getSource(), edgeId.getDestination(), directed, operation, inOutType));
        }
        // Do related - if operation doesn't have seed matching or it has seed matching equal to RELATED
        final boolean doRelated = !(operation instanceof SeedMatching) || !SeedMatching.SeedMatchingType.EQUAL.equals(((SeedMatching) operation).getSeedMatching());
        if (doRelated && operation.getView().hasEntities()) {
            // Get Entities related to EdgeIds
            ranges.addAll(getRange(edgeId.getSource(), operation, false));
            ranges.addAll(getRange(edgeId.getDestination(), operation, false));
        }
        return ranges;
    }
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) ArrayList(java.util.ArrayList) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) SeedMatching(uk.gov.gchq.gaffer.operation.SeedMatching) Range(org.apache.accumulo.core.data.Range)

Example 2 with SeedMatching

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

the class RowRangeFactory method getRowRange.

@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "If an element is not an Entity it must be an Edge")
public List<RowRange> getRowRange(final ElementId elementId, final GraphFilters operation) throws SerialisationException {
    if (elementId instanceof EntityId) {
        return getRowRange(((EntityId) elementId).getVertex(), operation, operation.getView().hasEdges());
    } else {
        final EdgeId edgeId = (EdgeId) elementId;
        final List<RowRange> ranges = new ArrayList<>();
        if (operation.getView().hasEdges() && DirectedType.areCompatible(operation.getDirectedType(), edgeId.getDirectedType())) {
            // Get Edges with the given EdgeSeed - This is applicable for
            // EQUALS and RELATED seed matching.
            final DirectedType directed = DirectedType.and(operation.getDirectedType(), edgeId.getDirectedType());
            // To do that we need to create 2 ranges
            if (DirectedType.isEither(directed)) {
                ranges.add(new RowRange(getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), false, false), true, getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), false, true), true));
                ranges.add(new RowRange(getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), true, false), true, getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), true, true), true));
            } else {
                ranges.add(new RowRange(getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), directed.isDirected(), false), true, getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), directed.isDirected(), true), true));
            }
        }
        // Do related - if operation doesn't have seed matching or it has seed matching equal to RELATED
        final boolean doRelated = !(operation instanceof SeedMatching) || !SeedMatchingType.EQUAL.equals(((SeedMatching) operation).getSeedMatching());
        if (doRelated && operation.getView().hasEntities()) {
            // Get Entities related to EdgeIds
            ranges.addAll(getRowRange(edgeId.getSource(), operation, false));
            ranges.addAll(getRowRange(edgeId.getDestination(), operation, false));
        }
        return ranges;
    }
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) RowRange(org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) ArrayList(java.util.ArrayList) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) SeedMatching(uk.gov.gchq.gaffer.operation.SeedMatching) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with SeedMatching

use of uk.gov.gchq.gaffer.operation.SeedMatching 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));
            }
        }
    }
}
Also used : RowRange(org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange) IncludeIncomingOutgoingType(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters.IncludeIncomingOutgoingType) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) SeededGraphFilters(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters) SeedMatching(uk.gov.gchq.gaffer.operation.SeedMatching) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair)

Example 4 with SeedMatching

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

the class ClassicRangeFactory method getRange.

@Override
protected List<Range> getRange(final Object vertex, final GraphFilters operation, final boolean includeEdgesParam) throws RangeFactoryException {
    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 from a type and value");
    }
    if (includeEntities && includeEdges) {
        return Collections.singletonList(getRange(serialisedVertex));
    } else if (includeEntities) {
        return Collections.singletonList(getEntityRangeFromVertex(serialisedVertex));
    } else {
        return Collections.singletonList(getEdgeRangeFromVertex(serialisedVertex));
    }
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) SeedMatching(uk.gov.gchq.gaffer.operation.SeedMatching) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) RangeFactoryException(uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)

Example 5 with SeedMatching

use of uk.gov.gchq.gaffer.operation.SeedMatching 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));
            }
        }
    }
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) IncludeIncomingOutgoingType(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters.IncludeIncomingOutgoingType) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) SeededGraphFilters(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters) SeedMatching(uk.gov.gchq.gaffer.operation.SeedMatching) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) Range(org.apache.accumulo.core.data.Range) RangeFactoryException(uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair)

Aggregations

SeedMatching (uk.gov.gchq.gaffer.operation.SeedMatching)5 DirectedType (uk.gov.gchq.gaffer.data.element.id.DirectedType)4 ArrayList (java.util.ArrayList)2 Range (org.apache.accumulo.core.data.Range)2 RowRange (org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange)2 RangeFactoryException (uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)2 Pair (uk.gov.gchq.gaffer.commonutil.pair.Pair)2 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)2 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)2 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)2 SeededGraphFilters (uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters)2 IncludeIncomingOutgoingType (uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters.IncludeIncomingOutgoingType)2 ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1