Skip to content

Commit

Permalink
map indexlabel various range type to RANGE (#628)
Browse files Browse the repository at this point in the history
Change-Id: I0e3d241de3bef100a3d789486c3eae96d203b791
  • Loading branch information
zhoney authored and Linary committed Aug 6, 2019
1 parent 0e66c64 commit e37937b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.baidu.hugegraph.api.schema;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -69,6 +70,7 @@ public String create(@Context GraphManager manager,
HugeGraph g = graph(manager, graph);
IndexLabel.Builder builder = jsonIndexLabel.convert2Builder(g);
IndexLabel.CreatedIndexLabel il = builder.createWithTask();
il.indexLabel(mapIndexLabel(il.indexLabel()));
return manager.serializer(g).writeCreatedIndexLabel(il);
}

Expand All @@ -81,7 +83,7 @@ public String list(@Context GraphManager manager,

HugeGraph g = graph(manager, graph);
List<IndexLabel> labels = g.schema().getIndexLabels();
return manager.serializer(g).writeIndexlabels(labels);
return manager.serializer(g).writeIndexlabels(mapIndexLabels(labels));
}

@GET
Expand All @@ -95,7 +97,7 @@ public String get(@Context GraphManager manager,

HugeGraph g = graph(manager, graph);
IndexLabel indexLabel = g.schema().getIndexLabel(name);
return manager.serializer(g).writeIndexlabel(indexLabel);
return manager.serializer(g).writeIndexlabel(mapIndexLabel(indexLabel));
}

@DELETE
Expand All @@ -116,6 +118,25 @@ public Map<String, Id> delete(@Context GraphManager manager,
g.schema().indexLabel(name).remove());
}

private static List<IndexLabel> mapIndexLabels(List<IndexLabel> labels) {
List<IndexLabel> results = new ArrayList<>(labels.size());
for (IndexLabel il : labels) {
results.add(mapIndexLabel(il));
}
return results;
}

/**
* Map RANGE_INT/RANGE_FLOAT/RANGE_LONG/RANGE_DOUBLE to RANGE
*/
private static IndexLabel mapIndexLabel(IndexLabel label) {
if (label.indexType().isRange()) {
label = (IndexLabel) label.copy();
label.indexType(IndexType.RANGE);
}
return label;
}

/**
* JsonIndexLabel is only used to receive create and append requests
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.apache.tinkerpop.gremlin.structure.Graph;

import com.baidu.hugegraph.HugeException;
import com.baidu.hugegraph.HugeGraph;
import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.backend.id.IdGenerator;
Expand All @@ -35,7 +36,8 @@
import com.baidu.hugegraph.type.define.SchemaStatus;
import com.baidu.hugegraph.util.E;

public abstract class SchemaElement implements Namifiable, Typifiable {
public abstract class SchemaElement implements Namifiable, Typifiable,
Cloneable {

public static final int MAX_PRIMITIVE_SYS_ID = 32;
public static final int NEXT_PRIMITIVE_SYS_ID = 7;
Expand Down Expand Up @@ -101,6 +103,14 @@ public boolean hidden() {
return Graph.Hidden.isHidden(this.name());
}

public SchemaElement copy() {
try {
return (SchemaElement) super.clone();
} catch (CloneNotSupportedException e) {
throw new HugeException("Failed to clone schema", e);
}
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof SchemaElement)) {
Expand Down

0 comments on commit e37937b

Please sign in to comment.