南大通用数据库-Gbase-8a-学习-14-LOAD加载数据

一、测试环境

名称
cpuIntel® Core™ i5-1035G1 CPU @ 1.00GHz
操作系统CentOS Linux release 7.9.2009 (Core)
Gbase-8a数据库版本9.5
FTP服务器IP192.168.142.11
数据库服务器IP192.168.142.10

二、LOAD相关数据库参数介绍

参数名描述
gbase_loader_buffer_count用于指定加载过程中分配的读缓冲内存块数量,其中单块内存固定大小为8M,每个加载任务单个节点占用的读缓冲内存为8M*gbase_loader_buffer_count。最大值:128
gbase_loader_check_charset用于设置是否打开字符集检查功能,该参数仅对加载有效,对其他 SQL 无影响。
gbase_loader_last_task_idSession 级只读变量,用于查询当前 Session 的最后加载任务 TASK_ID值。可以使用 select @@gbase_loader_last_task_id 方式查询。
gbase_loader_logs_collect用于控制日志汇总功能的开启。ON:表示开启加载错误数据日志汇总功能,加载过程中实时的将错误数据与溯源信息汇总至加载发起节点。OFF:表示关闭加载错误数据日志汇总功能,加载遵循现有规则,错误数据日志与溯源信息日志保存在加载节点。
gbase_loader_logs_dir用户指定错误数据与溯源日志文件汇总目录。
gbase_loader_max_line_length用于设置源文件中一行数据的最大长度,超过此长度,加载任务将报错停止。单位:字节。
gbase_loader_parallel_degree该参数用于设置控制加载 SQL 执行的并行度(并行线程数),如果不设定该参数值,则该参数的默认值是 0(0 表示用默认并行度,默认并行度取值是线程池最大可用资源数)。设置 gbase_loader_parallel_degree 参数对加载不再有效。
gbase_loader_read_timeout用于指定读取 FTP/HTTP/HDFS/SFTP 文件的超时时间,如果填充一个数据块(8M)的时间超过此参数值,加载任务将报错停止。0 表示永不超时。单位:秒。默认
gbase_loader_wildcard_switch控制是否打开多级目录通配加载功能。1(ON):表示开启多级目录通配功能,加载过程中对 SQL 中含有通配符的文件路径通配展开,获得精确文件路径;0(OFF):表示关闭多级目录通配功能,加载遵循现有规则,按 SQL 指定的路径进行加载。该参数默认值为 1。
gcluster_enable_serial_load设定超过边界值按当前设定参数的形式统一处理,默认值为 0,代表不受控制。
gcluster_kafka_loader_max_start_count控制 loader 型 consumer 最多可以启动的数量,如果超过了这个数量,start kafka consumer 命令将报错。
gcluster_loader_max_data_processors一次加载任务使用的最大加载机个数(参与数据解析处理的最大节点数)
gcluster_loader_min_chunk_size数据文件最小分块粒度,单位是字节,UINT_MAX 取值为 4294967295。

三 、LOAD语法树

LOAD DATA INFILE 'file_list'
INTO TABLE [dbname.]tbl_name
[options]
options:
 [CHARACTER SET charset_name]
 [DATA_FORMAT number [HAVING LINES SEPARATOR]]
 [NULL_VALUE 'string']
 [FIELDS
 [TERMINATED BY 'string']
 [ENCLOSED BY 'string']
 [PRESERVE [LEADING | TRAILING] BLANKS]
 [AUTOFILL]
 [LENGTH 'string']
 [TABLE_FIELDS 'string']
 ]
 [LINES
 [TERMINATED BY 'string']
 ]
 [MAX_BAD_RECORDS number]
 [DATETIME FORMAT format]
 [DATE FORMAT format]
 [TIMESTAMP FORMAT format]
 [TIME FORMAT format]
 [TRACE number]
 [TRACE_PATH 'string']
 [NOSPLIT]
 [PARALLEL number]
 [MAX_DATA_PROCESSORS number]
 [MIN_CHUNK_SIZE number]
 [SKIP_BAD_FILE number]
 [SET col_name = value[,...]]
 [IGNORE NUM LINES]
 [FILE_FORMAT format]
参数名描述
CHARACTER SET用来指定待加载数据文件的编码格式,目前支持GBK和UTF8两种格式。省略时,认为不需要转码。支持的字符集为GB系列(GB2312,GBK,GB18030)和UTF8系列(utf8,utf8mb4)。
DATA_FORMAT用来指定使用哪种方式解析数据文件并加载。指定为3,表示使用文本方式加载。指定为4,表示使用定长方式加载。如果某列数据可能包含了行分隔符,则需要在SQL中输入’HAVING LINES SEPARATOR’子句。指定为5,表示使用文本文件宽松模式,即数据源文件为包围符中含有换行符和包围符文本文件,或多列少列文本文件。
NULL_VALUE用于指定空值字符,支持不超过15个任意字符的组合,参数值以引号包围,指定方式与字段包围符一样。
FIELDS
TERMINATED BY用于指定字段分隔符,支持不超过15个任意字符的组合,支持任意字符,参数值以引号包围,仅当使用文本方式加载时有效。可使用字符本身(仅限可见字符,如:“|”)、C风格转义字符(如:“\a”)、\xhh十六进制(如:“\xFF”)或x’‘十六进(如:"x’09’")四种方式指定。例如:‘|’,表示用|作为分隔字符。
ENCLOSED BY用于指定字段包围符,支持任意单字符,参数值以单引号包围,仅当使用文本方式加载时有效。可使用字符本身(仅限可见字符,如:“|”)、C风格转义字符(如:“\a”)、\xhh十六进制(如:“\xFF”)或x’‘十六进制(如:"x’09’")四种方式指定。
PRESERVE BLANKS用于设定是否保留字段内容两端的空格,默认不保留空格。支持format=3、format=4。1、不保留空格,不写PRESERVE BLANKS(缺省);2、保留前空格,PRESERVE LEADING BLANKS;3、保留后空格,PRESERVE TRAILING BLANKS;
AUTOFILL用于设定是否启用缺失列自动补齐功能,启用该参数后,对缺失分割符的字段数据按照default值或者NULL值进行加载,默认不自动补齐。
DEFINER在使用定长模式加载时,用于设定字段长度的参数。定长格式数据导入时,设置每个字段的长度,有多个字段时,用逗号分隔。
LENGTH在使用定长模式加载时,用于设定字段长度的参数。定长格式数据导入时,设置每个字段的长度,有多个字段时,用逗号分隔。
TABLE_FIELDS用于指定列加载,对于日期时间类型可以设置每一列的格式。对于数据加载过程中,数据文件中不需要加载的字段,可以使用table_fields参数中的filler关键字将其忽略掉。
SET指定列值加载,加载系统将待加载文件和指定加载列值加载到集群系统的表中。输入的类型应为常量,包括字符串、整数值、浮点值和NULL。
LINES
TERMINATED BY行分隔符,支持任意单字符,参数值以引号包围。指定方式与包围符一样。默认行分隔符为’\n’。
MAX_BAD_RECORDS在每次加载的任务中,设定错误数据行数的上限。当本次加载任务产生的错误数据行数大于max_bad_records设定的值时,加载任务回滚,加载工具报错退出。不指定该参数表示不限制错误条数,指定该参数时,此参数取值范围为:[0, 4294967295]。0表示只要有错误数据就报错退出。最大加载错误数的计算方式:所有集群节点独立计算,一旦有一个节点加载时错误数据达到本限制,则终止所有节点的加载任务。集群加载提交之前检查总错误条数是否超出限制,如果超出限制,放弃提交,报错退出。
DATE FORMAT用来指定date列类型的默认格式,如’%Y-%m-%d’。
DATETIME FORMAT用来指定datetime列的默认格式,如’%Y-%m-%d %H:%i:%s’。
TIMESTAMP FORMAT用来指定timestamp列的默认格式,如’%Y-%m-%d %H:%i:%s.%f’。
TIME FORMAT用来指定time列的默认格式,如’%H:%i:%s’。
TRACE用来指示本次加载是否保存错误数据溯源。如果指定为0,则不溯源。如果指定为1,则进行溯源.默认值为1。溯源信息包括:错误数据所在的文件,所在行号。
TRACE_PATH用来指定本次加载过程中产生的错误数据和日志存放路径。支持设置为本地绝对路径,远程FTP或SFTP目录。在禁用日志汇总功能时,该参数才能起作用,默认值为加载节点的“/opt/gnode/log/gbase/loader_logs”中。
NOSPLIT用来指定本次加载任务中是否禁用分块加载功能,指定该参数将禁用分块加载功能。不指定该参数,在集群加载时,将自动启动分块加载功能,按照数据量和参与运算的加载节点数对数据进行均匀分块,以均衡数据服务器和数据处理节点的负载,优化加载性能。
PARALLEL用来控制集群加载并行度,取值范围[0,1024]。默认值为0,表示并行度取值是线程池最大可用线程数。
MAX_DATA_PROCESSORS用来指定本次加载任务中参与数据解析的处理的最大节点数,取值范围[1, 4294967295],默认值16。
MIN_CHUNK_SIZE用来指定本次加载任务中数据分块的最小粒度,取值范围[1, 4294967295],默认值64M。
SKIP_BAD_FILE用来指定本次加载任务中是否忽略不存在或没有读取权限的数据文件继续加载。如果指定为0,则加载报错终止。如果指定为1,则忽略异常文件继续加载。默认值为0。
IGNORE NUM LINES:配置该参数加载工具会将本次加载指定的所有数据文件的表头进行过滤,跳过每个文件的前NUM行(表头所占行数),NUM取值范围为[0,MAX_UINT]。
FILE_FORMAT用来指定被加载文件的格式。枚举型参数,取值为UNDEFINED、UNCOMPRESSED、GZIP、SNAPPY、LZO,默认为UNDEFINED。指定为UNDEFINED,表示不指定格式,按文件后缀自动判断文件格式;指定为UNCOMPRESSED,表示按普通文本方式加载文件;指定为GZIP,表示按GZIP格式加载文件;指定为SNAPPY,表示按SNAPPY格式加载文件;指定为LZO,表示按LZO格式加载文件。

四、支持的数据源

类型名备注
S3本文暂不介绍
local本文介绍
https本文暂不介绍
ftp本文介绍
sftp本文介绍
hdfs本文暂不介绍,由于安装包太大,流量不够,下次再写,嘿嘿!!!
gbfs本文暂不介绍

五、部署FTP服务器

参考原文连接:Linux 上搭建 FTP 服务

不测试LOAD的FTP加载可以不安装,跳过此步。

1-7步都在192.168.142.11节点执行。

1、安装vsftpd并配置自启

[root@xdw1 ~]# yum install -y vsftpd

[root@xdw1 ~]# systemctl enable vsftpd

[root@xdw1 ~]# systemctl start vsftpd

[root@xdw1 ~]# netstat -npl |grep ftp
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      9343/vsftpd   

2、创建FTP用户

[root@xdw1 ~]# useradd ftpuser

[root@xdw1 ~]# passwd ftpuser

密码我设置的是qwer1234。

3、建目录改权限

[root@xdw1 ~]# mkdir /var/ftp/test

[root@xdw1 ~]# chown -R ftpuser:ftpuser /var/ftp/test

4、配置vsftpd.conf

[root@xdw1 ~]# cat /etc/vsftpd/vsftpd.conf
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES
#tcp_wrappers=YES

5、配置chroot_list

[root@xdw1 ~]# cat /etc/vsftpd/chroot_list
ftpuser

6、重启FTP服务

[root@xdw1 ~]# systemctl restart vsftpd

7、生成测试文件

[root@xdw1 ~]# cat /var/ftp/test/test.txt 
1
2

8、验证FTP服务器(可做可不做)

192.168.142.10节点执行如下命令。

(1)安装FTP命令
yum install ftp
(2)登录FTP拉去文件
[root@xdw0 src]# ftp

ftp> open 192.168.142.11
Connected to 192.168.142.11 (192.168.142.11).
220 (vsFTPd 3.0.2)
Name (192.168.142.11:root): ftpuser
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

ftp> get /var/ftp/test/test.txt /opt/test.txt
local: /opt/test.txt remote: /var/ftp/test/test.txt
227 Entering Passive Mode (192,168,142,11,22,160).
150 Opening BINARY mode data connection for /var/ftp/test/test.txt (4 bytes).
226 Transfer complete.
4 bytes received in 0.000162 secs (24.69 Kbytes/sec)

ftp> quit
221 Goodbye.

[root@xdw0 src]# cat /opt/test.txt 
1
2

六、测试LOAD

0、加载之前建议配置参数(全局设置)

set global gbase_loader_read_timeout = 10000;

set global gcluster_loader_max_data_processors = 4;

1、FTP

gbase> desc sun;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| a     | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
1 row in set (Elapsed: 00:00:00.00)

gbase> LOAD DATA INFILE 'ftp://ftpuser:qwer1234@192.168.142.11//var/ftp/test/test.txt' into table sun DATA_FORMAT 3 FIELDS TERMINATED BY '|';
Query OK, 2 rows affected (Elapsed: 00:00:00.22)
Task 1310724 finished, Loaded 2 records, Skipped 0 records

gbase> select * from sun;
+------+
| a    |
+------+
|    1 |
|    2 |
+------+
2 rows in set (Elapsed: 00:00:00.00)

2、SFTP

gbase> LOAD DATA INFILE 'sftp://root:qwer1234@192.168.142.11//var/ftp/test/test.txt' into table sun DATA_FORMAT 3 FIELDS TERMINATED BY '|';
Query OK, 2 rows affected (Elapsed: 00:00:00.77)
Task 1310725 finished, Loaded 2 records, Skipped 0 records

gbase> select * from sun;
+------+
| a    |
+------+
|    1 |
|    2 |
|    1 |
|    2 |
+------+
4 rows in set (Elapsed: 00:00:00.01)

3、本地

gbase> LOAD DATA INFILE 'file://192.168.142.10//opt/test.txt' into table sun DATA_FORMAT 3 FIELDS TERMINATED BY '|';
Query OK, 2 rows affected (Elapsed: 00:00:00.04)
Task 1310728 finished, Loaded 2 records, Skipped 0 records

gbase> select * from sun;
+------+
| a    |
+------+
|    1 |
|    2 |
|    1 |
|    2 |
|    1 |
|    2 |
+------+
6 rows in set (Elapsed: 00:00:00.00)
  • 6
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值