Search in sources :

Example 1 with SeededGraphFilters

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;
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) SeededGraphFilters(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters) IteratorSettingBuilder(uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder)

Example 2 with SeededGraphFilters

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));
            }
        }
    }
}
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 3 with SeededGraphFilters

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));
            }
        }
    }
}
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)

Example 4 with SeededGraphFilters

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;
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) IncludeIncomingOutgoingType(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters.IncludeIncomingOutgoingType) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) SeededGraphFilters(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters) IteratorSettingBuilder(uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder)

Aggregations

DirectedType (uk.gov.gchq.gaffer.data.element.id.DirectedType)4 SeededGraphFilters (uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters)4 IncludeIncomingOutgoingType (uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters.IncludeIncomingOutgoingType)3 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)2 IteratorSettingBuilder (uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder)2 Pair (uk.gov.gchq.gaffer.commonutil.pair.Pair)2 SeedMatching (uk.gov.gchq.gaffer.operation.SeedMatching)2 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)2 Range (org.apache.accumulo.core.data.Range)1 RowRange (org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange)1 RangeFactoryException (uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1 ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)1