diff --git a/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraFeatures.java b/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraFeatures.java index 3ca43050d3..0993fde1be 100644 --- a/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraFeatures.java +++ b/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraFeatures.java @@ -21,6 +21,11 @@ public class CassandraFeatures implements BackendFeatures { + @Override + public boolean supportsFatherAndSubEdgeLabel() { + return false; + } + @Override public boolean supportsScanToken() { return true; diff --git a/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraTables.java b/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraTables.java index 40b7e5a19d..ece8f2ae8e 100644 --- a/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraTables.java +++ b/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraTables.java @@ -21,6 +21,8 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; import org.apache.hugegraph.backend.BackendException; import org.apache.hugegraph.backend.id.EdgeId; @@ -51,6 +53,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import org.apache.hugegraph.util.HashUtil; + public class CassandraTables { public static final String LABEL_INDEX = "label_index"; @@ -400,7 +404,9 @@ protected List pkColumnName() { @Override protected List idColumnName() { - return Arrays.asList(EdgeId.KEYS); + return Arrays.stream(EdgeId.KEYS) + .filter(key -> !Objects.equals(key, HugeKeys.SUB_LABEL)) + .collect(Collectors.toList()); } @Override diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/TableSerializer.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/TableSerializer.java index 0df8a622b7..30fa2dc124 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/TableSerializer.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/TableSerializer.java @@ -61,6 +61,9 @@ import org.apache.hugegraph.util.E; import org.apache.hugegraph.util.JsonUtil; +/** + * without father and sub label + */ public abstract class TableSerializer extends AbstractSerializer { public TableSerializer(HugeConfig config) { @@ -144,11 +147,10 @@ protected TableBackendEntry.Row formatEdge(HugeEdge edge) { row.ttl(edge.ttl()); row.column(HugeKeys.EXPIRED_TIME, edge.expiredTime()); } - // Id: ownerVertex + direction + edge-label + sub-edge-label + sortValues + otherVertex + // Id: ownerVertex + direction + edge-label + sortValues + otherVertex row.column(HugeKeys.OWNER_VERTEX, this.writeId(id.ownerVertexId())); row.column(HugeKeys.DIRECTION, id.directionCode()); row.column(HugeKeys.LABEL, id.edgeLabelId().asLong()); - row.column(HugeKeys.SUB_LABEL, id.subLabelId().asLong()); row.column(HugeKeys.SORT_VALUES, id.sortValues()); row.column(HugeKeys.OTHER_VERTEX, this.writeId(id.otherVertexId())); @@ -170,7 +172,6 @@ protected HugeEdge parseEdge(TableBackendEntry.Row row, Number dir = row.column(HugeKeys.DIRECTION); boolean direction = EdgeId.isOutDirectionFromCode(dir.byteValue()); Number label = row.column(HugeKeys.LABEL); - Number subLabel = row.column(HugeKeys.SUB_LABEL); String sortValues = row.column(HugeKeys.SORT_VALUES); Object otherVertexId = row.column(HugeKeys.OTHER_VERTEX); Number expiredTime = row.column(HugeKeys.EXPIRED_TIME); @@ -181,11 +182,10 @@ protected HugeEdge parseEdge(TableBackendEntry.Row row, } EdgeLabel edgeLabel = graph.edgeLabelOrNone(this.toId(label)); - EdgeLabel subEdgeLabel = graph.edgeLabelOrNone(this.toId(subLabel)); Id otherId = this.readId(otherVertexId); // Construct edge - HugeEdge edge = HugeEdge.constructEdge(vertex, direction, subEdgeLabel, + HugeEdge edge = HugeEdge.constructEdge(vertex, direction, edgeLabel, sortValues, otherId); // Parse edge properties @@ -278,11 +278,10 @@ public BackendEntry writeEdgeProperty(HugeEdgeProperty prop) { row.ttl(edge.ttl()); row.column(HugeKeys.EXPIRED_TIME, edge.expiredTime()); } - // Id: ownerVertex + direction + edge-label + sub-edge-label + sortValues + otherVertex + // Id: ownerVertex + direction + edge-label + sortValues + otherVertex row.column(HugeKeys.OWNER_VERTEX, this.writeId(id.ownerVertexId())); row.column(HugeKeys.DIRECTION, id.directionCode()); row.column(HugeKeys.LABEL, id.edgeLabelId().asLong()); - row.column(HugeKeys.SUB_LABEL, id.subLabelId().asLong()); row.column(HugeKeys.SORT_VALUES, id.sortValues()); row.column(HugeKeys.OTHER_VERTEX, this.writeId(id.otherVertexId())); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendFeatures.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendFeatures.java index 90001cc1e7..c6060944f0 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendFeatures.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendFeatures.java @@ -31,7 +31,13 @@ default boolean supportsSnapshot() { return false; } - default boolean supportsTaskAndServerVertex() { return false; } + default boolean supportsTaskAndServerVertex() { + return false; + } + + default boolean supportsFatherAndSubEdgeLabel() { + return true; + } boolean supportsScanToken(); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java index bb11408eb1..4d4c7ef6dc 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java @@ -1058,7 +1058,8 @@ protected Iterator queryEdgesFromBackend(Query query) { Stream> edgeIterators = flattenedQueries.map(cq -> { Id label = cq.condition(HugeKeys.LABEL); - if (label != null && + if (this.storeFeatures().supportsFatherAndSubEdgeLabel() && + label != null && graph().edgeLabel(label).isFather() && cq.condition(HugeKeys.SUB_LABEL) == null && cq.condition(HugeKeys.OWNER_VERTEX) != null && @@ -1626,7 +1627,7 @@ private Query optimizeQuery(ConditionQuery query) { */ boolean byLabel = (label != null && query.conditionsSize() == 1); if (!byLabel || this.store().features().supportsQueryByLabel()) { - if (byLabel && query.resultType().isEdge()) { + if (this.storeFeatures().supportsFatherAndSubEdgeLabel() && byLabel && query.resultType().isEdge()) { // for memory backend EdgeLabel edgeLabel = graph().edgeLabel(label); if (edgeLabel.hasFather()) { diff --git a/hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/MysqlSerializer.java b/hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/MysqlSerializer.java index 1557902bd2..595ab609bd 100644 --- a/hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/MysqlSerializer.java +++ b/hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/MysqlSerializer.java @@ -27,7 +27,7 @@ import org.apache.hugegraph.backend.id.Id; import org.apache.hugegraph.backend.id.IdGenerator; import org.apache.hugegraph.backend.serializer.TableBackendEntry; -import org.apache.hugegraph.backend.serializer.TableSerializer; +import org.apache.hugegraph.backend.serializer.TableSerializerV2; import org.apache.hugegraph.backend.store.BackendEntry; import org.apache.hugegraph.config.HugeConfig; import org.apache.hugegraph.schema.SchemaElement; @@ -39,7 +39,7 @@ import org.apache.hugegraph.util.InsertionOrderUtil; import org.apache.hugegraph.util.JsonUtil; -public class MysqlSerializer extends TableSerializer { +public class MysqlSerializer extends TableSerializerV2 { public MysqlSerializer(HugeConfig config) { super(config);