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

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接口服务,grpcghttp均可(不建议二者同时启动)

复制代码
# grpc服务
$ bin/grpc -p 9000

# ghttp服务
$ bin/ghttp -p 9000
  • 请求URL grpc: http://127.0.0.1:9000/grpc/api

    ghttp: http://localhost:9000

  • 参数

    参数名 必选 类型 说明
    operation string 操作名称,固定值为**build**
    username string 用户名
    password string 密码(明文)
    encryption string 为空,则密码为明文,为1表示用md5加密
    db_name string 数据库名称
    db_path string 数据库文件路径(可以是绝对路径,也可以是相对路径,相对路径以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中新增内置高级函数的使用详解。

相关推荐
卜及中1 小时前
【Redis/2】核心特性、应用场景与安装配置
数据库·redis·缓存
LucianaiB1 小时前
如何做好一份优秀的技术文档:专业指南与最佳实践
android·java·数据库
Eiceblue1 小时前
Python读取PDF:文本、图片与文档属性
数据库·python·pdf
码农101号2 小时前
Linux中shell编程表达式和数组讲解
linux·运维·服务器
是小满满满满吗2 小时前
传输层:udp与tcp协议
linux·服务器·网络
Mintimate3 小时前
云服务器 Linux 手动 DD 安装第三方 Linux 发行版:原理与实战
linux·运维·服务器
RussellFans3 小时前
Linux 环境配置
linux·运维·服务器
网硕互联的小客服3 小时前
503 Service Unavailable:服务器暂时无法处理请求,可能是超载或维护中如何处理?
服务器·git·github
高冷的肌肉码喽4 小时前
Linux-进程间的通信
linux·运维·服务器
敖云岚4 小时前
【Redis】分布式锁的介绍与演进之路
数据库·redis·分布式