Tunnel命令参考
本文主要介绍如何使用Tunnel命令导入数据到MaxCompute。
MaxCompute提供多种数据导入导出方式,本文主要学习在客户端上使用Tunnel命令操作进行数据导入。
Tunnel命令说明
命令格式
odps@ project_name>tunnel help;
Usage: tunnel <subcommand> [options] [args]
Type 'tunnel help <subcommand>' for help on a specific subcommand.
Available subcommands:
upload (u)
download (d)
resume (r)
show (s)
purge (p)
help (h)
tunnel is a command for uploading data to / downloading data from ODPS.
参数说明
upload:上传数据到MaxCompute的表中。支持文件或目录(指一级目录)的上传,每一次上传只支持数据上传到一张表或表的一个分区。分区表一定要指定上传的分区,多级分区一定要指定到末级分区。
-- 将log.txt中的数据上传至项目空间test_project的表test_table(二级分区表)中的p1="b1",p2="b2"分区。
tunnel upload log.txt test_project.test_table/p1="b1",p2="b2";
-- 将log.txt中的数据上传至表test_table中。scan参数表示需要扫描log.txt中的数据是否符合test_table的定义,如果不符合报错,并停止上传数据。
tunnel upload log.txt test_table --scan=true;
download:从MaxCompute的表中下载数据。只支持下载到单个文件,每一次下载只支持下载一张表或一个分区到一个文件。分区表一定要指定下载的分区,多级分区一定要指定到末级分区。
-- 将test_project.test_table表(二级分区表)中的数据下载到test_table.txt文件中。
tunnel download test_project.test_table/p1="b1",p2="b2" test_table.txt;
resume:因为网络或Tunnel服务的原因出错,支持续传文件或目录。如果上传数据失败,通过resume命令进行断点续传,仅支持上传数据的续传。每次上传、下载数据被称为一个Session。在resume后指定session id完成续传。
tunnel resume;
show:查看历史运行信息。
--显示前5次上传或下载数据的详细命令。
tunnel show history -n 5;
--显示最后一次上传或下载数据的日志。
tunnel show log;
purge:清理Session目录,默认清理3天内的日志。
--清理前5天的日志。
tunnel purge 5;
help:输出Tunnel帮助信息。
说明 使用Tunnel命令过程中遇到的各类问题与最佳实践可参考Tunnel命令相关问题。
Upload
命令功能
将本地文件的数据上传至MaxCompute的表中,以追加模式导入。
命令格式
odps@ project_name>tunnel help upload;
usage: tunnel upload [options] <path> <[project.]table[/partition]>
upload data from local file
-acp,-auto-create-partition <ARG> auto create target partition if not
exists, default false
-bs,-block-size <ARG> block size in MiB, default 100
-c,-charset <ARG> specify file charset, default ignore.
set ignore to download raw data
-cf,-csv-format <ARG> use csv format (true|false), default
false. When uploading in csv format,
file splitting not supported.
-cp,-compress <ARG> compress, default true
-dbr,-discard-bad-records <ARG> specify discard bad records
action(true|false), default false
-dfp,-date-format-pattern <ARG> specify date format pattern, default
yyyy-MM-dd HH:mm:ss
-fd,-field-delimiter <ARG> specify field delimiter, support
unicode, eg \u0001. default ","
-h,-header <ARG> if local file should have table
header, default false
-mbr,-max-bad-records <ARG> max bad records, default 1000
-ni,-null-indicator <ARG> specify null indicator string,
default ""(empty string)
-ow,-overwrite <true | false> overwrite specified table or
partition, default: false
-rd,-record-delimiter <ARG> specify record delimiter, support
unicode, eg \u0001. default "\r\n"
-s,-scan <ARG> specify scan file
action(true|false|only), default true
-sd,-session-dir <ARG> set session dir, default
D:\software\odpscmd_public\plugins\dship
-ss,-strict-schema <ARG> specify strict schema mode. If false,
extra data will be abandoned and
insufficient field will be filled
with null. Default true
-t,-threads <ARG> number of threads, default 1
-te,-tunnel_endpoint <ARG> tunnel endpoint
-time,-time <ARG> keep track of upload/download elapsed
time or not. Default false
-tz,-time-zone <ARG> time zone, default local timezone:
Asia/Shanghai
Example:
tunnel upload log.txt test_project.test_table/p1="b1",p2="b2"
参数说明
必选参数
path
上传数据文件的路径以及名称。
[project.]table[/partition]
目标表表名。如果是分区表,需要指定至最末级分区。如果不是当前空间的表,需要指定表所在的空间名。
可选参数
-acp
如果指定分区不存在,自动创建目标分区。默认值为False。
-bs
指定每次上传至Tunnel的数据块大小。默认值为100 MiB(1 MiB=1024×1024 Byte)。
说明 并发写入场景,MaxCompute会根据ACID进行并发写入保障。关于ACID的具体语义,请参见ACID语义。
-c 指定本地数据文件编码。默认不设定,下载源数据。
-cf 指定是否为CSV文件,默认值为False。
-cp 指定是否在本地压缩数据后再上传,减少网络流量。默认值为True。
-dbr 指定是否忽略脏数据(多列、少列、列数据类型不匹配等情况)。默认值为False。 True:忽略全部不符合表定义的数据。 False:如果遇到脏数据,则给出错误提示信息,目标表内的原始数据不会被污染。
-dfp
指定DATETIME类型数据格式,默认为yyyy-MM-dd HH:mm:ss。如果您想指定时间格式到毫秒级别,可以使用tunnel upload -dfp ‘yyyy-MM-dd HH:mm:ss.SSS’。DATETIME数据类型详情请参见数据类型版本说明。
-fd 指定本地数据文件的列分割符。默认值为英文逗号(,)。
-h 指定数据文件是否包括表头。默认值为False。如果为True,则dship会跳过表头从第二行开始上传数据。
-mbr 指定可容忍的脏数据量。超过此数据量时,终止上传。默认值为1000条。
-ni 指定NULL数据标识符。默认值为空字符串。-ow 指定上传数据是否覆盖表或分区。默认值为False,上传数据为累加方式。示例如下。 tunnel upload -overwrite true log.txt test_project.test_table/p1=“b1”,p2=“b2”;
-rd 指定本地数据文件的行分割符。默认值为\r\n。-s 指定是否扫描本地数据文件。默认值为True。 True:先扫描数据,若数据格式正确,再导入数据。 False:不扫描数据,直接导入数据。 Only:仅扫描本地数据,扫描结束后不继续导入数据。
-sd 指定Session目录。-ss 指定严格架构模式。默认值为True。如果为False,多余的数据将被丢弃,不足的字段将填充NULL。
-t 指定Threads的数量。默认值为1。
-te 指定Tunnel的Endpoint。
-time 指定是否跟踪上传所用时间。默认值为False。
-tz 指定时区。默认值为本地时区,例如Asia/Shanghai。
参考官网:https://help.aliyun.com/document_detail/27809.html?spm=a2c4g.11186623.2.32.2c4816dcR9PBCw