Repository: tobymao/sqlglot

Issue:
The translated results of MERGE INTO SQL statements often have poor readability.
**Fully reproducible code snippet**
```python
def main():
    import sqlglot

    sql = """
        MERGE INTO t USING s ON t.id = s.id WHEN MATCHED THEN UPDATE SET status = s.status, amount = s.amount
    """

    print(sqlglot.transpile(sql, read="spark", write="spark", identify=False, pretty=True)[0])


if __name__ == '__main__':
    main()
```

**Expect**
```sql
MERGE INTO t
USING s
ON t.id = s.id
WHEN MATCHED THEN UPDATE SET 
  status = s.status,
  amount = s.amount
```

**Actual**
```sql
MERGE INTO t
USING s
ON t.id = s.id
WHEN MATCHED THEN UPDATE SET status = s.status, amount = s.amount
```

Hints from issue comments:

Solution patch:
diff --git a/sqlglot/generator.py b/sqlglot/generator.py
index 0fcae398..4b9a296c 100644
--- a/sqlglot/generator.py
+++ b/sqlglot/generator.py
@@ -3841,7 +3841,7 @@ class Generator(metaclass=_Generator):
             if isinstance(then_expression.args.get("expressions"), exp.Star):
                 then = f"UPDATE {self.sql(then_expression, 'expressions')}"
             else:
-                then = f"UPDATE SET {self.expressions(then_expression, flat=True)}"
+                then = f"UPDATE SET{self.sep()}{self.expressions(then_expression)}"
         else:
             then = self.sql(then_expression)
         return f"WHEN {matched}{source}{condition} THEN {then}"


Test patch:
diff --git a/tests/dialects/test_tsql.py b/tests/dialects/test_tsql.py
index 8853a682..3dc152ba 100644
--- a/tests/dialects/test_tsql.py
+++ b/tests/dialects/test_tsql.py
@@ -962,7 +962,8 @@ FROM (
       ProductID
   ) AS src(ProductID, OrderQty)
   ON pi.ProductID = src.ProductID
-  WHEN MATCHED AND pi.Quantity - src.OrderQty >= 0 THEN UPDATE SET pi.Quantity = pi.Quantity - src.OrderQty
+  WHEN MATCHED AND pi.Quantity - src.OrderQty >= 0 THEN UPDATE SET
+    pi.Quantity = pi.Quantity - src.OrderQty
   WHEN MATCHED AND pi.Quantity - src.OrderQty <= 0 THEN DELETE
   OUTPUT $action, Inserted.ProductID, Inserted.LocationID, Inserted.Quantity AS NewQty, Deleted.Quantity AS PreviousQty
 ) AS Changes(Action, ProductID, LocationID, NewQty, PreviousQty)
diff --git a/tests/fixtures/pretty.sql b/tests/fixtures/pretty.sql
index ca5e4a99..172fb02e 100644
--- a/tests/fixtures/pretty.sql
+++ b/tests/fixtures/pretty.sql
@@ -449,3 +449,11 @@ SELECT
 FROM foo
 WHERE
   1 = 1 AND /* first comment */ foo.a /* second comment */ = 1;
+
+MERGE INTO t USING s ON t.id = s.id WHEN MATCHED THEN UPDATE SET status = s.status, amount = s.amount;
+MERGE INTO t
+USING s
+ON t.id = s.id
+WHEN MATCHED THEN UPDATE SET
+  status = s.status,
+  amount = s.amount;