Search in sources :

Example 6 with Identity

use of uk.gov.gchq.koryphe.impl.function.Identity in project Gaffer by gchq.

the class ViewTest method shouldAddGlobalElementTransformToEntityGroupFromBuilder.

@Test
public void shouldAddGlobalElementTransformToEntityGroupFromBuilder() {
    // Given
    final ElementTransformer elementTransformer = new ElementTransformer.Builder().select(TestPropertyNames.PROP_3).execute(new Identity()).project(TestPropertyNames.PROP_1).build();
    // When
    final View view = new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().groups(TestGroups.ENTITY).transformer(elementTransformer).build()).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().excludeProperties(TestPropertyNames.PROP_3).build()).expandGlobalDefinitions().build();
    // Then
    assertEquals(elementTransformer.getComponents().get(0).getFunction().getClass().getSimpleName(), view.getEntity(TestGroups.ENTITY).getTransformer().getComponents().get(0).getFunction().getClass().getSimpleName());
    assertEquals(Sets.newHashSet(TestPropertyNames.PROP_3), Sets.newHashSet(view.getEntity(TestGroups.ENTITY).getExcludeProperties()));
}
Also used : ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Identity(uk.gov.gchq.koryphe.impl.function.Identity) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 7 with Identity

use of uk.gov.gchq.koryphe.impl.function.Identity in project Gaffer by gchq.

the class ViewTest method shouldAddGlobalTransformToEntityGroup.

@Test
public void shouldAddGlobalTransformToEntityGroup() {
    // Given
    final ElementTransformer elementTransformer = new ElementTransformer.Builder().select(TestPropertyNames.PROP_3).execute(new Identity()).project(TestPropertyNames.PROP_1).build();
    final View view = new View.Builder().globalEntities(new GlobalViewElementDefinition.Builder().groups(TestGroups.ENTITY).transformer(elementTransformer).build()).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().excludeProperties(TestPropertyNames.PROP_3).build()).build();
    // When
    view.expandGlobalDefinitions();
    // Then
    assertEquals(elementTransformer.getComponents().get(0).getFunction().getClass().getSimpleName(), view.getEntity(TestGroups.ENTITY).getTransformer().getComponents().get(0).getFunction().getClass().getSimpleName());
    assertEquals(Sets.newHashSet(TestPropertyNames.PROP_3), Sets.newHashSet(view.getEntity(TestGroups.ENTITY).getExcludeProperties()));
}
Also used : ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Identity(uk.gov.gchq.koryphe.impl.function.Identity) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 8 with Identity

use of uk.gov.gchq.koryphe.impl.function.Identity in project Gaffer by gchq.

the class JoinIT method shouldLeftSideOuterJoinUsingKeyFunctionMatch.

@Test
public void shouldLeftSideOuterJoinUsingKeyFunctionMatch() throws OperationException {
    // Given
    final Map map = new Map.Builder<>().input(Lists.newArrayList(4L, 1L, 2L)).first(new Identity()).build();
    final ArrayList<Entity> input = Lists.newArrayList(getJoinEntity(TestGroups.ENTITY, 4), getJoinEntity(TestGroups.ENTITY_2, 4), getJoinEntity(TestGroups.ENTITY_3, 2), getJoinEntity(TestGroups.ENTITY_4, 5), getJoinEntity(TestGroups.ENTITY_4, 6), getJoinEntity(TestGroups.ENTITY_5, 5));
    final Join<Object> leftJoin = new Join.Builder<>().flatten(true).matchKey(MatchKey.LEFT).joinType(JoinType.OUTER).operation(map).matchMethod(new KeyFunctionMatch(new ExtractProperty("count"), new ToLong())).input(input).build();
    // When
    final Iterable<? extends MapTuple> results = graph.execute(leftJoin, user);
    final List<java.util.Map> loadedResults = new ArrayList<>();
    results.forEach(e -> loadedResults.add(e.getValues()));
    // Then
    assertThat(loadedResults).hasSize(3);
    assertThat(loadedResults.get(0)).containsEntry(MatchKey.LEFT.name(), getJoinEntity(TestGroups.ENTITY_4, 5)).containsEntry(MatchKey.RIGHT.name(), null);
    assertThat(loadedResults.get(1)).containsEntry(MatchKey.LEFT.name(), getJoinEntity(TestGroups.ENTITY_4, 6)).containsEntry(MatchKey.RIGHT.name(), null);
    assertThat(loadedResults.get(2)).containsEntry(MatchKey.LEFT.name(), getJoinEntity(TestGroups.ENTITY_5, 5)).containsEntry(MatchKey.RIGHT.name(), null);
}
Also used : ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) Entity(uk.gov.gchq.gaffer.data.element.Entity) ArrayList(java.util.ArrayList) Join(uk.gov.gchq.gaffer.operation.impl.join.Join) KeyFunctionMatch(uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) Identity(uk.gov.gchq.koryphe.impl.function.Identity) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.Test)

Example 9 with Identity

use of uk.gov.gchq.koryphe.impl.function.Identity in project gaffer-doc by gchq.

the class IdentityExample method identity2.

public void identity2() {
    // ---------------------------------------------------------
    final Identity function = new Identity();
    // ---------------------------------------------------------
    runExample(function, null, 6, 6.1, "input1", Lists.newArrayList(1, 2, 3), null);
}
Also used : Identity(uk.gov.gchq.koryphe.impl.function.Identity)

Example 10 with Identity

use of uk.gov.gchq.koryphe.impl.function.Identity 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)

Aggregations

Identity (uk.gov.gchq.koryphe.impl.function.Identity)13 Test (org.junit.jupiter.api.Test)9 Entity (uk.gov.gchq.gaffer.data.element.Entity)6 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)6 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)4 Transform (uk.gov.gchq.gaffer.operation.impl.function.Transform)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ExtractProperty (uk.gov.gchq.gaffer.data.element.function.ExtractProperty)3 Map (uk.gov.gchq.gaffer.operation.impl.Map)3 Join (uk.gov.gchq.gaffer.operation.impl.join.Join)3 KeyFunctionMatch (uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch)3 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 ToLong (uk.gov.gchq.koryphe.impl.function.ToLong)2 Schema (uk.gov.gchq.gaffer.store.schema.Schema)1 FunctionTest (uk.gov.gchq.koryphe.function.FunctionTest)1