Search in sources :

Example 1 with RangeFactoryException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException in project Gaffer by gchq.

the class AbstractGetRDDHandler method addRanges.

public <ELEMENT_SEED extends ElementSeed> void addRanges(final AccumuloStore accumuloStore, final Configuration conf, final GetSparkRDDOperation<ELEMENT_SEED, ?> operation) throws OperationException {
    final List<Range> ranges = new ArrayList<>();
    for (final ELEMENT_SEED entitySeed : operation.getSeeds()) {
        try {
            ranges.addAll(accumuloStore.getKeyPackage().getRangeFactory().getRange(entitySeed, operation));
        } catch (final RangeFactoryException e) {
            throw new OperationException("Failed to add ranges to configuration", e);
        }
    }
    InputConfigurator.setRanges(AccumuloInputFormat.class, conf, ranges);
}
Also used : ArrayList(java.util.ArrayList) Range(org.apache.accumulo.core.data.Range) OperationException(uk.gov.gchq.gaffer.operation.OperationException) RangeFactoryException(uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)

Example 2 with RangeFactoryException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException in project Gaffer by gchq.

the class ByteEntityRangeFactory method getKeyFromEdgeSeed.

@Override
protected <T extends GetElementsOperation<?, ?>> Key getKeyFromEdgeSeed(final EdgeSeed seed, final T operation, final boolean endKey) throws RangeFactoryException {
    final Serialisation vertexSerialiser = schema.getVertexSerialiser();
    final byte directionFlag1 = seed.isDirected() ? ByteEntityPositions.CORRECT_WAY_DIRECTED_EDGE : ByteEntityPositions.UNDIRECTED_EDGE;
    byte[] sourceValue;
    try {
        sourceValue = ByteArrayEscapeUtils.escape((vertexSerialiser.serialise(seed.getSource())));
    } catch (final SerialisationException e) {
        throw new RangeFactoryException("Failed to serialise Edge Source", e);
    }
    byte[] destinationValue;
    try {
        destinationValue = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(seed.getDestination()));
    } catch (final SerialisationException e) {
        throw new RangeFactoryException("Failed to serialise Edge Destination", e);
    }
    int length;
    byte[] key;
    if (endKey) {
        length = sourceValue.length + destinationValue.length + 6;
        key = new byte[length];
        key[key.length - 3] = ByteArrayEscapeUtils.DELIMITER;
        key[key.length - 2] = directionFlag1;
        key[key.length - 1] = ByteArrayEscapeUtils.DELIMITER_PLUS_ONE;
    } else {
        length = sourceValue.length + destinationValue.length + 5;
        key = new byte[length];
        key[key.length - 2] = ByteArrayEscapeUtils.DELIMITER;
        key[key.length - 1] = directionFlag1;
    }
    System.arraycopy(sourceValue, 0, key, 0, sourceValue.length);
    key[sourceValue.length] = ByteArrayEscapeUtils.DELIMITER;
    key[sourceValue.length + 1] = directionFlag1;
    key[sourceValue.length + 2] = ByteArrayEscapeUtils.DELIMITER;
    System.arraycopy(destinationValue, 0, key, sourceValue.length + 3, destinationValue.length);
    return new Key(key, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation) Key(org.apache.accumulo.core.data.Key) RangeFactoryException(uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)

Example 3 with RangeFactoryException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException in project Gaffer by gchq.

the class ClassicRangeFactory method getRange.

@Override
protected <T extends GetElementsOperation<?, ?>> List<Range> getRange(final Object vertex, final T operation, final IncludeEdgeType includeEdgesParam) throws RangeFactoryException {
    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);
    }
    final boolean returnEdges = includeEdges != IncludeEdgeType.NONE;
    if (!includeEntities && !returnEdges) {
        throw new IllegalArgumentException("Need to include either Entities or Edges or both when getting Range from a type and value");
    }
    if (includeEntities && returnEdges) {
        return Collections.singletonList(getRange(serialisedVertex));
    } else if (includeEntities) {
        return Collections.singletonList(getEntityRangeFromVertex(serialisedVertex));
    } else {
        return Collections.singletonList(getEdgeRangeFromVertex(serialisedVertex));
    }
}
Also used : IncludeEdgeType(uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) RangeFactoryException(uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)

Example 4 with RangeFactoryException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException 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)

Example 5 with RangeFactoryException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException in project Gaffer by gchq.

the class ClassicRangeFactory method getKeyFromEdgeSeed.

@Override
protected <T extends GetElementsOperation<?, ?>> Key getKeyFromEdgeSeed(final EdgeSeed seed, final T operation, final boolean endKey) throws RangeFactoryException {
    final byte directionFlag1 = seed.isDirected() ? (operation.getIncludeIncomingOutGoing() == IncludeIncomingOutgoingType.INCOMING ? ClassicBytePositions.INCORRECT_WAY_DIRECTED_EDGE : ClassicBytePositions.CORRECT_WAY_DIRECTED_EDGE) : ClassicBytePositions.UNDIRECTED_EDGE;
    final Serialisation vertexSerialiser = schema.getVertexSerialiser();
    // Serialise source and destination to byte arrays, escaping if
    // necessary
    byte[] source;
    try {
        source = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(seed.getSource()));
    } catch (final SerialisationException e) {
        throw new RangeFactoryException("Failed to serialise Edge Source", e);
    }
    byte[] destination;
    try {
        destination = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(seed.getDestination()));
    } catch (final SerialisationException e) {
        throw new RangeFactoryException("Failed to serialise Edge Destination", e);
    }
    // Length of row key is the length of the source
    // plus the length of the destination
    // plus one for the delimiter in between the source and destination
    // plus one for the delimiter in between the destination and the direction flag
    // plus one for the direction flag at the end.
    byte[] key;
    if (endKey) {
        key = new byte[source.length + destination.length + 4];
        key[key.length - 3] = ByteArrayEscapeUtils.DELIMITER;
        key[key.length - 2] = directionFlag1;
        key[key.length - 1] = ByteArrayEscapeUtils.DELIMITER_PLUS_ONE;
    } else {
        key = new byte[source.length + destination.length + 3];
        key[key.length - 2] = ByteArrayEscapeUtils.DELIMITER;
        key[key.length - 1] = directionFlag1;
    }
    // Create first key: source DELIMITER destination DELIMITER (CORRECT_WAY_DIRECTED_EDGE or UNDIRECTED_EDGE)
    // Here if we desire an EdgeID we and the user has asked for incoming
    // edges only for related items, we put the destination first so we find the flipped edge's key,
    // this key will pass the filter iterators check for incoming edges, but
    // the result will be flipped back to the correct edge on the client end conversion
    // Simply put when looking up an EDGE ID that ID counts as both incoming
    // and outgoing so we use the reversed key when looking up incoming.
    byte[] firstValue;
    byte[] secondValue;
    if (operation.getIncludeIncomingOutGoing() == IncludeIncomingOutgoingType.INCOMING) {
        firstValue = destination;
        secondValue = source;
    } else {
        firstValue = source;
        secondValue = destination;
    }
    System.arraycopy(firstValue, 0, key, 0, firstValue.length);
    key[firstValue.length] = ByteArrayEscapeUtils.DELIMITER;
    System.arraycopy(secondValue, 0, key, firstValue.length + 1, secondValue.length);
    return new Key(key, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation) Key(org.apache.accumulo.core.data.Key) RangeFactoryException(uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)

Aggregations

RangeFactoryException (uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)5 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)4 Key (org.apache.accumulo.core.data.Key)2 Range (org.apache.accumulo.core.data.Range)2 IncludeEdgeType (uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType)2 Serialisation (uk.gov.gchq.gaffer.serialisation.Serialisation)2 ArrayList (java.util.ArrayList)1 Pair (uk.gov.gchq.gaffer.accumulostore.utils.Pair)1 IncludeIncomingOutgoingType (uk.gov.gchq.gaffer.operation.GetOperation.IncludeIncomingOutgoingType)1 OperationException (uk.gov.gchq.gaffer.operation.OperationException)1