Search in sources :

Example 1 with VertexTypeMapper

use of com.alibaba.graphscope.groot.schema.mapper.VertexTypeMapper in project GraphScope by alibaba.

the class GraphSchemaMapper method toGraphSchema.

public GraphSchema toGraphSchema() {
    DefaultGraphSchema graphSchema = new DefaultGraphSchema();
    Map<String, GraphVertex> vertexTypeMap = Maps.newHashMap();
    for (SchemaElementMapper elementMapper : this.types) {
        if (elementMapper instanceof VertexTypeMapper) {
            GraphVertex graphVertex = ((VertexTypeMapper) elementMapper).toVertexType();
            graphSchema.createVertexType(graphVertex);
            vertexTypeMap.put(graphVertex.getLabel(), graphVertex);
        }
    }
    for (SchemaElementMapper elementMapper : this.types) {
        if (elementMapper instanceof EdgeTypeMapper) {
            GraphEdge graphEdge = ((EdgeTypeMapper) elementMapper).toEdgeType(vertexTypeMap);
            graphSchema.createEdgeType(graphEdge);
        }
    }
    return graphSchema;
}
Also used : GraphVertex(com.alibaba.maxgraph.compiler.api.schema.GraphVertex) DefaultGraphSchema(com.alibaba.graphscope.groot.schema.mapper.DefaultGraphSchema) VertexTypeMapper(com.alibaba.graphscope.groot.schema.mapper.VertexTypeMapper) EdgeTypeMapper(com.alibaba.graphscope.groot.schema.mapper.EdgeTypeMapper) GraphEdge(com.alibaba.maxgraph.compiler.api.schema.GraphEdge) SchemaElementMapper(com.alibaba.graphscope.groot.schema.mapper.SchemaElementMapper)

Example 2 with VertexTypeMapper

use of com.alibaba.graphscope.groot.schema.mapper.VertexTypeMapper in project GraphScope by alibaba.

the class GraphSchemaMapper method parseFromJson.

public static GraphSchemaMapper parseFromJson(String schemaJson) {
    JSONObject jsonObject = JSONObject.parseObject(schemaJson);
    GraphSchemaMapper graphSchema = new GraphSchemaMapper();
    Integer version = jsonObject.getInteger("version");
    if (null != version) {
        graphSchema.version = version;
    } else {
        graphSchema.version = 0;
    }
    graphSchema.types = Lists.newArrayList();
    JSONArray typeArray = jsonObject.getJSONArray("types");
    for (int i = 0; i < typeArray.size(); i++) {
        JSONObject typeObject = typeArray.getJSONObject(i);
        String type = typeObject.getString("type");
        if (StringUtils.equals("VERTEX", StringUtils.upperCase(type))) {
            VertexTypeMapper vertexTypeMapper = typeObject.toJavaObject(VertexTypeMapper.class);
            graphSchema.types.add(vertexTypeMapper);
        } else {
            EdgeTypeMapper edgeTypeMapper = typeObject.toJavaObject(EdgeTypeMapper.class);
            graphSchema.types.add(edgeTypeMapper);
        }
    }
    return graphSchema;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) VertexTypeMapper(com.alibaba.graphscope.groot.schema.mapper.VertexTypeMapper) JSONArray(com.alibaba.fastjson.JSONArray) EdgeTypeMapper(com.alibaba.graphscope.groot.schema.mapper.EdgeTypeMapper)

Aggregations

EdgeTypeMapper (com.alibaba.graphscope.groot.schema.mapper.EdgeTypeMapper)2 VertexTypeMapper (com.alibaba.graphscope.groot.schema.mapper.VertexTypeMapper)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 DefaultGraphSchema (com.alibaba.graphscope.groot.schema.mapper.DefaultGraphSchema)1 SchemaElementMapper (com.alibaba.graphscope.groot.schema.mapper.SchemaElementMapper)1 GraphEdge (com.alibaba.maxgraph.compiler.api.schema.GraphEdge)1 GraphVertex (com.alibaba.maxgraph.compiler.api.schema.GraphVertex)1