QuestionQ197

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

The code block below is intended to read JSON from the file path filePath into a DataFrame using the specified schema schema. Choose the response that correctly fills the numbered blanks in the code block to complete the task.

Code block:

__1__.__2__.__3__(__4__).format("csv").__5__(__6__)  
Explanation

The read entry point is the DataFrameReader accessed via the spark.read property — note that read is a property, not a method, so spark.read() (with parentheses) is invalid, eliminating options A, B and C. The correct fluent chain is spark.read.schema(schema).format(...).load(filePath): schema() takes the schema variable, and load() takes the file path. Option D fills the blanks as spark / read / schema / schema / load / filePath, which matches this pattern. (The literal "csv" is fixed in the template rather than one of the numbered blanks, so it does not affect the choice.)

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!