Search in sources :

Example 1 with SourceType

use of com.baidu.hugegraph.loader.source.SourceType 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 2 with SourceType

use of com.baidu.hugegraph.loader.source.SourceType in project incubator-hugegraph-toolchain by apache.

the class InputProgressDeser method readInputProgress.

@SuppressWarnings("unchecked")
private static InputProgress readInputProgress(JsonNode node) {
    JsonNode typeNode = getNode(node, FIELD_TYPE, JsonNodeType.STRING);
    String type = typeNode.asText().toUpperCase();
    SourceType sourceType = SourceType.valueOf(type);
    JsonNode loadedItemsNode = getNode(node, FIELD_LOADED_ITEMS, JsonNodeType.ARRAY);
    JsonNode loadingItemNode = getNode(node, FIELD_LOADING_ITEM, JsonNodeType.OBJECT, JsonNodeType.NULL);
    Set<InputItemProgress> loadedItems;
    InputItemProgress loadingItem;
    switch(sourceType) {
        case FILE:
        case HDFS:
            loadedItems = (Set<InputItemProgress>) (Object) JsonUtil.convertSet(loadedItemsNode, FileItemProgress.class);
            loadingItem = JsonUtil.convert(loadingItemNode, FileItemProgress.class);
            break;
        case JDBC:
        default:
            throw new AssertionError(String.format("Unsupported input source '%s'", type));
    }
    return new InputProgress(sourceType, loadedItems, loadingItem);
}
Also used : FileItemProgress(com.baidu.hugegraph.loader.progress.FileItemProgress) InputProgress(com.baidu.hugegraph.loader.progress.InputProgress) SourceType(com.baidu.hugegraph.loader.source.SourceType) InputItemProgress(com.baidu.hugegraph.loader.progress.InputItemProgress) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 3 with SourceType

use of com.baidu.hugegraph.loader.source.SourceType in project incubator-hugegraph-toolchain by apache.

the class InputSourceDeser method readInputSource.

private static InputSource readInputSource(JsonNode node) {
    JsonNode typeNode = getNode(node, FIELD_TYPE, JsonNodeType.STRING);
    String type = typeNode.asText().toUpperCase();
    SourceType sourceType = SourceType.valueOf(type);
    assert node instanceof ObjectNode;
    ObjectNode objectNode = (ObjectNode) node;
    // The node 'type' doesn't participate in deserialization
    objectNode.remove(FIELD_TYPE);
    switch(sourceType) {
        case FILE:
            return JsonUtil.convert(node, FileSource.class);
        case HDFS:
            return JsonUtil.convert(node, HDFSSource.class);
        case JDBC:
            JsonNode vendorNode = getNode(node, FIELD_VENDOR, JsonNodeType.STRING);
            vendorNode = TextNode.valueOf(vendorNode.asText().toUpperCase());
            objectNode.replace(FIELD_VENDOR, vendorNode);
            return JsonUtil.convert(node, JDBCSource.class);
        default:
            throw new AssertionError(String.format("Unsupported input source '%s'", type));
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SourceType(com.baidu.hugegraph.loader.source.SourceType) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

SourceType (com.baidu.hugegraph.loader.source.SourceType)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ElementMapping (com.baidu.hugegraph.loader.mapping.ElementMapping)1 InputStruct (com.baidu.hugegraph.loader.mapping.InputStruct)1 LoadMapping (com.baidu.hugegraph.loader.mapping.LoadMapping)1 FileItemProgress (com.baidu.hugegraph.loader.progress.FileItemProgress)1 InputItemProgress (com.baidu.hugegraph.loader.progress.InputItemProgress)1 InputProgress (com.baidu.hugegraph.loader.progress.InputProgress)1 InputSource (com.baidu.hugegraph.loader.source.InputSource)1 FileSource (com.baidu.hugegraph.loader.source.file.FileSource)1 ElementStructV1 (com.baidu.hugegraph.loader.struct.ElementStructV1)1 GraphStructV1 (com.baidu.hugegraph.loader.struct.GraphStructV1)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1