Search in sources :

Example 6 with ToLong

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

the class PropertiesTransformerTest method shouldJsonSerialiseAndDeserialise.

@Test
@Override
public void shouldJsonSerialiseAndDeserialise() throws IOException {
    // Given
    final PropertiesTransformer propertiesTransformer = new PropertiesTransformer.Builder().select(TestPropertyNames.PROP_1).execute(new ToLong()).project(TestPropertyNames.PROP_2).build();
    final Properties testProperties = new Properties();
    testProperties.put(TestPropertyNames.PROP_1, 1);
    // When
    final String json = new String(JSONSerialiser.serialise(propertiesTransformer));
    PropertiesTransformer deserialisedPropertiesTransformer = JSONSerialiser.deserialise(json, PropertiesTransformer.class);
    // Then
    assertEquals(propertiesTransformer, deserialisedPropertiesTransformer);
    assertEquals("{\"functions\":[{\"selection\":[\"property1\"],\"function\":{\"class\":\"uk.gov.gchq.koryphe.impl.function.ToLong\"},\"projection\":[\"property2\"]}]}", json);
}
Also used : ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) ToString(uk.gov.gchq.koryphe.impl.function.ToString) Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.jupiter.api.Test) FunctionTest(uk.gov.gchq.koryphe.function.FunctionTest)

Example 7 with ToLong

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

the class IfIT method shouldReturnOriginalInputWhenConditionIsFalseAndNoOtherwise.

@Test
public void shouldReturnOriginalInputWhenConditionIsFalseAndNoOtherwise() throws OperationException {
    // Given
    final If<Object, Object> ifOperation = new If<>();
    ifOperation.setInput(INPUT_CAMEL_CASE);
    ifOperation.setConditional(new Conditional(new IsA("java.lang.Integer")));
    ifOperation.setThen(new Map<>(Lists.newArrayList(new ToLong(), new ToList())));
    // When
    final Object output = graph.execute(ifOperation, getUser());
    // Then
    assertThat(output).isEqualTo(INPUT_CAMEL_CASE).isInstanceOf(String.class);
}
Also used : ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) IsA(uk.gov.gchq.koryphe.impl.predicate.IsA) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) ToList(uk.gov.gchq.koryphe.impl.function.ToList) Test(org.junit.Test)

Example 8 with ToLong

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

the class IfIT method shouldReturnOriginalInputWhenConditionIsTrueAndNoThen.

@Test
public void shouldReturnOriginalInputWhenConditionIsTrueAndNoThen() throws OperationException {
    // Given
    final If<Object, Object> ifOperation = new If<>();
    ifOperation.setInput(INPUT_CAMEL_CASE);
    ifOperation.setConditional(new Conditional(new IsA("java.lang.String")));
    ifOperation.setOtherwise(new Map<>(Lists.newArrayList(new ToLong(), new ToList())));
    // When
    final Object output = graph.execute(ifOperation, getUser());
    // Then
    assertThat(output).isEqualTo(INPUT_CAMEL_CASE).isInstanceOf(String.class);
}
Also used : ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) IsA(uk.gov.gchq.koryphe.impl.predicate.IsA) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) ToList(uk.gov.gchq.koryphe.impl.function.ToList) Test(org.junit.Test)

Example 9 with ToLong

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

the class SchemaMigrationIT method createMigration.

private SchemaMigration createMigration() {
    final SchemaMigration migration = new SchemaMigration();
    migration.setEntities(Collections.singletonList(new MigrateElement(MigrateElement.ElementType.ENTITY, "entityOld", "entityNew", new ElementTransformer.Builder().select("count").execute(new ToLong()).project("count").build(), new ElementTransformer.Builder().select("count").execute(new ToInteger()).project("count").build())));
    migration.setEdges(Arrays.asList(new MigrateElement(MigrateElement.ElementType.EDGE, "edgeOld", "edgeNew", new ElementTransformer.Builder().select("count").execute(new ToLong()).project("count").build(), new ElementTransformer.Builder().select("count").execute(new ToInteger()).project("count").build()), new MigrateElement(MigrateElement.ElementType.EDGE, "edgeAgg", "edgeAggNew", new ElementTransformer.Builder().select("count").execute(new ToLong()).project("count").build(), new ElementTransformer.Builder().select("count").execute(new ToInteger()).project("count").build()), new MigrateElement(MigrateElement.ElementType.EDGE, "oldEdgePostOpAgg", "newEdgePostOpAgg", new ElementTransformer.Builder().select("count").execute(new ToLong()).project("count").build(), new ElementTransformer.Builder().select("count").execute(new ToInteger()).project("count").build()), new MigrateElement(MigrateElement.ElementType.EDGE, "oldEdgeAggBeforePostFilter", "newEdgeAggBeforePostFilter", new ElementTransformer.Builder().select("count").execute(new ToLong()).project("count").build(), new ElementTransformer.Builder().select("count").execute(new ToInteger()).project("count").build()), new MigrateElement(MigrateElement.ElementType.EDGE, "edgeOldOpChain", "edgeNewOpChain", new ElementTransformer.Builder().select("count").execute(new ToLong()).project("count").build(), new ElementTransformer.Builder().select("count").execute(new ToInteger()).project("count").build())));
    return migration;
}
Also used : ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) ToInteger(uk.gov.gchq.koryphe.impl.function.ToInteger) SchemaMigration(uk.gov.gchq.gaffer.graph.hook.migrate.SchemaMigration) MigrateElement(uk.gov.gchq.gaffer.graph.hook.migrate.MigrateElement)

Example 10 with ToLong

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

the class JoinIT method shouldRightSideFullJoinUsingKeyFunctionMatch.

@Test
public void shouldRightSideFullJoinUsingKeyFunctionMatch() throws OperationException {
    // Given
    final Map map = new Map.Builder<>().input(Lists.newArrayList(2L, 1L, 2L, 3L)).first(new Identity()).build();
    final ArrayList<Entity> input = Lists.newArrayList(getJoinEntity(TestGroups.ENTITY, 1), getJoinEntity(TestGroups.ENTITY_2, 2), getJoinEntity(TestGroups.ENTITY_2, 2), getJoinEntity(TestGroups.ENTITY_5, 5));
    final Join<Object> leftJoin = new Join.Builder<>().flatten(false).matchKey(MatchKey.RIGHT).joinType(JoinType.FULL).operation(map).matchMethod(new KeyFunctionMatch(new ToLong(), new ExtractProperty("count"))).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(4);
    assertThat(loadedResults.get(0)).containsEntry(MatchKey.LEFT.name(), Lists.newArrayList(getJoinEntity(TestGroups.ENTITY_2, 2), getJoinEntity(TestGroups.ENTITY_2, 2))).containsEntry(MatchKey.RIGHT.name(), 2L);
    assertThat(loadedResults.get(1)).containsEntry(MatchKey.LEFT.name(), Lists.newArrayList(getJoinEntity(TestGroups.ENTITY, 1))).containsEntry(MatchKey.RIGHT.name(), 1L);
    assertThat(loadedResults.get(2)).containsEntry(MatchKey.LEFT.name(), Lists.newArrayList(getJoinEntity(TestGroups.ENTITY_2, 2), getJoinEntity(TestGroups.ENTITY_2, 2))).containsEntry(MatchKey.RIGHT.name(), 2L);
    assertThat(loadedResults.get(3)).containsEntry(MatchKey.LEFT.name(), Lists.newArrayList()).containsEntry(MatchKey.RIGHT.name(), 3L);
}
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)

Aggregations

ToLong (uk.gov.gchq.koryphe.impl.function.ToLong)10 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 ExtractProperty (uk.gov.gchq.gaffer.data.element.function.ExtractProperty)3 Element (uk.gov.gchq.gaffer.data.element.Element)2 Properties (uk.gov.gchq.gaffer.data.element.Properties)2 If (uk.gov.gchq.gaffer.operation.impl.If)2 Map (uk.gov.gchq.gaffer.operation.impl.Map)2 Join (uk.gov.gchq.gaffer.operation.impl.join.Join)2 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)2 KeyFunctionMatch (uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch)2 FunctionTest (uk.gov.gchq.koryphe.function.FunctionTest)2 Sum (uk.gov.gchq.koryphe.impl.binaryoperator.Sum)2 Identity (uk.gov.gchq.koryphe.impl.function.Identity)2 ToInteger (uk.gov.gchq.koryphe.impl.function.ToInteger)2 ToList (uk.gov.gchq.koryphe.impl.function.ToList)2 ToString (uk.gov.gchq.koryphe.impl.function.ToString)2 IsA (uk.gov.gchq.koryphe.impl.predicate.IsA)2