# ❌ 위험한 설정: schemaHints 없이 모든 것을 추론에 맡김
df = (spark.readStream
.format("cloudFiles")
.option("cloudFiles.format", "json")
.option("cloudFiles.inferColumnTypes", "true")
.option("cloudFiles.schemaLocation", "s3://bucket/schema/")
.load("s3://bucket/data/")
)
# → 첫 번째 파일에 amount가 5000(정수)이면 BIGINT로 추론
# → 나중에 amount가 5000.50(소수)이면 타입 불일치로 rescued_data로 빠짐
# ✅ 안전한 설정: 핵심 컬럼에 schemaHints 적용
df = (spark.readStream
.format("cloudFiles")
.option("cloudFiles.format", "json")
.option("cloudFiles.inferColumnTypes", "true")
.option("cloudFiles.schemaHints", """
order_id BIGINT,
amount DECIMAL(18,4),
user_id STRING,
created_at TIMESTAMP,
items ARRAY<STRUCT<product_id:STRING, qty:INT, price:DECIMAL(12,2)>>
""")
.option("cloudFiles.schemaLocation", "s3://bucket/schema/")
.option("rescuedDataColumn", "_rescued_data")
.load("s3://bucket/data/")
)