D2RQ 使用笔记

安装

d2rq 主页下载即可

# 下载 d2rq-0.8.1 包
$ wget https://github.com/downloads/d2rq/d2rq/d2rq-0.8.1.zip

# 解压
unzip d2rq-0.8.1.zip

使用

# 生成 ttl 映射文件
# 命令格式: generate-mapping -o <mapping ttl 配置文件> -d <jdbc driver> -u <username> -p <password> --tables <指定表, 多表用逗号链接> jdbc-url 
$ generate-mapping -o mapping.ttl -d org.postgresql.Driver -u dev -p dev123 --tables tbl_stock_list,tbl_stock_company  jdbc:postgresql://172.29.9.19/tushare

# 发布 rdf 服务,http://localhost:2020/ 即可查看结果, 也可以使用 http://localhost:2020/sparql 用 jena 来查询数据
$ d2r-server mapping.ttl

# 以 sparql 查询
$ d2r-query mapping.ttl "SELECT * { ?s ?p ?o } LIMIT 10"

# 使用 dump-rdf 工具转存为 rdf 信息, 输出为 nt 格式
$ dump-rdf -o stock_company.nt mapping.ttl

http://localhost:2020 类显示主页
http://localhost:2020/sparql sparql 查询接口
http://localhost:2020/snorql/ 界面化的 sparql 查询

常见问题

  1. Sorry, I don't know which columns to put into the uriPattern 警告信息
21:32:18 WARN  MappingGenerator     :: Sorry, I don't know which columns to put into the uriPattern
21:32:18 WARN  MappingGenerator     ::     for "tbl_stock_company" because the table doesn't have a primary key.
21:32:18 WARN  MappingGenerator     ::     Please specify it manuall

tbl_stock_company 表没有主键导致无法建立依赖关系导致

postgresql 设置主键的语句如下:

# 格式:alter table <表名称> add CONSTRAINT <主键名称> primary key(<字段名称>);
alter table public.tbl_stock_company add CONSTRAINT tbl_stock_company_pkey primary key(ts_code);
  1. driver 安装问题

driver 安装 lib 目录即可

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容