Search in sources :

Example 6 with AccumuloElementConversionException

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

the class ByteEntityBloomElementFunctorTest method shouldTransformRangeWhenUsingRangeNotExact.

@Test
public void shouldTransformRangeWhenUsingRangeNotExact() {
    try {
        // Create SimpleEntity
        final Entity simpleEntity = new Entity.Builder().group(TestGroups.ENTITY).vertex("1").build();
        final Key key = elementConverter.getKeyFromEntity(simpleEntity);
        final Range range = Range.exact(key.getRow());
        final org.apache.hadoop.util.bloom.Key expectedBloomKey1 = new org.apache.hadoop.util.bloom.Key(ELEMENT_FUNCTOR.getVertexFromRangeKey(key.getRowData().getBackingArray()));
        assertNotNull(ELEMENT_FUNCTOR.transform(range));
        assertEquals(expectedBloomKey1, ELEMENT_FUNCTOR.transform(range));
    } catch (final AccumuloElementConversionException e) {
        fail("ConversionException " + e);
    }
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException) Test(org.junit.jupiter.api.Test)

Example 7 with AccumuloElementConversionException

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

the class ByteEntityBloomElementFunctorTest method shouldTransformRangeWhenRangeHasUnspecifiedStartOrEndKey.

@Test
public void shouldTransformRangeWhenRangeHasUnspecifiedStartOrEndKey() {
    try {
        // Create Range with unspecified start key and shouldRetrieveElementsInRangeBetweenSeeds - should get null
        final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("3").dest("4").build();
        final Pair<Key, Key> keys = elementConverter.getKeysFromEdge(edge1);
        final Range range1 = new Range(null, true, keys.getFirst().getRow(), true);
        assertNull(ELEMENT_FUNCTOR.transform(range1));
        // Create Range with unspecified end key and shouldRetrieveElementsInRangeBetweenSeeds - should get null
        final Range range2 = new Range(keys.getFirst().getRow(), true, null, true);
        assertNull(ELEMENT_FUNCTOR.transform(range2));
    } catch (final AccumuloElementConversionException e) {
        fail("ConversionException " + e);
    }
}
Also used : Range(org.apache.accumulo.core.data.Range) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException) Test(org.junit.jupiter.api.Test)

Example 8 with AccumuloElementConversionException

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

the class Gaffer1BloomElementFunctorTest method shouldTransformRangeWhenRangeHasUnspecifiedStartOrEndKey.

@Test
public void shouldTransformRangeWhenRangeHasUnspecifiedStartOrEndKey() {
    try {
        // Create Range with unspecified start key and shouldRetrieveElementsInRangeBetweenSeeds - should get null
        final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("3").dest("4").build();
        final Pair<Key, Key> keys = elementConverter.getKeysFromEdge(edge1);
        final Range range1 = new Range(null, true, keys.getFirst().getRow(), true);
        assertNull(ELEMENT_FUNCTOR.transform(range1));
        // Create Range with unspecified end key and shouldRetrieveElementsInRangeBetweenSeeds - should get null
        final Range range2 = new Range(keys.getFirst().getRow(), true, null, true);
        assertNull(ELEMENT_FUNCTOR.transform(range2));
    } catch (final AccumuloElementConversionException e) {
        fail("ConversionException " + e);
    }
}
Also used : Range(org.apache.accumulo.core.data.Range) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException) Test(org.junit.jupiter.api.Test)

Example 9 with AccumuloElementConversionException

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

the class AccumuloStore method insertGraphElements.

protected void insertGraphElements(final Iterable<? extends Element> elements) throws StoreException {
    // Create BatchWriter
    final BatchWriter writer = TableUtils.createBatchWriter(this);
    // too high a latency, etc.
    if (null != elements) {
        for (final Element element : elements) {
            final Pair<Key, Key> keys;
            try {
                keys = keyPackage.getKeyConverter().getKeysFromElement(element);
            } catch (final AccumuloElementConversionException e) {
                LOGGER.error(FAILED_TO_CREATE_AN_ACCUMULO_FROM_ELEMENT_OF_TYPE_WHEN_TRYING_TO_INSERT_ELEMENTS, "key", element.getGroup());
                continue;
            }
            final Value value;
            try {
                value = keyPackage.getKeyConverter().getValueFromElement(element);
            } catch (final AccumuloElementConversionException e) {
                LOGGER.error(FAILED_TO_CREATE_AN_ACCUMULO_FROM_ELEMENT_OF_TYPE_WHEN_TRYING_TO_INSERT_ELEMENTS, "value", element.getGroup());
                continue;
            }
            final Mutation m = new Mutation(keys.getFirst().getRow());
            m.put(keys.getFirst().getColumnFamily(), keys.getFirst().getColumnQualifier(), new ColumnVisibility(keys.getFirst().getColumnVisibility()), keys.getFirst().getTimestamp(), value);
            try {
                writer.addMutation(m);
            } catch (final MutationsRejectedException e) {
                LOGGER.error("Failed to create an accumulo key mutation");
                continue;
            }
            // If the GraphElement is an Edge then there will be 2 keys.
            if (null != keys.getSecond()) {
                final Mutation m2 = new Mutation(keys.getSecond().getRow());
                m2.put(keys.getSecond().getColumnFamily(), keys.getSecond().getColumnQualifier(), new ColumnVisibility(keys.getSecond().getColumnVisibility()), keys.getSecond().getTimestamp(), value);
                try {
                    writer.addMutation(m2);
                } catch (final MutationsRejectedException e) {
                    LOGGER.error("Failed to create an accumulo key mutation");
                }
            }
        }
    } else {
        throw new GafferRuntimeException("Could not find any elements to add to graph.", Status.BAD_REQUEST);
    }
    try {
        writer.close();
    } catch (final MutationsRejectedException e) {
        LOGGER.warn("Accumulo batch writer failed to close", e);
    }
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) GafferRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferRuntimeException)

Example 10 with AccumuloElementConversionException

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

the class AbstractCoreKeyAccumuloElementConverter method serialiseSizeAndPropertyValue.

protected void serialiseSizeAndPropertyValue(final String propertyName, final SchemaElementDefinition elementDefinition, final Properties properties, final ByteArrayOutputStream stream) {
    try {
        final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName);
        final ToBytesSerialiser serialiser = (null == typeDefinition) ? null : (ToBytesSerialiser) typeDefinition.getSerialiser();
        byte[] bytes;
        if (null == serialiser) {
            bytes = AccumuloStoreConstants.EMPTY_BYTES;
        } else {
            Object value = properties.get(propertyName);
            // serialiseNull could be different to AccumuloStoreConstants.EMPTY_BYTES
            bytes = (null == value) ? serialiser.serialiseNull() : serialiser.serialise(value);
        }
        writeBytes(bytes, stream);
    } catch (final IOException e) {
        throw new AccumuloElementConversionException("Failed to write serialised property to ByteArrayOutputStream" + propertyName, e);
    }
}
Also used : ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) IOException(java.io.IOException) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Aggregations

AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)29 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)12 Key (org.apache.accumulo.core.data.Key)11 Properties (uk.gov.gchq.gaffer.data.element.Properties)7 Value (org.apache.accumulo.core.data.Value)6 Entity (uk.gov.gchq.gaffer.data.element.Entity)6 Range (org.apache.accumulo.core.data.Range)4 Test (org.junit.jupiter.api.Test)4 Edge (uk.gov.gchq.gaffer.data.element.Edge)4 EdgeDirection (uk.gov.gchq.gaffer.data.element.EdgeDirection)4 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)4 ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)3 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 BatchWriter (org.apache.accumulo.core.client.BatchWriter)2 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)2 Mutation (org.apache.accumulo.core.data.Mutation)2 PartialKey (org.apache.accumulo.core.data.PartialKey)2 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)2 GafferRuntimeException (uk.gov.gchq.gaffer.core.exception.GafferRuntimeException)2