nerdexam
Databricks

DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #41

In what order should the below lines of code be run in order to read a JSON file at the file path filePath into a DataFrame with the specified schema schema? Lines of code: 1. .json(filePath, schema…

The correct answer is C. 3, 5, 1. The correct order is lines 3, 5, 1: spark \ .read \ .json(filePath, schema = schema). In PySpark, you start with the spark SparkSession object, access its .read attribute (not a method call - no parentheses), and then call .json() passing the file path and the schema keyword…

Data Ingestion

Question

In what order should the below lines of code be run in order to read a JSON file at the file path filePath into a DataFrame with the specified schema schema? Lines of code: 1. .json(filePath, schema = schema) 2. .storesDF 3. .spark \ 4. .read() \ 5. .read \ 6. .json(filePath, format = schema)

Options

  • A3, 5, 6
  • B2, 4, 1
  • C3, 5, 1
  • D2, 5, 1
  • E3, 4, 1

How the community answered

(43 responses)
  • A
    2% (1)
  • B
    7% (3)
  • C
    88% (38)
  • E
    2% (1)

Explanation

The correct order is lines 3, 5, 1: spark \ .read \ .json(filePath, schema = schema). In PySpark, you start with the spark SparkSession object, access its .read attribute (not a method call - no parentheses), and then call .json() passing the file path and the schema keyword argument. Line 2 (storesDF) is an assignment target, not part of the read chain. Line 4 uses .read() with parentheses (incorrect - it's a property, not a method). Line 6 uses format = schema which is not the correct parameter name.

Topics

#Spark DataFrames#Reading Data#JSON Data Source#Schema Specification

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice