BigQuery - 处理十六进制字符串的函数

时间:2022-04-16 14:26:13

Is there a way in BigQuery to convert a hex string to a decimal value?

BigQuery中有没有办法将十六进制字符串转换为十进制值?

Something like:

select hex("ff")

3 个解决方案

#1


This should work, but it doesn't (I'm filing a feature request):

这应该有效,但它没有(我正在提交功能请求):

SELECT INTEGER('0xffff')  

In the meantime, this does work:

与此同时,这确实有效:

SELECT FLOAT('0xffff')  
255.0

For integer results:

对于整数结果:

SELECT INTEGER(FLOAT('0xffff'))
255

#2


Looking into the query reference, I'd say no.

查看查询引用,我会说不。

You have "HEX_STRING()" which does the opposite, but all the string to number functions seem to not take hex.

你有“HEX_STRING()”相反,但所有字符串到数字函数似乎不采取十六进制。

#3


CAST now supports converting hexadecimal strings to INT64 or FLOAT64 values, even though it's not specified in their reference

CAST现在支持将十六进制字符串转换为INT64或FLOAT64值,即使它们的引用中未指定

Here's how you use it:

以下是您使用它的方式:

SELECT
CAST(columnA as FLOAT64) as float,
CAST(columnB as INT64) as int
FROM table

#1


This should work, but it doesn't (I'm filing a feature request):

这应该有效,但它没有(我正在提交功能请求):

SELECT INTEGER('0xffff')  

In the meantime, this does work:

与此同时,这确实有效:

SELECT FLOAT('0xffff')  
255.0

For integer results:

对于整数结果:

SELECT INTEGER(FLOAT('0xffff'))
255

#2


Looking into the query reference, I'd say no.

查看查询引用,我会说不。

You have "HEX_STRING()" which does the opposite, but all the string to number functions seem to not take hex.

你有“HEX_STRING()”相反,但所有字符串到数字函数似乎不采取十六进制。

#3


CAST now supports converting hexadecimal strings to INT64 or FLOAT64 values, even though it's not specified in their reference

CAST现在支持将十六进制字符串转换为INT64或FLOAT64值,即使它们的引用中未指定

Here's how you use it:

以下是您使用它的方式:

SELECT
CAST(columnA as FLOAT64) as float,
CAST(columnB as INT64) as int
FROM table