Search in sources :

Example 26 with ViewElementDefinition

use of uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition in project Gaffer by gchq.

the class QueryAggregationProcessor 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 {
            final String group = elementCell.getGroup();
            final Set<String> schemaGroupBy = schema.getElement(group).getGroupBy();
            final ViewElementDefinition elementDef = view.getElement(group);
            final Set<String> groupBy = null != elementDef ? elementDef.getGroupBy() : null;
            if (!compareGroupByKeys(firstElementCell.getCell(), elementCell.getCell(), group, schemaGroupBy, groupBy)) {
                output(firstElementCell, aggregatedProperties, output);
                firstElementCell = elementCell;
                aggregatedProperties = null;
                aggregator = null;
            } else {
                if (null == aggregator) {
                    final ElementAggregator viewAggregator = null != elementDef ? elementDef.getAggregator() : null;
                    aggregator = schema.getElement(group).getQueryAggregator(groupBy, viewAggregator);
                    aggregatedProperties = firstElementCell.getElement().getProperties();
                }
                final Properties properties = elementCell.getElement().getProperties();
                aggregatedProperties = aggregator.apply(properties, aggregatedProperties);
            }
        }
    }
    output(firstElementCell, aggregatedProperties, output);
    return output;
}
Also used : Set(java.util.Set) LazyElementCell(uk.gov.gchq.gaffer.hbasestore.serialisation.LazyElementCell) ArrayList(java.util.ArrayList) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) Properties(uk.gov.gchq.gaffer.data.element.Properties) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator)

Example 27 with ViewElementDefinition

use of uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition in project Gaffer by gchq.

the class FederatedStoreUtilTest method shouldUpdateOperationViewAndReturnNullIfViewHasNoGroups.

@Test
public void shouldUpdateOperationViewAndReturnNullIfViewHasNoGroups() {
    // Given
    final Graph graph = createGraph();
    final GetElements operation = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE_2, new ViewElementDefinition()).entity(TestGroups.ENTITY_2, new ViewElementDefinition()).build()).build();
    // When
    final GetElements updatedOp = FederatedStoreUtil.updateOperationForGraph(operation, graph);
    // Then
    assertNull(updatedOp);
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Aggregations

ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)27 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)15 Test (org.junit.jupiter.api.Test)10 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)6 HashMap (java.util.HashMap)5 GlobalViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition)5 Graph (uk.gov.gchq.gaffer.graph.Graph)5 Set (java.util.Set)4 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Element (uk.gov.gchq.gaffer.data.element.Element)3 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)3 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)3 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)3 Store (uk.gov.gchq.gaffer.store.Store)3 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)3