CREATE TEMP FUNCTION ipv6_to_number(ip STRING)
RETURNS STRING
LANGUAGE js AS """
var parts = [];
ip.split(":").forEach(function(it) {
var bin = parseInt(it, 16).toString(2);
while (bin.length < 16) {
bin = "0" + bin;
}
parts.push(bin);
})
var bin = parts.join("");
var dec = BigInt("0b"+ bin)
return dec;
""";
Select "2001:0db8:0:0:8d3:0:0:0" ip, ipv6_to_number("2001:0db8:0:0:8d3:0:0:0") number
结果:
Row ip number
1 2001:0db8:0:0:8d3:0:0:0 42540766411282592857539836924043198464
1条答案
按热度按时间a14dhokn1#
如果需要将ipv6转换为十进制值,可以使用
JavaScript
自定义项如下所示。请记住,此操作产生的数值需要表示为字符串,因为它太大,无法放入BigQuery
数字类型结果: