在 Amazon Athena (Presto) 中投射无法正常工作? [英] Casting not working correctly in Amazon Athena (Presto)?

查看:29
本文介绍了在 Amazon Athena (Presto) 中投射无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个医生执照注册数据集,其中包括每位医生的 total_submitted_charge_amount 以及医疗保险和医疗保险的权利数量.医疗补助.我使用了下面建议的答案中的查询:

I have a doctor license registry dataset which includes the total_submitted_charge_amount for each doctor as well as the number of entitlements with medicare & medicaid . I used the query from the answer suggested below:

    with datamart AS 
    (SELECT npi,
         provider_last_name,
         provider_first_name,
         provider_mid_initial,
         provider_address_1,
         provider_address_2,
         provider_city,
         provider_zipcode,
         provider_state_code,
         provider_country_code,
         provider_type,
         number_of_services,

        CASE
        WHEN REPLACE(num_entitlement_medicare_medicaid,',', '') ='' THEN
        null
        ELSE CAST(REPLACE(num_entitlement_medicare_medicaid,',', '') AS DECIMAL)
        END AS medicare_medicaid_entitlement,
        CASE
        WHEN REPLACE(total_submitted_charge_amount,',', '') ='' THEN
        null
        ELSE CAST(REPLACE(num_entitlement_medicare_medicaid,',', '') AS DECIMAL)
        END AS total_submitted_charge_amount
    FROM cmsaggregatepayment2017)
SELECT *
FROM datamart
ORDER BY  total_submitted_charge_amount DESC

不幸的是我收到错误

INVALID_CAST_ARGUMENT:无法将 VARCHAR '' 转换为 DECIMAL(38, 0)

INVALID_CAST_ARGUMENT: Cannot cast VARCHAR '' to DECIMAL(38, 0)

此查询针对 aggregatepayment_data_2017 数据库运行,除非查询限定.请在我们的论坛上发布错误消息或使用查询 ID 联系客户支持:be01d1e8-dc4d-4c75-a648-428dcb6be3a5."我尝试了 Decimal、Real、Big int,但对转换 num_entitlement_medicare_medicaid 没有任何作用.下面是数据的截图:

This query ran against the aggregatepayment_data_2017 database, unless qualified by the query. Please post the error message on our forum or contact customer support with Query Id: be01d1e8-dc4d-4c75-a648-428dcb6be3a5." I have tried Decimal, Real, Big int and nothing works for casting num_entitlement_medicare_medicaid. Below is a screenshot of how the data looks like:

有人可以建议如何改写此查询吗?

Can someone please suggest how to rephrase this query?

推荐答案

出现错误的原因是列中有空白值(但不是 null),我们无法将 varchar '' 转换为十进制.您可能可以使用 case 语句.此外,根据数据集列 num_entitlement_medicare_medicaid 有逗号,",您不会替换它.

The reason you are getting error is you have blank value(but it is not null) in the column and we cannot cast varchar '' as decimal. You can probably use case statement. Also as per the data set column num_entitlement_medicare_medicaid has comma ',' in it which you are not replacing.

    SELECT npi, 
case
when REPLACE(num_entitlement_medicare_medicaid,'[^A-Za-z0-9.]', '') ='' then null
else CAST(REPLACE(num_entitlement_medicare_medicaid,'[^0-9.]', '') AS DECIMAL)
end as medicare_medicaid_entitlement,
case 
when REPLACE(total_submitted_charge_amount,'[^A-Za-z0-9.]', '') ='' then null
else CAST(REPLACE(total_submitted_charge_amount,'[^0-9.]', '') AS DECIMAL)
end as total_submitted_charge_amount
FROM cmsaggregatepayment2017

这篇关于在 Amazon Athena (Presto) 中投射无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆