Search in sources :

Example 1 with TypeDefinition

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

the class AccumuloStore method validateSchema.

@Override
protected void validateSchema(final ValidationResult validationResult, final Serialiser serialiser) {
    super.validateSchema(validationResult, serialiser);
    final String timestampProperty = getSchema().getConfig(AccumuloStoreConstants.TIMESTAMP_PROPERTY);
    if (null != timestampProperty) {
        final Iterable<SchemaElementDefinition> defs = new ChainedIterable<>(getSchema().getEntities().values(), getSchema().getEdges().values());
        for (final SchemaElementDefinition def : defs) {
            final TypeDefinition typeDef = def.getPropertyTypeDef(timestampProperty);
            if (null != typeDef && null != typeDef.getAggregateFunction() && !(typeDef.getAggregateFunction() instanceof Max)) {
                validationResult.addError("The aggregator for the " + timestampProperty + " property must be set to: " + Max.class.getName() + " this cannot be overridden for this Accumulo Store, as you have told Accumulo to store this property in the timestamp column.");
            }
        }
    }
}
Also used : Max(uk.gov.gchq.koryphe.impl.binaryoperator.Max) ChainedIterable(uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition)

Example 2 with TypeDefinition

use of uk.gov.gchq.gaffer.store.schema.TypeDefinition 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)

Example 3 with TypeDefinition

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

the class ElementSerialisation method getValue.

public byte[] getValue(final String group, final Properties properties) throws SerialisationException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    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 Iterator<String> propertyNames = elementDefinition.getProperties().iterator();
    String propertyName;
    while (propertyNames.hasNext()) {
        propertyName = propertyNames.next();
        final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName);
        if (isStoredInValue(propertyName, elementDefinition)) {
            final ToBytesSerialiser serialiser = (null != typeDefinition) ? (ToBytesSerialiser) typeDefinition.getSerialiser() : null;
            try {
                if (null != serialiser) {
                    Object value = properties.get(propertyName);
                    if (null != value) {
                        final byte[] bytes = serialiser.serialise(value);
                        writeBytes(bytes, out);
                    } else {
                        final byte[] bytes = serialiser.serialiseNull();
                        writeBytes(bytes, out);
                    }
                } else {
                    writeBytes(HBaseStoreConstants.EMPTY_BYTES, out);
                }
            } catch (final IOException e) {
                throw new SerialisationException("Failed to write serialise property to ByteArrayOutputStream" + propertyName, e);
            }
        }
    }
    return out.toByteArray();
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) IOException(java.io.IOException) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition)

Example 4 with TypeDefinition

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

the class ElementSerialisation method getPropertiesFromValue.

public Properties getPropertiesFromValue(final String group, final byte[] value) throws SerialisationException {
    final Properties properties = new Properties();
    if (null == value || value.length == 0) {
        return properties;
    }
    int lastDelimiter = 0;
    final int arrayLength = value.length;
    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 Iterator<String> propertyNames = elementDefinition.getProperties().iterator();
    while (propertyNames.hasNext() && lastDelimiter < arrayLength) {
        final String propertyName = propertyNames.next();
        if (isStoredInValue(propertyName, elementDefinition)) {
            final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName);
            final ToBytesSerialiser serialiser = (null != typeDefinition) ? (ToBytesSerialiser) typeDefinition.getSerialiser() : null;
            if (null != serialiser) {
                final int numBytesForLength = CompactRawSerialisationUtils.decodeVIntSize(value[lastDelimiter]);
                int currentPropLength;
                try {
                    // value is never larger than int.
                    currentPropLength = (int) CompactRawSerialisationUtils.readLong(value, lastDelimiter);
                } catch (final SerialisationException e) {
                    throw new SerialisationException("Exception reading length of property");
                }
                lastDelimiter += numBytesForLength;
                if (currentPropLength > 0) {
                    try {
                        properties.put(propertyName, serialiser.deserialise(value, lastDelimiter, currentPropLength));
                        lastDelimiter += 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);
                    }
                }
            } else {
                LOGGER.warn("No serialiser found in schema for property {} in group {}", propertyName, group);
            }
        }
    }
    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)

Example 5 with TypeDefinition

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

the class ElementSerialisation method getColumnQualifier.

public byte[] getColumnQualifier(final String group, final Properties properties) throws SerialisationException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    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?");
    }
    try {
        final byte[] groupBytes = Bytes.toBytes(group);
        writeBytes(groupBytes, out);
    } catch (final IOException e) {
        throw new SerialisationException("Failed to serialise group to ByteArrayOutputStream", e);
    }
    for (final String propertyName : elementDefinition.getGroupBy()) {
        final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName);
        final ToBytesSerialiser serialiser = (null != typeDefinition) ? (ToBytesSerialiser) typeDefinition.getSerialiser() : null;
        try {
            if (null != serialiser) {
                Object value = properties.get(propertyName);
                if (null != value) {
                    final byte[] bytes = serialiser.serialise(value);
                    writeBytes(bytes, out);
                } else {
                    final byte[] bytes = serialiser.serialiseNull();
                    writeBytes(bytes, out);
                }
            } else {
                writeBytes(HBaseStoreConstants.EMPTY_BYTES, out);
            }
        } catch (final IOException e) {
            throw new SerialisationException("Failed to write serialise property to ByteArrayOutputStream" + propertyName, e);
        }
    }
    return out.toByteArray();
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) 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