Hive failed error in semantic analysis invalid table alias or column reference
Posted
技术标签:
【中文标题】Hive failed error in semantic analysis invalid table alias or column reference【英文标题】: 【发布时间】:2018-12-07 11:54:24 【问题描述】:我有以下疑问:
select
PatientId,
EncounterId,
dead,
encounterEndTime,
max_Hr,
min_Hr,
mean_Hr
from((select SUBSTR(get_json_object(content,'$.patient.reference'),9) as PatientId,
get_json_object(content,'$.id') as EncounterId,(case
when get_json_object(content,'$.reason.coding.display') like '%Dead%' then "1"
else "0" end ) as dead, regexp_replace((get_json_object(content,'$.period.end')),"T"," ") as encounterEndTime from encounter_sample
where get_json_object(content,'$.patient.reference') like '%Patient/%' and get_json_object(content,'$.serviceProvider.reference') like '%Organization/6f5dd7a5-f643-4309-8602-8200c6c43893%' and get_json_object(content,'$.status') like 'finished')enc
LEFT OUTER JOIN
(select SUBSTR(get_json_object(content,'$.subject.reference'),9) as PatientIdHr,
max(cast (get_json_object(content,'$.component[0].valueQuantity.value')as int))as max_Hr,
min(cast (get_json_object(content,'$.component[0].valueQuantity.value') as int))as min_Hr,
round(avg(cast (get_json_object(content,'$.component[0].valueQuantity.value') as int)),2) as mean_Hr,
SUBSTR(get_json_object(content,'$.encounter.reference'),11) as EncounterIdHR
from production.observation_sample
where get_json_object(content,'$.meta.tag[0].code') like 'cm_vitalsigns_result%' and get_json_object(content,'$.component[0].code.coding[0].display') like 'Heart Rate (per minute)' and regexp_replace((get_json_object(content,'$.effectiveDateTime')),"T"," ") > from_unixtime(unix_timestamp(enc.encounterEndTime)-14400)
group by (get_json_object(content,'$.component[0].code.coding[0].display')),(SUBSTR(get_json_object(content,'$.subject.reference'),9)),SUBSTR(get_json_object(content,'$.encounter.reference'),11))Hr
on
PatientId=PatientIdHr and EncounterId=EncounterIdHR)
它说enc.encounterEndTime
不能使用并给出如下错误:
.我应该如何进行。
【问题讨论】:
FROM 之后和末尾的额外括号 那没有任何区别。我犯了同样的错误。Invalid table alias or column reference 'enc'
请检查我的答案,如果它对你有用,请接受/投票,这样它也可以帮助其他人寻求答案。请阅读:***.com/help/someone-answers
抱歉耽搁了。非常感谢。
【参考方案1】:
您不能引用为左连接子查询中的另一个子查询定义的表别名。
enc
LEFT OUTER JOIN (
..
> from_unixtime(unix_timestamp(enc.encounterendtime
^ --you can't reference it here.
..
) hr ON ..
既然是外连接,你可能想把它放在ON
子句中?
...
enc LEFT OUTER JOIN (
SELECT
..,
..,
regexp_replace
( (get_json_object(content,'$.effectiveDateTime')
),"T"," ") as effectiveDateTime
..,
..,
) hr ON patientid = patientidhr AND encounterid = encounteridhr AND
hr.effectiveDateTime > from_unixtime(unix_timestamp(enc.encounterendtime) - 14400)
【讨论】:
以上是关于Hive failed error in semantic analysis invalid table alias or column reference的主要内容,如果未能解决你的问题,请参考以下文章
Hive failed; error=‘Cannot allocate memory‘ (errno=12)
DataGrip 连接 Kerberos 认证的 hive 报 Hive JDBC Kerberose Authentication Error: GSS initiate failed 错误
启动hive报错[ERROR] Terminal initialization failed; falling back to unsupported
编译语句时出错:FAILED: SemanticException [Error 10002] - MAKE SELECT WITH MAX ON HIVE
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask