use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class ElementInputFormat method createRecordReader.
@Override
public RecordReader<Element, NullWritable> createRecordReader(final InputSplit split, final TaskAttemptContext context) throws IOException, InterruptedException {
log.setLevel(getLogLevel(context));
final Configuration conf = context.getConfiguration();
final String keyPackageClass = conf.get(KEY_PACKAGE);
final Schema schema = Schema.fromJson(conf.get(SCHEMA).getBytes(CommonConstants.UTF_8));
final View view = View.fromJson(conf.get(VIEW).getBytes(CommonConstants.UTF_8));
try {
return new ElementWithPropertiesRecordReader(keyPackageClass, schema, view);
} catch (final StoreException | SchemaException | SerialisationException e) {
throw new IOException("Exception creating RecordReader", e);
}
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method getPropertiesFromValue.
@Override
public Properties getPropertiesFromValue(final String group, final Value value) throws AccumuloElementConversionException {
final Properties properties = new Properties();
if (value == null || value.getSize() == 0) {
return properties;
}
final byte[] bytes = value.get();
int lastDelimiter = 0;
final int arrayLength = bytes.length;
long currentPropLength;
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();
while (propertyNames.hasNext() && lastDelimiter < arrayLength) {
final String propertyName = propertyNames.next();
if (isStoredInValue(propertyName, elementDefinition)) {
final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName);
final Serialisation<?> serialiser = (typeDefinition != null) ? typeDefinition.getSerialiser() : null;
if (null != serialiser) {
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) {
try {
properties.put(propertyName, serialiser.deserialise(Arrays.copyOfRange(bytes, lastDelimiter, lastDelimiter += currentPropLength)));
} catch (SerialisationException e) {
throw new AccumuloElementConversionException("Failed to deserialise property " + propertyName, e);
}
} else {
try {
properties.put(propertyName, serialiser.deserialiseEmptyBytes());
} catch (SerialisationException e) {
throw new AccumuloElementConversionException("Failed to deserialise property " + propertyName, e);
}
}
}
}
}
return properties;
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method getPropertiesFromColumnQualifier.
@Override
public Properties getPropertiesFromColumnQualifier(final String group, final byte[] bytes) 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 (bytes == null || bytes.length == 0) {
return properties;
}
int lastDelimiter = 0;
final int arrayLength = bytes.length;
long currentPropLength;
final Iterator<String> propertyNames = elementDefinition.getGroupBy().iterator();
while (propertyNames.hasNext() && lastDelimiter < arrayLength) {
final String propertyName = propertyNames.next();
final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName);
final Serialisation<?> serialiser = (typeDefinition != null) ? typeDefinition.getSerialiser() : null;
if (null != serialiser) {
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) {
try {
properties.put(propertyName, serialiser.deserialise(Arrays.copyOfRange(bytes, lastDelimiter, lastDelimiter += currentPropLength)));
} catch (SerialisationException e) {
throw new AccumuloElementConversionException("Failed to deserialise property " + propertyName, e);
}
}
}
}
return properties;
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class ByteEntityAccumuloElementConverter method getRowKeyFromEntity.
@Override
protected byte[] getRowKeyFromEntity(final Entity entity) throws AccumuloElementConversionException {
byte[] value;
try {
value = ByteArrayEscapeUtils.escape(getVertexSerialiser().serialise(entity.getVertex()));
final byte[] returnVal = Arrays.copyOf(value, value.length + 2);
returnVal[returnVal.length - 2] = ByteArrayEscapeUtils.DELIMITER;
returnVal[returnVal.length - 1] = ByteEntityPositions.ENTITY;
return returnVal;
} catch (final SerialisationException e) {
throw new AccumuloElementConversionException("Failed to serialise Entity Identifier", e);
}
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class ByteEntityAccumuloElementConverter method getEntityFromKey.
@Override
protected Entity getEntityFromKey(final Key key) throws AccumuloElementConversionException {
try {
final Entity entity = new Entity(getGroupFromKey(key), getVertexSerialiser().deserialise(ByteArrayEscapeUtils.unEscape(Arrays.copyOfRange(key.getRowData().getBackingArray(), 0, (key.getRowData().getBackingArray().length) - 2))));
addPropertiesToElement(entity, key);
return entity;
} catch (final SerialisationException e) {
throw new AccumuloElementConversionException("Failed to re-create Entity from key", e);
}
}
Aggregations