lingareddy_Alva
Honored Contributor III

@BF7 

1. Auto Loader is more conservative
It may default to StringType if the field has:
Inconsistent types across files
Mixed nulls and integers
Unexpected characters
This avoids schema evolution conflicts later in streaming

2. spark.read().option("inferSchema", true) is more aggressive
It can more confidently assign IntegerType or DoubleType in batch mode because it:
Samples more of the data at once
Doesn’t have to worry about downstream schema evolution

Example:
[
{ "id": "123" },
{ "id": 456 },
{ "id": "789" }
]
spark.read(..., inferSchema=True) → likely infers IntegerType (casts strings like "123" if parsable)

Auto Loader → likely infers StringType (preserves original types to avoid runtime failures)

 

LR