Databricks Data Engineer Associate exam dumps

Databricks Data Engineer Associate practice question 327 of 532

Databricks Certified Data Engineer Associate. Associate level, Databricks. Free question with the correct answer and a full explanation.

Databricks Data Engineer Associate Question 327

Select 2

You are working on a Databricks project where you need to update a table named 'sales_data' with the latest sales records. The table already exists, but you must ensure it is completely replaced with a new dataset stored in a DataFrame named new_sales. After replacing the table, you must append additional sales records from another DataFrame named additional_sales. Which of the following code snippets correctly achieves this?

  1. A

    new_sales.write.format('delta').mode('overwrite').saveAsTable('sales_data'); additional_sales.write.insertInto('sales_data')

  2. B

    spark.sql('CREATE OR REPLACE TABLE sales_data AS SELECT * FROM new_sales'); additional_sales.write.insertInto('sales_data')

  3. C

    new_sales.write.format('delta').mode('overwrite').saveAsTable('sales_data'); additional_sales.write.format('delta').mode('append').saveAsTable('sales_data')

  4. D

    spark.sql('CREATE OR REPLACE TABLE sales_data AS SELECT * FROM new_sales'); spark.sql('INSERT OVERWRITE TABLE sales_data SELECT * FROM additional_sales')

  5. E

    spark.sql('CREATE OR REPLACE TABLE sales_data AS SELECT * FROM new_sales'); additional_sales.write.format('delta').mode('overwrite').saveAsTable('sales_data')

Show answer and explanation

Correct answers: B, D

Explanation

The correct approach is to first replace the table using CREATE OR REPLACE TABLE with the new_sales DataFrame and then append the additional_sales DataFrame. Both options 2 and 4 achieve this by leveraging Databricks SQL commands (CREATE OR REPLACE TABLE and INSERT OVERWRITE) to ensure the table is replaced and data is appended correctly.

  • A. Incorrect.

    This option uses the correct 'overwrite' mode for replacing the table, but the insertInto method is not valid unless the table was created using Hive table syntax.

  • B. Correct.

    This option uses CREATE OR REPLACE TABLE to replace the table and then correctly inserts additional records using the insertInto method.

  • C. Incorrect.

    This option attempts to append data to the table after overwriting it, but saveAsTable with 'append' mode is not compatible with the required behavior of appending rows to an existing table.

  • D. Correct.

    This option uses CREATE OR REPLACE TABLE to replace the table and then uses INSERT OVERWRITE to append new records. Both methods are valid in this context.

  • E. Incorrect.

    This option incorrectly overwrites the table a second time with additional_sales, which does not meet the requirement of appending data to the replaced table.

Timed practice exam

Take a Databricks Data Engineer Associate practice test under exam conditions

45 questions in 90 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam