Search in sources :

Example 86 with Key

use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.

the class ByteEntityRangeFactory method getAllEdgeOnlyKeys.

private Pair<Key> getAllEdgeOnlyKeys(final byte[] serialisedVertex) {
    final byte[] endKeyBytes = Arrays.copyOf(serialisedVertex, serialisedVertex.length + 3);
    endKeyBytes[serialisedVertex.length] = ByteArrayEscapeUtils.DELIMITER;
    endKeyBytes[serialisedVertex.length + 1] = ByteEntityPositions.UNDIRECTED_EDGE;
    endKeyBytes[serialisedVertex.length + 2] = ByteArrayEscapeUtils.DELIMITER_PLUS_ONE;
    final byte[] startKeyBytes = Arrays.copyOf(serialisedVertex, serialisedVertex.length + 3);
    startKeyBytes[serialisedVertex.length] = ByteArrayEscapeUtils.DELIMITER;
    startKeyBytes[serialisedVertex.length + 1] = ByteEntityPositions.CORRECT_WAY_DIRECTED_EDGE;
    startKeyBytes[serialisedVertex.length + 2] = ByteArrayEscapeUtils.DELIMITER;
    return new Pair<>(new Key(startKeyBytes, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE), new Key(endKeyBytes, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE));
}
Also used : Key(org.apache.accumulo.core.data.Key) Pair(uk.gov.gchq.gaffer.accumulostore.utils.Pair)

Example 87 with Key

use of org.apache.accumulo.core.data.Key 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)

Example 88 with Key

use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.

the class ClassicRangeFactory method getRange.

private Range getRange(final byte[] serialisedVertex) {
    final byte[] endRowKey = new byte[serialisedVertex.length + 1];
    System.arraycopy(serialisedVertex, 0, endRowKey, 0, serialisedVertex.length);
    endRowKey[serialisedVertex.length] = ByteArrayEscapeUtils.DELIMITER_PLUS_ONE;
    final Key startKey = new Key(serialisedVertex, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
    final Key endKey = new Key(endRowKey, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
    return new Range(startKey, true, endKey, false);
}
Also used : Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key)

Example 89 with Key

use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldGetOriginalEdgeWithMatchAsSourceNotSet.

@Test
public void shouldGetOriginalEdgeWithMatchAsSourceNotSet() throws SchemaException, AccumuloElementConversionException, IOException {
    // Given
    final Edge edge = new Edge(TestGroups.EDGE);
    edge.setDestination("2");
    edge.setSource("1");
    edge.setDirected(true);
    edge.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 100);
    final Pair<Key> keys = converter.getKeysFromElement(edge);
    final Map<String, String> options = new HashMap<>();
    // When
    final Edge newEdge = (Edge) converter.getElementFromKey(keys.getSecond(), options);
    // Then
    assertEquals("1", newEdge.getSource());
    assertEquals("2", newEdge.getDestination());
    assertEquals(true, newEdge.isDirected());
    assertEquals(100, newEdge.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER));
}
Also used : HashMap(java.util.HashMap) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 90 with Key

use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldReturnAccumuloKeyConverterFromCFCQPropertydEntity.

@Test
public void shouldReturnAccumuloKeyConverterFromCFCQPropertydEntity() throws SchemaException, AccumuloElementConversionException, IOException {
    // Given
    final Entity entity = new Entity(TestGroups.ENTITY);
    entity.setVertex("3");
    entity.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 100);
    // When
    final Pair<Key> keys = converter.getKeysFromElement(entity);
    final Entity newEntity = (Entity) converter.getElementFromKey(keys.getFirst());
    // Then
    assertEquals("3", newEntity.getVertex());
    assertEquals(100, newEntity.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER));
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Aggregations

Key (org.apache.accumulo.core.data.Key)115 Value (org.apache.accumulo.core.data.Value)68 Test (org.junit.Test)66 Edge (uk.gov.gchq.gaffer.data.element.Edge)44 Range (org.apache.accumulo.core.data.Range)35 HashMap (java.util.HashMap)29 Text (org.apache.hadoop.io.Text)23 Element (uk.gov.gchq.gaffer.data.element.Element)23 Scanner (org.apache.accumulo.core.client.Scanner)19 Authorizations (org.apache.accumulo.core.security.Authorizations)18 Mutation (org.apache.accumulo.core.data.Mutation)17 Entity (uk.gov.gchq.gaffer.data.element.Entity)15 Entry (java.util.Map.Entry)14 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)13 AccumuloException (org.apache.accumulo.core.client.AccumuloException)11 Connector (org.apache.accumulo.core.client.Connector)11 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)11 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)11 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)11 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)11