【问题标题】:T-SQL isnumeric() replacement in hiveHive 中的 T-SQL isnumeric() 替换
【发布时间】:2013-09-06 18:47:40
【问题描述】:

hive 0.10 中 T-SQL isnumeric() 函数的替代品是什么?

http://technet.microsoft.com/en-us/library/ms186272.aspx

【问题讨论】:

    标签: hadoop mapreduce hive


    【解决方案1】:

    在 HIVE 中没有直接的等效项,但您可以使用 cast 函数。
    将任何不是“数字”的内容转换为 double 将返回 null,您可以像这样使用它:
    select x from table where cast(field as double) is not null

    【讨论】:

    • 我试过这个,但它一直让字母数字字符通过。这是因为“select cast('7E7' as double)”解析为“70000000”,而不是 null - 所以请改用“select x from table where cast(field as int) is not null”
    【解决方案2】:

    您可以通过以下检查来检查数字是否为十进制。这也可以在 where 子句中给出。

    select case when abs(x%1)>0 then x else cast(x as bigint) end ;

    【讨论】:

      猜你喜欢
      • 2011-01-20
      • 2017-04-15
      • 1970-01-01
      • 2020-02-25
      • 2015-05-14
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多