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);
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations