pub fn cast_to_file_schema(
batch: RecordBatch,
file_schema: &Schema,
) -> Result<RecordBatch, Error>Expand description
Aligns a Postgres-inferred batch to the declared file schema’s column types, casting column
by column where they differ. sql_arrow_bridge’s mapping is keyed on the Postgres type name
alone, so it cannot know that a TEXT column is declared as something narrower downstream:
blocks.audience is Dictionary(Int32, Utf8) in the file schema (matching every other view’s
audience column) but arrives as plain Utf8.
Positional, matching how the parquet writer zips declared fields against batch columns with no
name check (see write_partition::check_non_nullable_columns). Nullability and field metadata
come from the batch, never from the declared schema, so this stays a pure type alignment and
leaves the NOT NULL verdict to the write path’s own guard.