Skip to content

Fix sink schema validation: throw a proper error for value-less schemas - #199

Closed
dev-ankit wants to merge 1 commit into
streamnative:masterfrom
dev-ankit:fix/sink-invalid-schema-error
Closed

Fix sink schema validation: throw a proper error for value-less schemas#199
dev-ankit wants to merge 1 commit into
streamnative:masterfrom
dev-ankit:fix/sink-invalid-schema-error

Conversation

@dev-ankit

Copy link
Copy Markdown

Motivation

PulsarSinks.validateQuery is meant to reject a sink schema that has no value columns (only reserved meta fields such as __key/__topic). Two bugs make that guard ineffective:

  1. Missing throw. PulsarExceptions.pulsarSinkInvalidSchema appears as a bare statement with no throw, so the exception is constructed and discarded — validation falls through and the write proceeds with no value column.
  2. Undefined error class. The factory references error class PULSAR_SINK_INVALID_SCHEMA, which is not present in error/pulsar-error-classes.json (the defined key is PULSAR_SINK_INVALID_SCHEMA_TYPE). So merely evaluating the factory raises INTERNAL_ERROR: Cannot find main error class 'PULSAR_SINK_INVALID_SCHEMA' instead of the intended message ("Schema should have at least one non-key/non-topic field"). This bug currently masks Cleanup files that are not related to pulsar-spark #1.

Modifications

  • PulsarSinks.validateQuery: add the missing throw.
  • PulsarExceptions.pulsarSinkInvalidSchema: use the defined error class PULSAR_SINK_INVALID_SCHEMA_TYPE.
  • Add PulsarSinkValidateQuerySuite covering both the reject and accept paths.

Verifying this change

  • Make sure that the change passes the CI checks.

  • This change added tests and can be verified as follows:

    PulsarSinkValidateQuerySuite: a meta-only schema (__key + topic option) now throws PulsarIllegalArgumentException with condition PULSAR_SINK_INVALID_SCHEMA_TYPE; a schema with a value field passes. The reject test fails on the current code (no exception is thrown / INTERNAL_ERROR) and passes with the fix. Verified locally with ./mvnw test -Dsuites='org.apache.spark.sql.pulsar.PulsarSinkValidateQuerySuite'.

Documentation

Check the box below.

Need to update docs?

  • doc-required
  • no-need-doc
  • doc

PulsarSinks.validateQuery is meant to reject a sink schema with no value
fields (only reserved meta fields like __key/__topic). Two bugs made the
guard ineffective:

1. The exception was constructed but never thrown — pulsarSinkInvalidSchema
   appeared as a bare statement with no `throw`, so validation fell through.
2. The factory referenced error class "PULSAR_SINK_INVALID_SCHEMA", which is
   not defined in error/pulsar-error-classes.json (the defined key is
   "PULSAR_SINK_INVALID_SCHEMA_TYPE"), so even evaluating it raised
   INTERNAL_ERROR instead of the intended message.

- Add the missing `throw` in validateQuery.
- Point the factory at the defined error class PULSAR_SINK_INVALID_SCHEMA_TYPE.
- Add PulsarSinkValidateQuerySuite covering the reject and accept paths.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the no-need-doc This pr does not need any document label May 29, 2026
@dev-ankit dev-ankit closed this Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-need-doc This pr does not need any document

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant