手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Hive case when 引发错误一例

[日期:2012-07-08] 来源:Linux社区  作者:yaoyinjie [字体:大 中 小]
今天发现hive 在使用 case when then else end 方式下会存在BUG, 具体表现如下,
现有表: t_aa_pc_log, 其中一个字段为channel, 当channel值为'NA'或者'EMPTY'时
设置为'A', 其他值设置为'B', 然后输出channel值为'A'的前10个记录

查询一:根据需求写出SQL:

  1. select a.channel 
  2. from 
  3. ( 
  4.   select case when channel = 'NA' or channel = 'EMPTY' then 'A' else 'B' end as channel  
  5.   from t_aa_pc_log where pt = '2012-04-10-00' 
  6. )a where a.channel='A' limit 10; 

查询结果为空:

  1. hive>  
  2.     >  
  3.     >  
  4.     > select a.channel 
  5.     > from 
  6.     > ( 
  7.     >   select case when channel = 'NA' or channel = 'EMPTY' then 'A' else 'B' end as channel  
  8.     >   from t_aa_pc_log where pt = '2012-04-10-00' 
  9.     > )a where a.channel='A' limit 10; 
  10. Total MapReduce jobs = 1 
  11. Launching Job 1 out of 1 
  12. Number of reduce tasks is set to 0 since there's no reduce operator 
  13. Starting Job = job_201205162059_1490941, Tracking URL = http://jt.dc.sh-wgq.sdo.com:50030/jobdetails.jsp?jobid=job_201205162059_1490941 
  14. Kill Command = /home/hdfs/Hadoop-current/bin/hadoop job  -Dmapred.job.tracker=10.133.10.103:50020 -kill job_201205162059_1490941 
  15. 2012-07-05 14:00:10,528 Stage-1 map = 0%,  reduce = 0% 
  16. 2012-07-05 14:00:14,669 Stage-1 map = 100%,  reduce = 0% 
  17. 2012-07-05 14:00:15,731 Stage-1 map = 100%,  reduce = 100% 
  18. Ended Job = job_201205162059_1490941 
  19. OK 
  20. Time taken: 9.974 seconds 
  21. hive>  

查询二:去掉外部查询的where条件:

  1. select a.channel 
  2. from 
  3. ( 
  4.   select case when channel = 'NA' or channel = 'EMPTY' then 'A' else 'B' end as channel  
  5.   from t_aa_pc_log where pt = '2012-04-10-00' 
  6. )a limit 10; 

查询结果有值:

  1. hive> select a.channel 
  2.     > from 
  3.     > ( 
  4.     >   select case when channel = 'NA' or channel = 'EMPTY' then 'A' else 'B' end as channel  
  5.     >   from t_aa_pc_log where pt = '2012-04-10-00' 
  6.     > )a limit 10; 
  7. Total MapReduce jobs = 1 
  8. Launching Job 1 out of 1 
  9. Number of reduce tasks is set to 0 since there's no reduce operator 
  10. Starting Job = job_201205162059_1491035, Tracking URL = http://jt.dc.sh-wgq.sdo.com:50030/jobdetails.jsp?jobid=job_201205162059_1491035 
  11. Kill Command = /home/hdfs/hadoop-current/bin/hadoop job  -Dmapred.job.tracker=10.133.10.103:50020 -kill job_201205162059_1491035 
  12. 2012-07-05 14:03:55,864 Stage-1 map = 0%,  reduce = 0% 
  13. 2012-07-05 14:03:59,913 Stage-1 map = 20%,  reduce = 0% 
  14. 2012-07-05 14:04:00,923 Stage-1 map = 60%,  reduce = 0% 
  15. 2012-07-05 14:04:01,932 Stage-1 map = 80%,  reduce = 0% 
  16. 2012-07-05 14:04:07,019 Stage-1 map = 100%,  reduce = 0% 
  17. 2012-07-05 14:04:09,213 Stage-1 map = 100%,  reduce = 100% 
  18. Ended Job = job_201205162059_1491035 
  19. OK 
  20. A 
  21. A 
  22. A 
  23. A 
  24. A 
  25. A 
  26. A 
  27. A 
  28. A 
  29. A 
  30. Time taken: 19.339 seconds 

查询三: 在case when中去掉 OR 条件:

  1. select a.channel 
  2. from 
  3. ( 
  4.   select case when channel = 'NA' then 'A' else 'B' end as channel  
  5.   from t_aa_pc_log where pt = '2012-04-10-00' 
  6. )a where a.channel='A' limit 10; 

查询结果有值:

  1. hive> select a.channel 
  2.     > from 
  3.     > ( 
  4.     >   select case when channel = 'NA' then 'A' else 'B' end as channel  
  5.     >   from t_aa_pc_log where pt = '2012-04-10-00' 
  6.     > )a where a.channel='A' limit 10; 
  7. Total MapReduce jobs = 1 
  8. Launching Job 1 out of 1 
  9. Number of reduce tasks is set to 0 since there's no reduce operator 
  10. Starting Job = job_201205162059_1491066, Tracking URL = http://jt.dc.sh-wgq.sdo.com:50030/jobdetails.jsp?jobid=job_201205162059_1491066 
  11. Kill Command = /home/hdfs/hadoop-current/bin/hadoop job  -Dmapred.job.tracker=10.133.10.103:50020 -kill job_201205162059_1491066 
  12. 2012-07-05 14:05:19,557 Stage-1 map = 0%,  reduce = 0% 
  13. 2012-07-05 14:05:22,579 Stage-1 map = 20%,  reduce = 0% 
  14. 2012-07-05 14:05:23,736 Stage-1 map = 60%,  reduce = 0% 
  15. 2012-07-05 14:05:25,768 Stage-1 map = 80%,  reduce = 0% 
  16. 2012-07-05 14:05:26,779 Stage-1 map = 100%,  reduce = 0% 
  17. 2012-07-05 14:05:27,855 Stage-1 map = 100%,  reduce = 100% 
  18. Ended Job = job_201205162059_1491066 
  19. OK 
  20. A 
  21. A 
  22. A 
  23. A 
  24. A 
  25. A 
  26. A 
  27. A 
  28. A 
  29. A 
  30. Time taken: 15.219 seconds 
linux
相关资讯       Hive 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款