Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gh-3059: ApplyViewToElementsFunction apply Schema validation #3060

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from

Conversation

GCHQDev404
Copy link
Contributor

@GCHQDev404 GCHQDev404 commented Nov 3, 2023

@GCHQDev404 GCHQDev404 changed the title Gh 3059 ApplyViewToElementsFunction improving Schema validation gh-3059 ApplyViewToElementsFunction improving Schema validation Nov 3, 2023
…ation into view POST Aggregation to work after a groupBy aggregation change.
…wtoelements-schema-validation' into gh-3059-federated-store-applyviewtoelements-schema-validation

# Conflicts:
#	store-implementation/federated-store/src/main/java/uk/gov/gchq/gaffer/federatedstore/util/ApplyViewToElementsFunction.java
…ation should only be done for the TemporaryStore of type MapStore
@GCHQDev404 GCHQDev404 marked this pull request as ready for review November 3, 2023 16:49
Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Attention: Patch coverage is 73.33333% with 28 lines in your changes are missing coverage. Please review.

Project coverage is 66.77%. Comparing base (6213159) to head (384c308).

Files Patch % Lines
...ffer/federatedstore/util/MergeElementFunction.java 69.76% 18 Missing and 8 partials ⚠️
.../gchq/gaffer/data/elementdefinition/view/View.java 66.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #3060      +/-   ##
=============================================
+ Coverage      66.71%   66.77%   +0.05%     
  Complexity      2557     2557              
=============================================
  Files            907      907              
  Lines          29063    29111      +48     
  Branches        3239     3249      +10     
=============================================
+ Hits           19390    19439      +49     
+ Misses          8239     8232       -7     
- Partials        1434     1440       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

this.context = Collections.unmodifiableMap(context);
} catch (final Exception e) {
throw new GafferCheckedException("Unable to create TemporaryResultsGraph", e);
}

}

private static void updateViewWithValidationFromSchema(final Map<String, Object> context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the function ApplyViewToElementsFunction be renamed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To what?

It still applies view to elements. This additional new Validation suff is because of MapStore failings, this would be done for free otherwise. It should get ripped out when Mapstore is fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't just apply the view anymore, it also reapplies the schema now. On this topic, does your fix apply schema aggregation too? Or just schema validation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"does your fix apply schema aggregation too?" - I think this is not necessary as the MapStore does this.

Copy link
Contributor Author

@GCHQDev404 GCHQDev404 Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep correct, mapstore does aggregation. This is all due to Mapstore having issues that need validation added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should ApplyViewToElementsFunction be renamed then? As the View and Schema are reapplied.

Copy link
Contributor Author

@GCHQDev404 GCHQDev404 Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With regards to the schema validation being stolen for the filter. I don't think so because this temporary.

With regards too the schema doing schema things in within a working complete store... erm...
would you choose ReApplyViewFilterAndSchemaValidationFunction getting bit a wordy.

what about FederatedElementFunction ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this could actually be a different function called ApplyViewAndSchemaToElementsFunction and be an alternative?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we landed on "MergeElementFunction"

Comment on lines 148 to 168
private static void updateEntitiesViewFilterWithSchemaValidation(final Schema schema, final View view, final View.Builder updatedView) {
final Map<String, SchemaEntityDefinition> elements = schema.getEntities();
for (final Map.Entry<String, ? extends SchemaElementDefinition> schemaElement : elements.entrySet()) {

final String elementKey = schemaElement.getKey();
final ViewElementDefinition updatedViewElementDef = getUpdatedViewElementDef(elementKey, schemaElement.getValue(), view);

updatedView.entity(elementKey, updatedViewElementDef);
}
}

private static void updateEdgesViewFilterWithSchemaValidation(final Schema schema, final View view, final View.Builder updatedView) {
final Map<String, SchemaEdgeDefinition> elements = schema.getEdges();
for (final Map.Entry<String, ? extends SchemaElementDefinition> schemaElement : elements.entrySet()) {

final String elementKey = schemaElement.getKey();
final ViewElementDefinition updatedViewElementDef = getUpdatedViewElementDef(elementKey, schemaElement.getValue(), view);

updatedView.edge(elementKey, updatedViewElementDef);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a thought this might be a good place to use inline lambdas instead you could replace both these methods with just:

schema.getEntities().entrySet().forEach(entity -> {
    if (entity.getValue().hasValidation()) {
        updatedView.entity(entity.getKey(), getUpdatedViewElementDef(entity.getValue(), view, entity.getKey()));
    }
});

schema.getEdges().entrySet().forEach(edge -> {
    if (edge.getValue().hasValidation()) {
        updatedView.edge(edge.getKey(), getUpdatedViewElementDef(edge.getValue(), view, edge.getKey()));
    }
});

@gchq gchq deleted a comment from GCHQDev404 Nov 10, 2023
@gchq gchq deleted a comment from GCHQDev404 Nov 10, 2023
this.context = Collections.unmodifiableMap(context);
} catch (final Exception e) {
throw new GafferCheckedException("Unable to create TemporaryResultsGraph", e);
}

}

private static void updateViewWithValidationFromSchema(final Map<String, Object> context) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this method to be static if it is a private method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is not used by other classes so it's private. and the method is not tied to the instance of this class it is a utility method for updating a context object so it can be static.

It only changes the values of a context object. After that object has been modified it is then assigned to a persistent field.

Do you have a reason for it to not be private static?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please examine #3165

@@ -152,4 +220,12 @@ public Iterable<Object> apply(final Object update, final Iterable<Object> state)
throw new GafferRuntimeException("Error getting all elements from temporary graph, due to:" + e.getMessage(), e);
}
}

private static Graph getGraph(final Map<String, Object> context) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need static on this method considering it is private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used by this class so it is private.
It is not tied to the instance of the class, it a utility method for fetching graphs out of context which has been configured by this class. so it can be static.

Is there a reason for this to not be private static?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please examine #3165

@@ -77,16 +91,37 @@ public ApplyViewToElementsFunction(final Map<String, Object> context) throws Gaf
}
// Validate the supplied context before using
validate(context);

updateViewWithValidationFromSchema(context);

this.context = Collections.unmodifiableMap(context);
} catch (final Exception e) {
throw new GafferCheckedException("Unable to create TemporaryResultsGraph", e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to throw an exception here? Can we not just log the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the result graph is not able to be created for merging, then the currently execution cannot continue.
Exception gets thrown and more info is added as it travel up the stack.
There are places higher in the Stack that will log this error, but with more information.

…store-applyviewtoelements-schema-validation

# Conflicts:
#	store-implementation/federated-store/src/test/java/uk/gov/gchq/gaffer/federatedstore/FederatedStoreSchemaTest.java
* Refactor creating MergeSchema with a given context

* Refactor creating MergeElementFunction with context

* Refactor MergeElementFunction removing complicated logic from constructor to createFunctionWithContext

* Refactor MergeElementFunction validate improved boolean logic

* Refactor MergeElementFunction moving the updating of context to inside validation

* Refactor MergeElementFunction extracting making temp graph in context.

* spotless

* Refactor fixing orElseThrow on Optional Graph.

* Refactor Making more use of Optional

* bug error not found.

* spotless

* View Builder test

* spotless

* extra tests
…/gaffer/federatedstore/MergeElementFunctionAggregationViewFilterTest.java
…store-applyviewtoelements-schema-validation

# Conflicts:
#	store-implementation/federated-store/src/test/java/uk/gov/gchq/gaffer/federatedstore/operation/handler/impl/FederatedOperationChainHandlerTest.java
@GCHQDeveloper314 GCHQDeveloper314 changed the title gh-3059 ApplyViewToElementsFunction improving Schema validation Gh-3059: ApplyViewToElementsFunction apply Schema validation Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ApplyViewToElementsFunction does not apply Schema validation
5 participants