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

A data engineer has realized that the data files associated with a Delta table are incredibly small. They want to compact the small files to form larger files to improve performance. Which of the following keywords can be used to compact the small files?

Full set: 177 questions
Answer options
A: REDUCE
B: OPTIMIZE Correct answer
C: COMPACTION
D: REPARTITION
E: VACUUM
Correct Answer:
B. OPTIMIZE
Explanation

The OPTIMIZE command is the correct tool in Delta Lake for compacting small files into larger ones. This process, known as file compaction or bin-packing, rewrites existing data files to reduce their number and increase their size. Having fewer, larger files significantly improves the read performance of queries on the table, as the query engine needs to open and process fewer files. The command can be run on an entire table or on specific partitions.

Why Incorrect

A. REDUCE: This is not a valid SQL or Delta Lake command for file management. It is a concept often associated with data processing transformations (e.g., reduceByKey in Spark RDDs).
C. COMPACTION: While "compaction" is the term for the process of combining small files, it is not the actual keyword used in the Delta Lake command. The command itself is OPTIMIZE.
D. REPARTITION: This is a DataFrame transformation used to control the number of data partitions before writing data. It is not used to optimize the file layout of an existing Delta table.
E. VACUUM: The VACUUM command is used for garbage collection. It removes data files that are no longer referenced by the Delta table's transaction log and are older than the retention period.

References

1. Databricks Documentation

"Compact small files into larger ones using OPTIMIZE": "Delta Lake on Databricks can improve the speed of read queries from a table by coalescing small files into larger ones. You can trigger compaction by running the OPTIMIZE command."

Source: Databricks Documentation > Delta Lake > Table utility commands > OPTIMIZE.

2. Databricks Documentation

"What is VACUUM?": "You can remove files that are no longer referenced by a Delta table and are older than the retention threshold by running the VACUUM command on the table." This distinguishes its purpose from OPTIMIZE.

Source: Databricks Documentation > Delta Lake > Table utility commands > VACUUM.

3. Learning Spark

2nd Edition (by Jules S. Damji

et al.): Chapter 9

"Delta Lake

" discusses performance tuning. It explicitly states

"To compact small files

you can use the OPTIMIZE command... This operation is an idempotent operation

meaning that if it’s run twice on the same dataset

the second run has no effect." This confirms OPTIMIZE as the correct command for this task.

Source: O'Reilly

Learning Spark

2nd Edition

Chapter 9

Section: "Compacting Small Files and Z-Ordering".

Scroll to Top