title: How to add source file name to each row in Spark?
body: <p>I'm new to Spark and am trying to insert a column to each input row with the file name that it comes from.</p>
  
  <p>I've seen others ask a similar question, but all their answers used <code>wholeTextFile</code>, but I'm trying to do this for larger CSV files (read using the Spark-CSV library), JSON files, and Parquet files (not just small text files). </p>
  
  <p>I can use the <code>spark-shell</code> to get a list of the filenames:</p>
  
  <pre><code>val df = sqlContext.read.parquet("/blah/dir")
  val names = df.select(inputFileName())
  names.show
  </code></pre>
  
  <p>but that's a dataframe.
  I am not sure how to add it as a column to each row (and if that result is ordered the same as the initial data either, though I assume it always is) and how to do this as a general solution for all input types. </p>