python - F.monotonicly_increasing_id() 返回长随机数

标签 python dataframe apache-spark pyspark

x = df.withColumn("id_col", F.monotonically_increasing_id())

返回随机长整数而不是排序的 int 数字 enter image description here

最佳答案

您所看到的是该函数的预期行为。来自文档

The generated ID is guaranteed to be monotonically increasing and unique, but not consecutive. The current implementation puts the partition ID in the upper 31 bits, and the record number within each partition in the lower 33 bits. The assumption is that the data frame has less than 1 billion partitions, and each partition has less than 8 billion records

这就是您看到长随机整数的原因。它们可能不是连续的,但它们是按递增顺序排列的,并且出于所有实际目的,它们是唯一的。

关于python - F.monotonicly_increasing_id() 返回长随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58623659/

相关文章:

scala - 结构化流 - 无法使用 FileContext API 管理 AWS S3 上的元数据日志文件

python - 带有 databricks 的 Azure 文件系统事件

python - Tornado websockets : share open web sockets between processes

python - 更改 lxml 中 etree.tostring 的默认缩进

r - 来自 dplyr/tidyverse 的 Complete() 函数不适用于 Shiny 交互变量

python - 无法找出使用 apply lambda 在数据帧上实现 if 语句的正确方法

python - 切片稀疏(scipy)矩阵

Python,如何使用字典填充数据框中的空值

python - 为什么我的 Spark SVM 总是预测相同的标签?

python - key 错误 : SPARK_HOME during SparkConf initialization