暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

#gStore-weekly | gStore最新版1.2之空库的构建和批量数据构建

图谱学苑 2023-12-01
196

gStore1.2版本支持了空库的构建和批量数据构建,接下来我们将从本地命令、控制台、API接口三种方式来进行介绍如何使用:

1 使用本地命令构建

1.1 构建空库

通过本地命令构建数据库的方式如下,如果要构建一个空库,只要不指定-f
参数即可

$ bin/gbuild -db [db_name] -f [filename]
#Options:
#  -h, --help           Display this message.
#  -db,--database,      the database name. 
#  -f, --file[option],  the file path for building.

  • 参数-db
    : 指定数据库名

    -f
    : 数据文件路径,如果不指定则构建一个空库

  • 示例

    # 执行构建命令
    $ bin/gbuild -db blankDB
    #......
    #after Parsing, used 1ms.
    #write priviledge of update lock acquired
    #QueryCache cleared
    #Query time used (minus parsing): 0ms.
    #Total time used: 1ms.
    #Saving database info: update num 3
    #Build RDF database database_name successfully! Used 24 ms

    #
     查看blankDB信息
    $ bin/gmonitor -db blankDB
    #......
    #---------------------------------------
    #|     name      |        value        |
    #---------------------------------------
    #| database      | blankDB             |
    #| creator       | root                |
    #| built_time    | 2023-11-27 09:34:44 |
    #| triple_num    | 0                   |
    #| entity_num    | 0                   |
    #| literal_num   | 0                   |
    #| subject_num   | 0                   |
    #| predicate_num | 0                   |
    #| disk_used     | 0 MB                |
    #---------------------------------------

1.2 批量数据构建

如果有多个数据文件需要一次性构建到新库中,之前我们的做法是把多个文件合成一个大文件再执行构建命令,现在我们支持把多个文件打成一个压缩包(目前只支持zip包格式),再通过以下命令进行构建。

$ bin/gbuild -db [database_name] -f [zip_file_path]

  • 参数-db
    : 指定数据库名

    -f
    : 指定构建数据库的zip文件路径(数据文件处于zip包的更目录下)

    # zip文件结构示例
    |-lubm.zip
    |__lubm1.nt
    |__lubm2.nt
    |__lubm3.nt

  • 示例

    $ bin/gbuild -db batchDB -f ./data/lubm/lubm.zip
    #......
    #after Parsing, used 1ms.
    #write priviledge of update lock acquired
    #QueryCache cleared
    #Query time used (minus parsing): 0ms.
    #Total time used: 1ms.
    #Saving database info: update num 3
    #Build RDF database database_name successfully! Used 972 ms

2 使用gconsole构建

第二种方式可通过控制台来完成,首先通过gconsole进入控制台模式:

# 回车输入root用户密码
$ bin/gconsole -u root

# 进入控制台模式后将打印以下信息,并等待执行新的指令
#Gstore Console(gconsole), an interactive shell based utility to communicate with gStore repositories.
#Gstore version: 1.2 Source distribution
#Copyright (c) 2016, 2022, pkumod and/or its affiliates.

#Welcome to the gStore Console.
#Commands end with ;. Cross line input is allowed.
#Comment start with #. Redirect (> and >>) is supported.
#CTRL+C to quit current command. CTRL+D to exit this console.
#Type 'help;' for help. 

#File open failed: bin/.gconsole_history/root
$ gstore[no database]> 

2.1 构建空库

$ create [database_name];

  • 参数database_name
    : 数据库名

  • 返回值

    执行成功后,控制台会打印如下信息

    ......
    finish encode.
    Finish sub2id pre2id obj2id
    TripleNum is 1
    EntityNum is 1
    PreNum is 1
    LiteralNum is 1
    Database database_namecreated successfully.

2.2 批量数据构建

create [database_name] [zip_file_path];

  • 参数database_name
    : 数据库名zip_file_path
    : 构建数据库的zip文件路径

  • 返回值

    执行成功后,控制台会打印如下信息

    ......
    finish encode.
    Finish sub2id pre2id obj2id
    TripleNum is 26
    EntityNum is 33
    PreNum is 1
    LiteralNum is 9
    Database database_namcreated successfully. 

3 使用API构建

第三种方式就是通过API接口来完成,首先需要启动API接口服务,grpc
ghttp
均可(不建议二者同时启动)

# grpc服务
$ bin/grpc -p 9000

# ghttp服务
$ bin/ghttp -p 9000

  • 请求URLgrpc:  http://127.0.0.1:9000/grpc/api

    ghttp: http://localhost:9000

  • 参数

    参数名必选类型说明
    operationstring操作名称,固定值为**build
    **
    usernamestring用户名
    passwordstring密码(明文)
    encryptionstring为空,则密码为明文,为1表示用md5加密
    db_namestring数据库名称
    db_pathstring数据库文件路径(可以是绝对路径,也可以是相对路径,相对路径以gStore根目录为参照目录),路径为空即构建空库

3.1 构建空库

  • 请求参数

    {
        "operation""build",
        "username""root",
        "password""123456",
        "encryption""0",
        "db_name""blankDB"
    }

  • 请求示例

    # grpc示例
    $ curl -H "Content-Type: application/json" -d '{"username":"root","password":"123456","encryption":"0","operation":"build","db_name":"blankDB"}' http://127.0.0.1:9000/grpc/api

    #
     ghttp示例
    $ curl -H "Content-Type: application/json" -d '{"username":"root","password":"123456","encryption":"0","operation":"build","db_name":"blankDB"}' http://127.0.0.1:9000

  • 返回值

    {"StatusCode":0,"StatusMsg":"Import RDF file to database done.","failed_num":0}

3.2 批量数据构建

  • 请求参数

    {
        "operation""build",
        "username""root",
        "password""123456",
        "encryption""0",
        "db_name""batchDB",
        "db_path""./upload/lubm.zip"
    }

    【备注】zip文件可以通过upload接口(详见接口文档)上传到服务器,zip文件结构见1.2中zip文件结构示例

  • 请求示例

    # grpc示例
    $ curl -H "Content-Type: application/json" -d '{"username":"root","password":"123456","encryption":"0","operation":"build","db_name":"batchDB","db_path":"./upload/lubm.zip"}' http://127.0.0.1:9000/grpc/api

    #
     ghttp示例
    $ curl -H "Content-Type: application/json" -d '{"username":"root","password":"123456","encryption":"0","operation":"build","db_name":"batchDB","db_path":"./upload/lubm.zip"}' http://127.0.0.1:9000

  • 返回值

    {"StatusCode":0,"StatusMsg":"Import RDF file to database done.","failed_num":0}

以上为gStore1.2中支持空库构建和批量数据构建的使用详解,下一篇我们将介绍gStore1.2中新增内置高级函数的使用详解。



有任何问题可添加以下二维码联系我们的运营同学。

诚邀大家参加
·gStore-weekly技术文章征集活动·
  相关技术文章,包含但不限于以下内容:系统技术解析、案例分享、实践总结、开发心得、客户案例、使用技巧、学习笔记等。文章要求原创。
  入选周刊即送精美礼品~
欢迎关注北京大学王选计算机研究所数据管理实验室微信公众号“图谱学苑“
实验室官网:https://mod.wict.pku.edu.cn/
微信社区群:请回复“社区”获取
实验室开源产品图数据库gStore:
gStore官网:https://www.gstore.cn/
GitHub:https://github.com/pkumod/gStore
Gitee:https://gitee.com/PKUMOD/gStore

文章转载自图谱学苑,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论