title: Spark infer schema with limit during a read.csv
body: <p>I'd like to infer a Spark.DataFrame schema from a directory of CSV files using a small subset of the rows (say <code>limit(100)</code>).</p>
  
  <p>However, setting <code>inferSchema</code> to <code>True</code> means that the <code>Input Size / Records</code> for the <code>FileScanRDD</code> seems to always be equal to the number of rows in all the CSV files. </p>
  
  <p>Is there a way to make the FileScan more selective, such that Spark looks at fewer rows when inferring a schema?</p>
  
  <p>Note: setting the <a href="https://github.com/apache/spark/blob/e9af946/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVUtils.scala#L104-L107" rel="nofollow noreferrer"><code>samplingRatio</code> option</a> to be &lt; 1.0 does not have the desired behaviour, though it is clear that inferSchema uses only the sampled subset of rows.</p>