use of org.apache.accumulo.core.data.Value in project Gaffer by gchq.
the class ByteEntityRangeElementPropertyFilterIteratorTest method shouldOnlyAcceptDeduplicatedEdges.
@Test
public void shouldOnlyAcceptDeduplicatedEdges() throws OperationException, AccumuloElementConversionException {
// Given
final ByteEntityRangeElementPropertyFilterIterator filter = new ByteEntityRangeElementPropertyFilterIterator();
final Map<String, String> options = new HashMap<String, String>() {
{
put(AccumuloStoreConstants.OUTGOING_EDGE_ONLY, "true");
put(AccumuloStoreConstants.DEDUPLICATE_UNDIRECTED_EDGES, "true");
}
};
filter.validateOptions(options);
// value should not be used
final Value value = null;
// When / Then
for (final Element element : ELEMENTS) {
final Pair<Key> keys = converter.getKeysFromElement(element);
// First key is deduplicated, but only edges should be excepted
assertEquals("Failed for element: " + element.toString(), element instanceof Edge, filter.accept(keys.getFirst(), value));
if (null != keys.getSecond()) {
// self elements are not added the other way round
assertEquals("Failed for element: " + element.toString(), false, filter.accept(keys.getSecond(), value));
}
}
}
use of org.apache.accumulo.core.data.Value in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldSerialiseAndDeSerialiseBetweenPropertyAndValueWithNullProperty.
@Test
public void shouldSerialiseAndDeSerialiseBetweenPropertyAndValueWithNullProperty() throws AccumuloElementConversionException {
Properties properties = new Properties();
properties.put(AccumuloPropertyNames.PROP_1, 5);
properties.put(AccumuloPropertyNames.PROP_2, null);
properties.put(AccumuloPropertyNames.PROP_3, 299);
properties.put(AccumuloPropertyNames.PROP_4, 10);
properties.put(AccumuloPropertyNames.COUNT, 8);
final Value value = converter.getValueFromProperties(TestGroups.EDGE, properties);
final Properties deSerialisedProperties = converter.getPropertiesFromValue(TestGroups.EDGE, value);
assertEquals(5, deSerialisedProperties.get(AccumuloPropertyNames.PROP_1));
assertNull(deSerialisedProperties.get(AccumuloPropertyNames.PROP_2));
assertEquals(299, deSerialisedProperties.get(AccumuloPropertyNames.PROP_3));
assertEquals(10, deSerialisedProperties.get(AccumuloPropertyNames.PROP_4));
assertEquals(8, deSerialisedProperties.get(AccumuloPropertyNames.COUNT));
}
use of org.apache.accumulo.core.data.Value in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldSerialiseAndDeSerialiseBetweenPropertyAndValueMissingStartProperty.
@Test
public void shouldSerialiseAndDeSerialiseBetweenPropertyAndValueMissingStartProperty() throws AccumuloElementConversionException {
Properties properties = new Properties();
properties.put(AccumuloPropertyNames.PROP_2, 166);
properties.put(AccumuloPropertyNames.PROP_3, 299);
properties.put(AccumuloPropertyNames.PROP_4, 10);
properties.put(AccumuloPropertyNames.COUNT, 8);
final Value value = converter.getValueFromProperties(TestGroups.EDGE, properties);
final Properties deSerialisedProperties = converter.getPropertiesFromValue(TestGroups.EDGE, value);
assertEquals(166, deSerialisedProperties.get(AccumuloPropertyNames.PROP_2));
assertEquals(299, deSerialisedProperties.get(AccumuloPropertyNames.PROP_3));
assertEquals(10, deSerialisedProperties.get(AccumuloPropertyNames.PROP_4));
assertEquals(8, deSerialisedProperties.get(AccumuloPropertyNames.COUNT));
}
use of org.apache.accumulo.core.data.Value in project Gaffer by gchq.
the class AccumuloStore method insertGraphElements.
protected void insertGraphElements(final Iterable<Element> elements) throws StoreException {
// Create BatchWriter
final BatchWriter writer = TableUtils.createBatchWriter(this);
// too high a latency, etc.
if (elements != null) {
for (final Element element : elements) {
final Pair<Key> keys;
try {
keys = keyPackage.getKeyConverter().getKeysFromElement(element);
} catch (final AccumuloElementConversionException e) {
LOGGER.error("Failed to create an accumulo key from element of type " + element.getGroup() + " when trying to insert elements");
continue;
}
final Value value;
try {
value = keyPackage.getKeyConverter().getValueFromElement(element);
} catch (final AccumuloElementConversionException e) {
LOGGER.error("Failed to create an accumulo value from element of type " + element.getGroup() + " when trying to insert elements");
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 (keys.getSecond() != null) {
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 org.apache.accumulo.core.data.Value in project Gaffer by gchq.
the class ElementConverterFunction method call.
@Override
public Iterator<Tuple2<Key, Value>> call(final Element e) throws Exception {
final List<Tuple2<Key, Value>> tuples = new ArrayList<>(2);
final Pair<Key> keys = converterBroadcast.value().getKeysFromElement(e);
final Value value = converterBroadcast.value().getValueFromElement(e);
tuples.add(new Tuple2<>(keys.getFirst(), value));
final Key second = keys.getSecond();
if (second != null) {
tuples.add(new Tuple2<>(second, value));
}
return tuples.listIterator();
}
Aggregations