DATABRICKS-DATA-ENGINEER-ASSOCIATE practice question 3 of 25

A data engineer has developed a data pipeline to ingest data from a JSON source using Auto Loader, but the engineer has not provided any type…

Full set: 177 questions
A data engineer has developed a data pipeline to ingest data from a JSON source using Auto Loader, but the engineer has not provided any type inference or schema hints in their pipeline. Upon reviewing the data, the data engineer has noticed that all of the columns in the target table are of the string type despite some of the fields only including float or boolean values. Which of the following describes why Auto Loader inferred all of the columns to be of the string type?
Answer options
A: There was a type mismatch between the specific schema and the inferred schema
B: JSON data is a text-based format Correct answer
C: Auto Loader only works with string data
D: All of the fields had at least one null value
E: Auto Loader cannot infer the schema of ingested data
Correct Answer:
B. JSON data is a text-based format
Explanation

Auto Loader infers the schema by sampling the source data. JSON is a text-based format, which can lead to ambiguity in data types. For instance, a numeric value 123 can be represented as a number (123) or a string ("123") within different JSON records for the same field. When the schema inference process encounters such mixed types or quoted values (e.g., "true", "42.0") in its sample, it promotes the column's data type to string. This is the most flexible type to prevent data loss or parsing errors when inconsistencies exist in a text-based source file.

Why Incorrect

A. A type mismatch is a symptom or result of the schema inference process, not the underlying cause for why string was chosen.
C. This is factually incorrect. Auto Loader is designed to work with and infer a variety of complex data types, not just strings.
D. Null values are handled by schema inference and do not cause a column to be inferred as a string type. A column with integers and nulls would be inferred as an integer type.
E. This is factually incorrect. Schema inference and evolution are core, defining features of Auto Loader.

References

1. Databricks Documentation, "Configure schema inference and evolution in Auto Loader": This document explains the mechanism Auto Loader uses for schema inference: "To infer the schema, Auto Loader samples the first 50 GB or 1000 files that it discovers...". The behavior described in the question is a direct consequence of this sampling process acting on a potentially inconsistent text-based format like JSON.

2. Databricks Documentation, "Read and write JSON files": This page details how Apache Spark (the engine behind Auto Loader) handles JSON files. It notes that Spark infers the schema from the data. The documentation on data types implies that when different data types are present for the same field, Spark will choose a compatible type. For a mix of numbers and strings, the compatible type is string. The root cause is the text-based nature of JSON allowing this ambiguity.

3. Apache Spark Documentation, "Data Sources - JSON Files": The official Spark documentation (which Databricks is built upon) states, "Spark SQL can automatically infer the schema of a JSON dataset...". The inference logic will try to find a common type. If a field contains 1 in one record and "abc" in another, the inferred type for that field will be StringType. This behavior stems directly from JSON being a text format where such inconsistencies are possible.

Scroll to Top