Search in sources :

Example 1 with ExampleFilterFunction

use of uk.gov.gchq.gaffer.function.ExampleFilterFunction in project Gaffer by gchq.

the class ViewIT method shouldDeserialiseJsonView.

@Test
public void shouldDeserialiseJsonView() throws IOException {
    // Given
    // When
    View view = loadView();
    // Then
    final ViewElementDefinition edge = view.getEdge(TestGroups.EDGE);
    final ElementTransformer transformer = edge.getTransformer();
    assertNotNull(transformer);
    final List<ConsumerProducerFunctionContext<String, TransformFunction>> contexts = transformer.getFunctions();
    assertEquals(1, contexts.size());
    final List<String> selection = contexts.get(0).getSelection();
    assertEquals(2, selection.size());
    assertEquals(TestPropertyNames.PROP_1, selection.get(0));
    assertEquals(IdentifierType.SOURCE.name(), selection.get(1));
    final List<String> projection = contexts.get(0).getProjection();
    assertEquals(1, projection.size());
    assertEquals(TestPropertyNames.TRANSIENT_1, projection.get(0));
    assertTrue(contexts.get(0).getFunction() instanceof ExampleTransformFunction);
    final ElementFilter postFilter = edge.getPostTransformFilter();
    assertNotNull(postFilter);
    final List<ConsumerFunctionContext<String, FilterFunction>> filterContexts = postFilter.getFunctions();
    assertEquals(1, contexts.size());
    final List<String> postFilterSelection = filterContexts.get(0).getSelection();
    assertEquals(1, postFilterSelection.size());
    assertEquals(TestPropertyNames.TRANSIENT_1, postFilterSelection.get(0));
    assertTrue(filterContexts.get(0).getFunction() instanceof ExampleFilterFunction);
}
Also used : ConsumerProducerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext) ConsumerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ExampleTransformFunction(uk.gov.gchq.gaffer.function.ExampleTransformFunction) Test(org.junit.Test)

Example 2 with ExampleFilterFunction

use of uk.gov.gchq.gaffer.function.ExampleFilterFunction in project Gaffer by gchq.

the class SchemaTest method testLoadingSchemaFromJson.

@Test
public void testLoadingSchemaFromJson() {
    // Edge definitions
    SchemaElementDefinition edgeDefinition = schema.getEdge(TestGroups.EDGE);
    assertNotNull(edgeDefinition);
    assertEquals(EDGE_DESCRIPTION, edgeDefinition.getDescription());
    final Map<String, String> propertyMap = edgeDefinition.getPropertyMap();
    assertEquals(3, propertyMap.size());
    assertEquals("prop.string", propertyMap.get(TestPropertyNames.PROP_2));
    assertEquals("prop.date", propertyMap.get(TestPropertyNames.DATE));
    assertEquals("timestamp", propertyMap.get(TestPropertyNames.TIMESTAMP));
    assertEquals(Sets.newLinkedHashSet(Collections.singletonList(TestPropertyNames.DATE)), edgeDefinition.getGroupBy());
    // Check validator
    ElementFilter validator = edgeDefinition.getValidator();
    final List<ConsumerFunctionContext<String, FilterFunction>> valContexts = validator.getFunctions();
    int index = 0;
    ConsumerFunctionContext<String, FilterFunction> valContext = valContexts.get(index++);
    assertTrue(valContext.getFunction() instanceof IsA);
    assertEquals(1, valContext.getSelection().size());
    assertEquals(IdentifierType.SOURCE.name(), valContext.getSelection().get(0));
    valContext = valContexts.get(index++);
    assertTrue(valContext.getFunction() instanceof IsA);
    assertEquals(1, valContext.getSelection().size());
    assertEquals(IdentifierType.DESTINATION.name(), valContext.getSelection().get(0));
    valContext = valContexts.get(index++);
    assertTrue(valContext.getFunction() instanceof IsA);
    assertEquals(1, valContext.getSelection().size());
    assertEquals(IdentifierType.DIRECTED.name(), valContext.getSelection().get(0));
    valContext = valContexts.get(index++);
    assertTrue(valContext.getFunction() instanceof ExampleFilterFunction);
    assertEquals(1, valContext.getSelection().size());
    assertEquals(IdentifierType.DIRECTED.name(), valContext.getSelection().get(0));
    valContext = valContexts.get(index++);
    assertTrue(valContext.getFunction() instanceof IsA);
    assertEquals(1, valContext.getSelection().size());
    assertEquals(TestPropertyNames.PROP_2, valContext.getSelection().get(0));
    valContext = valContexts.get(index++);
    assertTrue(valContext.getFunction() instanceof ExampleFilterFunction);
    assertEquals(1, valContext.getSelection().size());
    assertEquals(TestPropertyNames.PROP_2, valContext.getSelection().get(0));
    valContext = valContexts.get(index++);
    assertTrue(valContext.getFunction() instanceof IsA);
    assertEquals(1, valContext.getSelection().size());
    assertEquals(TestPropertyNames.DATE, valContext.getSelection().get(0));
    valContext = valContexts.get(index++);
    assertTrue(valContext.getFunction() instanceof IsA);
    assertEquals(1, valContext.getSelection().size());
    assertEquals(TestPropertyNames.TIMESTAMP, valContext.getSelection().get(0));
    assertEquals(index, valContexts.size());
    TypeDefinition type = edgeDefinition.getPropertyTypeDef(TestPropertyNames.DATE);
    assertEquals(Date.class, type.getClazz());
    assertEquals(DATE_TYPE_DESCRIPTION, type.getDescription());
    assertNull(type.getSerialiser());
    assertTrue(type.getAggregateFunction() instanceof ExampleAggregateFunction);
    // Entity definitions
    SchemaElementDefinition entityDefinition = schema.getEntity(TestGroups.ENTITY);
    assertNotNull(entityDefinition);
    assertEquals(ENTITY_DESCRIPTION, entityDefinition.getDescription());
    assertTrue(entityDefinition.containsProperty(TestPropertyNames.PROP_1));
    type = entityDefinition.getPropertyTypeDef(TestPropertyNames.PROP_1);
    assertEquals(0, entityDefinition.getGroupBy().size());
    assertEquals(STRING_TYPE_DESCRIPTION, type.getDescription());
    assertEquals(String.class, type.getClazz());
    assertNull(type.getSerialiser());
    assertTrue(type.getAggregateFunction() instanceof ExampleAggregateFunction);
    ElementAggregator aggregator = edgeDefinition.getAggregator();
    List<PassThroughFunctionContext<String, AggregateFunction>> aggContexts = aggregator.getFunctions();
    assertEquals(3, aggContexts.size());
    PassThroughFunctionContext<String, AggregateFunction> aggContext = aggContexts.get(0);
    assertTrue(aggContext.getFunction() instanceof ExampleAggregateFunction);
    assertEquals(1, aggContext.getSelection().size());
    assertEquals(TestPropertyNames.PROP_2, aggContext.getSelection().get(0));
    aggContext = aggContexts.get(1);
    assertTrue(aggContext.getFunction() instanceof ExampleAggregateFunction);
    assertEquals(1, aggContext.getSelection().size());
    assertEquals(TestPropertyNames.DATE, aggContext.getSelection().get(0));
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) PassThroughFunctionContext(uk.gov.gchq.gaffer.function.context.PassThroughFunctionContext) ConsumerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext) IsA(uk.gov.gchq.gaffer.function.IsA) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ExampleAggregateFunction(uk.gov.gchq.gaffer.function.ExampleAggregateFunction) AggregateFunction(uk.gov.gchq.gaffer.function.AggregateFunction) ExampleAggregateFunction(uk.gov.gchq.gaffer.function.ExampleAggregateFunction) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.Test)

Example 3 with ExampleFilterFunction

use of uk.gov.gchq.gaffer.function.ExampleFilterFunction in project Gaffer by gchq.

the class ViewValidatorTest method shouldValidateAndReturnTrueWhenPostTransformerFilterSet.

@Test
public void shouldValidateAndReturnTrueWhenPostTransformerFilterSet() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_3, String.class).transformer(new ElementTransformer.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).project(TestPropertyNames.PROP_3).execute(new ExampleTransformFunction()).build()).postTransformFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_3).execute(new ExampleFilterFunction()).build()).build()).build();
    final Schema schema = new Schema.Builder().type("obj", Object.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "obj").property(TestPropertyNames.PROP_2, "obj").build()).build();
    // When
    final boolean isValid = validator.validate(view, schema, false);
    // Then
    assertTrue(isValid);
}
Also used : ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) ExampleTransformFunction(uk.gov.gchq.gaffer.function.ExampleTransformFunction) Test(org.junit.Test)

Example 4 with ExampleFilterFunction

use of uk.gov.gchq.gaffer.function.ExampleFilterFunction in project Gaffer by gchq.

the class SchemaElementDefinitionTest method shouldMergeDifferentSchemaElementDefinitions.

@Test
public void shouldMergeDifferentSchemaElementDefinitions() {
    // Given
    // When
    final T elementDef1 = createBuilder().property(TestPropertyNames.PROP_1, "property.integer").validator(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new ExampleFilterFunction()).build()).build();
    final T elementDef2 = createBuilder().property(TestPropertyNames.PROP_2, "property.object").validator(new ElementFilter.Builder().select(TestPropertyNames.PROP_2).execute(new ExampleFilterFunction()).build()).groupBy(TestPropertyNames.PROP_2).build();
    // When
    final T mergedDef = createEmptyBuilder().merge(elementDef1).merge(elementDef2).build();
    // Then
    assertEquals(2, mergedDef.getProperties().size());
    assertNotNull(mergedDef.getPropertyTypeDef(TestPropertyNames.PROP_1));
    assertNotNull(mergedDef.getPropertyTypeDef(TestPropertyNames.PROP_2));
    assertEquals(Sets.newLinkedHashSet(Collections.singletonList(TestPropertyNames.PROP_2)), mergedDef.getGroupBy());
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) Test(org.junit.Test)

Example 5 with ExampleFilterFunction

use of uk.gov.gchq.gaffer.function.ExampleFilterFunction in project Gaffer by gchq.

the class ViewValidatorTest method shouldValidateAndReturnFalseWhenEdgeFilterSelectionMissingProperty.

@Test
public void shouldValidateAndReturnFalseWhenEdgeFilterSelectionMissingProperty() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_3, String.class).preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new ExampleFilterFunction()).build()).build()).build();
    final Schema schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().build()).build();
    // When
    final boolean isValid = validator.validate(view, schema, false);
    // Then
    assertFalse(isValid);
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)8 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)8 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)5 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)4 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)3 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)3 ConsumerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext)2 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)1 AggregateFunction (uk.gov.gchq.gaffer.function.AggregateFunction)1 ExampleAggregateFunction (uk.gov.gchq.gaffer.function.ExampleAggregateFunction)1 FilterFunction (uk.gov.gchq.gaffer.function.FilterFunction)1 IsA (uk.gov.gchq.gaffer.function.IsA)1 ConsumerProducerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext)1 PassThroughFunctionContext (uk.gov.gchq.gaffer.function.context.PassThroughFunctionContext)1