Search in sources :

Example 26 with ElementFilter

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

the class SchemaElementDefinitionValidatorTest method shouldValidateFunctionSelectionsAndReturnFalseWhenAFunctionIsNull.

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

Example 27 with ElementFilter

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

the class FilterTest method shouldShallowCloneOperation.

@Test
@Override
public void shouldShallowCloneOperation() {
    // Given
    final List<Element> input = new ArrayList<>();
    final Edge edge = new Edge("road");
    input.add(edge);
    final Filter filter = new Filter.Builder().input(input).globalElements(new ElementFilter()).build();
    // When
    final Filter clone = filter.shallowClone();
    // Then
    assertNotSame(filter, clone);
    assertThat(clone.getInput().iterator().next()).isEqualTo(edge);
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Element(uk.gov.gchq.gaffer.data.element.Element) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ArrayList(java.util.ArrayList) Edge(uk.gov.gchq.gaffer.data.element.Edge) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 28 with ElementFilter

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

the class SchemaElementDefinitionValidator method validate.

/**
 * Checks each identifier and property has a type associated with it.
 * Checks all {@link java.util.function.Predicate}s and {@link java.util.function.BinaryOperator}s defined are
 * compatible with the identifiers and properties - this is done by comparing the function input and output types with
 * the identifier and property types.
 *
 * @param elementDef the {@link uk.gov.gchq.gaffer.data.elementdefinition.ElementDefinition} to validate
 * @return true if the element definition is valid, otherwise false and an error is logged
 */
public ValidationResult validate(final SchemaElementDefinition elementDef) {
    final ValidationResult result = new ValidationResult();
    final ElementFilter validator = elementDef.getValidator();
    final ElementAggregator aggregator = elementDef.getFullAggregator();
    result.add(validateAggregator(aggregator, elementDef));
    result.add(validateComponentTypes(elementDef));
    result.add(validateFunctionArgumentTypes(validator, elementDef));
    result.add(validateFunctionArgumentTypes(aggregator, elementDef));
    result.add(validateRequiredParameters(elementDef));
    result.add(validatePropertyNames(elementDef));
    return result;
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator)

Example 29 with ElementFilter

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

the class ElementValidator method validateAgainstViewFilter.

private boolean validateAgainstViewFilter(final Element element, final FilterType filterType) {
    if (null == element) {
        return false;
    }
    if (null == view) {
        return true;
    }
    final ViewElementDefinition elementDef = view.getElement(element.getGroup());
    if (null == elementDef) {
        return false;
    }
    final ElementFilter validator = getElementFilter(elementDef, filterType);
    return null == validator || validator.test(element);
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)

Example 30 with ElementFilter

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

the class ViewTest method shouldAddGlobalPostAggFiltersToGroup.

@Test
public void shouldAddGlobalPostAggFiltersToGroup() {
    // Given
    final ElementFilter filter = new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new Exists()).build();
    final View view = new View.Builder().globalEntities(new GlobalViewElementDefinition.Builder().groups(TestGroups.ENTITY).postAggregationFilter(filter).build()).entity(TestGroups.ENTITY).build();
    // When
    view.expandGlobalDefinitions();
    // Then
    assertTrue(view.hasPostAggregationFilters());
    assertEquals(Exists.class.getSimpleName(), view.getEntity(TestGroups.ENTITY).getPostAggregationFilter().getComponents().get(0).getPredicate().getClass().getSimpleName());
}
Also used : Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) 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