use of uk.gov.gchq.gaffer.function.ExampleAggregateFunction in project Gaffer by gchq.
the class SchemaElementDefinitionTest method setupSchema.
protected void setupSchema(final T elementDef) {
final Schema.Builder schemaBuilder = new Schema.Builder().type("id.integer", Integer.class).type("id.date", Date.class).type("directed.true", Boolean.class).type("property.integer", Integer.class).type("property.object", Object.class).type(PROPERTY_STRING_TYPE, new TypeDefinition.Builder().clazz(String.class).aggregateFunction(new ExampleAggregateFunction()).build());
if (elementDef instanceof SchemaEdgeDefinition) {
schemaBuilder.edge(TestGroups.EDGE, ((SchemaEdgeDefinition) elementDef));
} else {
schemaBuilder.entity(TestGroups.ENTITY, ((SchemaEntityDefinition) elementDef));
}
schemaBuilder.build();
}
use of uk.gov.gchq.gaffer.function.ExampleAggregateFunction in project Gaffer by gchq.
the class SchemaElementDefinitionTest method shouldReturnFullAggregator.
@Test
public void shouldReturnFullAggregator() {
// Given
final T elementDef = createBuilder().property("property", PROPERTY_STRING_TYPE).build();
setupSchema(elementDef);
// When
final ElementAggregator aggregator = elementDef.getAggregator();
// Then
assertEquals(1, aggregator.getFunctions().size());
assertTrue(aggregator.getFunctions().get(0).getFunction() instanceof ExampleAggregateFunction);
assertEquals(Collections.singletonList("property"), aggregator.getFunctions().get(0).getSelection());
}
use of uk.gov.gchq.gaffer.function.ExampleAggregateFunction in project Gaffer by gchq.
the class SchemaTest method shouldReturnTrueWhenSchemaHasNoAggregators.
@Test
public void shouldReturnTrueWhenSchemaHasNoAggregators() {
final Schema schemaWithAggregators = new Schema.Builder().type(TestTypes.ID_STRING, new TypeDefinition.Builder().clazz(String.class).description(STRING_TYPE_DESCRIPTION).build()).type(TestTypes.PROP_STRING, new TypeDefinition.Builder().clazz(String.class).description(STRING_TYPE_DESCRIPTION).build()).type(TestTypes.PROP_INTEGER, new TypeDefinition.Builder().clazz(Integer.class).description(INTEGER_TYPE_DESCRIPTION).build()).type(TestTypes.TIMESTAMP, new TypeDefinition.Builder().clazz(Long.class).aggregateFunction(new ExampleAggregateFunction()).description(TIMESTAMP_TYPE_DESCRIPTION).build()).visibilityProperty(TestPropertyNames.VISIBILITY).timestampProperty(TestPropertyNames.TIMESTAMP).build();
assertTrue(schemaWithAggregators.hasAggregators());
}
use of uk.gov.gchq.gaffer.function.ExampleAggregateFunction 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));
}
Aggregations