返回首页

gbase数据、南大通用产品文档:GBase8a静态游标的定义

更新日期:2024年09月11日

功能说明
GBase 8a MPP Cluster 中使用DECLARE 定义游标,标注的主体一定是一个SE
LECT 语句。
注意

可以在一个程序中定义多个游标,但是每个块中的游标只能有唯一的名
字;

SELECT 语句不能包含有INTO 子句。
语法格式
DECLARE cursor_name CURSOR FOR
表5- 181 参数说明
参数名称


cursor_name
要创建的游标的名称,游标名只允许a~z、A~Z、0~9、下
划线,且不能只包含数字;
select_statement
游标的内容,可以是任何合法的SELECT 语句
示例
DECLARE cur CURSOR FOR SELECT DISTINCT lo_orderkey FROM
ssbm.lineorder ORDER BY lo_orderkey LIMIT 10;

语法格式
CREATE FUNCTION ([[,…] [,parameter_n]])
RETURNS
type
$$

$$ LANGUAGE plpythonu
参数说明

要创建的函数的名称。在同一数据库内,函数的名称必须唯一。
函数名称只允许a~z、A~Z、0~9、下划线,且不能只包含数字;

([[,...] [,parameter_n]])定义函数的参数,每一个参数的
定义格式是:<参数名称><参数数据类型>。
说明

这里新增了字符串包围符“$$”,和包围符“ ’ ”相比,这种包围符能避免在Python 函
数定义中使用转义;

<参数名称>在同一个函数中必须唯一,只允许a~z、A~Z、0~9、下划线,且不能
只包含数字;

<参数数据类型>指定参数的数据类型;

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

<函数定义>是一系列的Python 语句的组合,
其中包含一些数据操作以完成一定的功
能逻辑;

定义函数时,函数名后面的括号是必需的,即使没有任何参数,也不能省略;

type 是GBase 8a MPP Cluster 支持的数据类型。
示例
示例1
gbase> create function getUrlTitle(url varchar) returns varchar $$
import lxml.html,urllib
return lxml.html.parse(urllib.urlopen(url)).xpath("//title")[0].text
$$ LANGUAGE plpythonu;
gbase> select getUrlTitle('http://192.168.6.253/') as result;
+----------------------+
| result
|
+----------------------+
| Login to Phabricator |
+---------------------------------+
gbase> drop function getUrlTitle;
示例2
tinyint 类型支持,示例如下:
gbase> create function type_tinyint(i tinyint) returns tinyint $$ return i $$ LANGUAGE
plpythonu;
gbase> select type_tinyint(127);
+-------------------+
| type_tinyint(127) |
+-------------------+
|
127 |
+-------------------+
示例3

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-09-15)
南大通用数据技术股份有限公司
1408
smallint 类型支持,示例如下:
gbase> create function type_smallint(i smallint) returns smallint $$ return i $$ LANGUAG
E plpythonu;
gbase> select type_smallint(32767);
+----------------------+
| type_smallint(32767) |
+----------------------+
|
32767 |
+----------------------+
示例4
int 类型支持,示例如下:
gbase> create function type_int(i int) returns int $$ return i $$ LANGUAGE plpythonu;
gbase> select type_int(2147483647);
+----------------------+
| type_int(2147483647) |
+----------------------+
|
2147483647 |
+----------------------+
示例5
bigint 类型支持,示例如下:
gbase> create function type_bigint(i bigint) returns bigint $$ return i $$ LANGUAGE plp
ythonu;
gbase> select type_bigint(9223372036854775806);
+----------------------------------+
| type_bigint(9223372036854775806) |
+----------------------------------+
|
9223372036854775806 |

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-09-15)
南大通用数据技术股份有限公司
1409
+----------------------------------+
示例6
float 类型支持,示例如下:
gbase> create function type_float(i float) returns float $$ return i $$ LANGUAGE plpytho
nu;
gbase> select type_float(3.40E+38);
+----------------------+
| type_float(3.40E+38) |
+----------------------+
| 3.39999995214436e+38 |
+----------------------+
示例7
double 类型支持,示例如下:
gbase> create function type_double(i double) returns double $$ return i $$ LANGUAGE p
lpythonu;
gbase> select type_double(1.7976931348623157E+308);
+--------------------------------------+
| type_double(1.7976931348623157E+308) |
+--------------------------------------+
|

问题现象
全文支持blob uri 格式:
索引列为varchar uri,
uri 协议为hbase,
更新全文索引报错。
gbase> show create table t_write1;
+----------+---------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------+
| Table
| Create Table
|
+----------+---------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------+
| t_write1 | CREATE TABLE "t_write1" (
"a" int(11) DEFAULT NULL,
"b" varchar(2048) URI DEFAULT NULL,
FULLTEXT "h1" ("b")
) ENGINE=EXPRESS DEFAULT CHARSET=utf8 TABLESPACE='sys_tables
pace' |

GBase 8a MPP Cluster 最佳实践
5 FAQ
文档版本(2022-02-11)
南大通用数据技术股份有限公司
175
+----------+---------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)
2、数据如下,数据通过demo-blob-on-hadoop-for-java灌入
gbase> select * from t_write;
+------+-------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------+
| a
| b
|
+------+-------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------+
|
1 | hbase://gc65.gbase.cn:9090/HbaseStream/file/252181202008311007411
4848xxxxx0xxxxxxxxx262148xxxxxxxxxxxxxx\r\nCONTENT-LENGTH:14848\r
\nLAST-MODIFIED:Mon, 31 Aug 2020 02:07:41 GMT\r\n\r\n |
+------+-------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------+
3、创建全文索引,更新报错
gbase> create fulltext index h1 on t_write1(b);
Records: 0
Duplicates: 0
Warnings: 0
gbase> update index h1 on t_write;
ERROR 1702 (HY000): gcluster table error: FULLTEXT:Not supported URI
path at row 0 reason: can not open the uri :hbase://gc65.gbase.cn:9090/Hba
seStream/file/2521812020083110074114848xxxxx0xxxxxxxxx262148xxxxxxxxx
xxxxx. Can not find correctly BLOB URI configuration...
4、gbcti的配置文件如下:
[gbase@namenode cfg]$ cat gbfticfg.xml


64M
4
4
3
100000000
2
0
0
16777216
0

128
5

GBase 8a MPP Cluster 最佳实践
5 FAQ
文档版本(2022-02-11)
南大通用数据技术股份有限公司
176


GBaseCharExt
..//lib//libGbaseCharExt.so
UTF-8





gc65.gbase.cn,gc68.gbase.cn,gc89.gbase.cn
8020



5
5
HbaseStream
file
16777216



gc68.gbase.cn
8020
gbase


/blobstorage
17179869184


/tmp
8589934592


解决方法
配置内容放入 标签内。

GBase 8a MPP Cluster 最佳实践
5 FAQ
文档版本(2022-02-11)
南大通用数据技术股份有限公司
177