Search in sources :

Example 11 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class ByteEntityRangeElementPropertyFilterIteratorTest method shouldOnlyAcceptOutgoingEdges.

@Test
public void shouldOnlyAcceptOutgoingEdges() throws OperationException, AccumuloElementConversionException {
    // Given
    final ByteEntityRangeElementPropertyFilterIterator filter = new ByteEntityRangeElementPropertyFilterIterator();
    final Map<String, String> options = new HashMap<String, String>() {

        {
            put(AccumuloStoreConstants.DIRECTED_EDGE_ONLY, "true");
            put(AccumuloStoreConstants.OUTGOING_EDGE_ONLY, "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);
        final boolean expectedResult = element instanceof Edge && ((Edge) element).isDirected();
        assertEquals("Failed for element: " + element.toString(), expectedResult, 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));
        }
    }
}
Also used : HashMap(java.util.HashMap) ByteEntityRangeElementPropertyFilterIterator(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityRangeElementPropertyFilterIterator) Element(uk.gov.gchq.gaffer.data.element.Element) Value(org.apache.accumulo.core.data.Value) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 12 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class GetElementsBetweenSetsHandlerTest method shouldReturnSummarisedElements.

private void shouldReturnSummarisedElements(final AccumuloStore store) throws OperationException {
    final View opView = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
    final GetElementsBetweenSets<Element> op = new GetElementsBetweenSets<>(seedsA, seedsB, opView);
    final GetElementsBetweenSetsHandler handler = new GetElementsBetweenSetsHandler();
    final CloseableIterable<Element> elements = handler.doOperation(op, user, store);
    //With query compaction the result size should be 2
    assertEquals(2, Iterables.size(elements));
    assertThat(elements, IsCollectionContaining.hasItems(expectedSummarisedEdge, expectedEntity1));
    elements.close();
}
Also used : GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) Element(uk.gov.gchq.gaffer.data.element.Element) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View)

Example 13 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class GetElementsBetweenSetsHandlerTest method setupGraph.

private static void setupGraph(final AccumuloStore store) {
    List<Element> data = new ArrayList<>();
    // Create edges A0 -> A1, A0 -> A2, ..., A0 -> A99. Also create an Entity for each.
    final Entity entity = new Entity(TestGroups.ENTITY, "A0");
    entity.putProperty(AccumuloPropertyNames.COUNT, 10000);
    data.add(entity);
    for (int i = 1; i < 100; i++) {
        final Edge edge = new Edge(TestGroups.EDGE, "A0", "A" + i, true);
        edge.putProperty(AccumuloPropertyNames.COUNT, 23);
        edge.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 1);
        edge.putProperty(AccumuloPropertyNames.PROP_1, 0);
        edge.putProperty(AccumuloPropertyNames.PROP_2, 0);
        edge.putProperty(AccumuloPropertyNames.PROP_3, 0);
        edge.putProperty(AccumuloPropertyNames.PROP_4, 0);
        data.add(edge);
        final Edge edge2 = new Edge(TestGroups.EDGE, "A0", "A" + i, true);
        edge2.putProperty(AccumuloPropertyNames.COUNT, 23);
        edge2.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 2);
        data.add(edge2);
        final Edge edge3 = new Edge(TestGroups.EDGE, "A0", "A" + i, true);
        edge3.putProperty(AccumuloPropertyNames.COUNT, 23);
        edge3.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 3);
        data.add(edge3);
        final Entity edgeEntity = new Entity(TestGroups.ENTITY, "A" + i);
        edgeEntity.putProperty(AccumuloPropertyNames.COUNT, i);
        data.add(edgeEntity);
    }
    addElements(data, store, new User());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 14 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class ElementPostAggregationFilterTest method shouldAcceptElementWhenViewValidatorAcceptsElement.

@Test
public void shouldAcceptElementWhenViewValidatorAcceptsElement() throws Exception {
    // Given
    final AbstractElementFilter filter = new ElementPostAggregationFilter();
    final Map<String, String> options = new HashMap<>();
    options.put(AccumuloStoreConstants.SCHEMA, getSchemaJson());
    options.put(AccumuloStoreConstants.VIEW, getViewJson());
    options.put(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS, ByteEntityAccumuloElementConverter.class.getName());
    filter.validateOptions(options);
    final ByteEntityAccumuloElementConverter converter = new ByteEntityAccumuloElementConverter(getSchema());
    final Element element = new Edge(TestGroups.EDGE, "source", "dest", true);
    final Pair<Key> key = converter.getKeysFromElement(element);
    final Value value = converter.getValueFromElement(element);
    // When
    final boolean accept = filter.accept(key.getFirst(), value);
    // Then
    assertTrue(accept);
}
Also used : AbstractElementFilter(uk.gov.gchq.gaffer.accumulostore.key.AbstractElementFilter) HashMap(java.util.HashMap) Element(uk.gov.gchq.gaffer.data.element.Element) Value(org.apache.accumulo.core.data.Value) ByteEntityAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityAccumuloElementConverter) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 15 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class ElementPostAggregationFilterTest method shouldNotAcceptElementWhenViewValidatorDoesNotAcceptElement.

@Test
public void shouldNotAcceptElementWhenViewValidatorDoesNotAcceptElement() throws Exception {
    // Given
    final AbstractElementFilter filter = new ElementPostAggregationFilter();
    final Map<String, String> options = new HashMap<>();
    options.put(AccumuloStoreConstants.SCHEMA, getSchemaJson());
    options.put(AccumuloStoreConstants.VIEW, getEmptyViewJson());
    options.put(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS, ByteEntityAccumuloElementConverter.class.getName());
    filter.validateOptions(options);
    final ByteEntityAccumuloElementConverter converter = new ByteEntityAccumuloElementConverter(getSchema());
    final Element element = new Edge(TestGroups.EDGE, "source", "dest", true);
    final Pair<Key> key = converter.getKeysFromElement(element);
    final Value value = converter.getValueFromElement(element);
    // When
    final boolean accept = filter.accept(key.getFirst(), value);
    // Then
    assertFalse(accept);
}
Also used : AbstractElementFilter(uk.gov.gchq.gaffer.accumulostore.key.AbstractElementFilter) HashMap(java.util.HashMap) Element(uk.gov.gchq.gaffer.data.element.Element) Value(org.apache.accumulo.core.data.Value) ByteEntityAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityAccumuloElementConverter) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Aggregations

Element (uk.gov.gchq.gaffer.data.element.Element)182 Test (org.junit.Test)102 Edge (uk.gov.gchq.gaffer.data.element.Edge)72 User (uk.gov.gchq.gaffer.user.User)53 Entity (uk.gov.gchq.gaffer.data.element.Entity)52 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)50 HashSet (java.util.HashSet)47 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)42 ArrayList (java.util.ArrayList)33 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)32 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)26 Key (org.apache.accumulo.core.data.Key)23 Value (org.apache.accumulo.core.data.Value)23 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)21 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)17 Graph (uk.gov.gchq.gaffer.graph.Graph)16 HashMap (java.util.HashMap)14 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)14 Configuration (org.apache.hadoop.conf.Configuration)12 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)12