If Delta Lake Uses Immutable Files, How Do UPDATE, DELETE, and MERGE Work?

Listen and Watch here One of the most common questions data engineers ask is: if Delta Lake stores data in immutable Parquet files, how can it support operations like UPDATE , DELETE , and MERGE ? The answer lies in Delta Lake’s transaction log and its clever file rewrite mechanism. 🔍 Immutable Files in Delta Lake Delta Lake stores data in Parquet files, which are immutable by design. This immutability ensures consistency and prevents accidental corruption. But immutability doesn’t mean data can’t change — it means changes are handled by creating new versions of files rather than editing them in place. ⚡ How UPDATE Works When you run an UPDATE statement, Delta Lake: Identifies the files containing rows that match the update condition. Reads those files and applies the update logic. Writes out new Parquet files with the updated rows. Marks the old files as removed in the transaction log. UPDATE people SET age = age + 1 WHERE country = 'India'; Result: ...

NVL vs COALESCE

 NVL vs COALESCE to handle NULL values in SQL.



Both NVL and COALESCE are used in SQL to handle null values, but they have some differences:

Syntax: NVL takes two arguments, while COALESCE takes two or more arguments.

Return value: NVL returns the first argument if it is not null, otherwise it returns the second argument. COALESCE returns the first non-null value from its arguments.

Here are some examples to illustrate the differences:

NVL Example:


SELECT NVL(NULL, 'hello') FROM dual;
This will return 'hello', since the first argument is null.


SELECT NVL('world', 'hello') FROM dual;
This will return 'world', since the first argument is not null.

COALESCE Example:

SELECT COALESCE(NULL, NULL, 'hello', 'world') FROM dual;

This will return 'hello', since it is the first non-null value.


SELECT COALESCE(NULL, 'hello', 'world') FROM dual;
This will also return 'hello', since it is the first non-null value.

Hope it helps.

#sql #null #handling

Comments

Popular posts from this blog

How to Configure a Databricks Cluster to Process 10 TB of Data Efficiently

5 Reasons Your Spark Jobs Are Slow — and How to Fix Them Fast

If Delta Lake Uses Immutable Files, How Do UPDATE, DELETE, and MERGE Work?