Search in sources :

Example 1 with ColumnMappingInfo

use of com.alibaba.maxgraph.dataload.databuild.ColumnMappingInfo in project GraphScope by alibaba.

the class CommitDataCommand method run.

public void run() {
    MaxGraphClient client = MaxGraphClient.newBuilder().setHosts(graphEndpoint).build();
    Map<Long, DataLoadTarget> tableToTarget = new HashMap<>();
    for (ColumnMappingInfo columnMappingInfo : columnMappingInfos.values()) {
        long tableId = columnMappingInfo.getTableId();
        int labelId = columnMappingInfo.getLabelId();
        GraphElement graphElement = schema.getElement(labelId);
        String label = graphElement.getLabel();
        DataLoadTarget.Builder builder = DataLoadTarget.newBuilder();
        builder.setLabel(label);
        if (graphElement instanceof GraphEdge) {
            builder.setSrcLabel(schema.getElement(columnMappingInfo.getSrcLabelId()).getLabel());
            builder.setDstLabel(schema.getElement(columnMappingInfo.getDstLabelId()).getLabel());
        }
        tableToTarget.put(tableId, builder.build());
    }
    client.commitDataLoad(tableToTarget);
}
Also used : MaxGraphClient(com.alibaba.graphscope.groot.sdk.MaxGraphClient) DataLoadTarget(com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget) ColumnMappingInfo(com.alibaba.maxgraph.dataload.databuild.ColumnMappingInfo) HashMap(java.util.HashMap) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) GraphEdge(com.alibaba.maxgraph.compiler.api.schema.GraphEdge)

Example 2 with ColumnMappingInfo

use of com.alibaba.maxgraph.dataload.databuild.ColumnMappingInfo in project GraphScope by alibaba.

the class DataCommand method initialize.

private void initialize() throws IOException {
    FileSystem fs = new Path(this.dataPath).getFileSystem(new Configuration());
    try (FSDataInputStream inputStream = fs.open(new Path(this.dataPath, "META"))) {
        String metaString = inputStream.readUTF();
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String, String> metaMap = objectMapper.readValue(metaString, new TypeReference<Map<String, String>>() {
        });
        this.graphEndpoint = metaMap.get("endpoint");
        this.schema = GraphSchemaMapper.parseFromJson(metaMap.get("schema")).toGraphSchema();
        this.columnMappingInfos = objectMapper.readValue(metaMap.get("mappings"), new TypeReference<Map<String, ColumnMappingInfo>>() {
        });
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ColumnMappingInfo(com.alibaba.maxgraph.dataload.databuild.ColumnMappingInfo) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ColumnMappingInfo (com.alibaba.maxgraph.dataload.databuild.ColumnMappingInfo)2 MaxGraphClient (com.alibaba.graphscope.groot.sdk.MaxGraphClient)1 GraphEdge (com.alibaba.maxgraph.compiler.api.schema.GraphEdge)1 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)1 DataLoadTarget (com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Configuration (org.apache.hadoop.conf.Configuration)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1