Search in sources :

Example 1 with InputStruct

use of com.baidu.hugegraph.loader.mapping.InputStruct 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 InputStruct

use of com.baidu.hugegraph.loader.mapping.InputStruct in project hugegraph-computer by hugegraph.

the class LoaderFileInputSplitFetcher method fetchEdgeInputSplits.

@Override
public List<InputSplit> fetchEdgeInputSplits() {
    List<InputSplit> splits = new ArrayList<>();
    for (InputStruct edgeInputStruct : this.edgeInputStructs) {
        FileSource source = (FileSource) edgeInputStruct.input();
        List<String> paths = this.scanPaths(source);
        if (CollectionUtils.isNotEmpty(paths)) {
            for (String path : paths) {
                FileInputSplit split = new FileInputSplit(ElemType.EDGE, edgeInputStruct, path);
                splits.add(split);
            }
        }
    }
    return splits;
}
Also used : InputStruct(com.baidu.hugegraph.loader.mapping.InputStruct) FileSource(com.baidu.hugegraph.loader.source.file.FileSource) ArrayList(java.util.ArrayList) InputSplit(com.baidu.hugegraph.computer.core.input.InputSplit)

Example 3 with InputStruct

use of com.baidu.hugegraph.loader.mapping.InputStruct in project hugegraph-computer by hugegraph.

the class FileInputSplitTest method testConstructor.

@Test
public void testConstructor() {
    InputStruct inputStruct = Mockito.mock(InputStruct.class);
    FileInputSplit split = new FileInputSplit(ElemType.VERTEX, inputStruct, "/tmp/test");
    Assert.assertEquals("/tmp/test", split.path());
    Assert.assertEquals(inputStruct, split.struct());
    Assert.assertSame(ElemType.VERTEX, split.type());
}
Also used : FileInputSplit(com.baidu.hugegraph.computer.core.input.loader.FileInputSplit) InputStruct(com.baidu.hugegraph.loader.mapping.InputStruct) Test(org.junit.Test)

Example 4 with InputStruct

use of com.baidu.hugegraph.loader.mapping.InputStruct in project hugegraph-computer by hugegraph.

the class FileInputSplitTest method testHashCode.

@Test
public void testHashCode() {
    InputStruct inputStruct = Mockito.mock(InputStruct.class);
    FileInputSplit split1 = new FileInputSplit(ElemType.VERTEX, inputStruct, "/tmp/test");
    FileInputSplit split2 = new FileInputSplit(ElemType.VERTEX, inputStruct, "/tmp/test");
    Assert.assertEquals(split1.hashCode(), split2.hashCode());
}
Also used : FileInputSplit(com.baidu.hugegraph.computer.core.input.loader.FileInputSplit) InputStruct(com.baidu.hugegraph.loader.mapping.InputStruct) Test(org.junit.Test)

Example 5 with InputStruct

use of com.baidu.hugegraph.loader.mapping.InputStruct in project hugegraph-computer by hugegraph.

the class FileInputSplitTest method testEquals.

@Test
public void testEquals() {
    InputStruct inputStruct = Mockito.mock(InputStruct.class);
    FileInputSplit split1 = new FileInputSplit(ElemType.VERTEX, inputStruct, "/tmp/test");
    FileInputSplit split2 = new FileInputSplit(ElemType.VERTEX, inputStruct, "/tmp/test");
    Assert.assertEquals(split1, split1);
    Assert.assertEquals(split1, split2);
    Assert.assertNotEquals(split1, null);
    Assert.assertNotEquals(split1, new Object());
    Assert.assertEquals(InputSplit.END_SPLIT, InputSplit.END_SPLIT);
    Assert.assertNotEquals(InputSplit.END_SPLIT, split1);
}
Also used : FileInputSplit(com.baidu.hugegraph.computer.core.input.loader.FileInputSplit) InputStruct(com.baidu.hugegraph.loader.mapping.InputStruct) Test(org.junit.Test)

Aggregations

InputStruct (com.baidu.hugegraph.loader.mapping.InputStruct)9 FileSource (com.baidu.hugegraph.loader.source.file.FileSource)5 FileInputSplit (com.baidu.hugegraph.computer.core.input.loader.FileInputSplit)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 InputSplit (com.baidu.hugegraph.computer.core.input.InputSplit)2 LoadMapping (com.baidu.hugegraph.loader.mapping.LoadMapping)2 EdgeMapping (com.baidu.hugegraph.entity.load.EdgeMapping)1 VertexMapping (com.baidu.hugegraph.entity.load.VertexMapping)1 InitException (com.baidu.hugegraph.loader.exception.InitException)1 LoadException (com.baidu.hugegraph.loader.exception.LoadException)1 ElementMapping (com.baidu.hugegraph.loader.mapping.ElementMapping)1 InputReader (com.baidu.hugegraph.loader.reader.InputReader)1 FileReader (com.baidu.hugegraph.loader.reader.file.FileReader)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