配置单元失败,语义分析中的错误无效的表别名或列引用

时间:2018-12-07 11:54:25

标签: hive hiveql

我有以下查询:

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无法使用,并给出如下错误: 蜂房在语义分析无效的错误表别名或列引用中失败。我应该如何进行。

1 个答案:

答案 0 :(得分: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)