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