返回首页

gbase数据、南大通用产品文档:GBase8aUDF 函数接口

更新日期:2024年09月11日

对每一个想在SQL 语句中使用的函数(假设函数名为func),应该定义对应的C
(或C++ ,C++函数声明要加上extern
"C ")函数,该函数满足以下规则:
func()(必需)
主函数。这是计算函数结果的地方,每行调用一次。SQL 类型与C/C++函数返回
类型的对应关系如下:
表5- 194 SQL 类型与C/C++函数返回类型的对应关系
SQL 类型
C/C++ 类型
STRING
char *
INTEGER
long long
REAL
double
func_init()(必需)
func()的初始化函数,只在开始调用一次,它可用于:

检查传到func()的参数个数;

检查参数类型是否正确或者当主函数被调用时将参数强制转换成需要的类
型;

分配主函数所需的内存;

指定返回结果的最大长度;

指定返回REAL 类型的函数的最大小数位;

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-09-15)
南大通用数据技术股份有限公司
1384

指定结果是否允许为NULL。
func_deinit()(可选)
func()的结束函数,
只在所有行结束后调用一次,
它可用于释放初始化函数分配的
内存。
说明

当一条SQL 语句调用func()时,GBase 调用初始化函数func_init(),执行所需的初
始化工作,例如参数检查或内存分配。

如果func_init()返回一个错误,SQL 语句返回一条错误消息同时不会调用主函数和
结束函数。否则,为每行调用主函数func()一次。

在所有行被处理完后,调用结束函数func_deinit(),执行必要的清理工作。
注意
所有函数必须是线程安全的(不仅是主函数,还有初始化和结束函数)。不允许
在函数中改变全局共享或静态的变量。如果需要内存,应该在func_init()中分
配它并且在func_deinit()中释放它。

Multi-Tenancy Capability
GBase 8a MPP Cluster provides multi-tenant capabilities through virtual cluster
technology to achieve physical or logical isolation between tenants.
The computing nodes are grouped into multiple virtual subsets within a virtual
cluster, with each subset physically isolated on resources and logically separated in
the namespace. The virtual cluster provides a unified access entry, metadata view,
execution scheduling, authentication, and permission management for all subsets.
On each computing node of a virtual subset, different application and user resource
quotas and query priorities can be flexibly configured through resource management
and resource groups.
With a sound permission authorization and management mechanism, different
applications can run in different virtual subsets, and different types of tasks of the
same application can run in the same subset, but with different resource quotas and
priorities, and necessary isolation is ensured. It's like running in a transparent
"sandbox."

GBase 8a MPP Cluster Technical White Paper
General Data Technology Co., Ltd.
- 19 -

参数说明:DCF 回调函数线程个数。如果节点数量超过7 个,需要增加这个参数的数
值(比如增加到40),否则可能会出现主节点一直处于promoting 状态,主备节点日志不推
进的状态。
该参数属于POSTMASTER 类型参数,请参考表15-1 中对应设置方法进行设置。
取值范围:整型,10~262143
默认值:10