QuestionQ225

VerifiedUsing Spark SQL

A data engineer is using Spark SQL with a large JSON file located at /data/input.json. The file has records with varying schemas, and the engineer wants to create an external Spark SQL table that queries the file directly, without first loading it into a DataFrame.

The engineer must:

  • Create an external table named users that reads from /data/input.json.
  • Ensure Spark automatically infers the schema.
  • Merge the differing record schemas.

Which code snippet should the data engineer use to complete this task?

Explanation

Spark data-source tables use CREATE TABLE ... USING json with a path option to point table metadata at existing JSON data. Spark SQL automatically infers a JSON dataset’s schema, incorporating fields encountered among its records. mergeSchema is not a JSON data-source option; it applies to formats such as Parquet and ORC. The Spark data-source table syntax is CREATE TABLE, and a table that points to an existing path acts as a pointer to that external data source.

Learn more

Community Discussion

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