Search in sources :

Example 6 with Transform

use of uk.gov.gchq.gaffer.operation.impl.function.Transform in project Gaffer by gchq.

the class TransformHandlerTest method shouldFailValidationWhenFunctionSignatureIsInvalid.

@Test
public void shouldFailValidationWhenFunctionSignatureIsInvalid() {
    // Given
    final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, TestPropertyNames.STRING).build()).type(TestPropertyNames.STRING, new TypeDefinition(String.class)).build();
    given(store.getSchema()).willReturn(schema);
    final Entity entity = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.INT).property(TestPropertyNames.PROP_2, TestPropertyNames.STRING).build();
    final Entity entity1 = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.INT).build();
    final ElementTransformer transformer = new ElementTransformer.Builder().select(TestPropertyNames.PROP_1).execute(new Divide()).project(TestPropertyNames.PROP_3).build();
    input.add(entity);
    input.add(entity1);
    final Transform transform = new Transform.Builder().input(input).entity(TestGroups.ENTITY, transformer).build();
    // When / Then
    assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(transform, context, store)).withMessageContaining("Incompatible number of types");
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Divide(uk.gov.gchq.koryphe.impl.function.Divide) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Test(org.junit.jupiter.api.Test)

Example 7 with Transform

use of uk.gov.gchq.gaffer.operation.impl.function.Transform in project Gaffer by gchq.

the class TransformHandlerTest method shouldFailValidationWhenSchemaElementDefinitionsAreNull.

@Test
public void shouldFailValidationWhenSchemaElementDefinitionsAreNull() {
    // Given
    given(store.getSchema()).willReturn(new Schema());
    final Entity entity = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.INT).property(TestPropertyNames.PROP_2, TestPropertyNames.STRING).build();
    final Entity entity1 = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.INT).build();
    final ElementTransformer transformer = new ElementTransformer.Builder().select(TestPropertyNames.PROP_1).execute(new Identity()).project(TestPropertyNames.PROP_3).build();
    input.add(entity);
    input.add(entity1);
    final Transform transform = new Transform.Builder().input(input).entity(TestGroups.ENTITY, transformer).build();
    // When / Then
    assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(transform, context, store)).withMessageContaining("Entity group: " + TestGroups.ENTITY + " does not exist in the schema.");
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Identity(uk.gov.gchq.koryphe.impl.function.Identity) Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) Test(org.junit.jupiter.api.Test)

Example 8 with Transform

use of uk.gov.gchq.gaffer.operation.impl.function.Transform in project Gaffer by gchq.

the class TransformHandlerTest method shouldSelectAdjacentMatchedVertexForTransform.

@Test
public void shouldSelectAdjacentMatchedVertexForTransform() throws OperationException {
    // Given
    given(store.getSchema()).willReturn(schema);
    final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source("srcVal").dest("destVal").matchedVertex(EdgeId.MatchedVertex.SOURCE).build();
    final Transform transform = new Transform.Builder().input(edge).edge(TestGroups.EDGE, new ElementTransformer.Builder().select(IdentifierType.ADJACENT_MATCHED_VERTEX.name()).execute(new Identity()).project(TestPropertyNames.PROP_3).build()).build();
    // When
    final Iterable<? extends Element> results = handler.doOperation(transform, context, store);
    // Then
    final Edge expectedEdge = new Edge.Builder().group(TestGroups.EDGE).source("srcVal").dest("destVal").matchedVertex(EdgeId.MatchedVertex.SOURCE).property(TestPropertyNames.PROP_3, "destVal").build();
    ElementUtil.assertElementEquals(Collections.singletonList(expectedEdge), results);
}
Also used : Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) Identity(uk.gov.gchq.koryphe.impl.function.Identity) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 9 with Transform

use of uk.gov.gchq.gaffer.operation.impl.function.Transform in project Gaffer by gchq.

the class TransformHandlerTest method shouldTransformElementsUsingMockFunction.

@Test
public void shouldTransformElementsUsingMockFunction() throws OperationException {
    // Given
    final Function<String, Integer> function = mock(Function.class);
    given(function.apply(TestPropertyNames.STRING)).willReturn(6);
    given(store.getSchema()).willReturn(schema);
    final Edge edge = new Edge.Builder().group(TestGroups.EDGE).property(TestPropertyNames.PROP_1, TestPropertyNames.STRING).build();
    final Entity entity = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.STRING).property(TestPropertyNames.PROP_2, 3).build();
    final ElementTransformer transformer = new ElementTransformer.Builder().select(TestPropertyNames.PROP_1).execute(function).project(TestPropertyNames.PROP_3).build();
    final Edge expectedEdge = new Edge.Builder().group(TestGroups.EDGE).property(TestPropertyNames.PROP_3, 6).build();
    final Entity expectedEntity = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_3, 6).property(TestPropertyNames.PROP_2, 3).build();
    final Transform transform = new Transform.Builder().input(input).edge(TestGroups.EDGE, transformer).entity(TestGroups.ENTITY, transformer).build();
    input.add(edge);
    input.add(entity);
    expected.add(expectedEdge);
    expected.add(expectedEntity);
    // When
    final Iterable<? extends Element> results = handler.doOperation(transform, context, store);
    final List<Element> resultsList = Lists.newArrayList(results);
    // Then
    boolean isSame = false;
    for (int i = 0; i < resultsList.size(); i++) {
        isSame = expected.get(i).getProperty(TestPropertyNames.PROP_3).equals(resultsList.get(i).getProperty(TestPropertyNames.PROP_3));
    }
    assertTrue(isSame);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Element(uk.gov.gchq.gaffer.data.element.Element) Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 10 with Transform

use of uk.gov.gchq.gaffer.operation.impl.function.Transform in project Gaffer by gchq.

the class TransformHandlerTest method shouldApplyDifferentTransformersToDifferentGroups.

@Test
public void shouldApplyDifferentTransformersToDifferentGroups() throws OperationException {
    // Given
    final Function<String, Integer> function = String::length;
    final Function<String, String> function1 = String::toUpperCase;
    final Map<String, ElementTransformer> edges = new HashMap<>();
    given(store.getSchema()).willReturn(schema);
    final Edge edge = new Edge.Builder().group(TestGroups.EDGE).property(TestPropertyNames.PROP_1, "testValue").property(TestPropertyNames.PROP_2, 5).build();
    final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE_2).property(TestPropertyNames.PROP_2, "otherValue").property(TestPropertyNames.PROP_3, 2L).build();
    final ElementTransformer elementTransformer = new ElementTransformer.Builder().select(TestPropertyNames.PROP_1).execute(function).project(TestPropertyNames.PROP_4).build();
    final ElementTransformer elementTransformer1 = new ElementTransformer.Builder().select(TestPropertyNames.PROP_2).execute(function1).project(TestPropertyNames.PROP_4).build();
    final Edge expectedEdge = new Edge.Builder().group(TestGroups.EDGE).property(TestPropertyNames.PROP_4, 9).property(TestPropertyNames.PROP_2, 5).build();
    final Edge expectedEdge1 = new Edge.Builder().group(TestGroups.EDGE_2).property(TestPropertyNames.PROP_4, "OTHERVALUE").property(TestPropertyNames.PROP_3, 2L).build();
    edges.put(TestGroups.EDGE, elementTransformer);
    edges.put(TestGroups.EDGE_2, elementTransformer1);
    input.add(edge);
    input.add(edge1);
    expected.add(expectedEdge);
    expected.add(expectedEdge1);
    final Transform transform = new Transform.Builder().input(input).edges(edges).build();
    // When
    final Iterable<? extends Element> results = handler.doOperation(transform, context, store);
    final List<Element> resultsList = Lists.newArrayList(results);
    // Then
    boolean isSame = false;
    for (int i = 0; i < resultsList.size(); i++) {
        isSame = expected.get(i).getProperty(TestPropertyNames.PROP_4).equals(resultsList.get(i).getProperty(TestPropertyNames.PROP_4));
    }
    assertTrue(isSame);
}
Also used : HashMap(java.util.HashMap) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Element(uk.gov.gchq.gaffer.data.element.Element) Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Aggregations

Transform (uk.gov.gchq.gaffer.operation.impl.function.Transform)13 Test (org.junit.jupiter.api.Test)11 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)7 Entity (uk.gov.gchq.gaffer.data.element.Entity)6 Element (uk.gov.gchq.gaffer.data.element.Element)5 Edge (uk.gov.gchq.gaffer.data.element.Edge)4 Identity (uk.gov.gchq.koryphe.impl.function.Identity)4 HashMap (java.util.HashMap)3 Schema (uk.gov.gchq.gaffer.store.schema.Schema)3 Operation (uk.gov.gchq.gaffer.operation.Operation)2 Context (uk.gov.gchq.gaffer.store.Context)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)1 FederatedStore (uk.gov.gchq.gaffer.federatedstore.FederatedStore)1 FederatedTransformHandler (uk.gov.gchq.gaffer.federatedstore.operation.handler.FederatedTransformHandler)1 TransformAndFilter (uk.gov.gchq.gaffer.graph.hook.migrate.predicate.TransformAndFilter)1 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1