그래프 데이터베이스 일괄 가져오기(HugeGraph-Loader)
Chapter
1 링크: 그래프 데이터베이스 일괄 가져오기(HugeGraph-Loader)
머리말
HugeGraph-Loader는 HugeGraph의 데이터 가져오기 구성 요소로, 다양한 데이터 소스의 데이터를 그래프 정점 및 가장자리로 변환하고 일괄적으로 그래프 데이터베이스로 가져올 수 있습니다.
현재 지원되는 데이터 소스는 다음과 같습니다.
- 로컬 디스크 파일 또는 디렉토리, TEXT, CSV 및 JSON 형식 파일 지원, 압축 파일 지원
- HDFS 파일 또는 디렉터리, 압축 파일 지원
- MySQL, PostgreSQL, Oracle, SQL Server 로컬 디스크 파일 및 HDFS 파일과 같은 주류 관계형 데이터베이스는 재개 가능한 업로드를 지원합니다.
1. 로더 실행 과정
HugeGraph-Loader를 사용하는 기본 프로세스는 다음 단계로 나뉩니다.
- 그래프 모델 작성
- 데이터 파일 준비
- 입력 소스 맵 파일 작성
- 명령 가져오기 실행
둘, csv 파일 불러오기
1. 데이터 매핑 파일
데이터 매핑 파일은 다음과 같으며, csv 파일에 헤더가 있는 경우 입력 아래 헤더에 값을 할당할 필요가 없으며, 할당하면 첫 번째 줄을 데이터 분석으로 사용합니다.
{
"version": "2.0",
"structs": [{
"id": "1",
"skip": false,
"input": {
"type": "FILE",
"path": "/mnt/parastor/aimind/kg-resources/Oakcsys1/d2r/job-63c3b6727701166100cd7426/file-mapping-7f19ceeea95a417495bc33bd54fa1bf9/人员列表1.csv",
"file_filter": {
"extensions": ["*"]
},
"format": "CSV",
"delimiter": ",",
"date_format": "yyyy-MM-dd HH:mm:ss",
"time_zone": "GMT+8",
"skipped_line": {
"regex": "(^#|^//).*|"
},
"compression": "NONE",
"batch_size": 500,
"header": null,
"charset": "GBK",
"list_format": {
"start_symbol": "",
"end_symbol": "",
"elem_delimiter": "|",
"ignored_elems": [""]
}
},
"vertices": [{
"label": "ry",
"skip": false,
"id": "姓名",
"unfold": true,
"field_mapping": {
"年龄": "nl",
"性别": "xb"
},
"value_mapping": {
},
"selected": ["姓名", "年龄", "性别"],
"ignored": [],
"null_values": ["Null"],
"update_strategies": {
},
"field_formats": []
}],
"edges": []
}]
}
셋, json 파일 가져오기
1. 데이터 매핑 파일
데이터 매핑 파일은 다음과 같습니다. json 파일에는 헤더가 없으며 헤더에 값을 할당해야 합니다. json 형식은 한 줄에 JSON 데이터 집합입니다. 예: {“name”: “
marko
”, “sex” : "남성", "나이": "12" , "체중": "0.4"} {
"이름": "조쉬", "성별": "여성", "나이": "16", "체중": "0.4"}
{
"version": "2.0",
"structs": [{
"id": "1",
"skip": false,
"input": {
"type": "FILE",
"path": "C:\\Users\\kmliu\\Desktop\\上传文件2\\t_user3.json",
"file_filter": {
"extensions": ["*"]
},
"format": "JSON",
"delimiter": ",",
"date_format": "yyyy-MM-dd HH:mm:ss",
"time_zone": "GMT+8",
"skipped_line": {
"regex": "(^#|^//).*|"
},
"compression": "NONE",
"batch_size": 500,
"header": ["sex", "name", "weight", "age"],
"charset": "UTF-8",
"list_format": {
"start_symbol": "",
"end_symbol": "",
"elem_delimiter": "|",
"ignored_elems": [""]
}
},
"vertices": [{
"label": "ry2",
"skip": false,
"id": "name",
"unfold": true,
"field_mapping": {
"sex": "sex",
"age": "age"
},
"value_mapping": {
},
"selected": ["sex", "name", "age"],
"ignored": [],
"null_values": ["Null"],
"update_strategies": {
},
"field_formats": []
}],
"edges": []
}]
}
세 번째, mysql 데이터 가져오기
1. 데이터 매핑 파일
데이터 매핑 파일은 다음과 같습니다.
{
"version": "2.0",
"structs": [{
"id": "1",
"skip": false,
"input": {
"type": "JDBC",
"vendor": "MYSQL",
"header": ["id", "name", "age", "sex"],
"charset": "UTF-8",
"list_format": {
"start_symbol": "",
"end_symbol": "",
"elem_delimiter": "|",
"ignored_elems": [""]
},
"driver": "com.mysql.cj.jdbc.Driver",
"url": "jdbc:mysql://xxx.xxx.xxx.xxx:3306",
"database": "baseName",
"schema": null,
"table": "user3",
"username": "root",
"password": "root",
"batch_size": 500,
"primary_key": "name"
},
"vertices": [{
"label": "ry",
"skip": false,
"id": "name",
"unfold": true,
"field_mapping": {
"age": "nl",
"sex": "xb"
},
"value_mapping": {
},
"selected": ["sex", "name", "age"],
"ignored": [],
"null_values": ["Null"],
"update_strategies": {
},
"field_formats": []
}],
"edges": []
}]
}
4. hugGraph 호출 단계
1. 호출 방식 입력
매개변수 Oakcsys1은 그래프 데이터베이스의 집합명사이고, json1.json은 데이터 매핑 파일이다. 그래프 데이터베이스 주소 및 IP.
public static void main(String[] args) {
// -g {GRAPH_NAME} -f ${INPUT_DESC_FILE} -s ${SCHEMA_FILE} -h {HOST} -p {PORT}
if (args.length == 0) {
args = new String[]{
"-g", "Oakcsys1",
"-f", "C:\\Users\\kmliu\\Desktop\\上传文件2\\json1.json",
"-h", "xxx.xx.xx.xx", "-p", "18081"
};
}
HugeGraphLoader loader;
try {
loader = new HugeGraphLoader(args);
} catch (Throwable e) {
Printer.printError("Failed to start loading", e);
return;
}
loader.load();
}
5. 데이터 로그 가져오기
1. 로그는 다음과 같다
: -----映射任务运行中-日志打印-----
: --------------------------------------------------
: detail metrics
: input-struct '1'
: read success : 4
: read failure : 0
: vertex 'ry'
: parse success : 4
: parse failure : 0
: insert success : 4
: insert failure : 0
: --------------------------------------------------
: count metrics
: input read success : 4
: input read failure : 0
: vertex parse success : 4
: vertex parse failure : 0
: vertex insert success : 4
: vertex insert failure : 0
: edge parse success : 0
: edge parse failure : 0
: edge insert success : 0
: edge insert failure : 0
: --------------------------------------------------
: meter metrics
: total time : 5.549s
: vertex load rate(vertices/s) : 0
: edge load rate(edges/s) : 0
: -----映射任务运行中-日志打印结束-----
요약하다
위는 그래프 데이터베이스로 데이터 세트를 가져오는 데 주로 사용되는 HugeGraphLoader를 사용하기 위한 기본 단계이며 csv, json, txt, mysql, hive 등의 데이터 가져오기를 지원합니다. 수입이 빠르다