index a dataframe from a csv file based on the file's original order (not based on any specific column, based on the entire row) using spark

andrew0117
Contributor

how to guarantee the index is always following the file's original order no matter what. Currently, I'm using val df = spark.read.options(Map("header"-> "true", "inferSchema" -> "true")).csv("filePath").withColumn("index", monotonically_increasing_id()) .

Thanks!