use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException in project Gaffer by gchq.
the class ByteEntityBloomElementFunctorTest method shouldTransformRangeWhenUsingRangeNotExact.
@Test
public void shouldTransformRangeWhenUsingRangeNotExact() {
try {
// Create SimpleEntity
final Entity simpleEntity = new Entity.Builder().group(TestGroups.ENTITY).vertex("1").build();
final Key key = elementConverter.getKeyFromEntity(simpleEntity);
final Range range = Range.exact(key.getRow());
final org.apache.hadoop.util.bloom.Key expectedBloomKey1 = new org.apache.hadoop.util.bloom.Key(ELEMENT_FUNCTOR.getVertexFromRangeKey(key.getRowData().getBackingArray()));
assertNotNull(ELEMENT_FUNCTOR.transform(range));
assertEquals(expectedBloomKey1, ELEMENT_FUNCTOR.transform(range));
} catch (final AccumuloElementConversionException e) {
fail("ConversionException " + e);
}
}
use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException in project Gaffer by gchq.
the class ByteEntityBloomElementFunctorTest method shouldTransformRangeWhenRangeHasUnspecifiedStartOrEndKey.
@Test
public void shouldTransformRangeWhenRangeHasUnspecifiedStartOrEndKey() {
try {
// Create Range with unspecified start key and shouldRetrieveElementsInRangeBetweenSeeds - should get null
final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("3").dest("4").build();
final Pair<Key, Key> keys = elementConverter.getKeysFromEdge(edge1);
final Range range1 = new Range(null, true, keys.getFirst().getRow(), true);
assertNull(ELEMENT_FUNCTOR.transform(range1));
// Create Range with unspecified end key and shouldRetrieveElementsInRangeBetweenSeeds - should get null
final Range range2 = new Range(keys.getFirst().getRow(), true, null, true);
assertNull(ELEMENT_FUNCTOR.transform(range2));
} catch (final AccumuloElementConversionException e) {
fail("ConversionException " + e);
}
}
use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException in project Gaffer by gchq.
the class Gaffer1BloomElementFunctorTest method shouldTransformRangeWhenRangeHasUnspecifiedStartOrEndKey.
@Test
public void shouldTransformRangeWhenRangeHasUnspecifiedStartOrEndKey() {
try {
// Create Range with unspecified start key and shouldRetrieveElementsInRangeBetweenSeeds - should get null
final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("3").dest("4").build();
final Pair<Key, Key> keys = elementConverter.getKeysFromEdge(edge1);
final Range range1 = new Range(null, true, keys.getFirst().getRow(), true);
assertNull(ELEMENT_FUNCTOR.transform(range1));
// Create Range with unspecified end key and shouldRetrieveElementsInRangeBetweenSeeds - should get null
final Range range2 = new Range(keys.getFirst().getRow(), true, null, true);
assertNull(ELEMENT_FUNCTOR.transform(range2));
} catch (final AccumuloElementConversionException e) {
fail("ConversionException " + e);
}
}
use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException in project Gaffer by gchq.
the class AccumuloStore method insertGraphElements.
protected void insertGraphElements(final Iterable<? extends Element> elements) throws StoreException {
// Create BatchWriter
final BatchWriter writer = TableUtils.createBatchWriter(this);
// too high a latency, etc.
if (null != elements) {
for (final Element element : elements) {
final Pair<Key, Key> keys;
try {
keys = keyPackage.getKeyConverter().getKeysFromElement(element);
} catch (final AccumuloElementConversionException e) {
LOGGER.error(FAILED_TO_CREATE_AN_ACCUMULO_FROM_ELEMENT_OF_TYPE_WHEN_TRYING_TO_INSERT_ELEMENTS, "key", element.getGroup());
continue;
}
final Value value;
try {
value = keyPackage.getKeyConverter().getValueFromElement(element);
} catch (final AccumuloElementConversionException e) {
LOGGER.error(FAILED_TO_CREATE_AN_ACCUMULO_FROM_ELEMENT_OF_TYPE_WHEN_TRYING_TO_INSERT_ELEMENTS, "value", element.getGroup());
continue;
}
final Mutation m = new Mutation(keys.getFirst().getRow());
m.put(keys.getFirst().getColumnFamily(), keys.getFirst().getColumnQualifier(), new ColumnVisibility(keys.getFirst().getColumnVisibility()), keys.getFirst().getTimestamp(), value);
try {
writer.addMutation(m);
} catch (final MutationsRejectedException e) {
LOGGER.error("Failed to create an accumulo key mutation");
continue;
}
// If the GraphElement is an Edge then there will be 2 keys.
if (null != keys.getSecond()) {
final Mutation m2 = new Mutation(keys.getSecond().getRow());
m2.put(keys.getSecond().getColumnFamily(), keys.getSecond().getColumnQualifier(), new ColumnVisibility(keys.getSecond().getColumnVisibility()), keys.getSecond().getTimestamp(), value);
try {
writer.addMutation(m2);
} catch (final MutationsRejectedException e) {
LOGGER.error("Failed to create an accumulo key mutation");
}
}
}
} else {
throw new GafferRuntimeException("Could not find any elements to add to graph.", Status.BAD_REQUEST);
}
try {
writer.close();
} catch (final MutationsRejectedException e) {
LOGGER.warn("Accumulo batch writer failed to close", e);
}
}
use of uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException 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);
}
}
Aggregations