Fix sink schema validation: throw a proper error for value-less schemas#199
Draft
dev-ankit wants to merge 1 commit into
Draft
Fix sink schema validation: throw a proper error for value-less schemas#199dev-ankit wants to merge 1 commit into
dev-ankit wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
PulsarSinks.validateQueryis 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:throw.PulsarExceptions.pulsarSinkInvalidSchemaappears as a bare statement with nothrow, so the exception is constructed and discarded — validation falls through and the write proceeds with no value column.PULSAR_SINK_INVALID_SCHEMA, which is not present inerror/pulsar-error-classes.json(the defined key isPULSAR_SINK_INVALID_SCHEMA_TYPE). So merely evaluating the factory raisesINTERNAL_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 missingthrow.PulsarExceptions.pulsarSinkInvalidSchema: use the defined error classPULSAR_SINK_INVALID_SCHEMA_TYPE.PulsarSinkValidateQuerySuitecovering 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 throwsPulsarIllegalArgumentExceptionwith conditionPULSAR_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-requiredno-need-docdoc