Search in sources :

Example 11 with AccumuloElementConversionException

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

the class AbstractCoreKeyAccumuloElementConverter method getPropertiesFromColumnQualifier.

@Override
public Properties getPropertiesFromColumnQualifier(final String group, final byte[] bytes) {
    final Properties properties = new Properties();
    if (null != bytes && bytes.length != 0) {
        int delimiterPosition = 0;
        final int arrayLength = bytes.length;
        final SchemaElementDefinition elementDefinition = getSchemaElementDefinition(group);
        final Iterator<String> propertyNames = elementDefinition.getGroupBy().iterator();
        while (propertyNames.hasNext() && delimiterPosition < arrayLength) {
            final String propertyName = propertyNames.next();
            try {
                delimiterPosition = addDeserialisedProperty(bytes, delimiterPosition, properties, elementDefinition, propertyName);
            } catch (final SerialisationException e) {
                throw new AccumuloElementConversionException("Failed to deserialise property " + propertyName, e);
            }
        }
    }
    return properties;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Properties(uk.gov.gchq.gaffer.data.element.Properties) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 12 with AccumuloElementConversionException

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

the class AbstractCoreKeyAccumuloElementConverter method getPropertiesFromValue.

@Override
public Properties getPropertiesFromValue(final String group, final Value value) {
    final Properties properties = new Properties();
    if (isNotEmpty(value)) {
        final byte[] bytes = value.get();
        int delimiterPosition = 0;
        final int arrayLength = bytes.length;
        final SchemaElementDefinition elementDefinition = getSchemaElementDefinition(group);
        final Iterator<String> propertyNames = elementDefinition.getProperties().iterator();
        while (propertyNames.hasNext() && delimiterPosition < arrayLength) {
            final String propertyName = propertyNames.next();
            try {
                if (isStoredInValue(propertyName, elementDefinition)) {
                    delimiterPosition = addDeserialisedProperty(bytes, delimiterPosition, properties, elementDefinition, propertyName);
                }
            } catch (final SerialisationException e) {
                throw new AccumuloElementConversionException("Failed to deserialise property " + propertyName, e);
            }
        }
    }
    return properties;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Properties(uk.gov.gchq.gaffer.data.element.Properties) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 13 with AccumuloElementConversionException

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

the class CoreKeyGroupByCombiner method findTop.

/**
 * Sets the topKey and topValue based on the top key of the source.
 */
private void findTop() {
    // check if aggregation is needed
    if (super.hasTop()) {
        workKey.set(super.getTopKey());
        if (workKey.isDeleted()) {
            return;
        }
        if (null != aggregatedGroups && !aggregatedGroups.contains(workKey)) {
            return;
        }
        final byte[] columnFamily = workKey.getColumnFamilyData().getBackingArray();
        final String group;
        try {
            group = elementConverter.getGroupFromColumnFamily(columnFamily);
        } catch (final AccumuloElementConversionException e) {
            throw new RuntimeException(e);
        }
        final ViewElementDefinition elementDef = view.getElement(group);
        Set<String> groupBy = elementDef.getGroupBy();
        if (null == groupBy) {
            groupBy = schema.getElement(group).getGroupBy();
        }
        final Iterator<Properties> iter = new KeyValueIterator(getSource(), group, elementConverter, schema, groupBy);
        final Properties aggregatedProperties = reduce(group, workKey, iter, groupBy, elementDef.getAggregator());
        try {
            final Properties properties = elementConverter.getPropertiesFromColumnQualifier(group, workKey.getColumnQualifierData().getBackingArray());
            properties.putAll(elementConverter.getPropertiesFromColumnVisibility(group, workKey.getColumnVisibilityData().getBackingArray()));
            properties.putAll(aggregatedProperties);
            topValue = elementConverter.getValueFromProperties(group, properties);
            topKey = new Key(workKey.getRowData().getBackingArray(), columnFamily, elementConverter.buildColumnQualifier(group, properties), elementConverter.buildColumnVisibility(group, properties), elementConverter.buildTimestamp(group, properties));
        } catch (final AccumuloElementConversionException e) {
            throw new RuntimeException(e);
        }
        while (iter.hasNext()) {
            iter.next();
        }
    }
}
Also used : SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) Properties(uk.gov.gchq.gaffer.data.element.Properties) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 14 with AccumuloElementConversionException

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

the class ElementConverterFunction method apply.

@Override
public TraversableOnce<Tuple2<Key, Value>> apply(final Element element) {
    final ArrayBuffer<Tuple2<Key, Value>> buf = new ArrayBuffer<>();
    Pair<Key, Key> keys = new Pair<>();
    Value value = null;
    try {
        keys = converterBroadcast.value().getKeysFromElement(element);
        value = converterBroadcast.value().getValueFromElement(element);
    } catch (final AccumuloElementConversionException e) {
        LOGGER.error(e.getMessage(), e);
    }
    final Key first = keys.getFirst();
    if (null != first) {
        buf.$plus$eq(new Tuple2<>(first, value));
    }
    final Key second = keys.getSecond();
    if (null != second) {
        buf.$plus$eq(new Tuple2<>(second, value));
    }
    return buf;
}
Also used : Tuple2(scala.Tuple2) Value(org.apache.accumulo.core.data.Value) ArrayBuffer(scala.collection.mutable.ArrayBuffer) Key(org.apache.accumulo.core.data.Key) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 15 with AccumuloElementConversionException

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

the class RowIDAggregator method findTop.

/**
 * Given the current position in the source}, filter to only the columns specified. Sets topKey and topValue to non-null on success
 *
 * @throws IOException Failure to seek
 */
protected void findTop() throws IOException {
    if (!source.hasTop()) {
        return;
    }
    PropertiesIterator iter = new PropertiesIterator(source, currentRange, currentColumnFamilies, currentColumnFamiliesInclusive, group, workKey, elementConverter);
    Properties topProperties = reduce(iter);
    try {
        topValue = elementConverter.getValueFromProperties(group, topProperties);
        topKey = new Key(workKey.getRowData().getBackingArray(), group.getBytes(CommonConstants.UTF_8), elementConverter.buildColumnQualifier(group, topProperties), elementConverter.buildColumnVisibility(group, topProperties), elementConverter.buildTimestamp(group, topProperties));
    } catch (final AccumuloElementConversionException e) {
        throw new RuntimeException(e);
    }
}
Also used : Properties(uk.gov.gchq.gaffer.data.element.Properties) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) 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