Search in sources :

Example 6 with LazyElementCell

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

the class CellUtil method getLazyCells.

public static Pair<LazyElementCell, LazyElementCell> getLazyCells(final Pair<Put, Put> puts, final ElementSerialisation serialisation, final boolean includeMatchedVertex) {
    final Pair<Cell, Cell> cells = getCells(puts);
    final Pair<LazyElementCell, LazyElementCell> lazyCells = new Pair<>();
    lazyCells.setFirst(new LazyElementCell(cells.getFirst(), serialisation, includeMatchedVertex));
    if (null != cells.getSecond()) {
        lazyCells.setSecond(new LazyElementCell(cells.getSecond(), serialisation, includeMatchedVertex));
    }
    return lazyCells;
}
Also used : LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) Cell(org.apache.hadoop.hbase.Cell) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair)

Example 7 with LazyElementCell

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

the class StoreAggregationProcessor method process.

@Override
public List<LazyElementCell> process(final List<LazyElementCell> elementCells) {
    if (elementCells.size() <= 1) {
        return elementCells;
    }
    final List<LazyElementCell> output = new ArrayList<>();
    ElementAggregator aggregator = null;
    Properties aggregatedProperties = null;
    LazyElementCell firstElementCell = null;
    for (final LazyElementCell elementCell : elementCells) {
        if (elementCell.isDeleted()) {
            continue;
        }
        if (!aggregatedGroups.contains(elementCell.getGroup())) {
            if (null != firstElementCell) {
                output(firstElementCell, aggregatedProperties, output);
                firstElementCell = null;
            }
            output(elementCell, null, output);
            aggregatedProperties = null;
            aggregator = null;
        } else if (null == firstElementCell) {
            firstElementCell = elementCell;
            aggregatedProperties = null;
            aggregator = null;
        } else if (!HBaseUtil.compareKeys(firstElementCell.getCell(), elementCell.getCell())) {
            output(firstElementCell, aggregatedProperties, output);
            firstElementCell = elementCell;
            aggregatedProperties = null;
            aggregator = null;
        } else {
            final String group = firstElementCell.getGroup();
            if (null == aggregator) {
                aggregator = schema.getElement(group).getIngestAggregator();
                aggregatedProperties = firstElementCell.getElement().getProperties();
            }
            final Properties properties = elementCell.getElement().getProperties();
            aggregatedProperties = aggregator.apply(properties, aggregatedProperties);
        }
    }
    output(firstElementCell, aggregatedProperties, output);
    return output;
}
Also used : LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) ArrayList(java.util.ArrayList) Properties(uk.gov.gchq.gaffer.data.element.Properties) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator)

Example 8 with LazyElementCell

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

the class ElementDedupeFilterProcessorTest method shouldOnlyAcceptUndirectedEdges.

@Test
public void shouldOnlyAcceptUndirectedEdges() throws OperationException, SerialisationException {
    // Given
    final ElementDedupeFilterProcessor processor = new ElementDedupeFilterProcessor(false, true, DirectedType.UNDIRECTED);
    // When / Then
    for (final Element element : ELEMENTS) {
        final boolean expectedResult = element instanceof Edge && !((Edge) element).isDirected();
        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 9 with LazyElementCell

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

the class ElementDedupeFilterProcessorTest method shouldOnlyAcceptDirectedEdges.

@Test
public void shouldOnlyAcceptDirectedEdges() throws OperationException, SerialisationException {
    // Given
    final ElementDedupeFilterProcessor processor = new ElementDedupeFilterProcessor(false, true, DirectedType.DIRECTED);
    // When / Then
    for (final Element element : ELEMENTS) {
        final boolean expectedResult = element instanceof Edge && ((Edge) element).isDirected();
        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 10 with LazyElementCell

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

the class ElementDedupeFilterProcessor method test.

@Override
public boolean test(final LazyElementCell elementCell) {
    final Cell cell = elementCell.getCell();
    final byte flag = getFlag(cell);
    final boolean isEdge = flag != HBaseStoreConstants.ENTITY;
    if (!edges && isEdge) {
        return false;
    }
    if (!entities && !isEdge) {
        return false;
    }
    return !isEdge || testEdge(flag, cell);
}
Also used : LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) Cell(org.apache.hadoop.hbase.Cell)

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