diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinarySerializer.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinarySerializer.java index 0a9ce85341..e195033f3f 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinarySerializer.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinarySerializer.java @@ -427,24 +427,24 @@ public BackendEntry writeVertex(HugeVertex vertex) { @Override public BackendEntry writeOlapVertex(HugeVertex vertex) { + // TODO: adapt to hstore (merge olap table) + BinaryBackendEntry entry = newBackendEntry(HugeType.OLAP, vertex.id()); BytesBuffer buffer = BytesBuffer.allocate(8 + 16); - HugeProperty hugeProperty = vertex.getProperties().iterator().next(); - PropertyKey propertyKey = hugeProperty.propertyKey(); + Collection> properties = vertex.getProperties(); + if (properties.size() != 1) { + E.checkArgument(false, + "Expect 1 property for olap vertex, but got %s", + properties.size()); + } + HugeProperty property = properties.iterator().next(); + PropertyKey propertyKey = property.propertyKey(); buffer.writeVInt(SchemaElement.schemaId(propertyKey.id())); - buffer.writeProperty(propertyKey, hugeProperty.value()); - - // olap表合并, key为 {property_key_id}{vertex_id} - BytesBuffer bufferName = - BytesBuffer.allocate(1 + propertyKey.id().length() + 1 + vertex.id().length()); - bufferName.writeId(propertyKey.id()); - byte[] idBytes = bufferName.writeId(vertex.id()).bytes(); + buffer.writeProperty(propertyKey, property.value()); // Fill column - BinaryBackendEntry entry = new BinaryBackendEntry(HugeType.OLAP, - new BinaryId(idBytes, vertex.id())); - - byte[] name = entry.id().asBytes(); + byte[] name = this.keyWithIdPrefix ? + entry.id().asBytes() : BytesBuffer.BYTES_EMPTY; entry.column(name, buffer.bytes()); entry.subId(propertyKey.id()); entry.olap(true); diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/VertexCoreTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/VertexCoreTest.java index 015f3e2772..f6ed6b3d07 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/VertexCoreTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/VertexCoreTest.java @@ -76,6 +76,7 @@ import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator; import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; +import org.junit.After; import org.junit.Assume; import org.junit.Before; import org.junit.Test; @@ -156,6 +157,12 @@ public void initSchema() { .create(); } + @After + public void resetGraphMode() { + // In OLAP-related tests, if an error occurs midway, the graph mode will not be reset. + graph().readMode(GraphReadMode.OLTP_ONLY); + } + protected void initPersonIndex(boolean indexCity) { SchemaManager schema = graph().schema();