在 Big Query 中从加密哈希函数创建 uuid

问题描述 投票:0回答:1
鉴于下表:

名字姓氏描述约翰肯尼迪美国总统伊丽莎白玛丽英国女王
我想对first_name 和last_name 列进行哈希处理,并为每一行创建一个UUID。 所以我计划使用加密哈希函数,如 md5 ou ha1,但我不知道如何使用大查询将其转换为 UUID 格式(如:

bc9020e9-df80-5be1-9ee1-ad01f9579649

)。

对于加密哈希函数:

md5(concat(first_name, last_name))


    

google-bigquery hash uuid bigquery-udf
1个回答
0
投票
CREATE TEMP FUNCTION to_uuid(x STRING) RETURNS STRING AS ( concat(substr(to_hex(md5(x)),1,8), "-", substr(to_hex(md5(x)),9,4), "-", substr(to_hex(md5(x)),13,4), "-", substr(to_hex(md5(x)),17,4), "-", substr(to_hex(md5(x)),21,12) ) );
    
© www.soinside.com 2019 - 2024. All rights reserved.