Search in sources :

Example 6 with ElementFilter

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

the class SchemaElementDefinitionValidatorTest method shouldValidateFunctionSelectionsAndReturnTrueWhenNoFunctionsSet.

@Test
public void shouldValidateFunctionSelectionsAndReturnTrueWhenNoFunctionsSet() {
    // Given
    final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
    final ElementFilter elementFilter = new ElementFilter();
    final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
    // When
    final ValidationResult result = validator.validateFunctionArgumentTypes(elementFilter, elementDef);
    // Then
    assertTrue(result.isValid());
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 7 with ElementFilter

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

the class SchemaElementDefinitionValidatorTest method shouldValidateFunctionSelectionsAndReturnTrueWhenElementFilterIsNull.

@Test
public void shouldValidateFunctionSelectionsAndReturnTrueWhenElementFilterIsNull() {
    // Given
    final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
    final ElementFilter elementFilter = null;
    final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
    // When
    final ValidationResult result = validator.validateFunctionArgumentTypes(elementFilter, elementDef);
    // Then
    assertTrue(result.isValid());
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 8 with ElementFilter

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

the class FilterHandler method doOperation.

public Iterable<? extends Element> doOperation(final Filter operation, final Schema schema) throws OperationException {
    if (null == operation.getInput()) {
        throw new OperationException("Filter operation has null iterable of elements");
    }
    // all elements should be used. This matches the way a View works.
    if (null == operation.getEntities() && null == operation.getEdges()) {
        final Map<String, ElementFilter> entityMap = new HashMap<>();
        schema.getEntityGroups().forEach(e -> entityMap.put(e, new ElementFilter()));
        operation.setEntities(entityMap);
        final Map<String, ElementFilter> edgeMap = new HashMap<>();
        schema.getEdgeGroups().forEach(e -> edgeMap.put(e, new ElementFilter()));
        operation.setEdges(edgeMap);
    }
    final ValidationResult result = validator.validate(operation, schema);
    if (!result.isValid()) {
        throw new OperationException("Filter operation is invalid. " + result.getErrorString());
    }
    return new StreamFilterIterable(operation);
}
Also used : StreamFilterIterable(uk.gov.gchq.gaffer.operation.util.StreamFilterIterable) HashMap(java.util.HashMap) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 9 with ElementFilter

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

the class GraphTest method shouldExpandGlobalEdges.

@Test
public void shouldExpandGlobalEdges() throws OperationException {
    final Schema twoEdgesNoEntities = new Schema.Builder().type(TestTypes.PROP_STRING, new TypeDefinition.Builder().clazz(String.class).build()).type("vertex", new TypeDefinition.Builder().clazz(String.class).build()).edge("firstEdge", new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).aggregate(false).source("vertex").destination("vertex").directed(DIRECTED_EITHER).build()).edge("secondEdge", new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).aggregate(false).source("vertex").destination("vertex").directed(DIRECTED_EITHER).build()).build();
    final Store store = mock(Store.class);
    final ArgumentCaptor<OperationChain> capturedOperation = ArgumentCaptor.forClass(OperationChain.class);
    final ArgumentCaptor<Context> capturedContext = ArgumentCaptor.forClass(Context.class);
    given(store.getSchema()).willReturn(twoEdgesNoEntities);
    given(store.getProperties()).willReturn(mock(StoreProperties.class));
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(twoEdgesNoEntities).build();
    final ElementFilter filter = mock(ElementFilter.class);
    final GlobalViewElementDefinition globalEdgeAggregate = new GlobalViewElementDefinition.Builder().postAggregationFilter(filter).build();
    final View view = new View.Builder().globalEdges(globalEdgeAggregate).build();
    operation = new GetElements.Builder().view(view).build();
    opChain = new OperationChain.Builder().first(operation).build();
    graph.execute(opChain, context);
    Mockito.verify(store, Mockito.times(1)).execute(capturedOperation.capture(), capturedContext.capture());
    assertEquals(1, capturedOperation.getAllValues().size());
    final OperationChain transformedOpChain = capturedOperation.getAllValues().get(0);
    assertEquals(1, transformedOpChain.getOperations().size());
    assertEquals(GetElements.class, transformedOpChain.getOperations().get(0).getClass());
    final View mergedView = ((GetElements) transformedOpChain.getOperations().get(0)).getView();
    assertTrue(mergedView.getGlobalEdges() == null || mergedView.getGlobalEdges().size() == 0);
    assertEquals(2, mergedView.getEdges().size());
    for (final Map.Entry<String, ViewElementDefinition> e : mergedView.getEdges().entrySet()) {
        assertNotNull(e.getValue().getPostAggregationFilter());
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Context(uk.gov.gchq.gaffer.store.Context) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 10 with ElementFilter

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

the class ValidateHandlerTest method shouldValidatedElements.

@Test
public void shouldValidatedElements() throws OperationException {
    // Given
    final ValidateHandler handler = new ValidateHandler();
    final Store store = mock(Store.class);
    final Validate validate = mock(Validate.class);
    final Element elm1 = mock(Element.class);
    final Iterable elements = Collections.singletonList(elm1);
    final Schema schema = mock(Schema.class);
    final Context context = new Context();
    given(validate.getInput()).willReturn(elements);
    given(validate.isSkipInvalidElements()).willReturn(false);
    given(store.getSchema()).willReturn(schema);
    final String group = "group";
    given(elm1.getGroup()).willReturn(group);
    final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
    final ElementFilter validator = mock(ElementFilter.class);
    given(validator.test(elm1)).willReturn(true);
    given(elementDef.getValidator(true)).willReturn(validator);
    given(schema.getElement(group)).willReturn(elementDef);
    // When
    final Iterable<? extends Element> result = handler.doOperation(validate, context, store);
    // Then
    final Iterator<? extends Element> itr = result.iterator();
    final Element elm1Result = itr.next();
    assertSame(elm1, elm1Result);
    assertThat(itr).isExhausted();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) Element(uk.gov.gchq.gaffer.data.element.Element) Schema(uk.gov.gchq.gaffer.store.schema.Schema) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Store(uk.gov.gchq.gaffer.store.Store) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)43 Test (org.junit.jupiter.api.Test)35 Schema (uk.gov.gchq.gaffer.store.schema.Schema)11 Element (uk.gov.gchq.gaffer.data.element.Element)10 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)10 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)8 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)6 Context (uk.gov.gchq.gaffer.store.Context)6 Store (uk.gov.gchq.gaffer.store.Store)6 Exists (uk.gov.gchq.koryphe.impl.predicate.Exists)6 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)5 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)5 GlobalViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition)5 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)5 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)5 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)5 HashMap (java.util.HashMap)4 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)4 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)4 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)4