且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将一列从十六进制字符串转换为长字符串?

更新时间:2022-12-12 10:19:51

你可以使用java hex to Long converter

java.lang.Long.parseLong(hex.trim(), 16)

你只需要定义一个udf函数如下

All you need is to define a udf function as below

import org.apache.spark.sql.functions.udf
def hexToLong = udf((hex: String) => java.lang.Long.parseLong(hex.trim(), 16))

并使用.withColumn api

df.withColumn("Icao", hexToLong($"Icao")).show(false)