Databricks Data Engineer Associate Question 106
Select 3You are tasked with creating two tables in Databricks: one from a JDBC connection to a MySQL database and another from an external CSV file stored in an Azure Data Lake. Which of the following steps are required to accomplish this task?
- A
Use the
spark.read.format('jdbc')method to read data from the MySQL database and write it to a Delta table. - B
Use the
spark.read.csv()method to read the CSV file and directly save it as a Delta table. - C
Specify the database connection properties such as URL, table name, user credentials, and driver while using the
jdbcformat. - D
Mount the Azure Data Lake storage to Databricks using a service principal or access key before accessing the CSV file.
- E
Use the
spark.sql()method to load data from the MySQL database into a Delta table.
Show answer and explanation
Correct answers: A, C, D
Explanation
To create a table from a JDBC connection, you need to use the spark.read.format('jdbc') method with the required connection properties. For external CSV files, the storage must first be accessible, which often involves mounting Azure Data Lake or providing credentials. Both data sources can then be written to Delta tables for further processing.
- A. Correct.
Correct. The
spark.read.format('jdbc')method is required to read data from a JDBC source like MySQL, and the data can then be written to a Delta table. - B. Incorrect.
Incorrect. While
spark.read.csv()can read the external CSV file, you need to specify additional options and save the data as a Delta table explicitly. This option is incomplete. - C. Correct.
Correct. The
jdbcformat requires specifying connection properties such as the database URL, table name, user credentials, and the appropriate driver. - D. Correct.
Correct. To access an external CSV file in Azure Data Lake, you must first mount the storage to Databricks or provide appropriate access credentials.
- E. Incorrect.
Incorrect. The
spark.sql()method is used to execute SQL queries, but it is not used to directly load data from databases like MySQL into Delta tables.