DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK-3-0 practice question 22 of 25

Which of the following code blocks reads all CSV files in directory filePath into a single DataFrame, with column names defined in the CSV file…

Full set: 180 questions
Which of the following code blocks reads all CSV files in directory filePath into a single DataFrame, with column names defined in the CSV file headers? Content of directory filePath: 1. _SUCCESS 2. _committed_2754546451699747124 3. _started_2754546451699747124 4. part-00000-tid-2754546451699747124-10eb85bf-8d91-4dd0-b60b-2f3c02eeecaa-298-1- part-00000-tid-2754546451699747124-10eb85bf-8d91-4dd0-b60b-2f3c02eeecaa-298-1- c000.csv.gz 5. part-00001-tid-2754546451699747124-10eb85bf-8d91-4dd0-b60b-2f3c02eeecaa-299-1- part-00001-tid-2754546451699747124-10eb85bf-8d91-4dd0-b60b-2f3c02eeecaa-299-1- c000.csv.gz 6. part-00002-tid-2754546451699747124-10eb85bf-8d91-4dd0-b60b-2f3c02eeecaa-300-1- part-00002-tid-2754546451699747124-10eb85bf-8d91-4dd0-b60b-2f3c02eeecaa-300-1- c000.csv.gz 7. part-00003-tid-2754546451699747124-10eb85bf-8d91-4dd0-b60b-2f3c02eeecaa-301-1- part-00003-tid-2754546451699747124-10eb85bf-8d91-4dd0-b60b-2f3c02eeecaa-301-1- c000.csv.gz spark.option("header",True).csv(filePath)
Answer options
A: spark.read.format("csv").option("header",True).option("compression","zip").load(filePath)
B: spark.read().option("header",True).load(filePath)
C: spark.read.format("csv").option("header",True).load(filePath) Correct answer
D: spark.read.load(filePath)
Correct Answer:
C. spark.read.format("csv").option("header",True).load(filePath)
Explanation

The files in directory filePath are partitions of a DataFrame that have been exported using gzip compression. Spark automatically recognizes this situation and imports the CSV files as separate partitions into a single DataFrame. It is, however, necessary to specify that Spark should load the file headers in the CSV with the header option, which is set to False by default.

Scroll to Top