Search in sources :

Example 1 with MaxGraphClient

use of com.alibaba.graphscope.groot.sdk.MaxGraphClient in project GraphScope by alibaba.

the class IngestDataCommand method run.

public void run() {
    MaxGraphClient client = MaxGraphClient.newBuilder().setHosts(graphEndpoint).build();
    client.ingestData(dataPath);
}
Also used : MaxGraphClient(com.alibaba.graphscope.groot.sdk.MaxGraphClient)

Example 2 with MaxGraphClient

use of com.alibaba.graphscope.groot.sdk.MaxGraphClient in project GraphScope by alibaba.

the class LdbcLoader method main.

public static void main(String[] args) throws IOException, ParseException {
    String dataDir = args[0];
    String host = args[1];
    int port = Integer.valueOf(args[2]);
    int batchSize = Integer.valueOf(args[3]);
    logger.info("dataDir [" + dataDir + "] host [" + host + "] port [" + port + "] batch [" + batchSize + "]");
    MaxGraphClient client = MaxGraphClient.newBuilder().addHost(host, port).build();
    int processed = 0;
    int ignored = 0;
    for (Path path : Files.list(Paths.get(dataDir)).collect(Collectors.toList())) {
        logger.info("process file [" + path.getFileName() + "]");
        String fileName = path.getFileName().toString();
        if (!fileName.endsWith("_0_0.csv") || fileName.startsWith(".") || fileName.startsWith("person_speaks_language") || fileName.startsWith("person_email_emailaddress")) {
            logger.info("ignore [" + fileName + "]");
            ignored++;
            continue;
        }
        String name = fileName.substring(0, fileName.length() - 8);
        String[] items = name.split("_");
        if (items.length == 1) {
            String label = firstUpperCase(items[0]);
            logger.info("vertex table: [" + label + "]");
            processVertex(client, label, path, batchSize);
        } else {
            String srcLabel = firstUpperCase(items[0]);
            String label = items[1];
            String dstLabel = firstUpperCase(items[2]);
            logger.info("edge table: [" + srcLabel + "-" + label + "->" + dstLabel + "]");
            processEdge(client, label, srcLabel, dstLabel, path, batchSize);
        }
        processed++;
    }
    logger.info("Total [" + (processed + ignored) + "]. processed [" + processed + "], ignored [" + ignored + "]");
}
Also used : Path(java.nio.file.Path) MaxGraphClient(com.alibaba.graphscope.groot.sdk.MaxGraphClient)

Example 3 with MaxGraphClient

use of com.alibaba.graphscope.groot.sdk.MaxGraphClient in project GraphScope by alibaba.

the class LoadLdbc method main.

public static void main(String[] args) throws IOException, ParseException {
    String dataDir = args[0];
    String host = args[1];
    int port = Integer.valueOf(args[2]);
    int batchSize = Integer.valueOf(args[3]);
    logger.info("dataDir [" + dataDir + "] host [" + host + "] port [" + port + "] batch [" + batchSize + "]");
    MaxGraphClient client = MaxGraphClient.newBuilder().addHost(host, port).build();
    int processed = 0;
    int ignored = 0;
    for (Path path : Files.list(Paths.get(dataDir)).collect(Collectors.toList())) {
        logger.info("process file [" + path.getFileName() + "]");
        String fileName = path.getFileName().toString();
        if (!fileName.endsWith("_0_0.csv") || fileName.startsWith(".") || fileName.startsWith("person_speaks_language") || fileName.startsWith("person_email_emailaddress")) {
            logger.info("ignore [" + fileName + "]");
            ignored++;
            continue;
        }
        String name = fileName.substring(0, fileName.length() - 8);
        String[] items = name.split("_");
        if (items.length == 1) {
            String label = firstUpperCase(items[0]);
            logger.info("vertex table: [" + label + "]");
            processVertex(client, label, path, batchSize);
        } else {
            String srcLabel = firstUpperCase(items[0]);
            String label = items[1];
            String dstLabel = firstUpperCase(items[2]);
            logger.info("edge table: [" + srcLabel + "-" + label + "->" + dstLabel + "]");
            processEdge(client, label, srcLabel, dstLabel, path, batchSize);
        }
        processed++;
    }
    logger.info("Total [" + (processed + ignored) + "]. processed [" + processed + "], ignored [" + ignored + "]");
}
Also used : Path(java.nio.file.Path) MaxGraphClient(com.alibaba.graphscope.groot.sdk.MaxGraphClient)

Example 4 with MaxGraphClient

use of com.alibaba.graphscope.groot.sdk.MaxGraphClient in project GraphScope by alibaba.

the class IngestFile method main.

public static void main(String[] args) throws IOException {
    String inputFile = args[0];
    String host = args[1];
    int port = Integer.valueOf(args[2]);
    int batchSize = Integer.valueOf(args[3]);
    MaxGraphClient client = MaxGraphClient.newBuilder().addHost(host, port).build();
    File file = new File(inputFile);
    String fileName = file.getName();
    String label = fileName.split("_")[0];
    logger.info("file [" + inputFile + "] host [" + host + "] port [" + port + "] label [" + label + "]");
    List<String> propertyNames = new ArrayList<>();
    int count = 0;
    long snapshotId = 0;
    try (BufferedReader br = new BufferedReader(new FileReader(file))) {
        String line;
        while ((line = br.readLine()) != null) {
            if (propertyNames.size() == 0) {
                // First line
                for (String item : line.split("\\|")) {
                    propertyNames.add(item);
                }
            } else {
                Map<String, String> properties = new HashMap<>();
                String[] items = line.split("\\|");
                for (int i = 0; i < items.length; i++) {
                    properties.put(propertyNames.get(i), items[i]);
                }
                client.addVertex(label, properties);
                count++;
                if (count == batchSize) {
                    snapshotId = client.commit();
                    count = 0;
                }
            }
        }
    }
    long maybeSnapshotId = client.commit();
    long flushSnapshotId = maybeSnapshotId == 0 ? snapshotId : maybeSnapshotId;
    logger.info("flush snapshotId [" + flushSnapshotId + "]");
    client.remoteFlush(flushSnapshotId);
    logger.info("done");
}
Also used : MaxGraphClient(com.alibaba.graphscope.groot.sdk.MaxGraphClient) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File)

Example 5 with MaxGraphClient

use of com.alibaba.graphscope.groot.sdk.MaxGraphClient 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)

Aggregations

MaxGraphClient (com.alibaba.graphscope.groot.sdk.MaxGraphClient)6 GraphEdge (com.alibaba.maxgraph.compiler.api.schema.GraphEdge)2 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)2 DataLoadTarget (com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)1 ColumnMappingInfo (com.alibaba.maxgraph.dataload.databuild.ColumnMappingInfo)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileReader (java.io.FileReader)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Configuration (org.apache.hadoop.conf.Configuration)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 Job (org.apache.hadoop.mapreduce.Job)1