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

ApplyViewToElementsFunction corrupts matchedVertex #3052

Open
t92549 opened this issue Nov 1, 2023 · 2 comments · May be fixed by #3057
Open

ApplyViewToElementsFunction corrupts matchedVertex #3052

t92549 opened this issue Nov 1, 2023 · 2 comments · May be fixed by #3057
Labels
bug Confirmed or suspected bug

Comments

@t92549
Copy link
Contributor

t92549 commented Nov 1, 2023

Describe the bug
The ApplyViewToElementsFunction merge function, which is the default merge function for federated stores, will corrupt the results' matchedVertex fields.

To Reproduce
Steps to reproduce the behaviour:

  1. Create FederatedStore -> AccumuloStore
  2. AddElements: A --> B
  3. GetElements(input=B)
  4. Result: A --> B: incorrectly shows matchedVertex = SOURCE

Expected behaviour
The resulting Edge should have matchedVertex = DESTINATION.

Additional context
ApplyViewToElementsFunction creates an internal MapStore to apply the view to all the results. Clearly, this is not applying the matchedVertex field properly from the actual results.
The same query works fine with the ConcatenateMergeFunction.
This bug also breaks GetWalks, because it relies on the matchedVertex field.

Platform

  • Gaffer Version: [e.g. 2.0.0]
@t92549 t92549 added the bug Confirmed or suspected bug label Nov 1, 2023
@GCHQDev404
Copy link
Contributor

GCHQDev404 commented Nov 2, 2023

examine https://github.com/gchq/Gaffer/tree/gh-3052-FederatedStore-Function-corrupts-matched-vertex for the test required to pass to prove/fix this.

void shouldPreserveMatchedVertex() throws Exception {
//given
final AccumuloStore accumuloStore = getTestStore("shouldPreserveMatchedVertex");
accumuloStore.execute(new AddElements.Builder()
.input(new Edge.Builder()
.source(SOURCE_BASIC)
.dest(DEST_BASIC)
.directed(true)
.group(GROUP_BASIC_EDGE)
.property(PROPERTY_1, FederatedStoreTestUtil.VALUE_PROPERTY1)
.build()).build(), contextBlankUser());
final View view = new View.Builder().edge(GROUP_BASIC_EDGE).build();
AccumuloElementsRetriever[] retrievers = getRetrievers(accumuloStore, new GetElements.Builder().input(DEST_BASIC).inOutType(INCOMING).view(view).build());
final ApplyViewToElementsFunction function = new ApplyViewToElementsFunction().createFunctionWithContext(
makeContext(view, SCHEMA.clone()));
//when
Iterable<Object> iterable = null;
for (AccumuloElementsRetriever elements : retrievers) {
iterable = function.apply(elements, iterable);
}
//then
final Edge edge5 = new Edge.Builder()
.source(SOURCE_BASIC)
.dest(DEST_BASIC)
.group(GROUP_BASIC_EDGE)
.directed(true)
//With aggregated property value of 5
.property(PROPERTY_1, 5)
.build();
assertThat(iterable)
.asInstanceOf(InstanceOfAssertFactories.iterable(Element.class))
.containsExactly(edge5);
//then because edge.equals ignores VertexMatched
assertThat(iterable.iterator().next())
.asInstanceOf(InstanceOfAssertFactories.type(Edge.class))
.extracting(Edge::getMatchedVertex)
.isEqualTo(EdgeId.MatchedVertex.DESTINATION);
}

@github-actions github-actions bot linked a pull request Nov 2, 2023 that will close this issue
GCHQDev404 added a commit that referenced this issue Nov 2, 2023
GCHQDev404 added a commit that referenced this issue Nov 2, 2023
@GCHQDev404
Copy link
Contributor

#3057

Test to be fixed to resolve this ticket.

@GCHQDeveloper314 GCHQDeveloper314 added this to the Medium Term Backlog milestone Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed or suspected bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants