使用JSON-SERDE将JSON数据导入Hive

时间:2018-08-03 23:48:17

标签: json hive

我正在尝试使用JSON-SERDE将以下JSON数据提取到Hive中,但出现错误。首先-此JSON数据有效吗?如果是,如何创建具有123456-123456值的agentId的这一列表。

{"agentId":{"string":"123456-123456"}}

CREATE EXTERNAL TABLE testingjson(
    agentId map <string>
)
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
STORED AS TEXTFILE
LOCATION '/.../json_table';
  

编译语句时出错:失败:ParseException行4:20   输入类型不匹配的“>”期望值,在地图类型的“字符串”附近

1 个答案:

答案 0 :(得分:0)

是的,json有效。

尝试使用以下ddl和

如果您想要的值是123456-123456,则使用从testingjson中选择agentid ['string'];

@Service("claimService")
class ClaimService {

    @Autowired
    lateinit var billingCodeRepository: BillingCodeRepository

    @Autowired
    lateinit var claimRepository: ClaimRepository

    @Autowired
    lateinit var specialtyRepository: SpecialtyRepository

    @Autowired
    lateinit var doctorRepository: DoctorRepository

    fun saveClaim(submittedClaim: ClaimDto) {

        val existingClaim: Optional<Claim> = claimRepository.findById(submittedClaim.claim.uuid)
        if (existingClaim.isPresent)
        {
            convertClaimFromDto(submittedClaim, existingClaim.get())
        } else {
            val claim = Claim()
            convertClaimFromDto(submittedClaim, claim)
        }
    }

    fun convertClaimFromDto(submittedClaim: ClaimDto, claim: Claim)
    {

        claim.payProgram = submittedClaim.claim.payProgram
        claim.dxCode = submittedClaim.claim.dxCode
        claim.facility = submittedClaim.claim.facility
        claim.billingDate = DateUtil.convertDate(submittedClaim.claim.claimDate)
        claim.patient = convertPatientFromDto(submittedClaim.claim.patient)

        for(billingCode in submittedClaim.claim.billedCodes)
        {
            val billedCode: Optional<BillingCode> = billingCodeRepository.findById(billingCode.code)
            if (billedCode.isPresent)
            {
                val claimCode = BilledCodes()
                claimCode.billingCode = billedCode.get()
                claimCode.billed = billingCode.amountBilled
                claim.billedCodes.add(claimCode)
            }
        }

        //Test values
        val testDoc: Optional<ca.billingpro.billingcore.Domain.Doctor> = doctorRepository.findById(1)
        claim.doc = testDoc.get()
        claim.createdBy = "TestPoint"

        claimRepository.save(claim)
    }

    fun convertPatientFromDto(submittedPatient: ClaimDto.Claim.Patient): Patient
    {
        val patient = Patient()
        patient.DOB = DateUtil.convertDate(submittedPatient.DOB)
        patient.name = submittedPatient.name
        patient.ohipNo = submittedPatient.ohipNo
        patient.ohipVer = submittedPatient.ohipNo
        patient.sex = submittedPatient.sex
        return patient
    }

 }