MaxCompute Console 实用小命令

    xiaoxiao2025-10-17  6

    MaxCompute Console 可以从 这里 下载。在阿里云官网可以查看 帮助文档。

    这里跟大家分享一些 MaxCompute Console 中实用的小命令。嗯,一般人我不告诉他~

    1 odpscmd -v 查看 odpscmd 版本

    /Users/zhenhong/tool/odps_clt ./bin/odpscmd -v ******Odps Command Line Tools****** BuildTime: 2016-06-27 18:14:48 Revision: 30d623d MavenVersion: 0.24.0-snapshot Branch: develop

    2 开启 debug 模式

    在 odps_config.ini 中加一行:debug=true,将开启调试模式。之后在 odpscmd 运行过程中会输出 debug 日志、异常 stacktrace 等,方便定位问题。

    /Users/zhenhong/tool/odps_clt cat conf/odps_config.ini debug=true access_id=*** access_key=*** end_point=*** project_name=***

    运行 odpscmd,输入错误命令,将会看到错误日志

    /Users/zhenhong/tool/odps_clt ./bin/odpscmd [DEBUG]:ODPSConsole Start Aliyun ODPS Command Line Tool Version 0.24.0-snapshot @Copyright 2015 Alibaba Cloud Computing Co., Ltd. All rights reserved. odps@ odps_test_tunnel_project_gcc492>ll tables; FAILED: ODPS-0130161:Parse exception - line 1:0 cannot recognize input near 'll' 'tables' '<EOF>' [DEBUG]: com.aliyun.openservices.odps.console.ODPSConsoleException: ODPS-0130161:Parse exception - line 1:0 cannot recognize input near 'll' 'tables' '<EOF>' at com.aliyun.openservices.odps.console.QueryCommand.run(QueryCommand.java:212) 。。。

    3 help <命令关键字> 获取命令使用提示

    大多数同学都知道使用 odpscmd -h 或者 help;来获取 odpscmd 的所有命令提示。除了这个,我们还有专门的 help + 关键字 命令呢。例如,使用help ls; 获取与 ls 相关的命令;使用 help table; 命令来获取所有与 table 相关的命令提示。

    /Users/zhenhong/tool/odps_clt ./bin/odpscmd [DEBUG]:ODPSConsole Start Aliyun ODPS Command Line Tool Version 0.24.0-snapshot @Copyright 2015 Alibaba Cloud Computing Co., Ltd. All rights reserved. odps@ odps_test_tunnel_project_gcc492>help table; Usage: show tables [in <projectname>] list|ls tables [-p,-project <projectname>] Usage: export table <tablename> Usage: alter table <tablename> merge smallfiles Usage: read <table_name> [<(col_name>[,..])][PARTITION <(partition_spec)>][line_num]

    是不是很方便呢?再也不用去翻文档了!

    另外,负责数据上传下载 tunnel 命令,除了有 help tunnel; 来获取提示,还有tunnel help <subcommand> 来获取详细命令提示,下面例子使用 tunnel help download; 得到与下载相关的命令参数。

    odps@ odps_test_tunnel_project_gcc492>tunnel help download; usage: tunnel download [options] <[project.]table[/partition]> <path> download data to local file -c,-charset <ARG> specify file charset, default ignore. set ignore to download raw data 。。。。(此处省略大量参数提示) -tz,-time-zone <ARG> time zone, default local timezone: Asia/Shanghai Example: tunnel download test_project.test_table/p1="b1",p2="b2" log.txt

    4 wait <instance_id> 获取 instance 详细信息:logview、 summary 等

    当一个作业已经运行完成,或者被放到后台执行,我们就不能再看到 instance 相关的执行信息,包括 logview 链接、instance summary、instance 运行的结果等等。这个时候,使用 wait <instance_id>命令可以再次获取到这些信息。

    odps@ odps_test>wait 20161008231329221gr58pvyi2; ID = 20161008231329221gr58pvyi2 Log view: http://logview.odps.aliyun-inc.com:8080/logview/?h=http://***:***/***&p=odps_test&i=20161008231329221gr58pvyi2&token=******** Summary: resource cost: cpu 0.00 Core * Min, memory 0.00 GB * Min inputs: odps_test.src: 500 (2608 bytes) outputs: [此处省略。。。] "_c0" 500

    5 命令自动补全

    由于历史原因,odpscmd 的命令没有统一的规范,完整的命令补全不是很好做,但是在 0.23.0 版本之后,我们做了命令关键字和文件路径的自动补全,使用TAB键即可。下面列出输入不同字符后,敲 TAB 键的结果:

    odps@ test_new_console_gcc>tunnel up update updateabtest upload odps@ test_new_console_gcc>tunnel upload test_dual ./te test test_body test_dual test_dual1 test_header test_out test_value text odps@ test_new_console_gcc>add resource /tmp/ com.apple.launchd.1YmqQ8L2kK com.apple.launchd.26PWVPElv8 entsafemgr.log

    6 history 命令查看历史

    用来找曾经写过的命令,特别方便哦。

    odps@ test_new_console_gcc>history; 1 count src; 2 select t1.prediction_result from pai_pred_output_perd_14561096286930 t1 join pai_pred_output_perd_14561096286930 t2 on t1.label ==t2.label; 3 desc instance 20160811091342933gtvve03; 4 desc instance 20160811091342933gtvve03; 5 wait 20160811091342933gtvve03; (省略 。。。)

    注: 最多缓存 500 条历史命令

    7 版本更新自动提示

    在最新的开发版本中,我们添加了版本的更新提示功能,先露个脸吧:

    /Users/zhenhong/tool/odps_clt ./bin/odpscmd Aliyun ODPS Command Line Tool Version 0.25.0-snapshot @Copyright 2015 Alibaba Cloud Computing Co., Ltd. All rights reserved. New version 0.25.1 available! Try it now! http://repo.aliyun.com/odpscmd/

    持续更新中 (欢迎补充,更欢迎吐槽(_))。。。

    如果上述命令的您还不能使用,请先升级版本哦,快来 试试 吧!

    更多问题欢迎加入MaxCompute钉钉群讨论

    最新回复(0)