-
Notifications
You must be signed in to change notification settings - Fork 825
getScopingInfo utility added #3118
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
base: master
Are you sure you want to change the base?
Conversation
Hi @vaibhavm99, thanks for opening a PR! I should have time to give it a full review by Monday at the latest. Could I ask a bit about the motivation for the new |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3118 +/- ##
============================================
+ Coverage 77.87% 78.17% +0.30%
- Complexity 13578 13799 +221
============================================
Files 1015 1025 +10
Lines 59308 60157 +849
Branches 6835 7016 +181
============================================
+ Hits 46184 47030 +846
+ Misses 10817 10779 -38
- Partials 2307 2348 +41 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Hi @vaibhavm99, will this change allow to save not the whole Path, but only the parts that are actually used? |
|
Hi @vkagamlyk , I'm sorry I don't understand what you mean by "the whole Path." This change should not have any breaking problems with older code, as it is just adding a new API. This would take in a traversal and provide us with the |
Hi @vaibhavm99! |
Hi @vaibhavm99 I'm happy with extending convenience interfaces for providers. I am curious since the |
...n-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/FormatStep.java
Outdated
Show resolved
Hide resolved
I see this PR is currently targeting the master branch, this branch is currently accumulating changes for TinkerPop 4.0.0-beta.2, and ultimately TinkerPop 4. I would recommend targeting this change to |
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/Scoping.java
Outdated
Show resolved
Hide resolved
* | ||
* @return A Set of {@link ScopingInfo} values which contain the label and Pop value | ||
*/ | ||
public default Set<ScopingInfo> getScopingInfo() {return null; } |
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 there be a default implementation here? If something implements Scoping
shouldn't it have a proper implementation? or are there cases where you would return getScopeKeys
but not getScopingInfo
? and if so, would return null
be the right default?
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.
Yes, there are a few classes that do not implement Pop
at all, so for them we do not need getScopingInfo()
but they do have getScopeKeys()
. For example, AddEdgeStep
and AddPropertyStep
. For those I added a default. Would changing it to return an empty Set be better?
This API would not cause any breaking change in |
Yes, |
Thank you for the detailed review. You got it right, that we're working on optimizing label identification in prefix traversals, with the goal of only injecting necessary labels rather than the entire path. This approach could indeed be valuable for Traverser injection in TinkerPop. You've made a good point about the current limitations of the Scoping interface, particularly regarding complete label information requirements. Let me explain why the current POJO structure might be more suitable than the proposed alternative: Consider this example:
In this case, the outermost where step requires [['a',Pop.first], ['b',Pop.last]], which wouldn't fit well with the proposed structure:
@spmallette : I hope above example explains why an simple getPop API wont be enough. Let me know if you have better suggestions. Regarding the implementation strategy, our idea was to merge to master first and then cherry-pick to 3.7 and 3.8. Would you like to suggest any specific concerns about this approach? Looking forward to your thoughts on this. |
Hi @upadhyay-prashant, I'm not sure I understand the limitation arising from the above example with a simple In the case of
There is never more than 1 Pop in a single step instance, I don't see why the same data as |
The typical approach for this in TinkerPop would be to target the initial PR to 3.7-dev. Whichever committer ends up merging the PR will then manually merge the changes up to 3.8-dev and master on your behalf. Typically the only time we ask contributors to open separate PRs for each branch is if each branch requires substantially different solutions for some reason. |
and TraversalParent.java, and classes that use these interfaces.
277612e
to
d2ec3a4
Compare
LGTM, thanks for the change! VOTE +1 |
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.
Overall it looks good to me. Left a couple of comments for small tweaks. There are a couple of steps which give their own implementation for getPopInstructions()
which do not have tests in this PR, which would be nice to have (TraversalSelectStep, AddVertexStep, AddVertexStartStep, AddEdgeStep, AddEdgeStartStep). It would also be nice to have some testing for steps which directly use the default implementations in Scpoing or TraversalParent.
For all of the steps which are TraversalParents, it would be nice if the tests also validated that getPopInstructions()
is successfully producing the PopInstruction's from child traversals, as well as from the step itself.
* - label: String | ||
* - pop: Pop value | ||
*/ | ||
class PopInstruction { |
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.
Nit: this child class is indented 4 spaces too deep
* @author Vaibhav Malhotra | ||
*/ | ||
public interface PopContaining { | ||
public default HashSet<PopInstruction> getPopInstructions() { |
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'm not sure if we want a default implementation which returns an empty set. Are there any steps which will utilize this default behaviour?
If everyone is expected to override this method to return useful/accurate results, I would prefer not to have any default implementation.
for (Object[] pair : pairs) { | ||
if (pair.length == 2 && pair[0] instanceof String && pair[1] instanceof Pop) { | ||
popInstructions.add(new PopContaining.PopInstruction((String)pair[0], (Pop)pair[1])); | ||
} |
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.
Nit: Would be good to add an else
which throws an IllegalArgumentException
to identify misuse of this helper.
final PopContaining.PopInstruction popInstruction1 = new PopContaining.PopInstruction(); | ||
popInstruction1.label = "Hello"; | ||
popInstruction1.pop = Pop.last; | ||
|
||
final PopContaining.PopInstruction popInstruction2 = new PopContaining.PopInstruction(); | ||
popInstruction2.label = "world"; | ||
popInstruction2.pop = Pop.last; | ||
|
||
final HashSet<PopContaining.PopInstruction> popInstructionSet = new HashSet<>(); | ||
popInstructionSet.add(popInstruction1); | ||
popInstructionSet.add(popInstruction2); | ||
|
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.
Nit: Could use TestDataBuilder.createPopInstructionSet()
@@ -63,4 +67,50 @@ public void shouldRequirePathsAccordingly() { | |||
assertEquals(traversalPath[0], ((Traversal.Admin<?, ?>) traversalPath[1]).getTraverserRequirements().contains(TraverserRequirement.LABELED_PATH)); | |||
} | |||
} | |||
|
|||
@Test | |||
public void testPopInstruction() { |
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.
Would be nice to also add equivalent tests to these for TraversalSelectStep
Added a utility function
getScopingInfo()
in all classes implementingScoping
and a methodgetScopingInfoForTraversal
to get the labels needed by a traversal, which returns a Set ofScopingInfo
class which contains the label and Pop info.