-
Notifications
You must be signed in to change notification settings - Fork 353
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
Gh-3059: ApplyViewToElementsFunction apply Schema validation #3060
Conversation
…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
Codecov ReportAttention: Patch coverage is
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. |
...store/src/test/java/uk/gov/gchq/gaffer/federatedstore/FederatedStoreViewAggregationTest.java
Outdated
Show resolved
Hide resolved
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"
...-store/src/main/java/uk/gov/gchq/gaffer/federatedstore/util/ApplyViewToElementsFunction.java
Outdated
Show resolved
Hide resolved
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); | ||
} | ||
} |
There was a problem hiding this comment.
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()));
}
});
…ts-schema-validation
...derated-store/src/main/java/uk/gov/gchq/gaffer/federatedstore/util/MergeElementFunction.java
Show resolved
Hide resolved
…ts-schema-validation
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please examine #3165
...derated-store/src/main/java/uk/gov/gchq/gaffer/federatedstore/util/MergeElementFunction.java
Outdated
Show resolved
Hide resolved
...derated-store/src/main/java/uk/gov/gchq/gaffer/federatedstore/util/MergeElementFunction.java
Outdated
Show resolved
Hide resolved
@@ -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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
...st/java/uk/gov/gchq/gaffer/federatedstore/MergeElementFunctionAggregationViewFilterTest.java
Outdated
Show resolved
Hide resolved
...st/java/uk/gov/gchq/gaffer/federatedstore/MergeElementFunctionAggregationViewFilterTest.java
Outdated
Show resolved
Hide resolved
…/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
…ts-schema-validation
This is a breaking change and is not a current priority. It can be revisited later. |
Related issue