如何在 openGauss 中使用 zhparser

如何在 openGauss 中使用 zhparser

准备

  1. 一个装有 openGauss 数据库的环境
  2. 下载 scws 代码到任意位置: https://github.com/hightman/scws master
  3. 下载 zhparser 代码到任意位置: https://github.com/amutu/zhparser master

步骤

  1. 登录环境并 source openGauss 的环境变量
  2. 编译安装 scws
    1. 解压并进入文件夹: unzip scws-master.zip && cd scws-master
    2. 生成 configure 文件并执行编译: ./acprep && ./configure && make
    3. 安装 scws 到相关 lib 目录(需要 root 权限):make install
    4. 修改刚刚安装的 scws lib 的到合适的权限(需要 root 权限):chmod 777 /usr/local/include/scws -R
  3. 编译安装 zhparser
    1. 解压并进入文件夹:unzip zhparser-master.zip && cd zhparser-master
    2. 按照下文 patch 修改 zhparser 代码。
    3. 编译安装(若报错见 Q&A):make && make install

PATCH

复制代码
diff --git a/zhparser-master/Makefile b/zhparser-master/Makefile
index ae048c3..20b1830 100644
--- a/zhparser-master/Makefile
--- b/zhparser-master/Makefile
@@ -12,7 +12,7 @@ DATA_TSEARCH = dict.utf8.xdb rules.utf8.ini
 REGRESS = zhparser

 SCWS_HOME ?= /usr/local
-PG_CPPFLAGS = -I$(SCWS_HOME)/include/scws
+PG_CPPFLAGS = -I$(SCWS_HOME)/include/scws -fpic
 SHLIB_LINK = -lscws -L$(SCWS_HOME)/lib -Wl,-rpath -Wl,$(SCWS_HOME)/lib

 PG_CONFIG ?= pg_config
diff --git a/zhparser-master/zhparser.c b/zhparser-master/zhparser.c
index 527cef0..6212533 100644
--- a/zhparser-master/zhparser.c
--- b/zhparser-master/zhparser.c
@@ -57,16 +57,16 @@ static void init_type(LexDescr descr[]);
  * prototypes
  */
 PG_FUNCTION_INFO_V1(zhprs_start);
-Datum          zhprs_start(PG_FUNCTION_ARGS);
+extern "C" Datum zhprs_start(PG_FUNCTION_ARGS);

 PG_FUNCTION_INFO_V1(zhprs_getlexeme);
-Datum          zhprs_getlexeme(PG_FUNCTION_ARGS);
+extern "C" Datum zhprs_getlexeme(PG_FUNCTION_ARGS);

 PG_FUNCTION_INFO_V1(zhprs_end);
-Datum          zhprs_end(PG_FUNCTION_ARGS);
+extern "C" Datum zhprs_end(PG_FUNCTION_ARGS);

 PG_FUNCTION_INFO_V1(zhprs_lextype);
-Datum          zhprs_lextype(PG_FUNCTION_ARGS);
+extern "C" Datum               zhprs_lextype(PG_FUNCTION_ARGS);

 static scws_t scws = NULL;
 static ParserState parser_state;
@@ -213,7 +213,7 @@ static void init(){
        }

        snprintf(dict_path, MAXPGPATH, "%s/base/%u/zhprs_dict_%s.txt",
-                       DataDir, MyDatabaseId, get_database_name(MyDatabaseId));
+                       t_thrd.proc_cxt.DataDir, u_sess->proc_cxt.MyDatabaseId, get_database_name(u_sess->proc_cxt.MyDatabaseId));
        if(scws_add_dict(scws, dict_path, load_dict_mem_mode | SCWS_XDICT_TXT) != 0 ){
                ereport(NOTICE,
                            (errcode(ERRCODE_INTERNAL_ERROR),

Q&A

1、编译 zhparser 时报错 error: access/ustore/undo/knl_uundotype.h: No such file or directory

​ 解决方法:将 openGauss-server/src/include/access/ustore/undo/knl_uundotype.h 拷贝到 $GAUSSHOME/include/postgresql/server/access/ustore/undo/中,若没有目标位置没有这个文件夹,需要自行创建。

2、编译 zhparser 时报错 error: communication/commproxy_basic.h: No such file or directory

​ 参考上一个。

相关推荐
能鈺CMS10 分钟前
能鈺CMS · 虚拟发货源码
java·大数据·数据库
泡沫·23 分钟前
4.iSCSI 服务器
运维·服务器·数据库
胡八一26 分钟前
解决PHP未检测到您服务器环境的sqlite3数据库扩展报错
服务器·数据库·php
Wang's Blog1 小时前
MongoDB小课堂: 游标操作与文档投影技术深度解析
数据库·mongodb
q***42051 小时前
使用Django Rest Framework构建API
数据库·django·sqlite
共享家95271 小时前
QT-界面优化(下)
开发语言·数据库·qt
maray2 小时前
Chroma 的设计哲学
数据库·人工智能
e***0962 小时前
SQL 中UPDATE 和 DELETE 语句的深入理解与应用
数据库·sql
程序员小白条3 小时前
你面试时吹过最大的牛是什么?
java·开发语言·数据库·阿里云·面试·职场和发展·毕设
老华带你飞4 小时前
社区养老保障|智慧养老|基于springboot+小程序社区养老保障系统设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·小程序·毕设·社区养老保障