Skip to content

[Spark] Keep the writer's two Spark type dispatchers in sync, and clean up if construction fails #13

Closed

Description

@ChristopherWirt

Since PR #7, the writer dispatches on Spark type in two places:

  • SparkToArrowSchema, which builds the Arrow schema;
  • ArrowFieldWriter.create, which builds the per-column writers.

Nothing keeps the two in sync.

Why it matters

The constructor only catches IOException, and ArrowFieldWriter.create runs after the native writer has opened the output file.

Suppose a type is added to SparkToArrowSchema but not to ArrowFieldWriter, or the vector classes don't line up. Then create throws IllegalArgumentException or ClassCastException out of the constructor. Spark never gets a DataWriter to abort, so the native writer, its open file, the RootAllocator and the VectorSchemaRoot all leak.

Impact

Latent. Both dispatchers cover the same types today, and an unsupported type throws in SparkToArrowSchema.convert, before the native writer is opened.

Where

Fix

  • Catch RuntimeException in the constructor and release whatever was opened before rethrowing.
  • Add a test that every type SparkToArrowSchema accepts also gets an ArrowFieldWriter.

Activity

  1. ChristopherWirt commented on Nov 2, 2026

    @ChristopherWirt
    CollaboratorAuthor

    PR #35 supersedes #22 as the fix for this issue. Its FileFormat writer creates the Arrow field writers before opening the native writer and catches RuntimeException during initialization to release the resources already allocated. PR #35 now includes the closing reference. This issue remains open until #35 merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions