presto-main/src/main/java/io/prestosql/operator/window/NTileFunction.java/NTileFunction/bucket
class NTileFunction:    private long bucket(long buckets, int currentRow)
    {
        if (rowCount < buckets) {
            return currentRow;
        }

        long remainderRows = rowCount % buckets;
        long rowsPerBucket = rowCount / buckets;

        // Remainder rows are assigned starting from the first bucket.
        // Thus, each of those buckets have an additional row.
        if (currentRow < ((rowsPerBucket + 1) * remainderRows)) {
            return currentRow / (rowsPerBucket + 1);
        }

        // Shift the remaining rows to account for the remainder rows.
        return (currentRow - remainderRows) / rowsPerBucket;
    }