NULLS LAST无效 - 我在后续查询中收到以下错误: FAILED:ParseException第41:9行在'ASC'附近'NULLS'丢失EOF
不确定是什么问题,查询否则运行并排序很好,没有空的最后一个语句。
set hive.cli.print.header=true;
SELECT
P3P.campaign_id,
P3P.campaign_name,
P3P.strategy_id,
P3P.strategy_name,
P3P.segment_id,
P3P.full_path,
COUNT(*) AS impressions,
COUNT(DISTINCT P3P.mm_uuid) AS distinct_users,
SUM(P3P.media_cost) AS media_cost,
SUM(P3P.total_ad_cost) AS total_ad_cost,
SUM(P3P.total_spend) AS total_spend,
AVG(P3P.total_spend_cpm) AS cpm,
SUM(CASE WHEN AE.event_type = 'click' THEN 1 ELSE NULL END) AS clicks,
SUM(CASE WHEN AE.event_type = 'conversion' THEN 1 ELSE NULL END) AS conversions,
(SUM(CASE WHEN AE.event_type = 'click' THEN 1 ELSE NULL END) / (COUNT(P3P.mm_uuid))) AS ctr,
(SUM(CASE WHEN AE.event_type = 'click' THEN 1 ELSE NULL END) / (SUM(CASE WHEN AE.event_type = 'conversion' THEN 1 ELSE NULL END))) AS ctc,
(SUM(P3P.total_spend)/(SUM(CASE WHEN AE.event_type = 'click' THEN 1 ELSE NULL END))) AS cost_per_click,
(SUM(P3P.total_spend) /(SUM(CASE WHEN AE.event_type = 'conversion' THEN 1 ELSE NULL END))) AS cpa,
((SUM(CASE WHEN AE.event_type = 'conversion' THEN 1 ELSE NULL END))*1000)/COUNT(*) AS rr_per_1k_imps,
AVG(P3P.segment_cpm) AS segment_cpm,
(SUM(P3P.segment_spend)/(SUM(CASE WHEN AE.event_type = 'click' THEN 1 ELSE NULL END))) AS segment_cpc,
(SUM(P3P.segment_spend)/(SUM(CASE WHEN AE.event_type = 'conversion' THEN 1 ELSE NULL END))) AS segment_cpc
FROM tmp_perfon3p2 P3P
LEFT JOIN mm_attributed_events AE ON AE.mm_uuid = P3P.mm_uuid
AND AE.event_date BETWEEN '2015-06-14' and '2015-06-21'
AND AE.organization_id = '100426'
AND AE.agency_id = '101286'
AND AE.advertiser_id = '108076'
GROUP BY
P3P.campaign_id,
P3P.campaign_name,
P3P.strategy_id,
P3P.strategy_name,
P3P.segment_id,
P3P.full_path
ORDER BY
cpa ASC NULLS LAST
LIMIT 100;
答案 0 :(得分:1)
错误很清楚。 Hive不喜欢ASC
和NULLS
之间第41行的内容
每Cloudera Documentation
注意:由于Hive查询目前无法使用NULLS FIRST和NULLS LAST关键字,因此使用这些关键字创建的所有视图都无法通过Hive获取
修改(解决方法):
假设您有这种汇总数据
col1
----
10.1
NULL
NULL
2.1
3.7
<强>查询强>:
select col1
from (
select col1
, case when col1 is null then 0 else 1 end as flg
from inner_query
order by flg desc, col1 asc) x
<强>输出强>:
col1
----
2.1
3.7
10.1
NULL
NULL