如何在 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

​ 参考上一个。

相关推荐
编程爱好者熊浪1 小时前
两次连接池泄露的BUG
java·数据库
TDengine (老段)2 小时前
TDengine 字符串函数 CHAR 用户手册
java·大数据·数据库·物联网·时序数据库·tdengine·涛思数据
qq7422349843 小时前
Python操作数据库之pyodbc
开发语言·数据库·python
姚远Oracle ACE3 小时前
Oracle 如何计算 AWR 报告中的 Sessions 数量
数据库·oracle
Dxy12393102164 小时前
MySQL的SUBSTRING函数详解与应用
数据库·mysql
码力引擎4 小时前
【零基础学MySQL】第十二章:DCL详解
数据库·mysql·1024程序员节
杨云龙UP4 小时前
【MySQL迁移】MySQL数据库迁移实战(利用mysqldump从Windows 5.7迁至Linux 8.0)
linux·运维·数据库·mysql·mssql
l1t4 小时前
利用DeepSeek辅助修改luadbi-duckdb读取DuckDB decimal数据类型
c语言·数据库·单元测试·lua·duckdb
安当加密4 小时前
Nacos配置安全治理:把数据库密码从YAML里请出去
数据库·安全
ColderYY5 小时前
Python连接MySQL数据库
数据库·python·mysql