【问题标题】:Convert scientific notation string to number in Hive将科学计数法字符串转换为 Hive 中的数字
【发布时间】:2022-01-04 06:36:53
【问题描述】:

我在 Cloudera 上有一个带有数字字符串列的脏表。有些数字是 8 位数字形式,而另一些数字是科学记数法,例如91234567 与 9.1234567E7。当数字以零结尾时,小数点较少,例如9.12E7 表示 91200000。如何将它们全部转换为它们的 8 位表示?

我尝试了以下方法,但无济于事:

-- Remove 'E7' then convert the string to a decimal
,CASE WHEN m_number LIKE '%E7' 
        THEN CAST(REPLACE(m_number, 'E7', '') AS DECIMAL(10,7)) * POW(10, 7)
        ELSE m_number END AS m_clean

返回:AnalysisException: Incompatible return types 'DECIMAL(10,7)' and 'STRING' of exprs 'CAST(replace(m_number, 'E7', '') AS DECIMAL(10,7))' and 'm_number'.

【问题讨论】:

    标签: sql hadoop hive cloudera impala


    【解决方案1】:

    简单的cast怎么样?

    cast (9.12e7 as  BIGINT)
    OR
    cast ('9.12E7' as  decimal(8,0))
    

    请检查哪个适合您。

    截图如下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-01
      • 1970-01-01
      • 2019-04-22
      • 1970-01-01
      • 1970-01-01
      • 2015-12-27
      相关资源
      最近更新 更多