[英]creating a hiveQL query that uses UDF function that can return column names
[英]HiveQL - How to find the column value is numeric or not using any UDF?
基本上我想根据一column value
return rows
。
如果该列包含non numeric
值,则从配置单元表中返回这些行。
Hive
是否有任何UDF
可用?
我相信 Hive 支持rlike
(正则表达式)。 所以,你可以这样做:
where col rlike '[^0-9]'
这将查找任何非数字字符。 如果您的数值可能有小数点或逗号,您可以扩展它。
使用cast(expr as <type>)
。 如果转换不成功,则返回null
。
case when cast(col as double) is null then 'N' else 'Y' end as isNumber
或者只是在 WHERE 中使用布尔表达式: cast(col as double) is not null
您也可以创建 isNumber 宏:
create temporary macro isNumber(s string)
cast(s as double) is not null;
并在您的查询中使用它:
hive> select isNumber('100.100'), isNumber('100'), isNumber('.0'), isNumber('abc');
OK
_c0 _c1 _c2 _c3
true true true false
如果您需要检查 Integer 然后使用cast(s as Int)
这种方法适用于负数和小数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.