Skip to content
Open
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 @@ -57,6 +57,7 @@ public class API {

public static final String ACTION_APPEND = "append";
public static final String ACTION_ELIMINATE = "eliminate";
public static final String ACTION_CLEAR = "clear";

private static final Meter succeedMeter =
MetricsUtil.registerMeter(API.class, "commit-succeed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,6 @@ private static class JsonVertex extends JsonElement {

@Override
public void checkCreate(boolean isBatch) {
E.checkArgumentNotNull(this.label,
"The label of vertex can't be null");
this.checkUpdate();
}

Expand All @@ -446,8 +444,10 @@ public void checkUpdate() {
public Object[] properties() {
Object[] props = API.properties(this.properties);
List<Object> list = new ArrayList<>(Arrays.asList(props));
list.add(T.label);
list.add(this.label);
if (this.label != null) {
list.add(T.label);
list.add(this.label);
}
if (this.id != null) {
list.add(T.id);
list.add(this.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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

import javax.annotation.security.RolesAllowed;
import javax.inject.Singleton;
Expand All @@ -41,6 +42,7 @@
import com.baidu.hugegraph.HugeGraph;
import com.baidu.hugegraph.api.API;
import com.baidu.hugegraph.api.filter.StatusFilter.Status;
import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.core.GraphManager;
import com.baidu.hugegraph.define.Checkable;
import com.baidu.hugegraph.schema.PropertyKey;
Expand All @@ -55,6 +57,7 @@
import com.codahale.metrics.annotation.Timed;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;

@Path("graphs/{graph}/schema/propertykeys")
@Singleton
Expand All @@ -77,8 +80,8 @@ public String create(@Context GraphManager manager,

HugeGraph g = graph(manager, graph);
PropertyKey.Builder builder = jsonPropertyKey.convert2Builder(g);
PropertyKey propertyKey = builder.create();
return manager.serializer(g).writePropertyKey(propertyKey);
PropertyKey.PropertyKeyWithTask pk = builder.createWithTask();
return manager.serializer(g).writePropertyKeyWithTask(pk);
}

@PUT
Expand All @@ -98,15 +101,29 @@ public String update(@Context GraphManager manager,
E.checkArgument(name.equals(jsonPropertyKey.name),
"The name in url(%s) and body(%s) are different",
name, jsonPropertyKey.name);

HugeGraph g = graph(manager, graph);
if (ACTION_CLEAR.equals(action)) {
PropertyKey propertyKey = g.propertyKey(name);
E.checkArgument(propertyKey.readFrequency().olap(),
"Only olap property key can do action clear, " +
"but got '%s'", propertyKey);
Id id = g.clearPropertyKey(propertyKey);
PropertyKey.PropertyKeyWithTask pk =
new PropertyKey.PropertyKeyWithTask(propertyKey, id);
return manager.serializer(g).writePropertyKeyWithTask(pk);
}

// Parse action parameter
boolean append = checkAndParseAction(action);

HugeGraph g = graph(manager, graph);
PropertyKey.Builder builder = jsonPropertyKey.convert2Builder(g);
PropertyKey propertyKey = append ?
builder.append() :
builder.eliminate();
return manager.serializer(g).writePropertyKey(propertyKey);
PropertyKey.PropertyKeyWithTask pk =
new PropertyKey.PropertyKeyWithTask(propertyKey, null);
return manager.serializer(g).writePropertyKeyWithTask(pk);
}

@GET
Expand Down Expand Up @@ -156,15 +173,16 @@ public String get(@Context GraphManager manager,
@Path("{name}")
@Consumes(APPLICATION_JSON)
@RolesAllowed({"admin", "$owner=$graph $action=property_key_delete"})
public void delete(@Context GraphManager manager,
@PathParam("graph") String graph,
@PathParam("name") String name) {
public Map<String, Id> delete(@Context GraphManager manager,
@PathParam("graph") String graph,
@PathParam("name") String name) {
LOG.debug("Graph [{}] remove property key by name '{}'", graph, name);

HugeGraph g = graph(manager, graph);
// Throw 404 if not exists
g.schema().getPropertyKey(name);
g.schema().propertyKey(name).remove();
return ImmutableMap.of("task_id",
g.schema().propertyKey(name).remove());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,22 @@ public Id getNextId(HugeType type) {
}

@Override
public void addPropertyKey(PropertyKey key) {
public Id addPropertyKey(PropertyKey key) {
verifySchemaPermission(HugePermission.WRITE, key);
this.hugegraph.addPropertyKey(key);
return this.hugegraph.addPropertyKey(key);
}

@Override
public void removePropertyKey(Id key) {
public Id removePropertyKey(Id key) {
PropertyKey pkey = this.hugegraph.propertyKey(key);
verifySchemaPermission(HugePermission.DELETE, pkey);
this.hugegraph.removePropertyKey(key);
return this.hugegraph.removePropertyKey(key);
}

@Override
public Id clearPropertyKey(PropertyKey propertyKey) {
verifySchemaPermission(HugePermission.DELETE, propertyKey);
return this.hugegraph.clearPropertyKey(propertyKey);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ public String writePropertyKey(PropertyKey propertyKey) {
return JsonUtil.toJson(propertyKey);
}

@Override
public String writePropertyKeyWithTask(PropertyKey.PropertyKeyWithTask pkt) {
StringBuilder builder = new StringBuilder();
long id = pkt.task() == null ? 0L : pkt.task().asLong();
return builder.append("{\"property_key\": ")
.append(this.writePropertyKey(pkt.propertyKey()))
.append(", \"task_id\": ").append(id).append("}")
.toString();
}

@Override
public String writePropertyKeys(List<PropertyKey> propertyKeys) {
return writeList("propertykeys", propertyKeys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public interface Serializer {

public String writePropertyKey(PropertyKey propertyKey);

public String writePropertyKeyWithTask(PropertyKey.PropertyKeyWithTask pkt);

public String writePropertyKeys(List<PropertyKey> propertyKeys);

public String writeVertexLabel(VertexLabel vertexLabel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ public boolean supportsTtl() {

@Override
public boolean supportsOlapProperties() {
return false;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import com.baidu.hugegraph.schema.PropertyKey;
import com.baidu.hugegraph.schema.SchemaElement;
import com.baidu.hugegraph.structure.HugeElement;
import com.baidu.hugegraph.structure.HugeIndex;
import com.baidu.hugegraph.structure.HugeProperty;
import com.baidu.hugegraph.structure.HugeVertex;
import com.baidu.hugegraph.type.HugeType;
import com.baidu.hugegraph.type.define.DataType;
import com.baidu.hugegraph.type.define.HugeKeys;
Expand All @@ -58,6 +60,16 @@ protected TableBackendEntry newBackendEntry(TableBackendEntry.Row row) {
return new CassandraBackendEntry(row);
}

@Override
protected TableBackendEntry newBackendEntry(HugeIndex index) {
TableBackendEntry backendEntry = newBackendEntry(index.type(),
index.id());
if (index.indexLabel().olap()) {
backendEntry.olap(true);
}
return backendEntry;
}

@Override
protected CassandraBackendEntry convertEntry(BackendEntry backendEntry) {
if (!(backendEntry instanceof CassandraBackendEntry)) {
Expand Down Expand Up @@ -130,6 +142,20 @@ protected void parseProperties(HugeElement element,
}
}

@Override
public BackendEntry writeOlapVertex(HugeVertex vertex) {
CassandraBackendEntry entry = newBackendEntry(HugeType.OLAP,
vertex.id());
entry.column(HugeKeys.ID, this.writeId(vertex.id()));
HugeProperty<?> prop = vertex.getProperties().values()
.iterator().next();
PropertyKey pk = prop.propertyKey();
entry.subId(pk.id());
entry.column(HugeKeys.PROPERTY_VALUE,
this.writeProperty(pk, prop.value()));
return entry;
}

@Override
protected Object writeProperty(PropertyKey propertyKey, Object value) {
BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_PROPERTY);
Expand Down
Loading