当前位置:网站首页>Maxcompute SQL 的查询结果条数受限1W
Maxcompute SQL 的查询结果条数受限1W
2022-06-27 06:18:00 【南风知我意丿】
问题描述
记一次使用阿里云的Data Works处理需求,由于我们的Sql处理后数据产生了很多行的数据,导出为excel时数据不全的问题
原因分析:
每天我们都会在 Maxcompute 平台上提交 select query,用于查询特定的数据。然而,熟悉平台的同学都知道,从平台获取 sql 查询结果是一个 Restful 请求,可能碰到以下两个问题:
1 获取数据超时。
如果数据分布在多个存储小文件上,平台需要花费大量时间来收集和归并这些数据。然而在这个漫长的归并过程中,获取数据的 Restful 请求可能已经超时了。此时 Maxcompute Console 会有如下警告:Warning: ODPS request failed, requestID:xxxx, retryCount:1, will retry in xxx seconds.
2 获取数据量受限。
由于一次 Restful 请求的返回数据有限,且一次性获取全量数据到本地时可能将内存撑爆等问题,Maxcompute SQL 的查询结果条数是受限的,具体的数值为 project 上的配置项 READ_TABLE_MAX_ROW (
默认为 10000)。这就会出现明明我们的查询结果 2W 条,最后却在 Maxcompute Console 或者 Logview 上只看到 1W条 的诡异情况了。
解决方案:
Instanc Tunnel功能
Instance Tunnel 提供使用 Tunnel 来下载 SQL 查询结果的功能,不仅能摆脱上述两类问题,可直接获取查询结果;还丰富了 Maxcompute Tunnel 下载通道,不再局限于表数据。换句话说,以前我们可以用 Tunnel 来下载 Maxcompute 表数据,如今,我们也可以用 Tunnel 来下载 Maxcompute Instance 的数据。
Instance Tunnel 使用
1. 用 Maxcompute Console 来获取 Instance 数据
1.1 使用 Tunnel download 命令将特定 Instance 的执行结果下载到本地文件
命令:
tunnel download instance://<[project_name/]instance_id> <path>
参数:
project_name: instance 所在的项目名称;
instance_id: 待下载数据的 instance id
举例:
// 执行一条 select 查询:
[email protected] odps_test_project>select * from wc_in;
ID = 20170724071705393ge3csfb8
... ...
// 使用 Instance Tunnel Download 命令下载执行结果到本地文件
[email protected] odps_test_project>tunnel download instance://20170724071705393ge3csfb8 result;
2017-07-24 15:18:47 - new session: 2017072415184785b6516400090ca8 total lines: 8
2017-07-24 15:18:47 - file [0]: [0, 8), result
downloading 8 records into 1 file
2017-07-24 15:18:47 - file [0] start
2017-07-24 15:18:48 - file [0] OK. total: 44 bytes
download OK
// 查看结果
cat result
slkdfj
hellp
apple
tea
peach
apple
tea
teaa
1.2 通过配置参数使 SQL 查询默认采用 Instance Tunnel 方式输出执行结果
在 Maxcompute Console 中打开 use_instance_tunnel 选项之后,执行的 select query 就会默认使用 Instance tunnel 来下载结果了,再也不会出现文章开头所描述的两种问题了。
打开该配置有两种方法:
- 如果已经下载最新的 Console,odps_config.ini 里面已经默认打开此选项,并
默认将 instance_tunnel_max_record 设置成了10000。 如下所示:
# download sql results by instance tunnel
use_instance_tunnel=true
# the max records when download sql results by instance tunnel
instance_tunnel_max_record=10000
其中 instance_tunnel_max_record 表示使用 Instance tunnel 下载 sql 查询结果的条数。
若不设置,下载条数不受限。
- 使用 set console.sql.result.instancetunnel=true; 开启此功能。
// 打开 Instance tunnel 选项
[email protected] odps_test_tunnel_project>set console.sql.result.instancetunnel=true;
OK
// 运行 select query
[email protected] odps_test_tunnel_project>select * from wc_in;
ID = 20170724081946458g14csfb8
Log view:
http://logview/xxxxx.....
+------------+
| key |
+------------+
| slkdfj |
| hellp |
| apple |
| tea |
| peach |
| apple |
| tea |
| teaa |
+------------+
A total of 8 records fetched by instance tunnel.
可以看到,如果使用 Instance tunnel 的方式来输出 select 查询结果,会在最后打印一条提示。比如上面例子中的提示告诉我们这个 instance 的执行结果一共有 8 条数据。同样也可以set console.sql.result.instancetunnel=false;来关闭此功能。
边栏推荐
猜你喜欢

JVM class loading mechanism

Scala函数柯里化(Currying)

JVM object composition and storage

Gaussian distribution, linear regression, logistic regression

美摄云服务方案:专为轻量化视频制作场景打造

How to check the frequency of memory and the number of memory slots in CPU-Z?

免费的 SSH 和 Telnet 客户端PuTTY

主动学习(active learning)

Quick personal site building guide using WordPress

JVM对象组成和存储
随机推荐
Sqlsever 字段相乘后保留2位小数
Multithreading basic Part3
主动学习(active learning)
C Primer Plus 第11章_字符串和字符串函数_代码和练习题
el-select多个时,el-select筛选选中过的值,第二个el-select中过滤上一个选中的值
Proxy reflect usage details
[QT dot] realize the watchdog function to detect whether the external program is running
426 binary tree (513. find the value in the lower left corner of the tree, 112. sum of paths, 106. construct a binary tree from the middle order and post order traversal sequence, 654. maximum binary
创建一个基础WDM驱动,并使用MFC调用驱动
Spark's projection
How to check the frequency of memory and the number of memory slots in CPU-Z?
我对于测试团队建设的意见
vscode korofileheader 的配置
427-二叉树(617.合并二叉树、700.二叉搜索树中的搜索、98. 验证二叉搜索树、530.二叉搜索树的最小绝对差)
427- binary tree (617. merge binary tree, 700. search in binary search tree, 98. verify binary search tree, 530. minimum absolute difference of binary search tree)
软件测试年终总结报告模板
Multithreading basic part2
汇编语言-王爽 第13章 int指令-笔记
693. alternate bit binary number
表单校验 v-model 绑定的变量,校验失效的解决方案