linux下。hive 0.11.0版本
select A.key key,
A.RECORDTIME RECORDTIME,
A.CONTENTID CONTENTID,
cast(A.RN_1 as int) RN_1,
cast(A.RN_2 as int) RN_2,
cast(B.RN_3 as int) RN_3
from
(SELECT key,
RECORDTIME,
CONTENTID,
ROW_NUMBER() OVER(PARTITION BY key ORDER BY RECORDTIME ASC) RN_1,
ROW_NUMBER() OVER(PARTITION BY key ORDER BY RECORDTIME DESC) RN_2
FROM ODS_IREAD.IREAD_COMMENT
WHERE RECORD_DAY ='20130812'
AND SUBSTR(key,1,1) <> '9')A
join
(SELECT CONTENTID,
COUNT(DISTINCT key) RN_3
FROM ODS_IREAD.IREAD_COMMENT
WHERE RECORD_DAY ='20130812'
AND SUBSTR(key,1,1) <> '9'
group by CONTENTID )B
on (A.CONTENTID=B.CONTENTID)
执行上面的语句是可以查询到数据的。
插入到目标表时候,无报错信息。但是目标表无任何数据。
create table test.tmp_test
as
select A.key key,
A.RECORDTIME RECORDTIME,
A.CONTENTID CONTENTID,
cast(A.RN_1 as int) RN_1,
cast(A.RN_2 as int) RN_2,
cast(B.RN_3 as int) RN_3
from
(SELECT key,
RECORDTIME,
CONTENTID,
ROW_NUMBER() OVER(PARTITION BY key ORDER BY RECORDTIME ASC) RN_1,
ROW_NUMBER() OVER(PARTITION BY key ORDER BY RECORDTIME DESC) RN_2
FROM ODS_IREAD.IREAD_COMMENT
WHERE RECORD_DAY ='20130812'
AND SUBSTR(key,1,1) <> '9')A
join
(SELECT CONTENTID,
COUNT(DISTINCT key) RN_3
FROM ODS_IREAD.IREAD_COMMENT
WHERE RECORD_DAY ='20130812'
AND SUBSTR(key,1,1) <> '9'
group by CONTENTID )B
on (A.CONTENTID=B.CONTENTID)
--创建一个表。信息如下:
Ended Job = job_201308241420_1933
Stage-11 is filtered out by condition resolver.
20879 Rows loaded to hdfs://namenode:9000/tmp/hive-hadoop/hive_2013-09-06_10-15-07_521_7704171105143537871/-ext-10000
MapReduce Jobs Launched:
Job 0: Map: 2 Reduce: 1 Cumulative CPU: 9.3 sec HDFS Read: 2656543 HDFS Write: 104959 SUCCESS
Job 1: Map: 2 Reduce: 1 Cumulative CPU: 11.79 sec HDFS Read: 2656543 HDFS Write: 1383576 SUCCESS
Job 2: Map: 1 Reduce: 1 Cumulative CPU: 10.44 sec HDFS Read: 1384108 HDFS Write: 1410015 SUCCESS
Job 3: Map: 1 Cumulative CPU: 4.64 sec HDFS Read: 1410547 HDFS Write: 905213 SUCCESS
Total MapReduce CPU Time Spent: 36 seconds 170 msec
OK
Time taken: 131.982 seconds
----再去查询创建的目标表,结果提示没有目标表。请大师没分析是哪里有问题。正常创建表以及使用as创建表都是可以的。
分成两步来操作试试:
第一步: createtabletmp_test(....);
第二步:
insertoverwritetabletmp_test
select*from
(
selectA.keykey,
A.RECORDTIMERECORDTIME,
A.CONTENTIDCONTENTID,
cast(A.RN_1asint)RN_1,
cast(A.RN_2asint)RN_2,
cast(B.RN_3asint)RN_3
from
(SELECTkey,
RECORDTIME,
CONTENTID,
ROW_NUMBER()OVER(PARTITIONBYkeyORDERBYRECORDTIMEASC)RN_1,
ROW_NUMBER()OVER(PARTITIONBYkeyORDERBYRECORDTIMEDESC)RN_2
FROMODS_IREAD.IREAD_COMMENT
WHERERECORD_DAY='20130812'
ANDSUBSTR(key,1,1)<>'9')A
join
(SELECTCONTENTID,
COUNT(DISTINCTkey)RN_3
FROMODS_IREAD.IREAD_COMMENT
WHERERECORD_DAY='20130812'
ANDSUBSTR(key,1,1)<>'9'
groupbyCONTENTID)B
on(A.CONTENTID=B.CONTENTID)
)TEMP;
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。