阅读497 返回首页    go 人物


Tunnel命令操作__常用命令_基本介绍_大数据计算服务-阿里云

用户可以通过客户端提供的Tunnel命令数据的长传及下载。

Tunnel命令,主要用于数据的上传下载等功能。主要功能包括如下:

  • Upload:支持文件或目录(指一级目录)的上传,每一次上传只支持数据上传到一个表或表的一个分区,有分区的表一定要指定上传的分区。
  1. tunnel upload log.txt test_project.test_table/p1="b1",p2="b2";
  2. -- 将log.txt中的数据上传至项目空间test_project的表test_table中的p1="b1",p2="b2"分区
  3. tunnel upload log.txt test_table --scan=true;
  4. -- 将log.txt中的数据上传至表 test_table 中。--scan参数表示需要扫描log.txt中的数据是否符合 test_table 的定义,如果不符合报错,并停止上传数据。
  • Download:只支持下载到单个文件,每一次下载只支持下载一个表或一个分区到一个文件,有分区的表一定要指定下载的分区。
  1. tunnel download test_project.test_table/p1="b1",p2="b2" test_table.txt;
  2. -- 将表中的数据下载到 test_table.txt 文件中
  • Resume:因为网络或tunnel服务的原因出错,支持文件或目录的续传。用户可以继续上一次的数据上传操作。但Resume命令暂时没有对下载操作的支持
  1. tunnel resume;
  • Show:显示历史任务信息。
  1. tunnel show history -n 5;
  2. --显示前5次上传/下载数据的详细命令
  3. tunnel show log;
  4. --显示最后一次上传/下载数据的日志
  • Purge:清理session目录,默认清理3天内的。
  1. tunnel purge 5;
  2. --清理前5天的日志

Tunnel命令使用说明

Tunnel命令支持在客户端通过help子命令获取帮助信息,每个命令和选择支持短命令格式:

  1. odps@ project_name>tunnel help;
  2. Usage: tunnel <subcommand> [options] [args]
  3. Type 'tunnel help <subcommand>' for help on a specific subcommand.
  4. Available subcommands:
  5. upload (u)
  6. download (d)
  7. resume (r)
  8. show (s)
  9. purge (p)
  10. help (h)
  11. tunnel is a command for uploading data to / downloading data from ODPS.

说明:

  • upload:帮助用户上传数据到 MaxCompute 的表中;
  • download:帮助用户从 MaxCompute 的表中下载数据;
  • resume:如果上传数据失败,通过resume命令进行断点续传,目前仅支持上传数据的续传。每次上传、下载数据被称为一个session。在resume命令后指定session id完成续传。
  • show:查看历史运行信息;
  • purge:清理 session 目录;
  • help:输出 tunnel 帮助信息;

Upload

将本地文件的数据导入 MaxCompute 的表中,以追加模式导入。子命令使用提示:

  1. odps@ project_name>tunnel help upload;
  2. usage: tunnel upload [options] <path> <[project.]table[/partition]>
  3. upload data from local file
  4. -bs,--block-size <ARG> block size in MiB, default 100
  5. -c,--charset <ARG> specify file charset, default utf8.
  6. set ignore to download raw data
  7. -cp,--compress <ARG> compress, default true
  8. -dbr,--discard-bad-records <ARG> specify discard bad records
  9. action(true|false), default false
  10. -dfp,--date-format-pattern <ARG> specify date format pattern, default
  11. yyyy-MM-dd HH:mm:ss
  12. -e,--endpoint <ARG> odps endpoint
  13. -fd,--field-delimiter <ARG> specify field delimiter, default ","
  14. -h,--header <ARG> if local file should have table
  15. header, default false
  16. -mbr,--max-bad-records <ARG> max bad records, default 1000
  17. -ni,--null-indicator <ARG> specify null indicator string, default
  18. ""(empty string)
  19. -rd,--record-delimiter <ARG> specify record delimiter, default
  20. "rn"
  21. -s,--scan <ARG> specify scan file
  22. action(true|false|only), default true
  23. -sd,--session-dir <ARG> set session dir, default
  24. /D:/console/plugins/dship/lib/..
  25. -te,--tunnel-endpoint <ARG> tunnel endpoint
  26. -tz,--time-zone <ARG> time zone, default local timezone:
  27. Asia/Shanghai
  28. Example:
  29. tunnel upload log.txt test_project.test_table/p1="b1",p2="b2"

主要参数说明:

  • -bs,—block-size:每次上传至Tunnel的数据块大小,默认值:100MiB (MiB=1024*1024B )。
  • -c,—charset:指定本地数据文件编码,默认为’UTF-8’;不设定,默认下载源数据。
  • -cp,—compress:指定是否在本地压缩后再上传,减少网络流量,默认开启。
  • -dfp:DateTime类型数据格式,默认为’yyyy-MM-dd HH:mm:ss’;
  • -dbr:是否忽略脏数据(多列,少列,列数据类型不匹配等情况)。值为’true’时,将全部不符合表定义的数据忽略。值为’false’,若遇到脏数据,则给出错误提示信息,目标表内的原始数据不会被污染。
  • -e: 指定odps的endpoint.
  • -fd:本地数据文件的列分割符,默认为逗号’,’;
  • -h: 数据文件是否包括表头,如果为true,则dship会跳过表头从第二行开始上传数据。
  • -mbr,—max-bad-records:默认情况下,当上传的脏数据超过1000条时,上传动作终止。通过此参数,可以调整可容忍的脏数据量;
  • -ni:NULL数据标志符,默认为” “(空字符串);
  • -rd:本地数据文件的行分割符,默认为’rn’;
  • -s:是否扫描本地数据文件,默认值为’false’。值为’true’时,先扫描数据,若数据格式正确,再导入数据。值为’false’,不扫描数据,直接进行数据导入。值为’only’时,仅进行扫描本地数据,扫描结束后不继续导入数据。
  • -te:指定tunnel的Endpoint.
  • -tz:指定时区。默认为本地时区:Asia/Shanghai。

程序示例:

  • 创建目标表:
  1. CREATE TABLE IF NOT EXISTS sale_detail(
  2. shop_name STRING,
  3. customer_id STRING,
  4. total_price DOUBLE)
  5. PARTITIONED BY (sale_date STRING,region STRING);
  • 添加分区:
  1. alter table sale_detail add partition (sale_date='201312', region='hangzhou');
  • 准备数据文件data.txt,其内容为:
  1. shop9,97,100
  2. shop10,10,200
  3. shop11,11

这份文件的第三行数据与sale_detail的表定义不符。sale_detail定义了三列,但数据只有两列。

  • 导入数据:
  1. odps@ project_name>tunnel u d:data.txt sale_detail/sale_date=201312,region=hangzhou -s false
  2. Upload session: 201506101639224880870a002ec60c
  3. Start upload:d:data.txt
  4. Total bytes:41 Split input to 1 blocks
  5. 2015-06-10 16:39:22 upload block: '1'
  6. ERROR: column mismatch -,expected 3 columns, 2 columns found, please check data or delimiter

由于data.txt中有脏数据,数据导入失败。并给出session id及错误提示信息。

数据验证:

  1. odps@ odpstest_ay52c_ay52> select * from sale_detail where sale_date='201312';
  2. ID = 20150610084135370gyvc61z5
  3. +-----------+-------------+-------------+-----------+--------+
  4. | shop_name | customer_id | total_price | sale_date | region |
  5. +-----------+-------------+-------------+-----------+--------+
  6. +-----------+-------------+-------------+-----------+--------+

由于有脏数据,数据导入失败,表中无数据。

Show

显示历史记录。子命令使用提示:

  1. usage: tunnel show history [options]
  2. show session information
  3. -c,--charset <ARG> specify file charset, default utf8.
  4. set ignore to download raw data
  5. -cp,--compress <ARG> compress, default true
  6. -dfp,--date-format-pattern <ARG> specify date format pattern, default
  7. yyyy-MM-dd HH:mm:ss
  8. -e,--endpoint <ARG> odps endpoint
  9. -fd,--field-delimiter <ARG> specify field delimiter, default ","
  10. -h,--header <ARG> if local file should have table
  11. header, default false
  12. -n,--number <ARG> lines
  13. -ni,--null-indicator <ARG> specify null indicator string, default
  14. ""(empty string)
  15. -rd,--record-delimiter <ARG> specify record delimiter, default
  16. "rn"
  17. -sd,--session-dir <ARG> set session dir, default
  18. /D:/console/plugins/dship/lib/..(plugins/dship/lib所在具体路径)
  19. -te,--tunnel-endpoint <ARG> tunnel endpoint
  20. -tz,--time-zone <ARG> time zone, default local timezone:
  21. Asia/Shanghai
  22. Example:
  23. tunnel show history -n 5
  24. tunnel show log

命令示例:

  1. odps@ project_name>tunnel show history;
  2. 201506101639224880870a002ec60c failed 'u --config-file /D:/console/conf/odps_config.ini --project odpstest_ay52c_ay52 --endpoint https://service.odps.aliyun.com/api --id UlVxOHuthHV1QrI1 --key 2m4r3WvTZbsNJjybVXj0InVke7UkvR d:data.txt sale_detail/sale_date=201312,region=hangzhou -s false'

说明:201506101639224880870a002ec60c是上节中导入数据失败时的运行id。

Resume

修复执行历史记录,仅对上传数据有效。子命令使用提示:

  1. usage: tunnel resume [session_id] [--force]
  2. download data to local file
  3. -c,--charset <ARG> specify file charset, default utf8.
  4. set ignore to download raw data
  5. -cp,--compress <ARG> compress, default true
  6. -dfp,--date-format-pattern <ARG> specify date format pattern, default
  7. yyyy-MM-dd HH:mm:ss
  8. -e,--endpoint <ARG> odps endpoint
  9. -f,--force force resume
  10. -fd,--field-delimiter <ARG> specify field delimiter, default ","
  11. -h,--header <ARG> if local file should have table
  12. header, default false
  13. -ni,--null-indicator <ARG> specify null indicator string, default
  14. ""(empty string)
  15. -rd,--record-delimiter <ARG> specify record delimiter, default
  16. "rn"
  17. -sd,--session-dir <ARG> set session dir, default
  18. /D:/console/plugins/dship/lib/..
  19. -te,--tunnel-endpoint <ARG> tunnel endpoint
  20. -tz,--time-zone <ARG> time zone, default local timezone:
  21. Asia/Shanghai
  22. Example:
  23. tunnel resume

命令示例:

修改data.txt文件为:

  1. shop9,97,100
  2. shop10,10,200

修复执行上传数据:

  1. odps@ project_name>tunnel resume 201506101639224880870a002ec60c --force;
  2. start resume
  3. 201506101639224880870a002ec60c
  4. Upload session: 201506101639224880870a002ec60c
  5. Start upload:d:data.txt
  6. Resume 1 blocks
  7. 2015-06-10 16:46:42 upload block: '1'
  8. 2015-06-10 16:46:42 upload block complete, blockid=1
  9. upload complete, average speed is 0 KB/s
  10. OK

其中,201506101639224880870a002ec60c为上传失败的session id。

数据验证:

  1. odps@ project_name>select * from sale_detail where sale_date='201312';
  2. ID = 20150610084801405g0a741z5
  3. +-----------+-------------+-------------+-----------+--------+
  4. | shop_name | customer_id | total_price | sale_date | region |
  5. +-----------+-------------+-------------+-----------+--------+
  6. | shop9 | 97 | 100.0 | 201312 | hangzhou |
  7. | shop10 | 10 | 200.0 | 201312 | hangzhou |
  8. +-----------+-------------+-------------+-----------+--------+

Download

子命令使用提示:

  1. odps@ project_name>tunnel help download;
  2. usage: tunnel download [options] <[project.]table[/partition]> <path>
  3. resume [session_id] [--force]
  4. -c,--charset <ARG> specify file charset, default utf8.
  5. set ignore to download raw data
  6. -cp,--compress <ARG> compress, default true
  7. -dfp,--date-format-pattern <ARG> specify date format pattern, default
  8. yyyy-MM-dd HH:mm:ss
  9. -e,--endpoint <ARG> odps endpoint
  10. -fd,--field-delimiter <ARG> specify field delimiter, default ","
  11. -h,--header <ARG> if local file should have table
  12. header, default false
  13. -ni,--null-indicator <ARG> specify null indicator string, default
  14. ""(empty string)
  15. -rd,--record-delimiter <ARG> specify record delimiter, default
  16. "rn"
  17. -sd,--session-dir <ARG> set session dir, default
  18. /D:/console/plugins/dship/lib/..(plugins/dship/lib所在的实际路径)
  19. -te,--tunnel-endpoint <ARG> tunnel endpoint
  20. -tz,--time-zone <ARG> time zone, default local timezone:
  21. Asia/Shanghai
  22. Example:
  23. tunnel download test_project.test_table/p1="b1",p2="b2" log.txt

说明:

  • -fd:本地数据文件的列分割符,默认为逗号’,’;
  • -rd:本地数据文件的行分割符,默认为’rn’;
  • -dfp:DateTime类型数据格式,默认为’yyyy-MM-dd HH:mm:ss’;
  • -ni:NULL数据标志符,默认为” “(空字符串);
  • -c:本地数据文件编码,默认为’UTF-8’;

命令示例:

下载数据到result.txt文件中:

  1. $ ./tunnel download sale_detail/sale_date=201312,region=hangzhou result.txt;
  2. Download session: 201506101658245283870a002ed0b9
  3. Total records: 2
  4. 2015-06-10 16:58:24 download records: 2
  5. 2015-06-10 16:58:24 file size: 30 bytes
  6. OK

数据验证,result.txt的文件内容为:

  1. shop9,97,100.0
  2. shop10,10,200.0

Purge

清除session目录,默认清除距离当前日期3天内的。子命令使用提示:

  1. usage: tunnel purge [n]
  2. force session history to be purged.([n] days before, default
  3. 3 days)
  4. -c,--charset <ARG> specify file charset, default utf8.
  5. set ignore to download raw data
  6. -cp,--compress <ARG> compress, default true
  7. -dfp,--date-format-pattern <ARG> specify date format pattern, default
  8. yyyy-MM-dd HH:mm:ss
  9. -e,--endpoint <ARG> odps endpoint
  10. -fd,--field-delimiter <ARG> specify field delimiter, default ","
  11. -h,--header <ARG> if local file should have table
  12. header, default false
  13. -ni,--null-indicator <ARG> specify null indicator string, default
  14. " "(empty string)
  15. -rd,--record-delimiter <ARG> specify record delimiter, default
  16. "rn"
  17. -sd,--session-dir <ARG> set session dir, default
  18. /D:/console/plugins/dship/lib/..
  19. -te,--tunnel-endpoint <ARG> tunnel endpoint
  20. -tz,--time-zone <ARG> time zone, default local timezone:
  21. Asia/Shanghai
  22. Example:
  23. tunnel purge 5

数据类型说明

类型 描述
STRING 字符串类型,长度不能超过8MB。
BOOLEN 上传值只支持”true”,”false”,”0”,”1”。下载值为true/false且不区分大小写。
BIGINT 取值范围[-9223372036854775807,9223372036854775807]。
DOUBLE 1.有效位数16位
2.上传支持科学计数法表示
3.下载仅使用数字表示
4.最大值:1.7976931348623157E308
5.最小值:4.9E-324
6.无穷大:Infinity
7.无穷小:-Infinity
DATETIME Datetime类型默认支持时区为GMT+8的数据上传,可以通过命令行指定用户数据日期格式的format pattern。

如果用户上传DATETIME类型的数据,需要指定时间日期格式,具体格式可参考 SimpleDateFormat :

  1. "yyyyMMddHHmmss": 数据格式"20140209101000"
  2. "yyyy-MM-dd HH:mm:ss"(默认):数据格式"2014-02-09 10:10:00"
  3. "yyyy年MM月dd日": 数据格式"2014年09月01日"

示例:

  1. tunnel upload log.txt test_table -dfp "yyyy-MM-dd HH:mm:ss"

空值

所有数据类型都可以有空值:

  • 默认空字符串为空值。

  • 可在命令行下通过-null-indicator参数来指定空值的字符串

  1. tunnel upload log.txt test_table -ni "NULL"

字符编码

用户可以指定文件的字符编码,默认为”UTF-8”。

  1. tunnel upload log.txt test_table -c "gbk"

分隔符

tunnel命令支持用户自定义的文件分隔符,行分隔符选项为”-record-delimiter”,列分隔符选项为”-field-delimiter”。 分隔符说明:

  • 支持多个字符的行列分隔符
  • 列分隔符不能够包含行分隔符
  • 转义字符分隔符,在命令行方式下只支持r、n和t

示例:

  1. tunnel upload log.txt test_table -fd "||" -rd "rn"

最后更新:2016-11-23 17:16:04

  上一篇:go 函数操作__常用命令_基本介绍_大数据计算服务-阿里云
  下一篇:go 其他操作__常用命令_基本介绍_大数据计算服务-阿里云