Nebula Importer

Nebula Importer(简称Importer)是一款Nebula Graph的CSV文件单机导入工具。Importer可以读取本地的CSV文件,然后导入数据至Nebula Graph图数据库中。

适用场景

Importer适用于将本地CSV文件的内容导入至Nebula Graph中。

优势

  • 轻量快捷:不需要复杂环境即可使用,快速导入数据。

  • 灵活筛选:通过配置文件可以实现对CSV文件数据的灵活筛选。

前提条件

在使用Nebula Importer之前,请确保:

操作步骤

配置yaml文件并准备好待导入的CSV文件,即可使用本工具向Nebula Graph批量写入数据。

源码编译运行

  1. 克隆仓库。

    1. $ git clone -b v2.6.0 https://github.com/vesoft-inc/nebula-importer.git

    Note

    请使用正确的分支。 Nebula Graph 1.x和2.x的rpc协议不同,因此:

    • Nebula Importer v1分支只能连接Nebula Graph 1.x。
    • Nebula Importer master分支和v2分支可以连接Nebula Graph 2.x。
  2. 进入目录nebula-importer

    1. $ cd nebula-importer
  3. 编译源码。

    1. $ make build
  4. 启动服务。

    1. $ ./nebula-importer --config <yaml_config_file_path>

    Note

    yaml配置文件说明请参见配置文件

无网络编译方式

如果服务器不能联网,建议在能联网的机器上将源码和各种依赖打包上传到对应的服务器上编译即可,操作步骤如下:

  1. 克隆仓库。

    1. $ git clone -b 2.6.0 https://github.com/vesoft-inc/nebula-importer.git
  2. 使用如下的命令下载并打包依赖的源码。

    1. $ cd nebula-importer
    2. $ go mod vendor
    3. $ cd .. && tar -zcvf nebula-importer.tar.gz nebula-importer
  3. 将压缩包上传到不能联网的服务器上。

  4. 解压并编译。

    1. $ tar -zxvf nebula-importer.tar.gz
    2. $ cd nebula-importer
    3. $ go build -mod vendor cmd/importer.go

Docker方式运行

使用Docker可以不必在本地安装Go语言环境,只需要拉取Nebula Importer的镜像,并将本地配置文件和CSV数据文件挂载到容器中。命令如下:

  1. $ docker run --rm -ti \
  2. --network=host \
  3. -v <config_file>:<config_file> \
  4. -v <csv_data_dir>:<csv_data_dir> \
  5. vesoft/nebula-importer:<version>
  6. --config <config_file>
  • <config_file>:本地yaml配置文件的绝对路径。
  • <csv_data_dir>:本地CSV数据文件的绝对路径。
  • <version>:Nebula Graph 2.x请填写v2

Note

建议使用相对路径。如果使用本地绝对路径,请检查路径映射到Docker中的路径。

配置文件说明

Nebula Importer通过nebula-importer/examples/v2/example.yaml配置文件来描述待导入文件信息、Nebula Graph服务器信息等。用户可以参考示例配置文件:无表头配置/有表头配置。下文将分类介绍配置文件内的字段。

基本配置

示例配置如下:

  1. version: v2
  2. description: example
  3. removeTempFiles: false
参数默认值是否必须说明
versionv2目标Nebula Graph的版本。
descriptionexample配置文件的描述。
removeTempFilesfalse是否删除临时生成的日志和错误数据文件。

客户端配置

客户端配置存储客户端连接Nebula Graph相关的配置。

示例配置如下:

  1. clientSettings:
  2. retry: 3
  3. concurrency: 10
  4. channelBufferSize: 128
  5. space: test
  6. connection:
  7. user: user
  8. password: password
  9. address: 192.168.11.13:9669,192.168.11.14:9669
  10. postStart:
  11. commands: |
  12. UPDATE CONFIGS storage:wal_ttl=3600;
  13. UPDATE CONFIGS storage:rocksdb_column_family_options = { disable_auto_compactions = true };
  14. afterPeriod: 8s
  15. preStop:
  16. commands: |
  17. UPDATE CONFIGS storage:wal_ttl=86400;
  18. UPDATE CONFIGS storage:rocksdb_column_family_options = { disable_auto_compactions = false };
参数默认值是否必须说明
clientSettings.retry3nGQL语句执行失败的重试次数。
clientSettings.concurrency10Nebula Graph客户端并发数。
clientSettings.channelBufferSize128每个Nebula Graph客户端的缓存队列大小。
clientSettings.space-指定数据要导入的Nebula Graph图空间。不要同时导入多个空间,以免影响性能。
clientSettings.connection.user-Nebula Graph的用户名。
clientSettings.connection.password-Nebula Graph用户名对应的密码。
clientSettings.connection.address-所有Graph服务的地址和端口。
clientSettings.postStart.commands-配置连接Nebula Graph服务器之后,在插入数据之前执行的一些操作。
clientSettings.postStart.afterPeriod-执行上述commands命令后到执行插入数据命令之间的间隔,例如8s
clientSettings.preStop.commands-配置断开Nebula Graph服务器连接之前执行的一些操作。

文件配置

文件配置存储数据文件和日志的相关配置,以及Schema的具体信息。

文件和日志配置

示例配置如下:

  1. logPath: ./err/test.log
  2. files:
  3. - path: ./student_without_header.csv
  4. failDataPath: ./err/studenterr.csv
  5. batchSize: 128
  6. limit: 10
  7. inOrder: false
  8. type: csv
  9. csv:
  10. withHeader: false
  11. withLabel: false
  12. delimiter: ","
参数默认值是否必须说明
logPath-导入过程中的错误等日志信息输出的文件路径。
files.path-数据文件的存放路径,如果使用相对路径,则会将路径和当前配置文件的目录拼接。可以使用星号(*)进行模糊匹配,导入多个名称相似的文件,但是文件的结构需要相同。
files.failDataPath-插入失败的数据文件存放路径,以便后面补写数据。
files.batchSize128单批次插入数据的语句数量。
files.limit-读取数据的行数限制。
files.inOrder-是否按顺序在文件中插入数据行。如果为false,可以避免数据倾斜导致的导入速率降低。
files.type-文件类型。
files.csv.withHeaderfalse是否有表头。详情请参见关于CSV文件表头
files.csv.withLabelfalse是否有LABEL。详情请参见有表头配置说明
files.csv.delimiter“,”指定csv文件的分隔符。只支持一个字符的字符串分隔符。

Schema配置

Schema配置描述当前数据文件的Meta信息,Schema的类型分为点和边两类,可以同时配置多个点或边。

  • 点配置

示例配置如下:

  1. schema:
  2. type: vertex
  3. vertex:
  4. vid:
  5. type: string
  6. index: 0
  7. tags:
  8. - name: student
  9. props:
  10. - name: name
  11. type: string
  12. index: 1
  13. - name: age
  14. type: int
  15. index: 2
  16. - name: gender
  17. type: string
  18. index: 3
参数默认值是否必须说明
files.schema.type-Schema的类型,可选值为vertexedge
files.schema.vertex.vid.type-点ID的数据类型,可选值为intstring
files.schema.vertex.vid.index-点ID对应CSV文件中列的序号。
files.schema.vertex.tags.name-Tag名称。
files.schema.vertex.tags.props.name-Tag属性名称,必须和Nebula Graph中的Tag属性一致。
files.schema.vertex.tags.props.type-属性数据类型,支持boolintfloatdoubletimestampstring
files.schema.vertex.tags.props.index-属性对应CSV文件中列的序号。

Note

CSV文件中列的序号从0开始,即第一列的序号为0,第二列的序号为1。

  • 边配置

示例配置如下:

  1. schema:
  2. type: edge
  3. edge:
  4. name: follow
  5. withRanking: true
  6. srcVID:
  7. type: string
  8. index: 0
  9. dstVID:
  10. type: string
  11. index: 1
  12. rank:
  13. index: 2
  14. props:
  15. - name: degree
  16. type: double
  17. index: 3
参数默认值是否必须说明
files.schema.type-Schema的类型,可选值为vertexedge
files.schema.edge.name-Edge type名称。
files.schema.edge.srcVID.type-边的起始点ID的数据类型。
files.schema.edge.srcVID.index-边的起始点ID对应CSV文件中列的序号。
files.schema.edge.dstVID.type-边的目的点ID的数据类型。
files.schema.edge.dstVID.index-边的目的点ID对应CSV文件中列的序号。
files.schema.edge.rank.index-边的rank值对应CSV文件中列的序号。
files.schema.edge.props.name-Edge type属性名称,必须和Nebula Graph中的Edge type属性一致。
files.schema.edge.props.type-属性类型,支持boolintfloatdoubletimestampstring
files.schema.edge.props.index-属性对应CSV文件中列的序号。

关于CSV文件表头(header)

Importer根据CSV文件有无表头,需要对配置文件进行不同的设置,相关示例和说明请参见:

视频


最后更新: September 17, 2021