Search in sources :

Example 1 with LazyElementCell

use of uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell in project Gaffer by gchq.

the class FilterProcessorTest method shouldSkipDeletedAndRemoveInvalidElements.

@Test
public void shouldSkipDeletedAndRemoveInvalidElements() throws OperationException, SerialisationException {
    // Given
    final FilterProcessor processor = new FilterProcessor() {

        @Override
        public boolean test(final LazyElementCell elementCell) {
            return elementCell.getElement() instanceof Entity;
        }
    };
    final List<LazyElementCell> lazyCells = CellUtil.getLazyCells(ELEMENTS, serialisation);
    final Cell deletedCell = mock(Cell.class);
    given(deletedCell.getTypeByte()).willReturn(KeyValue.Type.Delete.getCode());
    lazyCells.add(new LazyElementCell(deletedCell, serialisation, false));
    // When
    final List<LazyElementCell> result = processor.process(lazyCells);
    // When / Then
    assertThat(result).hasSize(2);
    assertEquals(ELEMENTS.get(0), result.get(0).getElement());
    assertEquals(deletedCell, result.get(1).getCell());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.jupiter.api.Test)

Example 2 with LazyElementCell

use of uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell in project Gaffer by gchq.

the class ElementDedupeFilterProcessorTest method shouldOnlyAcceptEdges.

@Test
public void shouldOnlyAcceptEdges() throws OperationException, SerialisationException {
    // Given
    final ElementDedupeFilterProcessor processor = new ElementDedupeFilterProcessor(false, true, DirectedType.EITHER);
    // When / Then
    for (final Element element : ELEMENTS) {
        final boolean expectedResult = element instanceof Edge;
        final Pair<LazyElementCell, LazyElementCell> cells = CellUtil.getLazyCells(element, serialisation);
        assertEquals(expectedResult, processor.test(cells.getFirst()), "Failed for element: " + element.toString());
        if (null != cells.getSecond()) {
            // self elements are not added the other way round
            assertEquals(false, processor.test(cells.getSecond()), "Failed for element: " + element.toString());
        }
    }
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 3 with LazyElementCell

use of uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell in project Gaffer by gchq.

the class ElementDedupeFilterProcessorTest method shouldAcceptOnlyEntities.

@Test
public void shouldAcceptOnlyEntities() throws OperationException, SerialisationException {
    // Given
    final ElementDedupeFilterProcessor processor = new ElementDedupeFilterProcessor(true, false, null);
    // When / Then
    for (final Element element : ELEMENTS) {
        final boolean expectedResult = element instanceof Entity;
        final Pair<LazyElementCell, LazyElementCell> cells = CellUtil.getLazyCells(element, serialisation);
        assertEquals(expectedResult, processor.test(cells.getFirst()), "Failed for element: " + element.toString());
        if (null != cells.getSecond()) {
            // entities and self edges are not added the other way round
            assertEquals(expectedResult, processor.test(cells.getSecond()), "Failed for element: " + element.toString());
        }
    }
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) Test(org.junit.jupiter.api.Test)

Example 4 with LazyElementCell

use of uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell in project Gaffer by gchq.

the class GafferScannerTest method shouldDelegateToEachProcessor.

@Test
public void shouldDelegateToEachProcessor() throws OperationException, IOException {
    // Given
    final List<LazyElementCell> lazyCells = CellUtil.getLazyCells(ELEMENTS, serialisation);
    final List<Cell> cells = new ArrayList<>();
    for (final LazyElementCell lazyElementCell : lazyCells) {
        cells.add(lazyElementCell.getCell());
    }
    final InternalScanner internalScanner = new InternalScanner() {

        @Override
        public boolean next(final List<Cell> results) throws IOException {
            results.addAll(cells);
            return true;
        }

        @Override
        public boolean next(final List<Cell> result, final ScannerContext scannerContext) throws IOException {
            throw new UnsupportedOperationException();
        }

        @Override
        public void close() throws IOException {
            throw new UnsupportedOperationException();
        }
    };
    final GafferScannerProcessor processor1 = mock(GafferScannerProcessor.class);
    final GafferScannerProcessor processor2 = mock(GafferScannerProcessor.class);
    final GafferScanner scanner = new GafferScanner(internalScanner, serialisation, Arrays.asList(processor1, processor2), false) {
    };
    final List<LazyElementCell> processedCells1 = mock(List.class);
    given(processor1.process(Mockito.anyList())).willReturn(processedCells1);
    given(processor2.process(processedCells1)).willReturn(lazyCells);
    final List<Cell> outputResult = new ArrayList<>();
    // When
    final boolean result = scanner.next(outputResult, null);
    // When / Then
    assertTrue(result);
    final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
    verify(processor1).process(captor.capture());
    assertEquals(lazyCells, captor.getValue());
    verify(processor2).process(processedCells1);
    assertEquals(cells, outputResult);
}
Also used : InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) ArrayList(java.util.ArrayList) GafferScannerProcessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor) ArrayList(java.util.ArrayList) List(java.util.List) LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) Cell(org.apache.hadoop.hbase.Cell) ScannerContext(org.apache.hadoop.hbase.regionserver.ScannerContext) Test(org.junit.jupiter.api.Test)

Example 5 with LazyElementCell

use of uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell in project Gaffer by gchq.

the class CellUtil method getLazyCells.

public static List<LazyElementCell> getLazyCells(final Iterable<Element> elements, final ElementSerialisation serialisation, final boolean includeMatchedVertex) throws SerialisationException {
    final List<LazyElementCell> cells = new ArrayList<>();
    for (final Element element : elements) {
        final Pair<LazyElementCell, LazyElementCell> cellPair = getLazyCells(element, serialisation, includeMatchedVertex);
        cells.add(cellPair.getFirst());
        if (null != cellPair.getSecond()) {
            cells.add(cellPair.getSecond());
        }
    }
    return cells;
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) ArrayList(java.util.ArrayList)

Aggregations

LazyElementCell (uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell)13 Element (uk.gov.gchq.gaffer.data.element.Element)7 Cell (org.apache.hadoop.hbase.Cell)6 Test (org.junit.jupiter.api.Test)6 ArrayList (java.util.ArrayList)4 Edge (uk.gov.gchq.gaffer.data.element.Edge)3 Entity (uk.gov.gchq.gaffer.data.element.Entity)2 Properties (uk.gov.gchq.gaffer.data.element.Properties)2 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)2 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)2 List (java.util.List)1 Set (java.util.Set)1 InternalScanner (org.apache.hadoop.hbase.regionserver.InternalScanner)1 ScannerContext (org.apache.hadoop.hbase.regionserver.ScannerContext)1 Pair (uk.gov.gchq.gaffer.commonutil.pair.Pair)1 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)1 GafferScannerProcessor (uk.gov.gchq.gaffer.hbasestore.coprocessor.processor.GafferScannerProcessor)1