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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations