QuestionQ45

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

A data engineer is working with a large JSON dataset that contains order information. The dataset is kept in a distributed file system and must be loaded into a Spark DataFrame for analysis. The data engineer wants to ensure the schema is properly defined and that the data is read efficiently.

Which approach should the data scientist use to efficiently load the JSON data into a Spark DataFrame using a predefined schema?

Explanation

Spark supports supplying a StructType to DataFrameReader.schema(...) before calling .json(...). Providing this schema avoids the extra schema-inference work and reads the JSON fields using the specified data types.

Learn more

Community Discussion

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