use of com.alibaba.maxgraph.compiler.api.schema.GraphSchema 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.GraphSchema in project GraphScope by alibaba.
the class ClientTest method testGetSchema.
@Test
void testGetSchema() {
GraphSchema schema = client.getSchema();
System.out.println(((GraphDef) schema).toProto().toString());
}
use of com.alibaba.maxgraph.compiler.api.schema.GraphSchema in project GraphScope by alibaba.
the class DataLoadingTest method testGetSchema.
@Test
public void testGetSchema() {
GraphSchema schema = client.getSchema();
System.out.println(((GraphDef) schema).toProto().toString());
}
use of com.alibaba.maxgraph.compiler.api.schema.GraphSchema in project GraphScope by alibaba.
the class RemoteProxy method scan.
public Iterator<Vertex> scan(Set<String> labelList) {
Pair<GraphSchema, Long> pair = schemaFetcher.getSchemaSnapshotPair();
Set<Integer> labelIdList = Sets.newHashSet();
if (null == labelList || labelList.isEmpty()) {
labelIdList.add(0);
} else {
for (String label : labelList) {
try {
labelIdList.add(pair.getLeft().getElement(label).getLabelId());
} catch (Exception ignored) {
}
}
}
if (labelIdList.isEmpty()) {
return new ArrayList<Vertex>().iterator();
}
List<Iterator<VertexResponse>> resList = Lists.newArrayList();
VertexScanRequest vertexScanRequest = VertexScanRequest.newBuilder().setTypeId(-1).setOrder(false).build();
Iterator<VertexResponse> scanResult = GremlinServiceGrpc.newBlockingStub(this.channel).withDeadlineAfter(timeout, TimeUnit.SECONDS).scan(vertexScanRequest);
resList.add(scanResult);
return new IteratorList<>(resList, new VertexResponseFunction(pair.getLeft(), this.graph));
}
use of com.alibaba.maxgraph.compiler.api.schema.GraphSchema 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