首页 > 解决方案 > 个性化 monotonically_increasing_id 火花

问题描述

我有几个数据框,我想唯一标识每个数据框中的每一行。因此我想使用个性化的 Ids 。我在 spark 中使用 monotonically_increasing_id() 内置函数,如下所示:

import org.apache.spark.sql.functions._
val dfWithId = trzuCom.withColumn("UniqueID", monotonically_increasing_id)

问题是当我尝试如下个性化它时:

val dfWithId = trzuCom.withColumn("UniqueID", "TB1_" + monotonically_increasing_id)

我得到错误。实际上,我想为数据帧 1、TB2_ID 等设置一个 TB1_ID 。任何我知道如何做到这一点。此致

标签: apache-sparkuuid

解决方案


推荐阅读