-
Notifications
You must be signed in to change notification settings - Fork 590
feat(hbase): support hash rowkey struct & pre-init tables #1696
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -19,11 +19,9 @@ | |
|
|
||
| package com.baidu.hugegraph.backend.serializer; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.*; | ||
|
|
||
| import com.baidu.hugegraph.config.HugeConfig; | ||
| import org.apache.commons.lang.NotImplementedException; | ||
|
|
||
| import com.baidu.hugegraph.HugeGraph; | ||
|
|
@@ -81,29 +79,54 @@ public class BinarySerializer extends AbstractSerializer { | |
| */ | ||
| private final boolean keyWithIdPrefix; | ||
| private final boolean indexWithIdPrefix; | ||
| private final boolean enablePartition; | ||
|
|
||
| public BinarySerializer() { | ||
| this(true, true); | ||
| this(true, true, false); | ||
| } | ||
|
|
||
| public BinarySerializer(HugeConfig config) { | ||
| this(true, true, false); | ||
| } | ||
|
|
||
| public BinarySerializer(boolean keyWithIdPrefix, | ||
| boolean indexWithIdPrefix) { | ||
| boolean indexWithIdPrefix, | ||
| boolean enablePartition) { | ||
| this.keyWithIdPrefix = keyWithIdPrefix; | ||
| this.indexWithIdPrefix = indexWithIdPrefix; | ||
| this.enablePartition = enablePartition; | ||
| } | ||
|
|
||
| @Override | ||
| protected BinaryBackendEntry newBackendEntry(HugeType type, Id id) { | ||
| if (type.isVertex()) { | ||
| BytesBuffer buffer = BytesBuffer.allocate(2 + 1 + id.length()); | ||
| writePartitionedId(HugeType.VERTEX, id, buffer); | ||
| return new BinaryBackendEntry(type, new BinaryId(buffer.bytes(), id)); | ||
| } | ||
|
|
||
| if (type.isEdge()) { | ||
| E.checkState(id instanceof BinaryId, | ||
| "Expect a BinaryId for BackendEntry with edge id"); | ||
| return new BinaryBackendEntry(type, (BinaryId) id); | ||
| } | ||
|
|
||
| if (type.isIndex()) { | ||
| if (this.enablePartition) { | ||
| if (type.isStringIndex()) { | ||
| // TODO: add string index partition | ||
| } | ||
| if (type.isNumericIndex()) { | ||
| // TODO: add numeric index partition | ||
| } | ||
| } | ||
| BytesBuffer buffer = BytesBuffer.allocate(1 + id.length()); | ||
| byte[] idBytes = buffer.writeIndexId(id, type).bytes(); | ||
| return new BinaryBackendEntry(type, new BinaryId(idBytes, id)); | ||
| } | ||
|
|
||
| BytesBuffer buffer = BytesBuffer.allocate(1 + id.length()); | ||
| byte[] idBytes = type.isIndex() ? | ||
| buffer.writeIndexId(id, type).bytes() : | ||
| buffer.writeId(id).bytes(); | ||
| byte[] idBytes = buffer.writeId(id).bytes(); | ||
| return new BinaryBackendEntry(type, new BinaryId(idBytes, id)); | ||
| } | ||
|
|
||
|
|
@@ -112,8 +135,7 @@ protected final BinaryBackendEntry newBackendEntry(HugeVertex vertex) { | |
| } | ||
|
|
||
| protected final BinaryBackendEntry newBackendEntry(HugeEdge edge) { | ||
| BinaryId id = new BinaryId(formatEdgeName(edge), | ||
| edge.idWithDirection()); | ||
| BinaryId id = writeEdgeId(edge.idWithDirection()); | ||
| return newBackendEntry(edge.type(), id); | ||
| } | ||
|
|
||
|
|
@@ -224,12 +246,6 @@ protected void parseExpiredTime(BytesBuffer buffer, HugeElement element) { | |
| element.expiredTime(buffer.readVLong()); | ||
| } | ||
|
|
||
| protected byte[] formatEdgeName(HugeEdge edge) { | ||
| // owner-vertex + dir + edge-label + sort-values + other-vertex | ||
| return BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID) | ||
| .writeEdgeId(edge.id()).bytes(); | ||
| } | ||
|
|
||
| protected byte[] formatEdgeValue(HugeEdge edge) { | ||
| int propsCount = edge.sizeOfProperties(); | ||
| BytesBuffer buffer = BytesBuffer.allocate(4 + 16 * propsCount); | ||
|
|
@@ -477,7 +493,8 @@ protected void parseVertexOlap(byte[] value, HugeVertex vertex) { | |
| public BackendEntry writeEdge(HugeEdge edge) { | ||
| BinaryBackendEntry entry = newBackendEntry(edge); | ||
| byte[] name = this.keyWithIdPrefix ? | ||
| this.formatEdgeName(edge) : EMPTY_BYTES; | ||
| entry.id().asBytes() : EMPTY_BYTES; | ||
|
|
||
| byte[] value = this.formatEdgeValue(edge); | ||
| entry.column(name, value); | ||
|
|
||
|
|
@@ -571,6 +588,10 @@ public BackendEntry writeId(HugeType type, Id id) { | |
| protected Id writeQueryId(HugeType type, Id id) { | ||
| if (type.isEdge()) { | ||
| id = writeEdgeId(id); | ||
| } else if (type.isVertex()) { | ||
| BytesBuffer buffer = BytesBuffer.allocate(2 + 1 + id.length()); | ||
| writePartitionedId(HugeType.VERTEX, id, buffer); | ||
| id = new BinaryId(buffer.bytes(), id); | ||
| } else { | ||
| BytesBuffer buffer = BytesBuffer.allocate(1 + id.length()); | ||
| id = new BinaryId(buffer.writeId(id).bytes(), id); | ||
|
|
@@ -600,13 +621,12 @@ private Query writeQueryEdgeRangeCondition(ConditionQuery cq) { | |
| } | ||
| Id label = cq.condition(HugeKeys.LABEL); | ||
|
|
||
| int size = 1 + vertex.length() + 1 + label.length() + 16; | ||
| BytesBuffer start = BytesBuffer.allocate(size); | ||
| start.writeId(vertex); | ||
| BytesBuffer start = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID); | ||
| writePartitionedId(HugeType.EDGE, vertex, start); | ||
| start.write(direction.type().code()); | ||
| start.writeId(label); | ||
|
|
||
| BytesBuffer end = BytesBuffer.allocate(size); | ||
| BytesBuffer end = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID); | ||
| end.copyFrom(start); | ||
|
|
||
| RangeConditions range = new RangeConditions(sortValues); | ||
|
|
@@ -655,7 +675,7 @@ private Query writeQueryEdgePrefixCondition(ConditionQuery cq) { | |
|
|
||
| if (key == HugeKeys.OWNER_VERTEX || | ||
| key == HugeKeys.OTHER_VERTEX) { | ||
| buffer.writeId((Id) value); | ||
| writePartitionedId(HugeType.EDGE, (Id) value, buffer); | ||
| } else if (key == HugeKeys.DIRECTION) { | ||
| byte t = ((Directions) value).type().code(); | ||
| buffer.write(t); | ||
|
|
@@ -800,18 +820,58 @@ private BinaryBackendEntry formatILDeletion(HugeIndex index) { | |
| return entry; | ||
| } | ||
|
|
||
| private static BinaryId writeEdgeId(Id id) { | ||
| private BinaryId writeEdgeId(Id id) { | ||
JackyYangPassion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| EdgeId edgeId; | ||
| if (id instanceof EdgeId) { | ||
| edgeId = (EdgeId) id; | ||
| } else { | ||
| edgeId = EdgeId.parse(id.asString()); | ||
| } | ||
| BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID) | ||
| .writeEdgeId(edgeId); | ||
| BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID); | ||
| if (this.enablePartition) { | ||
| buffer.writeShort(getPartition(HugeType.EDGE, edgeId.ownerVertexId())); | ||
| buffer.writeEdgeId(edgeId); | ||
| } else { | ||
| buffer.writeEdgeId(edgeId); | ||
| } | ||
JackyYangPassion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return new BinaryId(buffer.bytes(), id); | ||
| } | ||
|
|
||
| private void writePartitionedId(HugeType type, Id id, BytesBuffer buffer) { | ||
| if (this.enablePartition) { | ||
| buffer.writeShort(getPartition(type, id)); | ||
| buffer.writeId(id); | ||
| } else { | ||
| buffer.writeId(id); | ||
| } | ||
| } | ||
|
|
||
| protected short getPartition(HugeType type, Id id) { | ||
| return 0; | ||
| } | ||
|
|
||
| public BackendEntry parse(BackendEntry originEntry) { | ||
|
Contributor
Author
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. for serializer.BinarySerializerTest.testEdgeForPartition test error |
||
| byte[] bytes = originEntry.id().asBytes(); | ||
| BinaryBackendEntry parsedEntry = new BinaryBackendEntry(originEntry.type(), | ||
| bytes, | ||
| this.enablePartition); | ||
| if (this.enablePartition) { | ||
| bytes = Arrays.copyOfRange(bytes, parsedEntry.id().length() + 2, bytes.length); | ||
| } else { | ||
| bytes = Arrays.copyOfRange(bytes, parsedEntry.id().length(), bytes.length); | ||
| } | ||
| BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID); | ||
| buffer.write(parsedEntry.id().asBytes()); | ||
| buffer.write(bytes); | ||
| parsedEntry = new BinaryBackendEntry(originEntry.type(), | ||
| new BinaryId(buffer.bytes(), | ||
| BytesBuffer.wrap(buffer.bytes()).readEdgeId())); | ||
| for (BackendEntry.BackendColumn col : originEntry.columns()) { | ||
| parsedEntry.column(buffer.bytes(), col.value); | ||
| } | ||
| return parsedEntry; | ||
| } | ||
|
|
||
| private static Query prefixQuery(ConditionQuery query, Id prefix) { | ||
| Query newQuery; | ||
| if (query.paging() && !query.page().isEmpty()) { | ||
|
|
||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
for com.baidu.hugegraph.core.EdgeCoreTest test error
writeQueryEdgeRangeCondition() add writePartitionedId()