references/data_modeling_patterns.md · 24000
table` ADD COLUMNS (new_column STRING) """)
Schema merge on read
df = spark.read
.option("mergeSchema", "true")
.format("delta")
.load("/path/to/table")
### Backward Compatibility
```sql
-- Create view for backward compatibility
CREATE VIEW orders_v1 AS
SELECT
order_id,
customer_id,
amount,
-- Map new columns to old schema
COALESCE(discount_amount, 0) as discount,
COALESCE(currency, 'USD') as currency
FROM orders_v2;
-- Deprecation pattern
CREATE VIEW orders_deprecated AS
SELECT * FROM orders_v1;
-- Add comment: "DEPRECATED: Use orders_v2. Will be removed 2024-06-01"
Data Contracts for Schema Changes
# contracts/orders_contract.yaml
name: orders
version: "2.0.0"
owner: [email protected]
schema:
order_id:
type: string
required: true
breaking_change: never
customer_id:
type: string
required: true
breaking_change: never
amount:
type: decimal
precision: 10
scale: 2
required: true
# New in v2.0.0
discount_amount:
type: decimal
precision: 10
scale: 2
required: false
added_in: "2.0.0"
default: 0
# Deprecated in v2.0.0
legacy_status:
type: string
deprecated: true
removed_in: "3.0.0"
migration: "Use order_status instead"
compatibility:
backward: true # v2 readers can read v1 data
forward: true # v1 readers can read v2 data