Skip to content

[SPARK-58218][SQL] Replace generic RuntimeException with typed exceptions in AvroDeserializer#57376

Open
ganeshashree wants to merge 1 commit into
apache:masterfrom
ganeshashree:SPARK-58218
Open

[SPARK-58218][SQL] Replace generic RuntimeException with typed exceptions in AvroDeserializer#57376
ganeshashree wants to merge 1 commit into
apache:masterfrom
ganeshashree:SPARK-58218

Conversation

@ganeshashree

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

AvroDeserializer threw three generic java.lang.RuntimeExceptions. This replaces them with typed exceptions:

  • The BYTES -> BinaryType type-mismatch case now throws IncompatibleSchemaException (via errorPrefix), matching the five sibling type-mismatch cases in the same newWriter method that already do so.
  • The non-nullable array-element and map-value null-read cases now throw a SparkRuntimeException with a new error condition AVRO_CANNOT_READ_NULL_FIELD (SQLSTATE 22004), the read-side analog of the existing AVRO_CANNOT_WRITE_NULL_FIELD.

Why are the changes needed?

Generic RuntimeExceptions are not catchable by error class, carry no SQLSTATE, and (for the binary case) were inconsistent with the sibling cases in the same method. Spark has largely migrated runtime failures to the error-class framework; these sites were left behind. The write path already had a typed, catalogued error for the analogous non-null-field situation (AVRO_CANNOT_WRITE_NULL_FIELD); the read path now has its counterpart.

Does this PR introduce any user-facing change?

Yes. When reading Avro data where a null appears in a non-nullable array element or map value, or where a BYTES value is not a valid Avro binary, the exception type and message change from a generic RuntimeException to a typed SparkRuntimeException / IncompatibleSchemaException carrying an error condition and SQLSTATE.

How was this patch tested?

Added unit tests in AvroCatalystDataConversionSuite that deserialize Avro data containing a null into a non-nullable Catalyst array element and map value, asserting the AVRO_CANNOT_READ_NULL_FIELD error condition and field-path parameter via checkError. Also ran SparkThrowableSuite (error-conditions.json validation), AvroCatalystDataConversionSuite, and AvroSerdeSuite.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.8)

…ions in AvroDeserializer

### What changes were proposed in this pull request?

`AvroDeserializer` threw three generic `java.lang.RuntimeException`s. This replaces
them with typed exceptions:

- The `BYTES -> BinaryType` type-mismatch case now throws `IncompatibleSchemaException`
  (via `errorPrefix`), matching the five sibling type-mismatch cases in the same
  `newWriter` method that already do so.
- The non-nullable array-element and map-value null-read cases now throw a
  `SparkRuntimeException` with a new error condition `AVRO_CANNOT_READ_NULL_FIELD`
  (SQLSTATE 22004), the read-side analog of the existing `AVRO_CANNOT_WRITE_NULL_FIELD`.

### Why are the changes needed?

Generic `RuntimeException`s are not catchable by error class, carry no SQLSTATE, and
(for the binary case) were inconsistent with the sibling cases in the same method.
Spark has largely migrated runtime failures to the error-class framework; these sites
were left behind. The write path already had a typed, catalogued error for the
analogous non-null-field situation (`AVRO_CANNOT_WRITE_NULL_FIELD`); the read path
now has its counterpart.

### Does this PR introduce _any_ user-facing change?

Yes. When reading Avro data where a null appears in a non-nullable array element or
map value, or where a `BYTES` value is not a valid Avro binary, the exception type
and message change from a generic `RuntimeException` to a typed
`SparkRuntimeException` / `IncompatibleSchemaException` carrying an error condition
and SQLSTATE.

### How was this patch tested?

Added unit tests in `AvroCatalystDataConversionSuite` that deserialize Avro data
containing a null into a non-nullable Catalyst array element and map value, asserting
the `AVRO_CANNOT_READ_NULL_FIELD` error condition and field-path parameter via
`checkError`. Also ran `SparkThrowableSuite` (error-conditions.json validation),
`AvroCatalystDataConversionSuite`, and `AvroSerdeSuite`.

Co-authored-by: Isaac

@uros-b uros-b left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ganeshashree! cc @MaxGekk @HyukjinKwon for Avro errors

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants