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;
}
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;
}
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());
}
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;
}
Aggregations