use of com.alibaba.maxgraph.compiler.api.schema.GraphElement in project GraphScope by alibaba.
the class GraphWriter method addOverwriteVertexOperation.
private void addOverwriteVertexOperation(OperationBatch.Builder batchBuilder, GraphSchema schema, DataRecord dataRecord) {
VertexRecordKey vertexRecordKey = dataRecord.getVertexRecordKey();
Map<String, Object> properties = dataRecord.getProperties();
String label = vertexRecordKey.getLabel();
GraphElement vertexDef = schema.getElement(label);
int labelId = vertexDef.getLabelId();
Map<Integer, PropertyValue> pkVals = parseRawProperties(vertexDef, vertexRecordKey.getProperties());
Map<Integer, PropertyValue> propertyVals = parseRawProperties(vertexDef, properties);
propertyVals.putAll(pkVals);
long hashId = getHashId(labelId, propertyVals, vertexDef);
batchBuilder.addOperation(new OverwriteVertexOperation(new VertexId(hashId), new LabelId(labelId), propertyVals));
}
use of com.alibaba.maxgraph.compiler.api.schema.GraphElement in project GraphScope by alibaba.
the class VertexStreamObserver method onNext.
@Override
public void onNext(GremlinQuery.VertexResponse vertexResponse) {
GremlinQuery.VertexId id = vertexResponse.getId();
CompositeId rId = new CompositeId(id.getId(), id.getTypeId());
GraphElement type = schema.getElement(id.getTypeId());
Map<String, Object> properties = null;
try {
properties = RpcProcessorUtils.deserializeProperty(vertexResponse.getPros().toByteArray(), type, schema);
} catch (Exception e) {
throw new RuntimeException("query properties for vertex=>" + rId.toString() + " fail", e);
}
Map<String, Object> existProp = existPropMap.get(rId);
if (null != existProp) {
if (properties == null) {
properties = Maps.newHashMap();
}
properties.putAll(existProp);
}
MxVertex vertex = new MxVertex(new Vertex(rId, type.getLabel(), properties, this.graph.getBaseGraph()), this.graph);
if (vertexCacheFlag) {
vertexCache.put(rId, vertex);
}
int count = vertexCountList.remove(rId);
if (count > 1) {
for (int i = 0; i < count; i++) {
resultProcessor.process(vertex);
}
} else {
resultProcessor.process(vertex);
}
}
use of com.alibaba.maxgraph.compiler.api.schema.GraphElement in project GraphScope by alibaba.
the class DefaultGraphSchema method getPropertyList.
@Override
public Map<GraphElement, GraphProperty> getPropertyList(String propName) {
Map<GraphElement, GraphProperty> elementPropertyList = Maps.newHashMap();
vertexList.forEach((key, value) -> {
for (GraphProperty property : value.getPropertyList()) {
if (StringUtils.equals(property.getName(), propName)) {
elementPropertyList.put(value, property);
}
}
});
edgeList.forEach((key, value) -> {
for (GraphProperty property : value.getPropertyList()) {
if (StringUtils.equals(property.getName(), propName)) {
elementPropertyList.put(value, property);
}
}
});
return elementPropertyList;
}
use of com.alibaba.maxgraph.compiler.api.schema.GraphElement in project GraphScope by alibaba.
the class TinkerMaxGraph method parseVertexProperties.
private Pair<String, Map<String, Object>> parseVertexProperties(Object... keyValues) {
Map<String, Object> kvs = Utils.convertToMap(keyValues);
Object labelObj = kvs.remove(T.label.toString());
if (labelObj == null) {
labelObj = Vertex.DEFAULT_LABEL;
}
final String label = labelObj.toString();
GraphSchema schema = graph.getSchema();
GraphElement graphElement = schema.getElement(label);
if (!(graphElement instanceof GraphVertex)) {
throw new IllegalArgumentException("Label " + label + " is not vertex");
}
List<GraphProperty> primaryKeyList = ((GraphVertex) graphElement).getPrimaryKeyList();
if (kvs.isEmpty()) {
for (GraphProperty property : primaryKeyList) {
kvs.put(property.getName(), property.getDataType().getRandomValue());
}
} else {
for (GraphProperty property : primaryKeyList) {
if (!kvs.containsKey(property.getName())) {
kvs.put(property.getName(), property.getDataType().getRandomValue());
}
}
}
return Pair.of(label, kvs);
}
use of com.alibaba.maxgraph.compiler.api.schema.GraphElement in project GraphScope by alibaba.
the class RemoteProxy method getOutEdges.
public Iterator<Edge> getOutEdges(Set<Vertex> v, String... label) {
List<Iterator<StoreApi.GraphEdgeReponse>> iterEdgeList = Lists.newArrayList();
Pair<GraphSchema, Long> schemaPair = schemaFetcher.getSchemaSnapshotPair();
GraphSchema schema = schemaPair.getLeft();
long snapshotId = schemaPair.getRight();
for (Vertex vertex : v) {
if (label.length == 0) {
StoreApi.GetOutEdgesRequest.Builder req = StoreApi.GetOutEdgesRequest.newBuilder();
req.setSnapshotId(snapshotId).setSrcId(vertex.id.id()).setSnapshotId(schemaPair.getRight());
Iterator<StoreApi.GraphEdgeReponse> edgeResponse = stub.withDeadlineAfter(timeout, TimeUnit.SECONDS).getOutEdges(req.build());
iterEdgeList.add(edgeResponse);
} else {
for (String labelVal : label) {
try {
GraphElement element = schema.getElement(labelVal);
int labelId = element.getLabelId();
StoreApi.GetOutEdgesRequest.Builder req = StoreApi.GetOutEdgesRequest.newBuilder();
req.setSnapshotId(snapshotId).setSrcId(vertex.id.id()).setTypeId(labelId).setSnapshotId(schemaPair.getRight());
Iterator<StoreApi.GraphEdgeReponse> edgeResponse = stub.withDeadlineAfter(timeout, TimeUnit.SECONDS).getOutEdges(req.build());
iterEdgeList.add(edgeResponse);
} catch (Exception ignored) {
}
}
}
}
return new IteratorList<>(iterEdgeList, new EdgeResponseFunction(schema, this.graph));
}
Aggregations