Search in sources :

Example 11 with ViewElementDefinition

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

the class QueryGenerator method getPredicateFromView.

// TODO raise issue saying that could optimise so that only the filters that have not been fully applied
// are reapplied, and it should be able to return the fact that all filters have been applied
// Either the result is:
// - a filter and that fully applies the view
// - a filter and that doesn't fully apply the view
// - no filter and that doesn't fully apply the view
// - no filter and that fully applies the view
// Boolean indicates whether logic was fully applied
private Pair<FilterPredicate, Boolean> getPredicateFromView(final View view, final String group, final boolean isEntityGroup) throws SerialisationException, OperationException {
    if (null == view) {
        return new Pair<>(null, true);
    }
    final ViewElementDefinition ved = view.getElement(group);
    FilterPredicate filterPredicate = null;
    boolean fullyAppliedInAll = true;
    if (null != ved) {
        List<TupleAdaptedPredicate<String, ?>> preAggFilterFunctions = ved.getPreAggregationFilterFunctions();
        if (null != preAggFilterFunctions) {
            for (final TupleAdaptedPredicate<String, ?> filterFunctionContext : preAggFilterFunctions) {
                final JavaPredicateToParquetPredicate predicateConverter = new JavaPredicateToParquetPredicate(schemaUtils, filterFunctionContext.getPredicate(), filterFunctionContext.getSelection(), group);
                filterPredicate = FilterPredicateUtils.and(filterPredicate, predicateConverter.getParquetPredicate());
                if (!predicateConverter.isFullyApplied()) {
                    fullyAppliedInAll = false;
                }
            }
        }
    }
    return new Pair<>(filterPredicate, fullyAppliedInAll);
}
Also used : TupleAdaptedPredicate(uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) FilterPredicate(org.apache.parquet.filter2.predicate.FilterPredicate) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair)

Example 12 with ViewElementDefinition

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

the class SchemaMigration method applyMigration.

private void applyMigration(final Function<String, ViewElementDefinition> currentElementSupplier, final Map<String, ViewMigration> newElementDefs, final MigrateElement migration) {
    final ViewElementDefinition originalOldElement = currentElementSupplier.apply(migration.getOldGroup());
    final ViewElementDefinition originalNewElement = currentElementSupplier.apply(migration.getNewGroup());
    final boolean queriedForOld = null != originalOldElement;
    final boolean queriedForNew = null != originalNewElement;
    if (queriedForOld || queriedForNew) {
        final ViewMigration oldElement;
        final ViewMigration newElement;
        if (queriedForOld && queriedForNew) {
            // Queried for old and new
            oldElement = migrateViewOldFromOld(migration, originalOldElement);
            newElement = migrateViewNewFromNew(migration, originalNewElement);
        } else if (queriedForOld) {
            // Queried for old
            oldElement = migrateViewOldFromOld(migration, originalOldElement);
            newElement = migrateViewNewFromOld(migration, originalOldElement);
        } else {
            // Queried for new
            oldElement = migrateViewOldFromNew(migration, originalNewElement);
            newElement = migrateViewNewFromNew(migration, originalNewElement);
        }
        newElementDefs.put(migration.getOldGroup(), oldElement);
        newElementDefs.put(migration.getNewGroup(), newElement);
    }
}
Also used : ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)

Example 13 with ViewElementDefinition

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

the class AggregatorUtil method getQueryGroupBy.

public static Set<String> getQueryGroupBy(final String group, final Schema schema, final View view) {
    Set<String> groupBy = null;
    if (null != view) {
        final ViewElementDefinition elDef = view.getElement(group);
        if (null != elDef) {
            groupBy = elDef.getGroupBy();
        }
    }
    if (null == groupBy) {
        final SchemaElementDefinition elDef = schema.getElement(group);
        if (null == elDef) {
            throw new IllegalArgumentException("Received group " + group + " which was not found in the schema");
        }
        groupBy = elDef.getGroupBy();
    }
    return groupBy;
}
Also used : ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)

Example 14 with ViewElementDefinition

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

the class ElementValidatorTest method shouldReturnFalseWhenViewValidateWithInvalidElement.

@Test
public void shouldReturnFalseWhenViewValidateWithInvalidElement() {
    // Given
    final View view = mock(View.class);
    final String group = TestGroups.EDGE;
    final Element elm = mock(Element.class);
    final ViewElementDefinition elementDef = mock(ViewElementDefinition.class);
    final ElementFilter filter = mock(ElementFilter.class);
    final ElementValidator validator = new ElementValidator(view);
    given(elm.getGroup()).willReturn(group);
    given(view.getElement(group)).willReturn(elementDef);
    given(elementDef.getPreAggregationFilter()).willReturn(filter);
    given(filter.test(elm)).willReturn(false);
    // When
    final boolean isValid = validator.validate(elm);
    // Then
    assertFalse(isValid);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 15 with ViewElementDefinition

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

the class ExamplesService method generateViewBuilder.

protected View.Builder generateViewBuilder() {
    final View.Builder viewBuilder = new View.Builder();
    if (hasEntities()) {
        final ViewElementDefinition viewElement;
        if (null == getAnEntityPropertyName()) {
            viewElement = new ViewElementDefinition();
        } else {
            viewElement = new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(getAnEntityPropertyName()).execute(new ExampleFilterFunction()).build()).build();
        }
        viewBuilder.entity(getAnEntityGroup(), viewElement);
    }
    if (hasEdges()) {
        final ViewElementDefinition viewElement;
        if (null == getAnEdgePropertyName()) {
            viewElement = new ViewElementDefinition();
        } else {
            viewElement = new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(getAnEdgePropertyName()).execute(new ExampleFilterFunction()).build()).build();
        }
        viewBuilder.edge(getAnEdgeGroup(), viewElement);
    }
    viewBuilder.globalElements(new GlobalViewElementDefinition.Builder().groupBy().build());
    return viewBuilder;
}
Also used : GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) ExampleFilterFunction(uk.gov.gchq.gaffer.rest.example.ExampleFilterFunction) GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View)

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