Search in sources :

Example 66 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class FunctionValidator method validateEntity.

protected ValidationResult validateEntity(final Map.Entry<String, ?> entityEntry, final Schema schema) {
    final ValidationResult result = new ValidationResult();
    if (null != entityEntry) {
        final String group = entityEntry.getKey();
        final SchemaEntityDefinition schemaEntityDefinition = schema.getEntity(group);
        if (null == schemaEntityDefinition) {
            result.addError("Entity group: " + group + " does not exist in the schema.");
        }
    }
    return result;
}
Also used : SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 67 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class SchemaElementDefinitionValidator method validateAggregator.

private ValidationResult validateAggregator(final ElementAggregator aggregator, final SchemaElementDefinition elementDef) {
    final ValidationResult result = new ValidationResult();
    if (null == elementDef.getPropertyMap() || elementDef.getPropertyMap().isEmpty()) {
        // if no properties then no aggregation should be provided
        if (null != aggregator && !aggregator.getComponents().isEmpty()) {
            result.addError("Groups with no properties should not have any aggregators");
        }
        return result;
    }
    if (!elementDef.isAggregate()) {
        if (!elementDef.getGroupBy().isEmpty()) {
            result.addError("Groups with aggregation disabled should not have groupBy properties.");
        }
        return result;
    }
    if (null == aggregator || null == aggregator.getComponents() || aggregator.getComponents().isEmpty()) {
        result.addError("Some properties do not have aggregators defined.");
        return result;
    }
    // if aggregate functions are defined then check all properties are aggregated
    // also check that no identifiers are selected
    final Set<String> aggregatedProperties = new HashSet<>();
    if (null != aggregator.getComponents()) {
        for (final TupleAdaptedBinaryOperator<String, ?> adaptedFunction : aggregator.getComponents()) {
            final String[] selection = adaptedFunction.getSelection();
            if (null != selection) {
                for (final String key : selection) {
                    final IdentifierType idType = IdentifierType.fromName(key);
                    if (null == idType) {
                        if (elementDef.containsProperty(key)) {
                            aggregatedProperties.add(key);
                        } else {
                            result.addError("Unknown property used in an aggregator: " + key);
                        }
                    } else {
                        result.addError("Identifiers cannot be selected for aggregation: " + idType.name());
                    }
                }
                if (selection.length > 1) {
                    Boolean containsGroupByProp = null;
                    // Check properties are stored in the same position: groupBy, non-groupBy, visibility, timestamp
                    for (final String key : selection) {
                        if (key.equals(elementDef.getSchemaReference().getVisibilityProperty())) {
                            result.addError("The visibility property must be aggregated by itself. " + "It is currently aggregated in the tuple: " + Arrays.toString(selection) + ", by aggregate function: " + adaptedFunction.getBinaryOperator().getClass().getName());
                            break;
                        } else {
                            final boolean newContainsGroupByProp = elementDef.getGroupBy().contains(key);
                            if (null == containsGroupByProp) {
                                containsGroupByProp = newContainsGroupByProp;
                            } else if (newContainsGroupByProp != containsGroupByProp) {
                                result.addError("groupBy properties and non-groupBy properties (including timestamp) must be not be aggregated using the same BinaryOperator. " + "Selection tuple: " + Arrays.toString(selection) + ", is aggregated by: " + adaptedFunction.getBinaryOperator().getClass().getName());
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    final Set<String> propertyNamesTmp = new HashSet<>(elementDef.getProperties());
    propertyNamesTmp.removeAll(aggregatedProperties);
    if (!propertyNamesTmp.isEmpty()) {
        result.addError("No aggregator found for properties '" + propertyNamesTmp.toString() + "' in the supplied schema. " + "This framework requires that all of the defined properties have an aggregator function associated with them. " + "To disable aggregation for a group set the 'aggregate' field to false.");
    }
    return result;
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) IdentifierType(uk.gov.gchq.gaffer.data.element.IdentifierType) HashSet(java.util.HashSet)

Example 68 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class SchemaElementDefinitionValidator method validateFunctionArgumentTypes.

protected ValidationResult validateFunctionArgumentTypes(final ElementAggregator aggregator, final SchemaElementDefinition schemaElDef) {
    final ValidationResult result = new ValidationResult();
    if (null != aggregator && null != aggregator.getComponents()) {
        for (final TupleAdaptedBinaryOperator<String, ?> adaptedFunction : aggregator.getComponents()) {
            if (null == adaptedFunction.getBinaryOperator()) {
                result.addError(aggregator.getClass().getSimpleName() + " contains a null function.");
            } else {
                final Signature inputSig = Signature.getInputSignature(adaptedFunction.getBinaryOperator());
                result.add(inputSig.assignable(getTypeClasses(adaptedFunction.getSelection(), schemaElDef)));
                final Signature outputSig = Signature.getOutputSignature(adaptedFunction.getBinaryOperator());
                result.add(outputSig.assignable(getTypeClasses(adaptedFunction.getSelection(), schemaElDef)));
            }
        }
    }
    return result;
}
Also used : Signature(uk.gov.gchq.koryphe.signature.Signature) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 69 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class ViewValidator method validate.

/**
 * Checks all {@link java.util.function.Predicate}s and {@link java.util.function.Function}s defined are
 * compatible with the identifiers and properties in the {@link Schema}
 * and transient properties in the {@link View}.
 *
 * @param view        the {@link View} to validate
 * @param schema      the {@link Schema} to validate the view against
 * @param storeTraits the store traits
 * @return true if the element definition is valid, otherwise false and an error is logged
 */
public ValidationResult validate(final View view, final Schema schema, final Set<StoreTrait> storeTraits) {
    final boolean isStoreOrdered = storeTraits.contains(StoreTrait.ORDERED);
    final ValidationResult result = new ValidationResult();
    if (null != view) {
        validateEntities(view, schema, storeTraits, isStoreOrdered, result);
        validateEdge(view, schema, storeTraits, isStoreOrdered, result);
    }
    return result;
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 70 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class ViewValidator method validateGroupBy.

protected ValidationResult validateGroupBy(final boolean isStoreOrdered, final String group, final ViewElementDefinition viewElDef, final SchemaElementDefinition schemaElDef) {
    final ValidationResult result = new ValidationResult();
    final Set<String> viewGroupBy = viewElDef.getGroupBy();
    if (null != viewGroupBy && !viewGroupBy.isEmpty()) {
        final Set<String> schemaGroupBy = schemaElDef.getGroupBy();
        if (null != schemaGroupBy && schemaGroupBy.containsAll(viewGroupBy)) {
            if (isStoreOrdered) {
                final LinkedHashSet<String> schemaGroupBySubset = Sets.newLinkedHashSet(Iterables.limit(schemaGroupBy, viewGroupBy.size()));
                if (!viewGroupBy.equals(schemaGroupBySubset)) {
                    result.addError("Group by properties for group " + group + " are not in the same order as the group by properties in the schema. View groupBy:" + viewGroupBy + ". Schema groupBy:" + schemaGroupBy);
                }
            }
        } else {
            result.addError("Group by properties for group " + group + " in the view are not all included in the group by field in the schema. View groupBy:" + viewGroupBy + ". Schema groupBy:" + schemaGroupBy);
        }
    }
    return result;
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Aggregations

ValidationResult (uk.gov.gchq.koryphe.ValidationResult)132 Test (org.junit.jupiter.api.Test)86 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)32 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)27 HashMap (java.util.HashMap)13 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)12 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)11 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)11 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)9 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)9 OperationChainValidator (uk.gov.gchq.gaffer.store.operation.OperationChainValidator)9 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)8 Schema (uk.gov.gchq.gaffer.store.schema.Schema)8 Signature (uk.gov.gchq.koryphe.signature.Signature)8 Map (java.util.Map)7 OperationChainOptimiser (uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)7 Set (java.util.Set)6 Operation (uk.gov.gchq.gaffer.operation.Operation)6 Element (uk.gov.gchq.gaffer.data.element.Element)5 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)5