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-3220: Standardise GafferPop Tests #3243

Merged
merged 13 commits into from
Jul 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@

private static final Logger LOGGER = LoggerFactory.getLogger(GafferPopGraph.class);
private static final String GET_ALL_DEBUG_MSG = "Requested a GetAllElements, results will be truncated to: {}.";
private static final Pattern EDGE_ID_REGEX = Pattern.compile("^\\[\\s*(?<src>[a-zA-Z0-9|-]*)\\s*(,\\s*(?<label>[a-zA-Z0-9|-]*))?\\s*,\\s*(?<dest>[a-zA-Z0-9|-]*)\\s*\\]$");
private static final Pattern EDGE_ID_REGEX = Pattern.compile("^\\s*\\[\\s*(?<src>[a-zA-Z0-9|-]*)\\s*(,\\s*(?<label>[a-zA-Z0-9|-]*))?\\s*,\\s*(?<dest>[a-zA-Z0-9|-]*)\\s*\\]\\s*$");

public GafferPopGraph(final Configuration configuration) {
this(configuration, createGraph(configuration));
Expand Down Expand Up @@ -405,19 +405,15 @@
LOGGER.debug(GET_ALL_DEBUG_MSG, variables.getAllElementsLimit());
getOperation = new Builder()
.first(new GetAllElements.Builder()
.view(new View.Builder()
.entities(graph.getSchema().getEntityGroups())
.build())
.view(createAllEntitiesView())
.build())
.then(new Limit<Element>(variables.getAllElementsLimit(), true))
.build();
} else {
getOperation = new Builder()
.first(new GetElements.Builder()
.input(getElementSeeds(Arrays.asList(vertexIds)))
.view(new View.Builder()
.entities(graph.getSchema().getEntityGroups())
.build())
.view(createAllEntitiesView())
.build())
.build();
}
Expand Down Expand Up @@ -558,19 +554,26 @@
LOGGER.debug(GET_ALL_DEBUG_MSG, variables.getAllElementsLimit());
getOperation = new Builder()
.first(new GetAllElements.Builder()
.view(new View.Builder()
.edges(graph.getSchema().getEdgeGroups())
.build())
.view(createAllEdgesView())
.build())
.then(new Limit<>(variables.getAllElementsLimit(), true))
.build();
} else {

View.Builder builder = new View.Builder();
Set<String> edgeLabels = getEdgeLabelsFromIds(Arrays.asList(elementIds));
if (edgeLabels.isEmpty()) {
// Default to all edges
builder.allEdges(true);
} else {
// Get requested edges
builder.edges(edgeLabels);
}

getOperation = new Builder()
.first(new GetElements.Builder()
.input(getElementSeeds(Arrays.asList(elementIds)))
.view(new View.Builder()
.edges(getEdgeViewGroup(Arrays.asList(elementIds)))
.build())
.view(builder.build())
.build())
.build();
}
Expand Down Expand Up @@ -725,9 +728,7 @@

View entitiesView = view;
if (null == entitiesView) {
entitiesView = new View.Builder()
.entities(graph.getSchema().getEntityGroups())
.build();
entitiesView = createAllEntitiesView();
} else if (entitiesView.hasEdges()) {
entitiesView = new View.Builder()
.merge(entitiesView)
Expand Down Expand Up @@ -781,15 +782,16 @@
throw new UnsupportedOperationException("There could be a lot of vertices, so please add some seeds");
}

View processedView = view == null ? createAllEntitiesView() : view;
final Iterable<? extends Element> result = execute(new OperationChain.Builder()
.first(new GetAdjacentIds.Builder()
.input(seeds)
.view(processedView)
.view(view)
.inOutType(getInOutType(direction))
.build())
// GetAdjacentIds provides list of entity seeds so run a GetElements to get the actual Entities
.then(new GetElements())
.then(new GetElements.Builder()
.view(createAllEntitiesView())
.build())
.build());

// Translate results to Gafferpop elements
Expand All @@ -808,9 +810,7 @@

View edgesView = view;
if (null == edgesView) {
edgesView = new View.Builder()
.edges(graph.getSchema().getEdgeGroups())
.build();
edgesView = createAllEdgesView();
} else if (edgesView.hasEntities()) {
edgesView = new View.Builder()
.merge(edgesView)
Expand Down Expand Up @@ -888,11 +888,11 @@
}

private View createAllEntitiesView() {
final View.Builder viewBuilder = new View.Builder();
for (final String group : graph.getSchema().getEntityGroups()) {
viewBuilder.entity(group);
}
return viewBuilder.build();
return new View.Builder().allEntities(true).build();
}

private View createAllEdgesView() {
return new View.Builder().allEdges(true).build();
}

/**
Expand Down Expand Up @@ -941,17 +941,17 @@
}

/**
* Determines the edge group used in the view based on supplied IDs.
* If ID contains a label, this is extracted and used in the view.
* If not, all edge groups are used.
* Extracts edge labels from edge IDs if found.
* All ids must be of the [src, label, dest] format.
* Otherwise, returns an empty set.
*
* @param ids The iterable of IDs
* @return Set of edge labels for the view
*/
private Set<String> getEdgeViewGroup(final Iterable<Object> ids) {
private Set<String> getEdgeLabelsFromIds(final Iterable<Object> ids) {
Set<String> labels = new HashSet<>();

ids.forEach(id -> {
for (final Object id: ids) {
if ((id instanceof String) && (EDGE_ID_REGEX.matcher((String) id).matches())) {
Matcher edgeIdWithLabelMatcher = EDGE_ID_REGEX.matcher((String) id);

Expand All @@ -960,10 +960,11 @@
labels.add(edgeIdWithLabelMatcher.group("label"));
}
} else {
// Fallback is to use all schema edge groups
labels.addAll(graph.getSchema().getEdgeGroups());
// If a single ID isn't of the format [src, label, dest]
// Then all edge labels must be used
return Collections.emptySet();

Check warning on line 965 in library/tinkerpop/src/main/java/uk/gov/gchq/gaffer/tinkerpop/GafferPopGraph.java

View check run for this annotation

Codecov / codecov/patch

library/tinkerpop/src/main/java/uk/gov/gchq/gaffer/tinkerpop/GafferPopGraph.java#L965

Added line #L965 was not covered by tests
}
});
}

return labels;
}
Expand Down
Loading