Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 views
in Technique[技术] by (71.8m points)

endianness - How to parse 8-byte double-precision number (little endian) into float64 in BigQuery?

I have a string written as 8-byte double-precision number with little endian and would like to convert it with float64 so that BigQuery can handle it as a number.

# example
from: hex(little endian): EC51B81E852B4340

to: float64: 38.34

Is there an smart solution for this?

Thank you.

question from:https://stackoverflow.com/questions/66057688/how-to-parse-8-byte-double-precision-number-little-endian-into-float64-in-bigq

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have only the first step that you can resort to JavaScript capability. I searched but didn't find a library that you can directly reference from BigQuery. You'll have to find a library and upload it to GCS to reference it. I also found some code snippet to do the bytes -> double encoding but not sure about their quality.

CREATE TEMP FUNCTION hex_to_float(x BYTES) RETURNS FLOAT64
LANGUAGE js
AS """
  // Call a JS library to translate byte array to double
""";

SELECT hex_to_float(FROM_HEX('EC51B81E852B4340'));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...