Search in sources :

Example 16 with SchemaElementDefinition

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

the class AbstractCoreKeyAccumuloElementConverter method getPropertiesFromColumnVisibility.

@Override
public Properties getPropertiesFromColumnVisibility(final String group, final byte[] columnVisibility) throws AccumuloElementConversionException {
    final Properties properties = new Properties();
    final SchemaElementDefinition elementDefinition = schema.getElement(group);
    if (null == elementDefinition) {
        throw new AccumuloElementConversionException("No SchemaElementDefinition found for group " + group + ", is this group in your schema or do your table iterators need updating?");
    }
    if (null != schema.getVisibilityProperty()) {
        final TypeDefinition propertyDef = elementDefinition.getPropertyTypeDef(schema.getVisibilityProperty());
        if (null != propertyDef) {
            final Serialisation serialiser = propertyDef.getSerialiser();
            try {
                if (columnVisibility == null || columnVisibility.length == 0) {
                    final Object value = serialiser.deserialiseEmptyBytes();
                    if (value != null) {
                        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) Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation) 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) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition)

Example 17 with SchemaElementDefinition

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

the class AbstractCoreKeyAccumuloElementConverter method getPropertiesFromTimestamp.

/**
     * Get the properties for a given group defined in the Schema as being
     * stored in the Accumulo timestamp column.
     *
     * @param group     The {@link Element} type to be queried
     * @param timestamp the element timestamp property
     * @return The Properties stored within the Timestamp part of the
     * {@link Key}
     * @throws AccumuloElementConversionException If the supplied group has not been defined
     */
@Override
public Properties getPropertiesFromTimestamp(final String group, final long timestamp) throws AccumuloElementConversionException {
    final SchemaElementDefinition elementDefinition = schema.getElement(group);
    if (null == elementDefinition) {
        throw new AccumuloElementConversionException("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 the element group requires a timestamp property then add it.
    if (null != schema.getTimestampProperty() && elementDefinition.containsProperty(schema.getTimestampProperty())) {
        properties.put(schema.getTimestampProperty(), timestamp);
    }
    return properties;
}
Also used : 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 18 with SchemaElementDefinition

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

the class AbstractCoreKeyAccumuloElementConverter method getValueFromProperties.

@Override
public Value getValueFromProperties(final String group, final Properties properties) throws AccumuloElementConversionException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final SchemaElementDefinition elementDefinition = schema.getElement(group);
    if (null == elementDefinition) {
        throw new AccumuloElementConversionException("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 Serialisation serialiser = (typeDefinition != null) ? 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(AccumuloStoreConstants.EMPTY_BYTES, out);
                }
            } catch (final IOException e) {
                throw new AccumuloElementConversionException("Failed to write serialise property to ByteArrayOutputStream" + propertyName, e);
            }
        }
    }
    return new Value(out.toByteArray());
}
Also used : Value(org.apache.accumulo.core.data.Value) Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition)

Example 19 with SchemaElementDefinition

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

the class AbstractCoreKeyAccumuloElementConverter method getPropertiesAsBytesFromColumnQualifier.

@Override
public byte[] getPropertiesAsBytesFromColumnQualifier(final String group, final byte[] bytes, final int numProps) throws AccumuloElementConversionException {
    if (numProps == 0 || bytes == null || bytes.length == 0) {
        return AccumuloStoreConstants.EMPTY_BYTES;
    }
    final SchemaElementDefinition elementDefinition = schema.getElement(group);
    if (null == elementDefinition) {
        throw new AccumuloElementConversionException("No SchemaElementDefinition found for group " + group + ", is this group in your schema or do your table iterators need updating?");
    }
    if (numProps == elementDefinition.getProperties().size()) {
        return bytes;
    }
    int lastDelimiter = 0;
    final int arrayLength = bytes.length;
    long currentPropLength;
    int propIndex = 0;
    while (propIndex < numProps && lastDelimiter < arrayLength) {
        final int numBytesForLength = CompactRawSerialisationUtils.decodeVIntSize(bytes[lastDelimiter]);
        final byte[] length = new byte[numBytesForLength];
        System.arraycopy(bytes, lastDelimiter, length, 0, numBytesForLength);
        try {
            currentPropLength = CompactRawSerialisationUtils.readLong(length);
        } catch (final SerialisationException e) {
            throw new AccumuloElementConversionException("Exception reading length of property", e);
        }
        lastDelimiter += numBytesForLength;
        if (currentPropLength > 0) {
            lastDelimiter += currentPropLength;
        }
        propIndex++;
    }
    final byte[] propertyBytes = new byte[lastDelimiter];
    System.arraycopy(bytes, 0, propertyBytes, 0, lastDelimiter);
    return propertyBytes;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Aggregations

SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)19 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)7 Element (uk.gov.gchq.gaffer.data.element.Element)5 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)5 Schema (uk.gov.gchq.gaffer.store.schema.Schema)5 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)5 Test (org.junit.Test)4 Properties (uk.gov.gchq.gaffer.data.element.Properties)4 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)4 Serialisation (uk.gov.gchq.gaffer.serialisation.Serialisation)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 Value (org.apache.accumulo.core.data.Value)1 DataType (org.apache.spark.sql.types.DataType)1