seatunnel icon indicating copy to clipboard operation
seatunnel copied to clipboard

[Improve][Connector-V2] Migrate Kafka Source imperative validation to declarative OptionRule

Open nzw921rx opened this issue 5 months ago • 0 comments

Purpose of this pull request

Related #11007 Depends on #11121

  1. Migrate 4 imperative if/throw checks in KafkaSourceConfig.createConsumerMetadata() to declarative Conditions in KafkaSourceFactory.optionRule()
  2. Add greaterOrEqual(START_MODE_TIMESTAMP, 0L) constraint when start_mode = TIMESTAMP
  3. Add greaterOrEqual(START_MODE_END_TIMESTAMP, 0L) optional value constraint
  4. Add mapNotEmpty(START_MODE_OFFSETS) constraint when start_mode = SPECIFIC_OFFSETS
  5. Replace KEY_PARTITION_DISCOVERY_INTERVAL_MILLIS conditional-required with greaterThan(..., 0L) value constraint when ignore_no_leader_partition = true
  6. Retain runtime-only checks (> currentTimestamp) with explanatory comments

Does this PR introduce any user-facing change?

Yes — previously invalid configurations (negative timestamps, empty offsets map) were rejected at task execution time with generic IllegalArgumentException. Now they are rejected earlier at job submission time with structured OptionValidationException including option name, constraint type, and violation details.

How was this patch tested?

Unit tests in KafkaFactoryTest:

  • testValidTimestampConfig — valid TIMESTAMP mode passes validation
  • testNegativeTimestampRejected — negative start_mode.timestamp is rejected
  • testNegativeEndTimestampRejected — negative start_mode.end_timestamp is rejected
  • testValidSpecificOffsetsConfig — valid SPECIFIC_OFFSETS mode passes validation
  • testEmptyOffsetsMapRejected — empty offsets map is rejected
./mvnw test -pl seatunnel-connectors-v2/connector-kafka -Dtest="KafkaFactoryTest" -DfailIfNoTests=false

nzw921rx avatar Jun 22 '26 05:06 nzw921rx