解决NION‘. Failed rule: ‘orderByClause clusterByClause distributeByClause sortByClause limitClause can

(157) 2024-04-19 11:01:01

‘UNION’. Failed rule: ‘orderByClause clusterByClause distributeByClause sortByClause limitClause can only be applied to the whole union.’ in statement

解决NION‘. Failed rule: ‘orderByClause clusterByClause distributeByClause sortByClause limitClause can (https://mushiming.com/)  第1张
hive中是不支持上面的这种查询的
但是在impala中是支持的

解决NION‘. Failed rule: ‘orderByClause clusterByClause distributeByClause sortByClause limitClause can (https://mushiming.com/)  第2张
我表示很抑郁
由于我写的sql是要放到脚本里面的
因为impala也是可以用写sql到脚本的中的
确实可以解决这个办法

解释一下

union不支持orderByClause、clusterByClause、distributeByClause、sortByClause或limitClause
union all

union

相同点 是 相当于上下拼接 上下两个拼接表必须字段保持一致

不同 union有去重效果,速度会更慢。

union all的子句里不支持orderByClause、clusterByClause、distributeByClause、sortByClause或limitClause

其实在上面的sql要做改变就可以的

SELECT '-998' distinct_id,
              itemid,
              itemtypeid,
              isfreeview
FROM t_item_info_tmp
WHERE itemtypeid=14
  AND isfreeview=1
LIMIT 10
UNION ALL
SELECT '-998' distinct_id,
              itemid,
              itemtypeid,
              isfreeview
FROM t_item_info_tmp
WHERE itemtypeid=14
  AND isfreeview=0
LIMIT 10

这种方式是错的,在hive上是不能运行的

SELECT * from (SELECT '-998' distinct_id,
              itemid,
              itemtypeid,
              isfreeview
FROM t_item_info_tmp
WHERE itemtypeid=14
  AND isfreeview=1
ORDER BY rand()
LIMIT 100)h
UNION ALL
select * from ( SELECT '-998' distinct_id,
              itemid,
              itemtypeid,
              isfreeview
FROM t_item_info_tmp
WHERE itemtypeid=14
  AND isfreeview=0
ORDER BY rand()
LIMIT 100)i

解决NION‘. Failed rule: ‘orderByClause clusterByClause distributeByClause sortByClause limitClause can (https://mushiming.com/)  第3张
这种方式就是可以的
完美的了
哈哈

THE END

发表回复