返回首页

gbase数据、南大通用产品文档:GBase8s类定义

更新日期:2024年09月11日

以下示例中的 charattrUDT 是 C 不透明类型的类,它必须实现 SQLData 接口:
import java.sql.*;
import com.gbasedbt.jdbc.*;
/*
* C struct of charattr_udt:
*

GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 190
-
* typedef struct charattr_type
* {
* char chr1[4+1];
* mi_boolean bold; // mi_boolean (1 byte)
* mi_smallint fontsize; // mi_smallint (2 bytes)
* }
* charattr;
*
* typedef charattr charattr_udt;
*
*/
public class charattrUDT implements SQLData
{
private String sql_type = "charattr_udt";
// an ASCII character/a multibyte character, and is null-terminated.
public String chr1;
// Is the character in boldface?
public boolean bold;
// font size of the character
public short fontsize;

public charattrUDT() { }

public charattrUDT(String chr1, boolean bold, short fontsize)
{
this.chr1 = chr1;
this.bold = bold;
this.fontsize = fontsize;
}

public String getSQLTypeName()
{
return sql_type;
}
// reads a stream of data values and builds a Java object
public void readSQL(SQLInput stream, String type) throws SQLException
{

GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 191
-
sql_type = type;
chr1 = ((IfmxUDTSQLInput)stream).readString(5);
bold = stream.readBoolean();
fontsize = stream.readShort();
}
// writes a sequence of values from a Java object to a stream
public void writeSQL(SQLOutput stream) throws SQLException
{
((IfmxUDTSQLOutput)stream).writeString(chr1, 5);
stream.writeBoolean(bold);
stream.writeShort(fontsize);
}
// overides Object.equals()
public boolean equals(Object b)
{
return (chr1.equals(((charattrUDT)b).chr1) &&
bold == ((charattrUDT)b).bold &&
fontsize == ((charattrUDT)b).fontsize);
}

public String toString()
{
return "chr1=" + chr1 + " bold=" + bold + " fontsize=" + fontsize;
}
}
在 JDBC 应用程序中,自定义类型映射必须将 SQL 类型名 charattr_udt 映射
到 charattrUDT 类:
java.util.Map customtypemap = conn.getTypeMap();
if (customtypemap == null)
{
System.out.println("\n***ERROR: typemap is null!");
return;
}
customtypemap.put("charattr_udt", Class.forName("charattrUDT"));

使用 SQL 管理 API 来通过 SQL 语句远程地管理 GBase 8s 。
SQL 管理 API 由两个函数组成:admin() 和 task()。这些函数执行相同的操作,但返回
不同格式的结果。这些函数带有一个或多个定义操作的参数。许多操作是您也可通过命令
行实用程序完成的操作。使用 SQL 管理 API 函数的好处是,您可从其他数据库服务器远
程地运行它们;反之,您必须直接地连接到运行命令行实用程序命令的那台数据库服务器
上。
您可在 SQL 语句内调用 admin() 和 task() 函数,该语句可包括表达式,或您可使用
EXECUTE FUNCTION 语句来调用它们。在一个事务内运行 admin() 或 task() 函数,该事
务不包括任何其他语句。
在 sysadmin 数据库中定义 SQL 管理 API 函数。您必须连接到 sysadmin 数据库,或直
接地或远程地来运行这些函数。
仅下列用户可运行 SQL 管理 API 函数:
 用户 gbasedbt
 root 用户,如果将 sysadmin 数据库上的 Connect 权限授予该用户
 DBSA 组成员,如果将 sysadmin 数据库上的 Connect 权限授予该角色
 通过带有 grant admin 参数的 admin() 和 task() 函数授予 SQL 管理 API 命令
权限的用户。
为了复制文件中存在的存储空间、chunk 和日志,您可生成 SQL 管理 API 命令。为此,
请运行带有 -c 选项的 dbschema 实用程序。

功能说明
执行rebalance instance 命令,将数据重分布到使用freenode 新建的distribution 上。
注意

本次数据重分布将进行实际数据的重分布;

重分布的所需时间需要根据数据量,系统CPU,磁盘,网络等综合情况进
行评估。
操作步骤
步骤1:执行rebalance instance 命令,将数据重分布到新建的distribution
(Distribution=4)上。
$ gccli
GBase client 9.5.3.17.117651. Copyright (c) 2004-2020, GBase.
All Rights
Reserved.
gbase> use vc vc1;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)
gbase> rebalance instance;
Query OK, 3 rows affected (Elapsed: 00:00:01.20)
gbase> select * from gclusterdb.rebalancing_status;
+------------+---------+------------+----------+----------------------------+-------------------
---------+-----------+------------+----------+---------------+-----------------+
| index_name | db_name | table_name | tmptable | start_time
| end_time
| status
| percentage | priority | host
| distribution_id |
+------------+---------+------------+----------+----------------------------+-------------------

GBase 8a MPP Cluster 产品手册
4 管理员指南
文档版本953(2022-09-15)
南大通用数据技术股份有限公司
323
---------+-----------+------------+----------+---------------+-----------------+
| demo.t
| demo
| t
|
| 2020-07-29 18:31:39.332
000 | 2020-07-29 18:31:41.392000 | COMPLETED |
100 |
5
| 172.168.83.11 |
4 |
| demo.ttt
| demo
| ttt
|
| 2020-07-29 18:31:39.33600
0 | 2020-07-29 18:31:41.389000 | COMPLETED |
100 |
5 |