Search in sources :

Example 16 with TypeDefinition

use of uk.gov.gchq.gaffer.store.schema.TypeDefinition in project Gaffer by gchq.

the class AbstractCoreKeyAccumuloElementConverter method getPropertiesFromColumnVisibility.

@Override
public Properties getPropertiesFromColumnVisibility(final String group, final byte[] columnVisibility) {
    final Properties properties = new Properties();
    final SchemaElementDefinition elementDefinition = getSchemaElementDefinition(group);
    if (null != schema.getVisibilityProperty()) {
        final TypeDefinition propertyDef = elementDefinition.getPropertyTypeDef(schema.getVisibilityProperty());
        if (null != propertyDef) {
            final ToBytesSerialiser serialiser = (ToBytesSerialiser) propertyDef.getSerialiser();
            try {
                if (null == columnVisibility || columnVisibility.length == 0) {
                    final Object value = serialiser.deserialiseEmpty();
                    if (null != value) {
                        properties.put(schema.getVisibilityProperty(), value);
                    }
                } else {
                    properties.put(schema.getVisibilityProperty(), serialiser.deserialise(columnVisibility));
                }
            } catch (final SerialisationException e) {
                throw new AccumuloElementConversionException(e.getMessage(), e);
            }
        }
    }
    return properties;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) Properties(uk.gov.gchq.gaffer.data.element.Properties) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 17 with TypeDefinition

use of uk.gov.gchq.gaffer.store.schema.TypeDefinition in project Gaffer by gchq.

the class AbstractCoreKeyAccumuloElementConverter method buildColumnVisibility.

@Override
public byte[] buildColumnVisibility(final String group, final Properties properties) {
    byte[] rtn = AccumuloStoreConstants.EMPTY_BYTES;
    final SchemaElementDefinition elementDefinition = getSchemaElementDefinition(group);
    if (null != schema.getVisibilityProperty()) {
        final TypeDefinition propertyDef = elementDefinition.getPropertyTypeDef(schema.getVisibilityProperty());
        if (null != propertyDef) {
            final Object property = properties.get(schema.getVisibilityProperty());
            final ToBytesSerialiser serialiser = (ToBytesSerialiser) propertyDef.getSerialiser();
            if (null != property) {
                try {
                    rtn = serialiser.serialise(property);
                } catch (final SerialisationException e) {
                    throw new AccumuloElementConversionException(e.getMessage(), e);
                }
            } else {
                rtn = serialiser.serialiseNull();
            }
        }
    }
    return rtn;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Example 18 with TypeDefinition

use of uk.gov.gchq.gaffer.store.schema.TypeDefinition in project Gaffer by gchq.

the class ElementSerialisation method getPropertiesFromColumnQualifier.

public Properties getPropertiesFromColumnQualifier(final String group, final byte[] bytes) throws SerialisationException {
    final SchemaElementDefinition elementDefinition = schema.getElement(group);
    if (null == elementDefinition) {
        throw new SerialisationException("No SchemaElementDefinition found for group " + group + ", is this group in your schema or do your table iterators need updating?");
    }
    final Properties properties = new Properties();
    if (null == bytes || bytes.length == 0) {
        return properties;
    }
    int carriage = CompactRawSerialisationUtils.decodeVIntSize(bytes[0]) + Bytes.toBytes(group).length;
    final int arrayLength = bytes.length;
    final Iterator<String> propertyNames = elementDefinition.getGroupBy().iterator();
    while (propertyNames.hasNext() && carriage < arrayLength) {
        final String propertyName = propertyNames.next();
        final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName);
        final ToBytesSerialiser serialiser = (null != typeDefinition) ? (ToBytesSerialiser) typeDefinition.getSerialiser() : null;
        if (null != serialiser) {
            final int numBytesForLength = CompactRawSerialisationUtils.decodeVIntSize(bytes[carriage]);
            int currentPropLength;
            try {
                // this value is never greater than int.
                currentPropLength = (int) CompactRawSerialisationUtils.readLong(bytes, carriage);
            } catch (final SerialisationException e) {
                throw new SerialisationException("Exception reading length of property");
            }
            carriage += numBytesForLength;
            if (currentPropLength > 0) {
                try {
                    properties.put(propertyName, serialiser.deserialise(bytes, carriage, currentPropLength));
                    carriage += currentPropLength;
                } catch (final SerialisationException e) {
                    throw new SerialisationException("Failed to deserialise property " + propertyName, e);
                }
            } else {
                try {
                    properties.put(propertyName, serialiser.deserialiseEmpty());
                } catch (final SerialisationException e) {
                    throw new SerialisationException("Failed to deserialise property " + propertyName, e);
                }
            }
        }
    }
    return properties;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) Properties(uk.gov.gchq.gaffer.data.element.Properties) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition)

Aggregations

TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)18 ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)9 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)9 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)8 Test (org.junit.jupiter.api.Test)5 Schema (uk.gov.gchq.gaffer.store.schema.Schema)5 IOException (java.io.IOException)3 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)3 Edge (uk.gov.gchq.gaffer.data.element.Edge)3 Properties (uk.gov.gchq.gaffer.data.element.Properties)3 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)3 Filter (uk.gov.gchq.gaffer.operation.impl.function.Filter)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 SchemaEntityDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition)2 IsIn (uk.gov.gchq.koryphe.impl.predicate.IsIn)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 MessageType (org.apache.parquet.schema.MessageType)1 ChainedIterable (uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable)1