Search in sources :

Example 16 with GraphSchema

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);
}
Also used : GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) GraphVertex(com.alibaba.maxgraph.compiler.api.schema.GraphVertex) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema)

Example 17 with GraphSchema

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());
}
Also used : GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) Test(org.junit.jupiter.api.Test)

Example 18 with GraphSchema

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());
}
Also used : GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) Test(org.junit.jupiter.api.Test)

Example 19 with GraphSchema

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));
}
Also used : Vertex(com.alibaba.maxgraph.structure.Vertex) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) VertexResponseFunction(com.alibaba.maxgraph.iterator.function.VertexResponseFunction) IteratorList(com.alibaba.maxgraph.iterator.IteratorList)

Example 20 with GraphSchema

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));
}
Also used : Vertex(com.alibaba.maxgraph.structure.Vertex) EdgeResponseFunction(com.alibaba.maxgraph.iterator.function.EdgeResponseFunction) StoreApi(com.alibaba.maxgraph.proto.StoreApi) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) IteratorList(com.alibaba.maxgraph.iterator.IteratorList)

Aggregations

GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)26 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)12 List (java.util.List)9 Map (java.util.Map)8 Lists (com.google.common.collect.Lists)7 Sets (com.google.common.collect.Sets)7 Set (java.util.Set)7 TreeNode (com.alibaba.maxgraph.compiler.tree.TreeNode)6 Maps (com.google.common.collect.Maps)6 Collectors (java.util.stream.Collectors)6 EdgeRelation (com.alibaba.maxgraph.compiler.api.schema.EdgeRelation)5 GraphEdge (com.alibaba.maxgraph.compiler.api.schema.GraphEdge)5 EdgeOtherVertexTreeNode (com.alibaba.maxgraph.compiler.tree.EdgeOtherVertexTreeNode)5 EdgeTreeNode (com.alibaba.maxgraph.compiler.tree.EdgeTreeNode)5 EdgeVertexTreeNode (com.alibaba.maxgraph.compiler.tree.EdgeVertexTreeNode)5 VertexTreeNode (com.alibaba.maxgraph.compiler.tree.VertexTreeNode)5 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)5 Direction (org.apache.tinkerpop.gremlin.structure.Direction)5 JSONObject (com.alibaba.fastjson.JSONObject)4 SchemaFetcher (com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher)4