jessea
jessea
ATApache TinkerPop
Created by jessea on 3/21/2023 in #questions
Extracting the ProjectStep of a GraphTraversal instance during unit testing
For now, we're not going to handle cases where the final step is a TraversalParent with more than one child step, since I'm not sure we can easily cover all cases. All traversals are proxied through extractProjectKeysFromMapTraversal which will guarantee the traversal actually returns a Map, so hopefully this should reduce the chance of running into one of those cases.
16 replies
ATApache TinkerPop
Created by jessea on 3/21/2023 in #questions
Extracting the ProjectStep of a GraphTraversal instance during unit testing
This is indeed much simpler! Since we have access to plain GraphTraversal instances, we don't even need to mock the GraphTraversalSource. Thanks for the tips!
16 replies
ATApache TinkerPop
Created by jessea on 3/21/2023 in #questions
Extracting the ProjectStep of a GraphTraversal instance during unit testing
/**
* A wrapper around {@link #extractProjectKeys(Traversal)} that guarantees the passed-in traversal
* at least ends with a step that produces a {@code Map<String, Object>} when terminated.
*/
private List<String> extractProjectKeysFromMapTraversal(
GraphTraversal<?, Map<String, Object>> traversalEndingWithMap) {
return this.extractProjectKeys(traversalEndingWithMap);
}


/**
* Extracts the keys of the final {@link ProjectStep} in a given {@link Traversal}.
*
* <p>
* If the traversal ends with a {@link TraversalParent}, the last child of that step is then
* recursively processed again. This continues until either a {@link ProjectStep} is found, or an
* exception is raised as the traversal does not end on a {@link ProjectStep}.
*
* <p>
* NB: This method assumes the traversal given ends with a {@code Map<String, Object>}, so this
* should be validated prior to calling this method.
*
* @param traversal the {@link Traversal} from which to extract the keys of the final
* {@link ProjectStep}
* @return the keys of the final {@link ProjectStep} in the provided {@link Traversal}
* @throws IllegalStateException if the final step is not a {@link ProjectStep} or a
* {@link TraversalParent} which can be further processed (must have only one child)
*/
private List<String> extractProjectKeys(Traversal<?, ?> traversal) throws IllegalStateException {
Step<?, ?> end = traversal.asAdmin().clone().getEndStep();
Preconditions.checkArgument(
end instanceof ProjectStep || end instanceof TraversalParent,
"Traversal must end with project step or a parent step containing a project step.");

// If the last step is a ProjectStep, we're done.
if (end instanceof ProjectStep) {
return ((ProjectStep<?, ?>) end).getProjectKeys();
}

// Otherwise recursively find the project step if the final step is a parent step (e.g. local())
List<Traversal.Admin<Object, Object>> childSteps = ((TraversalParent) end).getLocalChildren();
// TODO: Should we validate all children of a parent step? If a parent takes multiple children
// it might be a condition, so we could validate that all branches end with project()
Preconditions.checkArgument(
childSteps.size() == 1,
"Encountered a final step which is a TraversalParent with more than one child. This is not yet supported.");
return extractProjectKeys(childSteps.get(0));
}
/**
* A wrapper around {@link #extractProjectKeys(Traversal)} that guarantees the passed-in traversal
* at least ends with a step that produces a {@code Map<String, Object>} when terminated.
*/
private List<String> extractProjectKeysFromMapTraversal(
GraphTraversal<?, Map<String, Object>> traversalEndingWithMap) {
return this.extractProjectKeys(traversalEndingWithMap);
}


/**
* Extracts the keys of the final {@link ProjectStep} in a given {@link Traversal}.
*
* <p>
* If the traversal ends with a {@link TraversalParent}, the last child of that step is then
* recursively processed again. This continues until either a {@link ProjectStep} is found, or an
* exception is raised as the traversal does not end on a {@link ProjectStep}.
*
* <p>
* NB: This method assumes the traversal given ends with a {@code Map<String, Object>}, so this
* should be validated prior to calling this method.
*
* @param traversal the {@link Traversal} from which to extract the keys of the final
* {@link ProjectStep}
* @return the keys of the final {@link ProjectStep} in the provided {@link Traversal}
* @throws IllegalStateException if the final step is not a {@link ProjectStep} or a
* {@link TraversalParent} which can be further processed (must have only one child)
*/
private List<String> extractProjectKeys(Traversal<?, ?> traversal) throws IllegalStateException {
Step<?, ?> end = traversal.asAdmin().clone().getEndStep();
Preconditions.checkArgument(
end instanceof ProjectStep || end instanceof TraversalParent,
"Traversal must end with project step or a parent step containing a project step.");

// If the last step is a ProjectStep, we're done.
if (end instanceof ProjectStep) {
return ((ProjectStep<?, ?>) end).getProjectKeys();
}

// Otherwise recursively find the project step if the final step is a parent step (e.g. local())
List<Traversal.Admin<Object, Object>> childSteps = ((TraversalParent) end).getLocalChildren();
// TODO: Should we validate all children of a parent step? If a parent takes multiple children
// it might be a condition, so we could validate that all branches end with project()
Preconditions.checkArgument(
childSteps.size() == 1,
"Encountered a final step which is a TraversalParent with more than one child. This is not yet supported.");
return extractProjectKeys(childSteps.get(0));
}
16 replies
ATApache TinkerPop
Created by jessea on 3/21/2023 in #questions
Extracting the ProjectStep of a GraphTraversal instance during unit testing
Gotcha, yeah this is more or less how we're doing it. Will try to simplify this and post an update when I get something concise working
16 replies
ATApache TinkerPop
Created by jessea on 3/21/2023 in #questions
Extracting the ProjectStep of a GraphTraversal instance during unit testing
https://gist.github.com/JeeZeh/1a3030ce71595c5ec6c0cac9190abb9c Here's what I have so far, but I think this could be greatly simplified with the snippet you provided with getEndStep
16 replies
ATApache TinkerPop
Created by jessea on 3/21/2023 in #questions
Extracting the ProjectStep of a GraphTraversal instance during unit testing
In your mocking example, you override a pre-defined termination step to do some tidy up (returning a mocked response in your case). I've been using this same block to return project keys gathered during the traversal
16 replies
ATApache TinkerPop
Created by jessea on 3/21/2023 in #questions
Extracting the ProjectStep of a GraphTraversal instance during unit testing
VerificationStrategy is probably a good fit for this otherwise (graph-permitting)
16 replies
ATApache TinkerPop
Created by jessea on 3/21/2023 in #questions
Extracting the ProjectStep of a GraphTraversal instance during unit testing
at execution time
Ideally even earlier, before we even have a graph to work against (since this requires developers to deploy the latest build to their developer accounts). Right now, I have this running as a unit test that pulls in all queries and their required keys, and analyses the GraphTraversal instances entirely offline.
16 replies
ATApache TinkerPop
Created by moosasaadat on 2/21/2023 in #questions
repeat with times(1) causing timeout
We're on engine version 1.1.1.0
9 replies
ATApache TinkerPop
Created by moosasaadat on 2/21/2023 in #questions
repeat with times(1) causing timeout
(adding to this - I work with @moosa - we're seeing this behaviour with Neptune)
9 replies
ATApache TinkerPop
Created by Tomcat on 2/11/2023 in #questions
Does anybody know
In the official javadocs, each method includes a since field that indicates when that feature was introduced: https://tinkerpop.apache.org/javadocs/current/core/org/apache/tinkerpop/gremlin/process/traversal/TextP.html#regex(java.lang.String) Unfortunately I can't see where the current version is mentioned in the Neptune documentation itself, but you can check the version by curling your cluster endpoint or from the Neptune Notebook: https://stackoverflow.com/a/59595714/5100832
22 replies
ATApache TinkerPop
Created by Tomcat on 2/11/2023 in #questions
Does anybody know
Neptune
Ah, Neptune does not yet support TinkerPop 3.6.0, which is crucially when TextP.regex was introduced: https://tinkerpop.apache.org/docs/current/reference/#a-note-on-predicates
22 replies
ATApache TinkerPop
Created by Tomcat on 2/11/2023 in #questions
Does anybody know
Interesting. This might be related to the C# library or the graph engine then. Which DB are you using? (e.g. Neptune, JanusGraph, etc.)
22 replies
ATApache TinkerPop
Created by Tomcat on 2/11/2023 in #questions
Does anybody know
How many nodes do you have in the graph? Depending on the DB engine you are using, some text predicates may not be able to use an index-based search, and instead require a full search across the graph. This can be very slow with large graphs. The query you've written I believe will also attempt to find all matches exhaustively before returning the results. If you supply .limit(n) after the .has(), it will stop once it has found n matches.
22 replies
ATApache TinkerPop
Created by jessea on 1/26/2023 in #questions
Limiting .path() results to a number of valid starting vertices
The .filter(select('e').unfold()) serves to remove paths that couldn't be constructed, i.e. invalid neighbourhoods?
34 replies