x = df.withColumn("id_col", F.monotonically_increasing_id())
returns random long integers instead of sorted int numbersenter image description here
x = df.withColumn("id_col", F.monotonically_increasing_id())
returns random long integers instead of sorted int numbersenter image description here
What you are seeing is the expected behavior of the function. From the documentation
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
This is why you see long random integers. They may not be sequential but they are in increasing order and for all practical purposes, unique.