Search in sources :

Example 11 with Sort

use of uk.gov.gchq.gaffer.operation.impl.compare.Sort in project Gaffer by gchq.

the class SortHandlerTest method shouldReturnNullsLast.

@Test
public void shouldReturnNullsLast() throws OperationException, JsonProcessingException {
    // Given
    final Entity entity1 = new Entity.Builder().group(TestGroups.ENTITY).property("property", 1).build();
    final Entity entity2 = new Entity.Builder().group(TestGroups.ENTITY).property("property", 2).build();
    final Entity entity3 = new Entity.Builder().group(TestGroups.ENTITY).property("property", 3).build();
    final Entity entity4 = new Entity.Builder().group(TestGroups.ENTITY).build();
    final Entity entity5 = new Entity.Builder().group(TestGroups.ENTITY).build();
    final List<Entity> input = Lists.newArrayList(entity1, entity3, entity2, entity4, entity5);
    final Sort sort = new Sort.Builder().input(input).comparators(new ElementPropertyComparator.Builder().property("property").groups(TestGroups.ENTITY).comparator(new PropertyComparatorImpl()).build()).deduplicate(false).build();
    final SortHandler handler = new SortHandler();
    // When
    final Iterable<? extends Element> result = handler.doOperation(sort, null, null);
    // Then
    assertEquals(5, Iterables.size(result));
    assertNull(Iterables.getLast(result).getProperty("property"));
    assertNotNull(Iterables.getFirst(result, null).getProperty("property"));
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Sort(uk.gov.gchq.gaffer.operation.impl.compare.Sort) ElementPropertyComparator(uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator) Test(org.junit.jupiter.api.Test)

Example 12 with Sort

use of uk.gov.gchq.gaffer.operation.impl.compare.Sort in project Gaffer by gchq.

the class AbstractExamplesFactoryTest method shouldUseSchemaForGroupsInSortOperation.

@Test
public void shouldUseSchemaForGroupsInSortOperation() throws InstantiationException, IllegalAccessException {
    // Given
    TestExamplesFactory examplesFactory = new TestExamplesFactory(SCHEMA);
    // When
    Sort operation = (Sort) examplesFactory.generateExample(Sort.class);
    // Then
    // Sort has no equals method
    assertEquals(1, operation.getComparators().size());
    assertEquals(Sets.newHashSet("BasicEdge"), ((ElementPropertyComparator) operation.getComparators().get(0)).getGroups());
    assertEquals("count", ((ElementPropertyComparator) operation.getComparators().get(0)).getProperty());
}
Also used : Sort(uk.gov.gchq.gaffer.operation.impl.compare.Sort) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)12 Sort (uk.gov.gchq.gaffer.operation.impl.compare.Sort)12 Entity (uk.gov.gchq.gaffer.data.element.Entity)8 ElementPropertyComparator (uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator)7 Element (uk.gov.gchq.gaffer.data.element.Element)2 Random (java.util.Random)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 TestOperationsImpl (uk.gov.gchq.gaffer.operation.TestOperationsImpl)1 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)1 GenerateObjects (uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects)1 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)1 Context (uk.gov.gchq.gaffer.store.Context)1 User (uk.gov.gchq.gaffer.user.User)1