Skip to content
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

fix(client): serialize source and target label for non-father edge label #628

Merged
merged 6 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public enum EdgeLabelType {

SUB(2, "SUB");

private byte code = 0;
private String name = null;
private final byte code;
private final String name;

EdgeLabelType(int code, String name) {
assert code < 256;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public class EdgeLabel extends SchemaLabel {
private String parentLabel;
@JsonProperty("frequency")
private Frequency frequency;
@JsonProperty("source_label")
private String sourceLabel;
@JsonProperty("target_label")
private String targetLabel;
@JsonProperty("links")
private Set<Map<String, String>> links;
@JsonProperty("sort_keys")
Expand All @@ -56,6 +60,8 @@ public class EdgeLabel extends SchemaLabel {
public EdgeLabel(@JsonProperty("name") String name) {
super(name);
this.frequency = Frequency.DEFAULT;
this.sourceLabel = null;
this.targetLabel = null;
this.links = new HashSet<>();
this.sortKeys = new CopyOnWriteArrayList<>();
this.ttl = 0L;
Expand Down Expand Up @@ -108,7 +114,7 @@ public Set<Map<String, String>> links() {

public boolean linkedVertexLabel(String vertexLabel) {
if (this.edgeLabelType.parent() || this.links == null ||
this.links.isEmpty()) {
this.links.isEmpty()) {
return false;
}

Expand Down Expand Up @@ -136,15 +142,14 @@ public String ttlStartTime() {

@Override
public String toString() {
return String.format("{name=%s, " + "edgeLabel_type=%s, " + "parent_label=%s" +
"links=%s, sortKeys=%s, indexLabels=%s, " +
"nullableKeys=%s, properties=%s, ttl=%s, " +
"ttlStartTime=%s, status=%s}",
this.name,
this.edgeLabelType, this.parentLabel,
this.links, this.sortKeys, this.indexLabels,
this.nullableKeys, this.properties, this.ttl,
this.ttlStartTime, this.status);
return String.format("{name=%s, sourceLabel=%s, targetLabel=%s, " + "edgeLabel_type=%s, " +
"parent_label=%s, links=%s, sortKeys=%s, indexLabels=%s, " +
"nullableKeys=%s, properties=%s, ttl=%s, ttlStartTime=%s, status=%s}",
this.name, this.sourceLabel(), this.targetLabel(),
this.edgeLabelType, this.parentLabel,
this.links, this.sortKeys, this.indexLabels,
this.nullableKeys, this.properties, this.ttl,
this.ttlStartTime, this.status);
}

public EdgeLabelV53 switchV53() {
Expand All @@ -167,18 +172,12 @@ public interface Builder extends SchemaBuilder<EdgeLabel> {

/**
* Set the source label of the edge label
*
* @deprecated Suggested use {@link #link(String, String)} to set the source and target label pair
*/
@Deprecated
Builder sourceLabel(String label);

/**
* Set the target label of the edge label
*
* @deprecated Suggested use {@link #link(String, String)} to set the source and target label pair
*/
@Deprecated
Builder targetLabel(String label);

Builder frequency(Frequency frequency);
Expand All @@ -202,13 +201,9 @@ public static class BuilderImpl implements Builder {

private final EdgeLabel edgeLabel;
private final SchemaManager manager;
private String sourceLabel;
private String targetLabel;

public BuilderImpl(String name, SchemaManager manager) {
this.edgeLabel = new EdgeLabel(name);
this.sourceLabel = null;
this.targetLabel = null;
this.manager = manager;
}

Expand Down Expand Up @@ -246,10 +241,10 @@ public Builder properties(String... properties) {
@Override
public Builder sortKeys(String... keys) {
E.checkArgument(this.edgeLabel.sortKeys.isEmpty(),
"Not allowed to assign sort keys multi times");
"Not allowed to assign sort keys multi times");
List<String> sortKeys = Arrays.asList(keys);
E.checkArgument(CollectionUtil.allUnique(sortKeys),
"Invalid sort keys %s, which contains some " +
"Invalid sort keys %s, which contains some " +
"duplicate properties", sortKeys);
this.edgeLabel.sortKeys.addAll(sortKeys);
return this;
Expand All @@ -266,8 +261,6 @@ public Builder link(String sourceLabel, String targetLabel) {
HashMap<String, String> map = new HashMap<>();
map.put(sourceLabel, targetLabel);
this.edgeLabel.links.add(map);
this.sourceLabel = null;
this.targetLabel = null;
return this;
}

Expand All @@ -286,40 +279,34 @@ public Builder withBase(String parentLabel) {

/**
* Set the source label of the edge label
*
* @deprecated Suggested use {@link #link(String, String)} to set the source and target label pair
*/
@Deprecated
@Override
public Builder sourceLabel(String label) {
E.checkArgument(this.edgeLabel.links.isEmpty(),
"Not allowed add source label to an edge label which " +
"Not allowed add source label to an edge label which " +
"already has links");
if (this.targetLabel != null) {
link(label, this.targetLabel);
this.targetLabel = null;
if (this.edgeLabel.targetLabel != null) {
link(label, this.edgeLabel.targetLabel);
this.edgeLabel.targetLabel = null;
} else {
this.sourceLabel = label;
this.edgeLabel.sourceLabel = label;
}
return this;
}

/**
* Set the target label of the edge label
*
* @deprecated Suggested use {@link #link(String, String)} to set the source and target label pair
*/
@Deprecated
@Override
public Builder targetLabel(String label) {
E.checkArgument(this.edgeLabel.links.isEmpty(),
"Not allowed add source label to an edge label " +
"which already has links");
if (this.sourceLabel != null) {
link(this.sourceLabel, label);
this.sourceLabel = null;
if (this.edgeLabel.sourceLabel != null) {
link(this.edgeLabel.sourceLabel, label);
this.edgeLabel.sourceLabel = null;
} else {
this.targetLabel = label;
this.edgeLabel.targetLabel = label;
}
return this;
}
Expand Down
Loading