-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Enable setting custom vertex ids in TP3 interface #147 #148
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,17 @@ | |
* Utility methods for handling JanusGraph ids and converting them between indexing and storage backend representations. | ||
* | ||
* @author Matthias Broecheler ([email protected]) | ||
* @deprecated This class does not produce valid JanusGraph vertex ids as it does not take into account partitioning | ||
* bits used in vertex id assignment. Use {@link org.janusgraph.graphdb.idmanagement.IDManager}, which can be obtained | ||
* through {@link org.janusgraph.graphdb.database.StandardJanusGraph#getIDManager()} and includes methods for converting | ||
* a user id to ({@link org.janusgraph.graphdb.idmanagement.IDManager#toVertexId(long)}) and from | ||
* ({@link org.janusgraph.graphdb.idmanagement.IDManager#fromVertexId(long)}) JanusGraph vertex id. | ||
* <p/> | ||
* <pre> | ||
* <code>IDManager idManager = ((StandardJanusGraph) graph).getIDManager();</code> | ||
* </pre> | ||
*/ | ||
@Deprecated | ||
public class JanusGraphId { | ||
|
||
/** | ||
|
@@ -31,6 +41,7 @@ public class JanusGraphId { | |
* | ||
* @param id long id | ||
* @return a corresponding JanusGraph vertex id | ||
* @deprecated Use {@link org.janusgraph.graphdb.idmanagement.IDManager#toVertexId(long)}. | ||
*/ | ||
public static final long toVertexId(long id) { | ||
Preconditions.checkArgument(id > 0, "Vertex id must be positive: %s", id); | ||
|
@@ -43,6 +54,7 @@ public static final long toVertexId(long id) { | |
* | ||
* @param id JanusGraph vertex id (must be positive) | ||
* @return original user provided id | ||
* @deprecated Use {@link org.janusgraph.graphdb.idmanagement.IDManager#fromVertexId(long)} | ||
*/ | ||
public static final long fromVertexId(long id) { | ||
Preconditions.checkArgument(id > 0, "Invalid vertex id provided: %s", id); | ||
|
@@ -54,6 +66,7 @@ public static final long fromVertexId(long id) { | |
* | ||
* @param v Vertex | ||
* @return original user provided id | ||
* @deprecated Use {@link org.janusgraph.graphdb.idmanagement.IDManager#fromVertexId(long)} | ||
*/ | ||
public static final long fromVertexID(JanusGraphVertex v) { | ||
Preconditions.checkArgument(v.hasId(), "Invalid vertex provided: %s", v); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -567,6 +567,33 @@ public long[] getPartitionedVertexRepresentatives(long partitionedVertexId) { | |
return ids; | ||
} | ||
|
||
/** | ||
* Converts a user provided long id into a JanusGraph vertex id. The id must be positive and less than {@link #getVertexCountBound()}. | ||
* This method is useful when providing ids during vertex creation via {@link org.apache.tinkerpop.gremlin.structure.Graph#addVertex(Object...)}. | ||
* | ||
* @param id long id | ||
* @return a corresponding JanusGraph vertex id | ||
* @see #fromVertexId(long) | ||
*/ | ||
public long toVertexId(long id) { | ||
Preconditions.checkArgument(id > 0, "Vertex id must be positive: %s", id); | ||
Preconditions.checkArgument(vertexCountBound > id, "Vertex id is too large: %s", id); | ||
return id<<(partitionBits+USERVERTEX_PADDING_BITWIDTH); | ||
} | ||
|
||
/** | ||
* Converts a JanusGraph vertex id to the user provided id as the inverse mapping of {@link #toVertexId(long)}. | ||
* | ||
* @param id JanusGraph vertex id (must be positive) | ||
* @return original user provided id | ||
* @see #toVertexId(long) | ||
*/ | ||
public long fromVertexId(long id) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you test this method? |
||
Preconditions.checkArgument(id >>> USERVERTEX_PADDING_BITWIDTH+partitionBits > 0 | ||
&& id <= (vertexCountBound-1)<<USERVERTEX_PADDING_BITWIDTH+partitionBits, "Invalid vertex id provided: %s", id); | ||
return id>>USERVERTEX_PADDING_BITWIDTH+partitionBits; | ||
} | ||
|
||
public boolean isPartitionedVertex(long id) { | ||
return isUserVertexId(id) && VertexIDType.PartitionedVertex.is(id); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can you test this 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.
@amcp There's a test added as part of the commit (see VertexIDAssignerTest#testCustomIdAssignment).