Skip to content

Commit

Permalink
try fix cassandra
Browse files Browse the repository at this point in the history
  • Loading branch information
VGalaxies committed Sep 21, 2024
1 parent a67be44 commit 7371937
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

public class CassandraFeatures implements BackendFeatures {

@Override
public boolean supportsFatherAndSubEdgeLabel() {
return false;
}

@Override
public boolean supportsScanToken() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -400,7 +404,9 @@ protected List<HugeKeys> pkColumnName() {

@Override
protected List<HugeKeys> idColumnName() {
return Arrays.asList(EdgeId.KEYS);
return Arrays.stream(EdgeId.KEYS)
.filter(key -> !Objects.equals(key, HugeKeys.SUB_LABEL))
.collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()));

Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,8 @@ protected Iterator<HugeEdge> queryEdgesFromBackend(Query query) {

Stream<Iterator<HugeEdge>> 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 &&
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 7371937

Please sign in to comment.