Microsoft Certified Azure Data Engineer Associate · Free Practice Question Medium

Question 18

How do you infer the data types and column names when you read a JSON file?

  • A

    spark.read.option("inferData", "true").json(jsonFile)

  • B

    spark.read.option("inferSchema", "true").json(jsonFile)

  • C

    spark.read.inferSchema("true").json(jsonFile)

  • D

    spark.read.option.inferSchema("true").json(jsonFile)

Reveal correct answer

Correct answer: B

Explanation

The spark.read.option("inferSchema", "true").json(jsonFile)  approach is the correct way to infer the file's schema.

A. The method spark.read.option("inferData", "true").json(jsonFile) contains a typo in the parameter name. The correct parameter name to enable schema inference in Spark is inferSchema, not inferData. This choice is incorrect due to the incorrect parameter name.

B. Using the spark.read.option("inferSchema", "true").json(jsonFile) method in Spark allows the system to automatically infer the data types and column names when reading a JSON file. This is the correct way to achieve this functionality in Spark.

C. The method spark.read.inferSchema("true").json(jsonFile) is not a valid syntax in Spark for inferring data types and column names when reading a JSON file. The correct syntax involves using the option method to specify the inferSchema parameter.

D. The method spark.read.option.inferSchema("true").json(jsonFile) is not a valid syntax in Spark for enabling schema inference when reading a JSON file. The correct syntax involves using the option method with the inferSchema parameter to achieve this functionality. This choice is incorrect due to the incorrect syntax.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need