hive ipv4与十进制整数的转换

2022-11-21 09:50:18 浏览数 (3)

1、ipv4转十进制整数

代码语言:javascript复制
CAST(split(ip, '\.') [0] * 256 * 256 * 256   split(ip, '\.') [1] * 256 * 256   split(ip, '\.') [2] * 256   split(ip, '\.') [3] AS bigint)

2、十进制整数转ipv4

代码语言:javascript复制
select concat_ws('.'
,conv(substr(hex(cast('3097097128' as bigint)),1,2),16,10)
,conv(substr(hex(cast('3097097128' as bigint)),3,2),16,10)
,conv(substr(hex(cast('3097097128' as bigint)),5,2),16,10)
,conv(substr(hex(cast('3097097128' as bigint)),7,2),16,10)
);

0 人点赞