作者:刘书盛

热衷技术分享、编写技术文档

原创作品

oceanbase 数据库

原创内容未经授权不得随意使用,转载请联系小编并注明来源,谢谢!

预处理函数:

函数签名 返回类型 描述
LOWER(char) String 对参数值中的字母转换为小写。 参数值可以是列名、常量或者嵌套表达式。当参数值是常量时,请使用单引号。 示例:LOWER('A')
LTRIM(char[,set]) String 对参数值从左到右进行匹配并截断操作。 参数 char 的值可以是列名、常量或函数表达式。参数 set 的值是常量。若省略参数 set,则默认按照空格进行匹配。 示例:LTRIM(' abc ')
RTRIM(char[,set]) String 对参数值从右到左进行匹配并截断操作。 参数 char 的值可以是列名、常量或函数表达式,参数 set 的值是常量。若省略参数 set,则默认按照空格进行匹配。 示例:RTRIM(' abc ')
SUBSTR(char,position[,length ]) String 对参数值根据起始位置与长度进行截断。 参数 char 的值可以是列名、常量或函数表达式,参数 position 的值是数值型常量,参数 length 的值是数值型常量。 示例:SUBSTR('abc',0,3)
TRIM(char) String 对参数值的左右两端进行空格截断。参数 char 的值可以是列名、常量或函数表达式。 示例:TRIM(' abc ')
REVERSE(char) String 对参数值进行逆序操作。 示例:REVERSE("C1") 将颠倒 C1 列值的字符串顺序。
UPPER(char) String 对参数值中的字母转换为大写。 参数 char 的值可以是列名、常量或者嵌套表达式。当值为常量时,请使用单引号。 示例:UPPER('a')
NANVL(char, default) String 对参数值进行数值合法验证,若验证失败,则返回默认值。 参数 char 的值可以是列名、常量或函数表达式,参数 default 的值是常量。 示例:NANVL('1','1')
REPLACE(char,search[,replacement ]) String 对参数值根据搜索条件进行替换。 参数 char 的值可以是列名、常量或函数表达式,参数 search 的值是常量,参数 replacement 的值是常量。 示例:REPLACE('abc','a','A')
NVL(char, default) String 对参数值进行判空,若为空,则返回默认值。 参数 char 的值可以是列名、常量或函数表达式,参数 default 的值是常量。 示例:NVL('a','--')
TO_TIMESTAMP(char,fmt1[,fmt2]) String 对参数值进行日期格式化,若转换失败返回 NULL。 参数 char 的值可以是列名、常量或函数表达式,参数 fmt1 的值是日期解析模板,可选参数 fmt2 的值是日期格式化模板。 参数 fmt2 返回值的默认格式:yyyy-MM-dd HH:mm:ss.SSS。
LENGTH(char) String 对参数值进行长度计算。 参数 char 的值可以是列名、常量或函数表达式。
LPAD(char,length[,pad_string]) String 对参数值从左侧追加指定长度的字符,若指定的长度小于参数长度则截断。 参数 char 的值可以是列名、常量或函数表达式,参数 lengthpad_string 的值是常量,且参数 pad_string 的值要求传入单字节字符。 示例:LPAD('a',1,'x')
RPAD(char,length[,pad_string]) String 对参数值从右侧追加指定长度的字符,指定的长度小于参数长度则截断。 参数 char 的值可以是列名、常量或函数表达式,参数 lengthpad_string 的值是常量,且参数 pad_string 的值要求传入单字节字符。 示例:RPAD('a',1,'x')
CONVERT(char,charset1[,charset2]) String 对参数值进行字符编码转换。 参数 char 的值可以是列名、常量或函数表达式,参数 charset1charset2 的值是常量。 示例:CONVERT('a','utf-8','gbk')
CONCAT(char1,char2) String 对参数值进行拼接。 参数 char1char2 的值可以是列名、常量或函数表达式。 示例:CONCAT('a','b')
NONE String 对参数不作任何处理,直接返回参数值。
SYSTIMESTAMP String 对参数不作任何处理,直接返回当前机器的时间戳。 默认格式:yyyy-MM-dd HH:mm:ss.SSS。
SYSDATE String 对参数不作任何处理,直接返回当前机器的日期。 默认格式:yyyy-MM-dd HH:mm:ss。
CONSTANT(char) String 对参数不作任何处理,直接返回定义的常量值。参数 char 的值是常量。 示例:CONSTANT('1')
TMSFMT(char,fmt1,default,fmt2) String 对参数进行日期格式验证,若验证失败,则返回默认的日期格式。 示例:TMSFMT(c1,'yyyyMMddHHmmssSSS','2021-03-10 00:00:00.000','yyyy-MM-dd HH:mm:ss.SSS')
LPADB(char,byte_size[,pad_char]) String 对参数值从左侧追加指定长度的字节,指定的长度小于参数长度则截断。 参数 char 的值可以是列名、常量或函数表达式,参数 byte_sizepad_char 的值是常量。 示例:LPADB('a',1,'x')
RPADB(char,byte_size[,pad_char]) String 对参数值从右侧追加指定长度的字节,指定的长度小于参数长度则截断。 参数 char 的值可以是列名、常量或函数表达式,参数 byte_sizepad_char 的值是常量。 示例:RPADB('a',1,'x')
MASK(string str[, string upper[, string lower[, string number]]]) String 对字段中的大小写字母、数字进行脱敏操作。 示例:MASK("C1",A,a,b) ,将 C1 列的大写字母转换为字母 A,小写字母转化为 a,数字转换为 b。
MASK_FIRST_N(string str[, int n]) String 指定对字段值的前 n 个字符进行脱敏操作。 示例:MASK_FIRST_N("C1",'A','a','b',5),将 C1 列的前 5 个字符中的大写字母转换为字母 A,小写字母转化为 a,数字转换为 b。
MASK_LAST_N(string str[, int n]) String 指定对字段值的后 n 个字符进行脱敏操作。 示例:MASK_LAST_N("C1",'A','a','b',5),将 C1 列的后 5 个字符中的大写字母转换为字母 A,小写字母转化为 a,数字转换为 b。
MASK_SHOW_FIRST_N(string str[, int n]) String 指定对除前 n 个字符之外的所有字符进行脱敏操作。 示例:MASK_SHOW_FIRST_N("C1",'A','a','b',5),将 C1 列的除前 5 个字符之外的所有字符中的大写字母转换为字母 A,小写字母转化为 a,数字转换为 b。
MASK_SHOW_LAST_N(string str[, int n]) String 指定对除后 n 个字符之外的所有字符进行脱敏操作。 示例:MASK_SHOW_LAST_N("C1",'A','a','b',5),将 C1 列的除后 5 个字符之外的所有字符中的大写字母转换为字母 A,小写字母转化为 a,数字转换为 b。
SEQUENCE(int m,int n) String 对指定的列生成递增的序列值,m 代表初始值,n 代表递增值。 示例:SEQUENCE(100,1) 生成初始值为 100,递增值为 1 的序列。
DB_SEQUENCE(string sequence) String 指定数据库中已定义的序列导入数据。 示例:DB_SEQUENCE(seq01),指定序列值为 seq01。说明 OBLOADER 4.1.0 及之后的版本支持该功能。

场景1. 文件中的字段比数据表中的字段多

通过Obloader 控制文件对导入数据进行处理
#文件模板.ctl
lang=java
(
列名 字节偏移位置(可选) "预处理函数"(可选) 映射定义(可选),
列名 字节偏移位置(可选) "预处理函数"(可选) 映射定义(可选),
列名 字节偏移位置(可选) "预处理函数"(可选) 映射定义(可选),
列名 字节偏移位置(可选) "预处理函数"(可选) 映射定义(可选)
);

#举例
lang=java
server=mysql|oracle (    
  c1 "nvl(c1, 'not null')" map(field_position),    
  c2 "none" map(field_position)
);
注意:
field_position 为导入的数据文件中预处理数据的列位置。
控制文件的命名规范为 <表名>.ctrl。
对于 --cut, --csv, --sql 格式数据,无需定义字节偏移位置。
预处理函数定义请参考 预处理函数
#导入文件
[root@10-186-63-38 bin]# cat /tmp/backup/data/test/TABLE/t1.1.0.csv
'a','b','c','d'
1,66662,111111111,555
3,44444,111111111,555
5,33336,111111111,555
6,22226,111111111,555
7,66664,111111111,555
8,88882,111111111,555

#t1表定义
obclient [test]> desc t1;
+-------+---------+------+-----+---------+-------+
| Field | Type   | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| a     | int(11) | NO   | PRI | NULL   |       |
| b     | int(11) | YES | MUL | NULL   |       |
| c     | int(11) | YES |     | NULL   |       |
+-------+---------+------+-----+---------+-------+
3 rows in set (0.037 sec)

#定义obloader控制文件t1.ctl   文件路径:/tmp/t1.ctl
vi /tmp/t1.ctl
lang=java
server=mysql|oracle (          
  a "none" map(1),    
  b "none" map(2),
  c "none" map(4)
);

控制文件解释:
server 指定数据库为mysql或者oracle,不写也行
a、b、c为表定义实际列
map(1)、map(2)、map(3) 为导入数据文件中实际列,1为第一列,2位第二列,3位第三列
#导入数据,导入数据文件列多余数据库表列
确认数据为空
obclient [test]> select * from t1;
Empty set (0.025 sec)

导入数据,--column-splitter
./obloader -h 10.186.63.38 -P 2883 -uroot -p 'aaAA11__' --sys-password='Wa33Wa33?*' -c demo -t ten_mysql -D test --csv --column-splitter ',' --replace-data  --ctl-path '/tmp/t1.ctl' --table 't1' -f /tmp/backup/
#参数解释
--column-splitter   指定列分隔符
--replace-data     标识替换重复的数据
--ctl-path         控制文件位置

[root@10-186-63-38 bin]# ./obloader -h 10.186.63.38 -P 2883 -uroot -p 'aaAA11__' --sys-password='Wa33Wa33?*' -c demo -t ten_mysql -D test --csv --column-splitter ',' --replace-data --ctl-path '/tmp/t1.ctl' --table 't1' -f /tmp/backup/
2023-05-24 09:57:09 [INFO] Parsed args:
[--csv] true
[--ctl-path] /tmp/t1.ctl
[--file-path] /tmp/backup/
[--column-splitter] ,
[--host] 10.186.63.38
[--port] 2883
[--user] root
[--tenant] ten_mysql
[--cluster] demo
[--password] ******
[--database] test
[--sys-user] root
[--sys-password] ******
[--table] [t1]
[--replace-data] true
2023-05-24 09:57:09 [INFO] Load jdbc driver class: "com.oceanbase.jdbc.Driver" finished
2023-05-24 09:57:09 [INFO] Manifest: "/tmp/backup/data/MANIFEST.bin" has been saved
2023-05-24 09:57:10 [INFO] Parse ctrl definition: "/tmp/t1.ctl" success
2023-05-24 09:57:10 [INFO] File: "/tmp/backup/data/test/TABLE/t2.3.0.csv" is not contained, ignore it
2023-05-24 09:57:10 [INFO] Binding table: "t1" to the file: "/tmp/backup/data/test/TABLE/t1.1.0.csv" finished
2023-05-24 09:57:10 [INFO] File: "/tmp/backup/data/test/TABLE/t2.2.0.csv" is not contained, ignore it
2023-05-24 09:57:10 [INFO] File: "/tmp/backup/data/test/TABLE/t2.4.0.csv" is not contained, ignore it
2023-05-24 09:57:10 [INFO] Find 1 resources in local path: "/tmp/backup" success. Elapsed: 57.43 ms
2023-05-24 09:57:10 [INFO] Split 1 data files to 1 subfiles by 64.0 MB success. Elapsed: 20.05 ms
2023-05-24 09:57:10 [INFO] Ignore to clean any tables as --truncate-table or --delete-from-table is not specified
2023-05-24 09:57:10 [INFO] Query table entry and primary key for table: "t1" finished. Remain: 0
2023-05-24 09:57:10 [INFO] Query the leader location of "t1" finished. Remain: 0
2023-05-24 09:57:10 [INFO] Calculate leader: 10.186.63.39:2881 of table "t1", part: 0. Remain: 0
2023-05-24 09:57:10 [INFO] Waiting to refresh observer load status ......
2023-05-24 09:57:10 [INFO] Refresh observer load status success. Table: "t1". Remain: 0
2023-05-24 09:57:10 [INFO] Refresh observer load status finished. Elapsed: 46.46 ms
2023-05-24 09:57:10 [INFO] Use c.l.d.LiteBlockingWaitStrategy as available cpu(s) is 4
2023-05-24 09:57:10 [INFO] Create 16 slots for ring buffer finished. [10.186.63.39:2881]
2023-05-24 09:57:10 [INFO] Start 8 database writer threads finished. [10.186.63.39:2881]
2023-05-24 09:57:10 [INFO] Start 8 record file reader threads success
2023-05-24 09:57:10 [INFO] File: "/tmp/backup/data/test/TABLE/t1.1.0.csv" has been parsed finished
2023-05-24 09:57:11 [INFO] Wait for the all the workers to drain of published events then halt the workers
2023-05-24 09:57:11 [INFO] Close connection count: 5 of the DataSource. Key: BIZ
2023-05-24 09:57:11 [INFO] Close connection count: 25 of the DataSource. Key: SYS
2023-05-24 09:57:11 [INFO] Shutdown task context finished
2023-05-24 09:57:11 [INFO] ----------   Finished Tasks: 1       Running Tasks: 0       Progress: 100.00%       ----------
2023-05-24 09:57:11 [INFO]
All Load Tasks Finished:
----------------------------------------------------------------------------------------------------------------------------
      No.#       |       Type       |             Name             |           Count             |       Status
----------------------------------------------------------------------------------------------------------------------------
        1         |       TABLE       |             t1             |            6 -> 6           |     SUCCESS
----------------------------------------------------------------------------------------------------------------------------
Total Count: 6         End Time: 2023-05-24 09:57:11
2023-05-24 09:57:11 [INFO] Load record finished. Total Elapsed: 1.891 s
2023-05-24 09:57:11 [INFO] System exit 0

#查看导入数据
obclient [test]> select * from t1;
+---+-------+------+
| a | b     | c   |
+---+-------+------+
| 1 | 66662 |  555 |
| 3 | 44444 |  555 |
| 5 | 33336 |  555 |
| 6 | 22226 |  555 |
| 7 | 66664 |  555 |
| 8 | 88882 |  555 |
+---+-------+------+
6 rows in set (0.002 sec)

场景2. 文件中的字段比数据表中的字段少

#导入数据
[root@10-186-63-38 bin]# cat /tmp/backup/data/test/TABLE/t2.2.0.csv
'a','b','c','d'
1,66662,111111111,555
3,44444,111111111,555
5,33336,111111111,555
6,22226,111111111,555
7,66664,111111111,555
8,88882,111111111,555
#表结构
obclient [test]> desc t2;
+-------+---------+------+-----+---------+-------+
| Field | Type   | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| c1   | int(11) | NO   | PRI | NULL   |       |
| c2   | int(11) | YES |     | NULL   |       |
| c3   | int(11) | YES |     | NULL   |       |
| c4   | int(11) | YES |     | NULL   |       |
| c5   | int(11) | YES |     | NULL   |       |
+-------+---------+------+-----+---------+-------+
5 rows in set (0.100 sec)
#编写控制文件,导入数据列少于表定义列,如果对多不处理,则c5列不写,数据为空NULL
vi /tmp/t2.ctl
lang=java
server=mysql (
  c1 "none" map(1),
  c2 "none" map(2),
  c3 "none" map(4),
  c4 "none" map(3),
  c5 "none" map(2)
);
#确认数据为空
obclient [test]> select * from t2;
Empty set (0.097 sec)

#导入数据
cd /root/ob-loader-dumper-4.2.1-RELEASE/bin
./obloader -h 10.186.63.38 -P 2883 -uroot -p 'aaAA11__' --sys-password='Wa33Wa33?*' -c demo -t ten_mysql -D test --csv --column-splitter ',' --replace-data  --ctl-path '/tmp/t2.ctl' --table 't2' -f /tmp/backup/
[root@10-186-63-38 bin]# ./obloader -h 10.186.63.38 -P 2883 -uroot -p 'aaAA11__' --sys-password='Wa33Wa33?*' -c demo -t ten_mysql -D test --csv --column-splitter ',' --replace-data --ctl-path '/tmp/t2.ctl' --table 't2' -f /tmp/backup/
2023-05-24 10:21:07 [INFO] Parsed args:
[--csv] true
[--ctl-path] /tmp/t2.ctl
[--file-path] /tmp/backup/
[--column-splitter] ,
[--host] 10.186.63.38
[--port] 2883
[--user] root
[--tenant] ten_mysql
[--cluster] demo
[--password] ******
[--database] test
[--sys-user] root
[--sys-password] ******
[--table] [t2]
[--replace-data] true

2023-05-24 10:21:07 [INFO] Load jdbc driver class: "com.oceanbase.jdbc.Driver" finished
2023-05-24 10:21:07 [INFO] Manifest: "/tmp/backup/data/MANIFEST.bin" has been saved
2023-05-24 10:21:07 [INFO] Parse ctrl definition: "/tmp/t2.ctl" success
2023-05-24 10:21:07 [INFO] Found 1 empty tables before executing.... Elapsed: 42.03 ms
2023-05-24 10:21:07 [INFO] File: "/tmp/backup/data/test/TABLE/t1.1.0.csv" is not contained, ignore it
2023-05-24 10:21:08 [INFO] Binding table: "t2" to the file: "/tmp/backup/data/test/TABLE/t2.2.0.csv" finished
2023-05-24 10:21:08 [INFO] Find 1 resources in local path: "/tmp/backup" success. Elapsed: 18.52 ms
2023-05-24 10:21:08 [INFO] Split 1 data files to 1 subfiles by 64.0 MB success. Elapsed: 24.21 ms
2023-05-24 10:21:08 [INFO] Ignore to clean any tables as --truncate-table or --delete-from-table is not specified
2023-05-24 10:21:08 [INFO] Query table entry and primary key for table: "t2" finished. Remain: 0
2023-05-24 10:21:08 [INFO] Query the leader location of "t2" finished. Remain: 0
2023-05-24 10:21:08 [INFO] Calculate leader: 10.186.63.38:2881 of table "t2", part: 1. Remain: 0
2023-05-24 10:21:08 [INFO] Waiting to refresh observer load status ......
2023-05-24 10:21:08 [INFO] Refresh observer load status success. Table: "t2". Remain: 0
2023-05-24 10:21:08 [INFO] Refresh observer load status finished. Elapsed: 43.75 ms
2023-05-24 10:21:08 [INFO] Use c.l.d.LiteBlockingWaitStrategy as available cpu(s) is 4
2023-05-24 10:21:08 [INFO] Create 4 slots for ring buffer finished. [10.186.63.38:2881]
2023-05-24 10:21:08 [INFO] Start 8 database writer threads finished. [10.186.63.38:2881]
2023-05-24 10:21:08 [INFO] Use c.l.d.LiteBlockingWaitStrategy as available cpu(s) is 4
2023-05-24 10:21:08 [INFO] Create 4 slots for ring buffer finished. [10.186.63.40:2881]
2023-05-24 10:21:08 [INFO] Start 8 database writer threads finished. [10.186.63.40:2881]
2023-05-24 10:21:08 [INFO] Use c.l.d.LiteBlockingWaitStrategy as available cpu(s) is 4
2023-05-24 10:21:08 [INFO] Create 4 slots for ring buffer finished. [10.186.63.39:2881]
2023-05-24 10:21:08 [INFO] Start 8 database writer threads finished. [10.186.63.39:2881]
2023-05-24 10:21:08 [INFO] Start 8 record file reader threads success
2023-05-24 10:21:09 [INFO] File: "/tmp/backup/data/test/TABLE/t2.2.0.csv" has been parsed finished
2023-05-24 10:21:09 [INFO] Wait for the all the workers to drain of published events then halt the workers
2023-05-24 10:21:09 [INFO] Close connection count: 5 of the DataSource. Key: BIZ
2023-05-24 10:21:09 [INFO] Close connection count: 27 of the DataSource. Key: SYS
2023-05-24 10:21:09 [INFO] Shutdown task context finished
2023-05-24 10:21:09 [INFO] ----------   Finished Tasks: 1       Running Tasks: 0       Progress: 100.00%       ----------
2023-05-24 10:21:09 [INFO]
All Load Tasks Finished:
----------------------------------------------------------------------------------------------------------------------------
      No.#       |       Type       |             Name             |           Count             |       Status
----------------------------------------------------------------------------------------------------------------------------
        1         |       TABLE       |             t2             |            6 -> 6           |     SUCCESS
----------------------------------------------------------------------------------------------------------------------------
Total Count: 6         End Time: 2023-05-24 10:21:09
2023-05-24 10:21:09 [INFO] Load record finished. Total Elapsed: 2.214 s
2023-05-24 10:21:09 [INFO] System exit 0

#确认数据
obclient [test]> select * from t2;
+----+-------+------+-----------+-------+
| c1 | c2   | c3   | c4       | c5   |
+----+-------+------+-----------+-------+
|  7 | 66664 |  555 | 111111111 | 66664 |
|  1 | 66662 |  555 | 111111111 | 66662 |
|  6 | 22226 |  555 | 111111111 | 22226 |
|  3 | 44444 |  555 | 111111111 | 44444 |
|  8 | 88882 |  555 | 111111111 | 88882 |
|  5 | 33336 |  555 | 111111111 | 33336 |
+----+-------+------+-----------+-------+
6 rows in set (0.022 sec)

场景3. 生成自定义字段数据

#修改控制文件
[root@10-186-63-38 bin]# cat /tmp/t1.ctl
lang=java
server=mysql (
  a "none" map(1),
  b "replace('33336','3','9')" map(2),
  c "concat('888','666')" map(3),
  d "lower('AAA')" map(4)
   
#参数解释:
b "replace('33336','3','9')" map(2)    #导入b列数据为33336,将3用9替换插入b列
c "concat('888','666')" map(3)         #拼接888666插入c列中    
d "lower('AAA')" map(4)                #将d列中所有AAA转换为aaa插入d列

#导入数据文件
[root@10-186-63-38 bin]# cat /tmp/backup/data/test/TABLE/t1.1.0.csv
'a','b','c','d'
1,66662,111111111,'AAA'
3,44444,111111111,'AAA'
5,33336,111111111,'AAA'
6,22226,111111111,'AAA'
7,66664,111111111,'AAA'
8,88882,111111111,'AAA'

#导入数据
[root@10-186-63-38 bin]# ./obloader -h 10.186.63.38 -P 2883 -uroot -p 'aaAA11__' --sys-password='Wa33Wa33?*' -c demo -t ten_mysql -D test --csv --column-splitter ',' --replace-data --ctl-path '/tmp/t1.ctl' --table 't1' -f /tmp/backup/
2023-05-24 11:18:47 [INFO] Parsed args:
[--csv] true
[--ctl-path] /tmp/t1.ctl
[--file-path] /tmp/backup/
[--column-splitter] ,
[--host] 10.186.63.38
[--port] 2883
[--user] root
[--tenant] ten_mysql
[--cluster] demo
[--password] ******
[--database] test
[--sys-user] root
[--sys-password] ******
[--table] [t1]
[--replace-data] true

2023-05-24 11:18:47 [INFO] Load jdbc driver class: "com.oceanbase.jdbc.Driver" finished
2023-05-24 11:18:47 [INFO] Manifest: "/tmp/backup/data/MANIFEST.bin" has been saved
2023-05-24 11:18:47 [INFO] Parse ctrl definition: "/tmp/t1.ctl" success
2023-05-24 11:18:48 [INFO] Binding table: "t1" to the file: "/tmp/backup/data/test/TABLE/t1.1.0.csv" finished
2023-05-24 11:18:48 [INFO] File: "/tmp/backup/data/test/TABLE/t2.2.0.csv" is not contained, ignore it
2023-05-24 11:18:48 [INFO] Find 1 resources in local path: "/tmp/backup" success. Elapsed: 42.81 ms
2023-05-24 11:18:48 [INFO] Split 1 data files to 1 subfiles by 64.0 MB success. Elapsed: 20.61 ms
2023-05-24 11:18:48 [INFO] Ignore to clean any tables as --truncate-table or --delete-from-table is not specified
2023-05-24 11:18:48 [INFO] Query table entry and primary key for table: "t1" finished. Remain: 0
2023-05-24 11:18:48 [INFO] Query the leader location of "t1" finished. Remain: 0
2023-05-24 11:18:48 [INFO] Calculate leader: 10.186.63.39:2881 of table "t1", part: 0. Remain: 0
2023-05-24 11:18:48 [INFO] Waiting to refresh observer load status ......
2023-05-24 11:18:48 [INFO] Refresh observer load status success. Table: "t1". Remain: 0
2023-05-24 11:18:48 [INFO] Refresh observer load status finished. Elapsed: 34.41 ms
2023-05-24 11:18:48 [INFO] Use c.l.d.LiteBlockingWaitStrategy as available cpu(s) is 4
2023-05-24 11:18:48 [INFO] Create 16 slots for ring buffer finished. [10.186.63.39:2881]
2023-05-24 11:18:48 [INFO] Start 8 database writer threads finished. [10.186.63.39:2881]
2023-05-24 11:18:48 [INFO] Start 8 record file reader threads success
2023-05-24 11:18:48 [INFO] File: "/tmp/backup/data/test/TABLE/t1.1.0.csv" has been parsed finished
2023-05-24 11:18:49 [INFO] Wait for the all the workers to drain of published events then halt the workers
2023-05-24 11:18:49 [INFO] Close connection count: 5 of the DataSource. Key: BIZ
2023-05-24 11:18:49 [INFO] Close connection count: 23 of the DataSource. Key: SYS
2023-05-24 11:18:49 [INFO] Shutdown task context finished
2023-05-24 11:18:49 [INFO] ----------   Finished Tasks: 1       Running Tasks: 0       Progress: 100.00%       ----------
2023-05-24 11:18:49 [INFO]

All Load Tasks Finished:

----------------------------------------------------------------------------------------------------------------------------
      No.#       |       Type       |             Name             |           Count             |       Status
----------------------------------------------------------------------------------------------------------------------------
        1         |       TABLE       |             t1             |            6 -> 6           |     SUCCESS
----------------------------------------------------------------------------------------------------------------------------
Total Count: 6         End Time: 2023-05-24 11:18:49
2023-05-24 11:18:49 [INFO] Load record finished. Total Elapsed: 1.639 s
2023-05-24 11:18:49 [INFO] System exit 0

#确认数据,数据插入OK
obclient [test]> select * from t1;
+---+-------+--------+------+
| a | b     | c     | d   |
+---+-------+--------+------+
| 1 | 99996 | 888666 | aaa |
| 3 | 99996 | 888666 | aaa |
| 5 | 99996 | 888666 | aaa |
| 6 | 99996 | 888666 | aaa |
| 7 | 99996 | 888666 | aaa |
| 8 | 99996 | 888666 | aaa |
+---+-------+--------+------+
6 rows in set (0.002 sec)
#参数解释:
b "replace('33336','3','9')" map(2)    #导入b列数据为33336,将3用9替换插入b列
c "concat('888','666')" map(3)         #拼接888666插入c列中    
d "lower('AAA')" map(4)                #将d列中所有AAA转换为aaa插入d列

场景4. 文件是定长数据,如何导入

#修改控制文件
[root@10-186-63-38 bin]# cat /tmp/t1.ctl
lang=java
server=mysql (
  a "none" map(1),
  b "substr(b,1,2)" map(2),
  c "concat('999','555')" map(3),
  d "substr(d,1,1)" map(4)
);

   
#参数解释:
b "substr(b,1,2)" map(2),              #截取b列数据第一位开始,截取2位
c "concat('999','555')" map(3)         #拼接888666插入c列中    
d "substr(d,1,1)" map(4)               #截取d列数据第一位开始,截取2位

#导入数据文件
[root@10-186-63-38 bin]# cat /tmp/backup/data/test/TABLE/t1.1.0.csv
'a','b','c','d'
1,66662,111111111,'AAA'
3,44444,111111111,'AAA'
5,33336,111111111,'AAA'
6,22226,111111111,'AAA'
7,66664,111111111,'AAA'
8,88882,111111111,'AAA'

#导入数据
[root@10-186-63-38 bin]# ./obloader -h 10.186.63.38 -P 2883 -uroot -p 'aaAA11__' --sys-password='Wa33Wa33?*' -c demo -t ten_mysql -D test --csv --column-splitter ',' --replace-data --ctl-path '/tmp/t1.ctl' --table 't1' -f /tmp/backup/
2023-05-24 12:09:02 [INFO] Parsed args:
[--csv] true
[--ctl-path] /tmp/t1.ctl
[--file-path] /tmp/backup/
[--column-splitter] ,
[--host] 10.186.63.38
[--port] 2883
[--user] root
[--tenant] ten_mysql
[--cluster] demo
[--password] ******
[--database] test
[--sys-user] root
[--sys-password] ******
[--table] [t1]
[--replace-data] true

2023-05-24 12:09:02 [INFO] Load jdbc driver class: "com.oceanbase.jdbc.Driver" finished
2023-05-24 12:09:02 [INFO] Manifest: "/tmp/backup/data/MANIFEST.bin" has been saved
2023-05-24 12:09:02 [INFO] Parse ctrl definition: "/tmp/t1.ctl" success
2023-05-24 12:09:02 [INFO] Binding table: "t1" to the file: "/tmp/backup/data/test/TABLE/t1.1.0.csv" finished
2023-05-24 12:09:02 [INFO] File: "/tmp/backup/data/test/TABLE/t2.2.0.csv" is not contained, ignore it
2023-05-24 12:09:02 [INFO] Find 1 resources in local path: "/tmp/backup" success. Elapsed: 52.84 ms
2023-05-24 12:09:02 [INFO] Split 1 data files to 1 subfiles by 64.0 MB success. Elapsed: 33.91 ms
2023-05-24 12:09:02 [INFO] Ignore to clean any tables as --truncate-table or --delete-from-table is not specified
2023-05-24 12:09:03 [INFO] Query table entry and primary key for table: "t1" finished. Remain: 0
2023-05-24 12:09:03 [INFO] Query the leader location of "t1" finished. Remain: 0
2023-05-24 12:09:03 [INFO] Calculate leader: 10.186.63.39:2881 of table "t1", part: 0. Remain: 0
2023-05-24 12:09:03 [INFO] Waiting to refresh observer load status ......
2023-05-24 12:09:03 [INFO] Refresh observer load status success. Table: "t1". Remain: 0
2023-05-24 12:09:03 [INFO] Refresh observer load status finished. Elapsed: 64.82 ms
2023-05-24 12:09:03 [INFO] Use c.l.d.LiteBlockingWaitStrategy as available cpu(s) is 4
2023-05-24 12:09:03 [INFO] Create 16 slots for ring buffer finished. [10.186.63.39:2881]
2023-05-24 12:09:03 [INFO] Start 8 database writer threads finished. [10.186.63.39:2881]
2023-05-24 12:09:03 [INFO] Start 8 record file reader threads success
2023-05-24 12:09:03 [INFO] File: "/tmp/backup/data/test/TABLE/t1.1.0.csv" has been parsed finished
2023-05-24 12:09:04 [INFO] Wait for the all the workers to drain of published events then halt the workers
2023-05-24 12:09:04 [INFO] Close connection count: 5 of the DataSource. Key: BIZ
2023-05-24 12:09:04 [INFO] Close connection count: 24 of the DataSource. Key: SYS
2023-05-24 12:09:04 [INFO] Shutdown task context finished
2023-05-24 12:09:04 [INFO] ----------   Finished Tasks: 1       Running Tasks: 0       Progress: 100.00%       ----------
2023-05-24 12:09:04 [INFO]
All Load Tasks Finished:
----------------------------------------------------------------------------------------------------------------------------
      No.#       |       Type       |             Name             |           Count             |       Status
----------------------------------------------------------------------------------------------------------------------------
        1         |       TABLE       |             t1             |            6 -> 6           |     SUCCESS
----------------------------------------------------------------------------------------------------------------------------
Total Count: 6         End Time: 2023-05-24 12:09:04
2023-05-24 12:09:04 [INFO] Load record finished. Total Elapsed: 1.700 s
2023-05-24 12:09:04 [INFO] System exit 0
#确认数据
obclient [test]> select * from t1;
+---+------+--------+------+
| a | b   | c     | d   |
+---+------+--------+------+
| 1 |   66 | 999555 | A   |
| 3 |   44 | 999555 | A   |
| 5 |   33 | 999555 | A   |
| 6 |   22 | 999555 | A   |
| 7 |   66 | 999555 | A   |
| 8 |   88 | 999555 | A   |
+---+------+--------+------+
6 rows in set (0.002 sec)
 

obloader 基于典型场景数据导入的更多相关文章

  1. 数据搬运组件:基于Sqoop管理数据导入和导出

    本文源码:GitHub || GitEE 一.Sqoop概述 Sqoop是一款开源的大数据组件,主要用来在Hadoop(Hive.HBase等)与传统的数据库(mysql.postgresql.ora ...

  2. Streamr助你掌控自己的数据(2)——三种整合数据至Streamr的典型场景

    博客说明 所有刊发内容均可转载但是需要注明出处. 三种整合数据至Streamr的典型场景 本系列文档主要介绍怎么通过Streamr管理自己的DATA,整个系列包括三篇教程文档,分别是:教你5分钟上传数 ...

  3. 大数据学习day26----hive01----1hive的简介 2 hive的安装(hive的两种连接方式,后台启动,标准输出,错误输出)3. 数据库的基本操作 4. 建表(内部表和外部表的创建以及应用场景,数据导入,学生、分数sql练习)5.分区表 6加载数据的方式

    1. hive的简介(具体见文档) Hive是分析处理结构化数据的工具   本质:将hive sql转化成MapReduce程序或者spark程序 Hive处理的数据一般存储在HDFS上,其分析数据底 ...

  4. java基于xml配置的通用excel单表数据导入组件(五、Action处理类)

    package xxxxxx.manage.importexcel; import java.io.File; import java.util.HashMap; import java.util.M ...

  5. java基于xml配置的通用excel单表数据导入组件(四、DAO主处理类)

    package XXXXX.manage.importexcel; import java.beans.IntrospectionException; import java.io.BufferedR ...

  6. HBase 实战(1)--HBase的数据导入方式

    前言: 作为Hadoop生态系统中重要的一员, HBase作为分布式列式存储, 在线实时处理的特性, 备受瞩目, 将来能在很多应用场景, 取代传统关系型数据库的江湖地位. 本篇博文重点讲解HBase的 ...

  7. 极限挑战—C#100万条数据导入SQL SERVER数据库仅用4秒 (附源码)

    原文:极限挑战-C#100万条数据导入SQL SERVER数据库仅用4秒 (附源码) 实际工作中有时候需要把大量数据导入数据库,然后用于各种程序计算,本实验将使用5中方法完成这个过程,并详细记录各种方 ...

  8. C#100万条数据导入SQL SERVER数据库仅用4秒 (附源码)

    作者: Aicken(李鸣)  来源: 博客园  发布时间: 2010-09-08 15:00  阅读: 4520 次  推荐: 0                   原文链接   [收藏] 摘要: ...

  9. Solr系列四:Solr(solrj 、索引API 、 结构化数据导入)

    一.SolrJ介绍 1. SolrJ是什么? Solr提供的用于JAVA应用中访问solr服务API的客户端jar.在我们的应用中引入solrj: <dependency> <gro ...

  10. MongoDB-Elasticsearch 实时数据导入

    时间  2017-09-18 栏目 MongoDB 原文   http://blog.csdn.net/liangxw1/article/details/78019356 5 ways to sync ...

随机推荐

  1. 文件的上传&预览&下载学习(五)

    1.背景 一个知识库,要求文件对不同的角色有不同的实现,比如某些角色只能在线预览,某些可以下载.在线观看. 2.分析 知识库其实也可以看做商品表,商品有商品图片(商品表与文件信息表做关联,因为商品有多 ...

  2. find和filter有什么区别

    JavaScript 在 ES6 上有很多数组方法,每种方法都有独特的用途和好处. 在开发应用程序时,大多使用数组方法来获取特定的值列表并获取单个或多个匹配项. 在列出这两种方法的区别之前,我们先来一 ...

  3. 基于PaddleOCR的多视角集装箱箱号检测识别

    基于PaddleOCR的多视角集装箱箱号检测识别 一.项目介绍 集装箱号是指装运出口货物集装箱的箱号,填写托运单时必填此项.标准箱号构成基本概念:采用ISO6346(1995)标准 标准集装箱箱号由1 ...

  4. 页面div垂直内容超出后,edge浏览器右侧没有自动出现滚动条

    搜索网上解决办法,是给父元素添加样式 overflow-y:scroll; height:100vh; 但此举只是给该父元素侧边添加滚动条,而且不好配合回到顶部这一效果 最后发现是在父组件的包裹元素中 ...

  5. MarkdownStudy02DOS窗口

    打开dos窗口 开始里面win系统 win+r,输入cmd 在任意文件下,按住shift+鼠标右键点击,在此处打开PowerShell窗口 资源管理器的地址栏前面加上cmd路径 管理员身份运行 常用的 ...

  6. What's the best way to read and understand someone else's code?

    Find one thing you know the code does, and trace those actions backward, starting at the end Say, fo ...

  7. 深入理解 python 虚拟机:字节码教程(1)——原来装饰器是这样实现的

    深入理解 python 虚拟机:字节码教程(1)--原来装饰器是这样实现的 在本篇文章当中主要给大家介绍在 cpython 当中一些比较常见的字节码,从根本上理解 python 程序的执行.在本文当中 ...

  8. ASP.NET Core如何知道一个请求执行了哪些中间件?

    第一步,添加Nuget包引用 需要添加两个Nuget包分别是:Microsoft.AspNetCore.MiddlewareAnalysis和Microsoft.Extensions.Diagnost ...

  9. 这个小项目,上周被国外 AI 新闻网站报道,前些天又上了 github 热榜

    疫情期间在校花了几个月时间,写了这个小项目,是关于音频特征提取和分析的,自己是 AI 专业研究音频的,但受限于对音频特征的理解,做研究时总感觉缺乏"底料",所以当做是学习练手做了这 ...

  10. day11:return关键字&全局/局部变量&函数名的使用&函数的嵌套&nonlocal关键字&locals/globals

    关键字:return 自定义函数的返回值,return可以把值返回到函数的调用处        1.return+六大标准数据类型,还有类和对象,函数        如果不定义return,默认返回的 ...