use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ElementFilterTest method shouldWrapElementInElementTupleAndCallSuper.
@Test
public void shouldWrapElementInElementTupleAndCallSuper() {
// Given
final String reference = "reference1";
final String value = "value";
final ElementFilter filter = new ElementFilter();
final ConsumerFunctionContext<String, FilterFunction> functionContext1 = mock(ConsumerFunctionContext.class);
final FilterFunction function = mock(FilterFunction.class);
given(functionContext1.getFunction()).willReturn(function);
filter.addFunction(functionContext1);
final Element element = mock(Element.class);
given(element.getProperty(reference)).willReturn(value);
final ArgumentCaptor<ElementTuple> elementTupleCaptor = ArgumentCaptor.forClass(ElementTuple.class);
given(functionContext1.select(elementTupleCaptor.capture())).willReturn(new Object[] { value });
// When
filter.filter(element);
// Then
assertSame(element, elementTupleCaptor.getValue().getElement());
verify(functionContext1).getFunction();
final ArgumentCaptor<Object[]> argumentCaptor = ArgumentCaptor.forClass(Object[].class);
verify(function).isValid(argumentCaptor.capture());
assertEquals(value, argumentCaptor.getValue()[0]);
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class AccumuloIDWithinSetRetrieverTest method returnElementsFromOperation.
private Set<Element> returnElementsFromOperation(final AccumuloStore store, final GetElements operation, final User user, final boolean loadIntoMemory) throws StoreException {
final AccumuloRetriever<?> retriever = new AccumuloIDWithinSetRetriever(store, operation, user, loadIntoMemory);
final Set<Element> results = new HashSet<>();
for (final Element elm : retriever) {
results.add(elm);
}
retriever.close();
return results;
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class GetJavaRDDOfElementsExample method getJavaRddOfElements.
public void getJavaRddOfElements(final JavaSparkContext sc, final Graph graph) throws OperationException {
ROOT_LOGGER.setLevel(Level.INFO);
// Avoid using getMethodNameAsSentence as it messes up the formatting of the "RDD" part
log("#### get Java RDD of elements\n");
printGraph();
ROOT_LOGGER.setLevel(Level.OFF);
final GetJavaRDDOfElements<ElementSeed> operation = new GetJavaRDDOfElements.Builder<>().addSeed(new EdgeSeed(1, 2, true)).addSeed(new EdgeSeed(2, 3, true)).javaSparkContext(sc).build();
final JavaRDD<Element> rdd = graph.execute(operation, new User("user01"));
final List<Element> elements = rdd.collect();
ROOT_LOGGER.setLevel(Level.INFO);
printJava("GetJavaRDDOfElements<ElementSeed> operation = new GetJavaRDDOfElements.Builder<>()\n" + " .addSeed(new EdgeSeed(1, 2, true))\n" + " .addSeed(new EdgeSeed(2, 3, true))\n" + " .javaSparkContext(sc)\n" + " .build();\n" + "JavaRDD<Element> rdd = graph.execute(operation, new User(\"user01\"));\n" + "List<Element> elements = rdd.collect();");
log("The results are:");
log("```");
for (final Element e : elements) {
log(e.toString());
}
log("```");
ROOT_LOGGER.setLevel(Level.OFF);
}
use of uk.gov.gchq.gaffer.data.element.Element 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 uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method getFullElement.
@Override
public Element getFullElement(final Key key, final Value value, final Map<String, String> options) throws AccumuloElementConversionException {
final Element element = getElementFromKey(key, options);
element.copyProperties(getPropertiesFromValue(element.getGroup(), value));
return element;
}
Aggregations