Search in sources :

Example 11 with Transform

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

the class TransformHandlerTest method shouldSelectMatchedVertexForTransform.

@Test
public void shouldSelectMatchedVertexForTransform() 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.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, "srcVal").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 12 with Transform

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

the class TransformHandlerTest method shouldFailValidationWhenElementTransformerOperationIsNull.

@Test
public void shouldFailValidationWhenElementTransformerOperationIsNull() {
    // Given
    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(null).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(transformer.getClass().getSimpleName() + " contains a null function.");
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) Test(org.junit.jupiter.api.Test)

Example 13 with Transform

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

the class FederatedTransformHandlerTest method shouldDelegateToHandler.

@Test
public void shouldDelegateToHandler() throws OperationException {
    // Given
    final FederatedStore store = mock(FederatedStore.class);
    final TransformHandler handler = mock(TransformHandler.class);
    final Transform op = mock(Transform.class);
    final Context context = mock(Context.class);
    final Iterable expectedResult = mock(Iterable.class);
    final Schema schema = mock(Schema.class);
    given(store.getSchema(op, context)).willReturn(schema);
    given(handler.doOperation(op, schema)).willReturn(expectedResult);
    final FederatedTransformHandler federatedHandler = new FederatedTransformHandler(handler);
    // When
    final Object result = federatedHandler.doOperation(op, context, store);
    // Then
    assertSame(expectedResult, result);
    verify(handler).doOperation(op, schema);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) FederatedTransformHandler(uk.gov.gchq.gaffer.federatedstore.operation.handler.FederatedTransformHandler) TransformHandler(uk.gov.gchq.gaffer.store.operation.handler.function.TransformHandler) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) FederatedTransformHandler(uk.gov.gchq.gaffer.federatedstore.operation.handler.FederatedTransformHandler) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) 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