Search in sources :

Example 1 with LoadMapping

use of com.baidu.hugegraph.loader.mapping.LoadMapping in project incubator-hugegraph-toolchain by apache.

the class MappingConverter method main.

public static void main(String[] args) {
    E.checkArgument(args.length == 1, "args: file");
    String input = args[0];
    LOG.info("Prepare to convert mapping file {}", input);
    File file = FileUtils.getFile(input);
    if (!file.exists() || !file.isFile()) {
        LOG.error("The file '{}' doesn't exists or not a file", input);
        throw new IllegalArgumentException(String.format("The file '%s' doesn't exists or not a file", input));
    }
    LoadMapping mapping = LoadMapping.of(input);
    String outputPath = getOutputPath(file);
    MappingUtil.write(mapping, outputPath);
    LOG.info("Convert mapping file successfuly, stored at {}", outputPath);
}
Also used : File(java.io.File) LoadMapping(com.baidu.hugegraph.loader.mapping.LoadMapping)

Example 2 with LoadMapping

use of com.baidu.hugegraph.loader.mapping.LoadMapping in project incubator-hugegraph-toolchain by apache.

the class MappingUtil method parseV1.

private static LoadMapping parseV1(String json) {
    GraphStructV1 graphStruct = JsonUtil.fromJson(json, GraphStructV1.class);
    Map<FileSourceKey, InputStruct> fileSourceInputStructs = InsertionOrderUtil.newMap();
    List<InputStruct> jdbcSourceInputStructs = new ArrayList<>();
    for (ElementStructV1 originStruct : graphStruct.structs()) {
        InputSource inputSource = originStruct.input();
        ElementMapping targetStruct = convertV1ToV2(originStruct);
        SourceType type = inputSource.type();
        if (type == SourceType.FILE || type == SourceType.HDFS) {
            FileSource source = (FileSource) inputSource;
            FileSourceKey key = new FileSourceKey(type, source.path());
            fileSourceInputStructs.compute(key, (k, inputStruct) -> {
                if (inputStruct == null) {
                    inputStruct = new InputStruct(null, null);
                    inputStruct.input(source);
                }
                inputStruct.add(targetStruct);
                return inputStruct;
            });
        } else {
            assert type == SourceType.JDBC;
            InputStruct inputStruct = new InputStruct(null, null);
            inputStruct.input(inputSource);
            inputStruct.add(targetStruct);
            jdbcSourceInputStructs.add(inputStruct);
        }
    }
    // Generate id for every input mapping
    List<InputStruct> inputStructs = new ArrayList<>();
    int id = 0;
    for (InputStruct inputStruct : fileSourceInputStructs.values()) {
        inputStruct.id(String.valueOf(++id));
        inputStructs.add(inputStruct);
    }
    for (InputStruct inputStruct : jdbcSourceInputStructs) {
        inputStruct.id(String.valueOf(++id));
        inputStructs.add(inputStruct);
    }
    return new LoadMapping(inputStructs);
}
Also used : ElementMapping(com.baidu.hugegraph.loader.mapping.ElementMapping) InputSource(com.baidu.hugegraph.loader.source.InputSource) SourceType(com.baidu.hugegraph.loader.source.SourceType) FileSource(com.baidu.hugegraph.loader.source.file.FileSource) ArrayList(java.util.ArrayList) LoadMapping(com.baidu.hugegraph.loader.mapping.LoadMapping) InputStruct(com.baidu.hugegraph.loader.mapping.InputStruct) GraphStructV1(com.baidu.hugegraph.loader.struct.GraphStructV1) ElementStructV1(com.baidu.hugegraph.loader.struct.ElementStructV1)

Example 3 with LoadMapping

use of com.baidu.hugegraph.loader.mapping.LoadMapping in project incubator-hugegraph-toolchain by apache.

the class LoadTaskService method buildLoadMapping.

private LoadMapping buildLoadMapping(GraphConnection connection, FileMapping fileMapping) {
    FileSource source = this.buildFileSource(fileMapping);
    List<com.baidu.hugegraph.loader.mapping.VertexMapping> vMappings;
    vMappings = this.buildVertexMappings(connection, fileMapping);
    List<com.baidu.hugegraph.loader.mapping.EdgeMapping> eMappings;
    eMappings = this.buildEdgeMappings(connection, fileMapping);
    InputStruct inputStruct = new InputStruct(vMappings, eMappings);
    inputStruct.id("1");
    inputStruct.input(source);
    return new LoadMapping(ImmutableList.of(inputStruct));
}
Also used : VertexMapping(com.baidu.hugegraph.entity.load.VertexMapping) InputStruct(com.baidu.hugegraph.loader.mapping.InputStruct) FileSource(com.baidu.hugegraph.loader.source.file.FileSource) EdgeMapping(com.baidu.hugegraph.entity.load.EdgeMapping) LoadMapping(com.baidu.hugegraph.loader.mapping.LoadMapping)

Example 4 with LoadMapping

use of com.baidu.hugegraph.loader.mapping.LoadMapping in project incubator-hugegraph-toolchain by apache.

the class LoadTaskService method buildLoadTask.

private LoadTask buildLoadTask(GraphConnection connection, FileMapping fileMapping) {
    try {
        LoadOptions options = this.buildLoadOptions(connection, fileMapping);
        // NOTE: For simplicity, one file corresponds to one import task
        LoadMapping mapping = this.buildLoadMapping(connection, fileMapping);
        this.bindMappingToOptions(options, mapping, fileMapping.getPath());
        return new LoadTask(options, connection, fileMapping);
    } catch (Exception e) {
        Throwable rootCause = Ex.rootCause(e);
        throw new ExternalException("load.build-task.failed", rootCause);
    }
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) LoadOptions(com.baidu.hugegraph.loader.executor.LoadOptions) ExternalException(com.baidu.hugegraph.exception.ExternalException) LoadMapping(com.baidu.hugegraph.loader.mapping.LoadMapping) ExternalException(com.baidu.hugegraph.exception.ExternalException) IOException(java.io.IOException) InternalException(com.baidu.hugegraph.exception.InternalException)

Aggregations

LoadMapping (com.baidu.hugegraph.loader.mapping.LoadMapping)4 InputStruct (com.baidu.hugegraph.loader.mapping.InputStruct)2 FileSource (com.baidu.hugegraph.loader.source.file.FileSource)2 EdgeMapping (com.baidu.hugegraph.entity.load.EdgeMapping)1 LoadTask (com.baidu.hugegraph.entity.load.LoadTask)1 VertexMapping (com.baidu.hugegraph.entity.load.VertexMapping)1 ExternalException (com.baidu.hugegraph.exception.ExternalException)1 InternalException (com.baidu.hugegraph.exception.InternalException)1 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)1 ElementMapping (com.baidu.hugegraph.loader.mapping.ElementMapping)1 InputSource (com.baidu.hugegraph.loader.source.InputSource)1 SourceType (com.baidu.hugegraph.loader.source.SourceType)1 ElementStructV1 (com.baidu.hugegraph.loader.struct.ElementStructV1)1 GraphStructV1 (com.baidu.hugegraph.loader.struct.GraphStructV1)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1