nebula-importer 导入csv报错

  • nebula 2.0.1版本
  • 部署方式( 单机 ):
  • 是否为线上版本:Y

报错信息为:

[root@test-oa-app cmd]# ./nebula-importer --config /home/fintech/nebula-importer/examples/v2/Industry.yaml
2021/07/20 11:12:35 --- START OF NEBULA IMPORTER ---
2021/07/20 11:12:35 yaml: invalid trailing UTF-8 octet
2021/07/20 11:12:36 --- END OF NEBULA IMPORTER ---

Industry.yaml配置为

version: v2

description: example

# 是否删除临时生成的日志和错误数据文件。
removeTempFiles: false

clientSettings:

  # nGQL语句执行失败的重试次数。
  retry: 3

  # Nebula Graph客户端并发数。
  concurrency: 10

  # 每个Nebula Graph客户端的缓存队列大小。
  channelBufferSize: 128

  # 指定数据要导入的Nebula Graph图空间。
  space: inc_local

  # 连接信息。
  connection:
    user: user
    password: password
    address: 100.65.240.45:9669


  postStart:
    # 配置连接Nebula Graph服务器之后,在插入数据之前执行的一些操作。
    commands: |
      DROP SPACE IF EXISTS inc_local;
      CREATE SPACE IF NOT EXISTS inc_local(partition_num=5, replica_factor=1, vid_type=FIXED_STRING(300));
      USE inc_local;
      CREATE TAG IF NOT EXISTS Industry(code string,name string,parent string,level string,is_leaf string,remark string);
	  CREATE TAG IF NOT EXISTS IndustryMinceRelationship(type int DEFAULT 3,level string,relation_type string DEFAULT '细分');

    # 执行上述命令后到执行插入数据命令之间的间隔。
    afterPeriod: 15s

  preStop:
    # 配置断开Nebula Graph服务器连接之前执行的一些操作。
    commands: |

# 错误等日志信息输出的文件路径。    
logPath: ./err/test.log

# CSV文件相关设置。
files:

    # 数据文件的存放路径,如果使用相对路径,则会将路径和当前配置文件的目录拼接。本示例第一个数据文件为点的数据。
  - path: ./Industry.csv

    # 插入失败的数据文件存放路径,以便后面补写数据。
    failDataPath: ./err/Industryerr.csv

    # 单批次插入数据的语句数量。
    batchSize: 10

    # 读取数据的行数限制。
    limit: 10

    # 是否按顺序在文件中插入数据行。如果为false,可以避免数据倾斜导致的导入速率降低。
    inOrder: true

    # 文件类型,当前仅支持csv。
    type: csv

    csv:
      # 是否有表头。
      withHeader: false

      # 是否有LABEL。
      withLabel: false

      # 指定csv文件的分隔符。只支持一个字符的字符串分隔符。
      delimiter: ","

    schema:
      # Schema的类型,可选值为vertex和edge。
      type: vertex

      vertex:

        # 点ID设置。
        vid:
           # 点ID对应CSV文件中列的序号。CSV文件中列的序号从0开始。
           index: 0

           # 点ID的数据类型,可选值为int和string,分别对应Nebula Graph中的INT64和FIXED_STRING。
           type: string

        # 标签设置。  
        tags:
            # 标签名称。
          - name: Industry

            # 标签内的属性设置。
            props:
                # 属性名称。
              - name: name

                # 属性数据类型。
                type: string

                # 属性对应CSV文件中列的序号。
                index: 1

              - name: parent
                type: string
                index: 2
              - name: level
                type: string
                index: 3
			  - name: is_leaf
                type: string
                index: 4
              - name: remark
                type: string
                index: 5
				
- path: ./Industry.csv
    failDataPath: ./err/IndustryMinceRelationshiperr.csv
    batchSize: 10
    limit: 10
    inOrder: true
    type: csv
    csv:
      withHeader: false
      withLabel: false
    schema:
      # Schema的类型为edge。
      type: edge
      edge:
        # 边类型名称。
        name: IndustryMinceRelationship

        # 是否包含rank。
        withRanking: false

        # 起始点ID设置。
        srcVID:
           # 数据类型。
           type: string

           # 起始点ID对应CSV文件中列的序号。
           index: 2

        # 目的点ID设置。
        dstVID:
           type: string
           index: 0
        # 边类型内的属性设置。
        props:
             # 属性名称。
           - level: level

             # 属性数据类型。
             type: string

             # 属性对应CSV文件中列的序号。
             index: 3 

Industry.csvcsv文件数据为:
3404040518,氨糖软骨素加钙片,34040405,5,1,
3404040517,多维素片,34040405,5,1,
3404040519,母婴营养品,34040405,5,1,
28020102010111,前悬浮拱形座,280201020101,7,1,
3404040514,益生菌粉,34040405,5,1,
61020103,其他玻璃,610201,4,0,
28020102010110,前翼子板,280201020101,7,1,

不知道是不是论坛格式的原因,您这个配置有好几个缩进问题,改的过程中有一些 yaml: 的问题,没能重现您的问题,我改了一下,能跑起来,

version: v2

description: example

# 是否删除临时生成的日志和错误数据文件。
removeTempFiles: false

clientSettings:

  # nGQL语句执行失败的重试次数。
  retry: 3
  # Nebula Graph客户端并发数。
  concurrency: 1
  # 每个Nebula Graph客户端的缓存队列大小。
  channelBufferSize: 128
  # 指定数据要导入的Nebula Graph图空间。
  space: inc_local
  # 连接信息。
  connection:
    user: root
    password: password
    address: 192.168.8.96:32410
  postStart:
    # 配置连接Nebula Graph服务器之后,在插入数据之前执行的一些操作。
    commands: |
      DROP SPACE IF EXISTS inc_local;
      CREATE SPACE IF NOT EXISTS inc_local(partition_num=5, replica_factor=1, vid_type=FIXED_STRING(300));
      USE inc_local;
      CREATE TAG IF NOT EXISTS Industry(code string,name string,parent string,level string,is_leaf string,remark string);
      CREATE TAG IF NOT EXISTS IndustryMinceRelationship(type int DEFAULT 3,level string,relation_type string DEFAULT '细分');
    # 执行上述命令后到执行插入数据命令之间的间隔。
    afterPeriod: 15s
  preStop:
    # 配置断开Nebula Graph服务器连接之前执行的一些操作。
    commands: USE inc_local; # put some random lines instead of the empty...

# 错误等日志信息输出的文件路径。    
logPath: ./err/test.log

# CSV文件相关设置。
files:
    # 数据文件的存放路径,如果使用相对路径,则会将路径和当前配置文件的目录拼接。本示例第一个数据文件为点的数据。
  - path: ./Industry.csv
    # 插入失败的数据文件存放路径,以便后面补写数据。
    failDataPath: ./err/Industryerr.csv
    # 单批次插入数据的语句数量。
    batchSize: 6
    # 读取数据的行数限制。
    limit: 6
    # 是否按顺序在文件中插入数据行。如果为false,可以避免数据倾斜导致的导入速率降低。
    inOrder: true
    # 文件类型,当前仅支持csv。
    type: csv
    csv:
      # 是否有表头。
      withHeader: false
      # 是否有LABEL。
      withLabel: false
      # 指定csv文件的分隔符。只支持一个字符的字符串分隔符。
      delimiter: ","
    schema:
      # Schema的类型,可选值为vertex和edge。
      type: vertex
      vertex:
        # 点ID设置。
        vid:
           # 点ID对应CSV文件中列的序号。CSV文件中列的序号从0开始。
           index: 0
           # 点ID的数据类型,可选值为int和string,分别对应Nebula Graph中的INT64和FIXED_STRING。
           type: string
        # 标签设置。  
        tags:
            # 标签名称。
          - name: Industry
            # 标签内的属性设置。
            props:
                # 属性名称。
              - name: name
                # 属性数据类型。
                type: string
                # 属性对应CSV文件中列的序号。
                index: 1
              - name: parent
                type: string
                index: 2
              - name: level
                type: string
                index: 3
              - name: is_leaf
                type: string
                index: 4
              - name: remark
                type: string
                index: 5
        
  - path: ./Industry.csv
    failDataPath: ./err/IndustryMinceRelationshiperr.csv
    batchSize: 6
    limit: 6
    inOrder: true
    type: csv
    csv:
      withHeader: false
      withLabel: false
    schema:
      # Schema的类型为edge。
      type: edge
      edge:
        # 边类型名称。
        name: IndustryMinceRelationship
        # 是否包含rank。
        withRanking: false
        # 起始点ID设置。
        srcVID:
           # 数据类型。
           type: string
           # 起始点ID对应CSV文件中列的序号。
           index: 2
        # 目的点ID设置。
        dstVID:
           type: string
           index: 0
        # 边类型内的属性设置。
        props:
             # 属性名称。
           - level: level
             # 属性数据类型。
             type: string
             # 属性对应CSV文件中列的序号。
             index: 3 

  1. preStop commands 后边的 | 表示是有内容的,这么留空应该不行
  preStop:
    # 配置断开Nebula Graph服务器连接之前执行的一些操作。

    commands: |
  1. 第二个 file path 缩进不对

files:

    # 数据文件的存放路径,如果使用相对路径,则会将路径和当前配置文件的目录拼接。本示例第一个数据文件为点的数据。
  - path: ./Industry.csv

    # 插入失败的数据文件存放路径,以便后面补写数据。
    failDataPath: ./err/Industryerr.csv
...
- path: ./Industry.csv  #<---------
    failDataPath: ./err/IndustryMinceRelationshiperr.csv
    batchSize: 10
    limit: 10

不能用记事本编辑yaml文件

如果你觉得上面的 wey 的回复解决了你的问题,可以勾选为【解决方案】哈,谢谢 liaochunlin

嗯嗯,推荐使用现代的文本编辑器,而且最好不引入 windows/dos newline char 的。

schema:
# Schema的类型,可选值为vertex和edge。
type: vertex
vertex:
# 点ID设置。
vid:

现在ivd这一行报found character that cannot start any token

这个也是格式问题,我解决了

1 个赞

检查,不要混用 tab 与 space

ref: YAML error: found character that cannot start any token · Issue #1 · moraes/config · GitHub

复制粘贴进来的内容很容易报格式问题,只能删除报错的哪一行,重新手输入

还有怎么yaml文件设置vid的前缀,跟数据拼接起来

@jievince 的帮忙下,又找到一个错误的地方

        props:
             # 属性名称。
           - name: level # <--------这里 原来写成了level: level
             # 属性数据类型。
             type: string
             # 属性对应CSV文件中列的序号。
             index: 3 

另外,我往下执行发现你把 IndustryMinceRelationship 创建成了 TAG,他应该是边才对

CREATE TAG IF NOT EXISTS IndustryMinceRelationship(type int DEFAULT 3,level string,relation_type string DEFAULT '细分');

现在 importer 没有加 prefix 的功能,您可以来提一个 feature request 在 github,只能预处理 CSV 文件本身加上 prefix 哈

我改好了一份在我这里能跑通的给你参考哈:

Archive.zip (2.2 KB)

❯ docker run --rm -ti \
    -v ${HOME}/importer/nebula-importer.yaml:/root/nebula-importer.yaml \
    -v ${HOME}/importer:/root \
    vesoft/nebula-importer:latest \
    --config /root/nebula-importer.yaml
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
2021/07/20 06:45:09 --- START OF NEBULA IMPORTER ---
2021/07/20 06:45:09 [INFO] connection_pool.go:77: [nebula-clients] connection pool is initialized successfully
2021/07/20 06:45:24 [INFO] clientmgr.go:28: Create 1 Nebula Graph clients
2021/07/20 06:45:24 [INFO] reader.go:26: The delimiter of /root/Industry.csv is U+002C ','
2021/07/20 06:45:24 [INFO] reader.go:64: Start to read file(0): /root/Industry.csv, schema: < :VID(string),Industry.name:string,Industry.parent:string,Industry.level:string,Industry.is_leaf:string,Industry.remark:string >
2021/07/20 06:45:24 [INFO] reader.go:64: Start to read file(1): /root/Industry.csv, schema: < :DST_VID(string),:IGNORE,:SRC_VID(string),IndustryMinceRelationship.level:string >
2021/07/20 06:45:24 [INFO] reader.go:180: Total lines of file(/root/Industry.csv) is: 6, error lines: 0
2021/07/20 06:45:24 [INFO] reader.go:180: Total lines of file(/root/Industry.csv) is: 6, error lines: 0
2021/07/20 06:45:24 [INFO] statsmgr.go:61: Done(/root/Industry.csv): Time(15.17s), Finished(6), Failed(0), Latency AVG(2791us), Batches Req AVG(18705us), Rows AVG(0.40/s)
2021/07/20 06:45:24 [INFO] statsmgr.go:61: Done(/root/Industry.csv): Time(15.19s), Finished(12), Failed(0), Latency AVG(2794us), Batches Req AVG(20260us), Rows AVG(0.79/s)
2021/07/20 06:45:25 Finish import data, consume time: 15.73s
2021/07/20 06:45:26 --- END OF NEBULA IMPORTER ---
1 个赞

谢谢

[root@test-oa-app cmd]# ./nebula-importer --config /home/fintech/nebula-importer/examples/v2/Industry.yaml
2021/07/20 16:08:56 --- START OF NEBULA IMPORTER ---
2021/07/20 16:08:56 [INFO] connection_pool.go:77: [nebula-clients] connection pool is initialized successfully
2021/07/20 16:08:56 [INFO] clientmgr.go:28: Create 10 Nebula Graph clients
2021/07/20 16:08:56 [INFO] reader.go:64: Start to read file(1): /home/fintech/nebula-importer/examples/v2/Industry.csv, schema: < :DST_VID(string),:IGNORE,:SRC_VID(string),IndustryMinceRelationship.level:string >
2021/07/20 16:08:56 [INFO] reader.go:26: The delimiter of /home/fintech/nebula-importer/examples/v2/Industry.csv is U+002C ','
2021/07/20 16:08:56 [INFO] reader.go:180: Total lines of file(/home/fintech/nebula-importer/examples/v2/Industry.csv) is: 10, error lines: 0
2021/07/20 16:08:56 [INFO] reader.go:64: Start to read file(0): /home/fintech/nebula-importer/examples/v2/Industry.csv, schema: < :VID(string)/Industry.code:string,Industry.name:string,Industry.parent:string,Industry.level:string,Industry.is_leaf:ststring >
2021/07/20 16:08:56 [INFO] reader.go:180: Total lines of file(/home/fintech/nebula-importer/examples/v2/Industry.csv) is: 10, error lines: 0
2021/07/20 16:08:59 [ERROR] handler.go:63: Client 0 fail to execute: INSERT EDGE `IndustryMinceRelationship`(`level`) VALUES  "280201020101"->"28020102010111":("7") ;, ErrMsg: EdgeName `IndustryMinceRelationship'  is nonexistent, ErrCode: -8
2021/07/20 16:08:59 [ERROR] handler.go:63: Client 8 fail to execute: INSERT VERTEX `Industry`(`code`,`name`,`parent`,`level`,`is_leaf`,`remark`) VALUES  "61020102": ("61020102","深加工玻璃","610201","4","0","");, ErrMsg: SemanticError: No schema fourCode: -12
2021/07/20 16:08:59 [ERROR] handler.go:63: Client 9 fail to execute: INSERT EDGE `IndustryMinceRelationship`(`level`) VALUES  "34040405"->"3404040517":("5") , "280201020101"->"28020102010110":("7") , "34040405"->"3404040513":("5") ;, ErrMsg: EdgeNamionship'  is nonexistent, ErrCode: -8
2021/07/20 16:08:59 [ERROR] handler.go:63: Client 5 fail to execute: INSERT EDGE `IndustryMinceRelationship`(`level`) VALUES  "34040405"->"3404040516":("5") ;, ErrMsg: EdgeName `IndustryMinceRelationship'  is nonexistent, ErrCode: -8
2021/07/20 16:08:59 [ERROR] handler.go:63: Client 7 fail to execute: INSERT EDGE `IndustryMinceRelationship`(`level`) VALUES  "34040405"->"\ufeff3404040518":("5") ;, ErrMsg: EdgeName `IndustryMinceRelationship'  is nonexistent, ErrCode: -8
2021/07/20 16:08:59 [ERROR] handler.go:63: Client 4 fail to execute: INSERT EDGE `IndustryMinceRelationship`(`level`) VALUES  "34040405"->"3404040514":("5") ;, ErrMsg: EdgeName `IndustryMinceRelationship'  is nonexistent, ErrCode: -8
2021/07/20 16:08:59 [ERROR] handler.go:63: Client 3 fail to execute: INSERT EDGE `IndustryMinceRelationship`(`level`) VALUES  "34040405"->"3404040519":("5") , "610201"->"61020102":("4") ;, ErrMsg: EdgeName `IndustryMinceRelationship'  is nonexistent
2021/07/20 16:08:59 [ERROR] handler.go:63: Client 6 fail to execute: INSERT VERTEX `Industry`(`code`,`name`,`parent`,`level`,`is_leaf`,`remark`) VALUES  "3404040513": ("3404040513","胶原蛋白粉","34040405","5","1","");, ErrMsg: SemanticError: No schey', ErrCode: -12
2021/07/20 16:08:59 [ERROR] handler.go:63: Client 2 fail to execute: INSERT EDGE `IndustryMinceRelationship`(`level`) VALUES  "610201"->"61020103":("4") ;, ErrMsg: EdgeName `IndustryMinceRelationship'  is nonexistent, ErrCode: -8
2021/07/20 16:08:59 [INFO] statsmgr.go:61: Done(/home/fintech/nebula-importer/examples/v2/Industry.csv): Time(3.05s), Finished(12), Failed(12), Latency AVG(0us), Batches Req AVG(0us), Rows AVG(3.94/s)
2021/07/20 16:09:01 [INFO] statsmgr.go:61: Tick: Time(5.00s), Finished(12), Failed(12), Latency AVG(0us), Batches Req AVG(0us), Rows AVG(2.40/s)
2021/07/20 16:09:02 [ERROR] handler.go:63: Client 0 fail to execute: INSERT VERTEX `Industry`(`code`,`name`,`parent`,`level`,`is_leaf`,`remark`) VALUES  "61020103": ("61020103","其他玻璃","610201","4","0",""), "28020102010110": ("28020102010110","前","7","1","");, ErrMsg: SemanticError: No schema found for `Industry', ErrCode: -12
2021/07/20 16:09:02 [ERROR] handler.go:63: Client 9 fail to execute: INSERT VERTEX `Industry`(`code`,`name`,`parent`,`level`,`is_leaf`,`remark`) VALUES  "\ufeff3404040518": ("\ufeff3404040518","氨糖软骨素加钙片","34040405","5","1",""), "3404040517":素片","34040405","5","1","");, ErrMsg: SemanticError: No schema found for `Industry', ErrCode: -12
2021/07/20 16:09:02 [ERROR] handler.go:63: Client 3 fail to execute: INSERT VERTEX `Industry`(`code`,`name`,`parent`,`level`,`is_leaf`,`remark`) VALUES  "3404040516": ("3404040516","钙铁锌咀嚼片","34040405","5","1","");, ErrMsg: SemanticError: No sctry', ErrCode: -12
2021/07/20 16:09:02 [ERROR] handler.go:63: Client 5 fail to execute: INSERT VERTEX `Industry`(`code`,`name`,`parent`,`level`,`is_leaf`,`remark`) VALUES  "3404040514": ("3404040514","益生菌粉","34040405","5","1","");, ErrMsg: SemanticError: No schema, ErrCode: -12
2021/07/20 16:09:02 [ERROR] handler.go:63: Client 4 fail to execute: INSERT VERTEX `Industry`(`code`,`name`,`parent`,`level`,`is_leaf`,`remark`) VALUES  "28020102010111": ("28020102010111","前悬浮拱形座","280201020101","7","1","");, ErrMsg: Semanticd for `Industry', ErrCode: -12
2021/07/20 16:09:02 [ERROR] handler.go:63: Client 7 fail to execute: INSERT VERTEX `Industry`(`code`,`name`,`parent`,`level`,`is_leaf`,`remark`) VALUES  "3404040519": ("3404040519","母婴营养品","34040405","5","1","");, ErrMsg: SemanticError: No schey', ErrCode: -12
2021/07/20 16:09:02 [INFO] statsmgr.go:61: Done(/home/fintech/nebula-importer/examples/v2/Industry.csv): Time(6.05s), Finished(20), Failed(20), Latency AVG(0us), Batches Req AVG(0us), Rows AVG(3.31/s)
2021/07/20 16:09:03 Total 20 lines fail to insert into nebula graph database
2021/07/20 16:09:04 --- END OF NEBULA IMPORTER ---

比如这个报错 ,就指向 IndustryMinceRelationship 这个 EDGE不存在,请保证这个 EDGE 被创建了我给你的例子里就修改了你本来的 create tag 为 create edge。

剩下的报错请一个一个去仔细看看哈。

2021/07/20 16:08:59 [ERROR] handler.go:63: Client 0 fail to execute: INSERT EDGE `IndustryMinceRelationship`(`level`) VALUES  "280201020101"->"28020102010111":("7") ;, ErrMsg: EdgeName `IndustryMinceRelationship'  is nonexistent, ErrCode: -8

nebula-importer是先创建 tag,tag创建完才创建edge吗?我想要的效果是先创建完tag,然后才创建edge,而不是一边创建tag,一边创建edge,这样肯定会报不存在。

这个yaml怎么配置啊,先创建tag,在创建edge,还有应该能创建部分数据啊,为什么没创建部分数据

而不是一遇到不存在,报措,下面存在的数据就不创建了