monotonically_increasing_id {SparkR}R Documentation

monotonically_increasing_id

Description

Return a column that generates monotonically increasing 64-bit integers.

Usage

## S4 method for signature 'missing'
monotonically_increasing_id()

monotonically_increasing_id(x = "missing")

Arguments

x

empty. Should be used with no argument.

Details

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 SparkDataFrame has less than 1 billion partitions, and each partition has less than 8 billion records.

As an example, consider a SparkDataFrame with two partitions, each with 3 records. This expression would return the following IDs: 0, 1, 2, 8589934592 (1L << 33), 8589934593, 8589934594.

This is equivalent to the MONOTONICALLY_INCREASING_ID function in SQL.

See Also

Other misc_funcs: crc32, crc32, crc32,Column-method; hash, hash, hash,Column-method; md5, md5, md5,Column-method; sha1, sha1, sha1,Column-method; sha2, sha2, sha2,Column,numeric-method

Examples

## Not run: select(df, monotonically_increasing_id())

[Package SparkR version 2.0.1 Index]