presto中不同类型的字段关联问题

今天在使用presto查数据时,遇到一个诡异的问题,相同的sql,每次查询的结果确不一样,sql如下

1
2
3
4
5
6
7
8
9
select
t1.orderid,t1.ext,t2.id
from (
select
distinct orderid,ext
from odl_order_detail_cps
where billdate>='2019-05-06' and order_type=1 and isbill=1
) t1
left join dim_short_link_cps t2 on cast(t1.ext as int)=t2.id;

执行很多次,每次的结果数都不一样,查了很多资料都无济于事,后来猜测是不是ext转int时报错了,在有些节点上执行失败,调整sql如下

1
2
3
4
5
6
7
8
9
select
t1.orderid,t1.ext,t2.id
from (
select
distinct orderid,ext
from odl_order_detail_cps
where billdate>='2019-05-06' and order_type=1 and isbill=1
) t1
left join dim_short_link_cps t2 on t1.ext=cast(t2.id as varchar);

结果竟然正常了,证实了上面的猜测。

这种错误是因为ext参数有null的情况,在cast转换时,出错了,然后造成节点的任务失败,所以结果是执行正常的节点返回的数据。
在hive中就不存在这样的问题