db2start #开启数据库db2look -d HGQW1108 -a -e -i db2inst1 -w HUBBLE -o db2.sql[db2inst1@hilbert02 data]$ ls
db2.sqldb2 connect to HGQW1108export to /home/db2inst1/data/tb_BBS.csv of del select * from tb_BBSdb2 => export to /home/db2inst1/data/tb_BBS.csv of del select * from tb_BBS
SQL3104N The Export utility is beginning to export data to file
"/home/db2inst1/data/tb_BBS.csv".
SQL3105N The Export utility has finished exporting "3" rows.
Number of rows exported: 3quit[db2inst1@hilbert02 data]$ ls *.csv
tb_BBS.csv使用之前步骤一生成的SQL文件,编写IMPORT TABLE与要导入的表数据的模式匹配的语句。
删除所有特定于DB2的属性,重新映射所有据类型,重构所有CREATE TABLE语句
数据类型映射表
| DB2数据类型 | Hubble数据类型 |
|---|---|
| BLOB | BYTES 1个 |
| CHAR(n) | CHAR(n) |
| CLOB | STRING 1个 |
| DATE | DATE |
| FLOAT(n) | DECIMAL(n) |
| VARCHAR2(n) | VARCHAR(n) |
| TIMESTAMP | TIMESTAMP |
| Integer | TNT4 |
| FLOAT(n) | DECIMAL(n) |
| Double | DECIMAL |
| Smallint | TNT4 |
| Bigint | TNT8 |
| Numeric(p,s) | DECIMAL(p,s) |
| Decimal(p,s) | DECIMAL(p,s) |
| Vargraphic(n) | varchar(n) |
| Graphicn) | varchar(n) |
| Real | DECIMAL(n) |
确定好数据类型后修改对应的建表语句
调整主键的建表格式,以上述tb_bs表举例
db2语法
create table TB_BS(id int not null,title varchar(10),content varchar(40),primary key(id))create table TB_BS(id int not null primary key,title varchar(10),content varchar(40));Hubble集群中的每个节点都需要访问到需导入的数据文件。
URL必须使用以下格式:
[scheme]://[host]/[path]?[parameters]当前支持的类型如下:
| 类型 | schema | host | 参数 | 示例 |
|---|---|---|---|---|
| NFS/Local | nodelocal | 节点ID或为空 | N/A | nodelocal:///path/mydatest,nodelocal://n/path/mydatest |
IMPORT into TB_BS( id ,title,content
) CSV DATA ( 'nodelocal://1/cus/tb_BBS.csv' )
WITH
DELIMITER = ','
; job_id | status | fraction_completed | rows | index_entries | bytes
---------------------+-----------+--------------------+------+---------------+--------
749715636016250881 | succeeded | 1 | 3 | 0 | 93
(1 row)
Time: 365ms total (execution 365ms / network 0ms)select * from tb_bs;
id | title | content
------+-------+-----------
111 | TXT | 文章描述
123 | SQL | 文本内容
222 | CSV | 文本导入
(3 rows)
Time: 2ms total (execution 2ms / network 0ms)可参考CSV数据迁移