nzw921rx opened a new pull request, #10977:
URL: https://github.com/apache/seatunnel/pull/10977
## Purpose
Closes #10976
## Description
The current `OptionRule` + `Condition` system only supports presence checks
and equality conditions. This forces connector developers to write imperative
`if/else` validation scattered across `*Config.java` and `Source/Sink`
constructors — invisible to REST API, CLI, Web UI, `--check` offline
validation, and AI-assisted config generation.
This PR enhances the existing `required()` / `optional()` / `conditional()`
methods with `Condition`-accepting overloads so that value constraints can be
declared directly in `optionRule()`.
### What's changed
**`ConditionOperator` enum (new)** — 30 operators with self-describing
metadata (`category`, `arity`, `source`, `displaySymbol`), covering:
- Numeric: `>`, `>=`, `<`, `<=`
- String: `is not blank`, `starts with`, `ends with`, `contains`, `matches`,
`is uppercase`, `is lowercase`
- String length: `length ==`, `length >=`, `length <=`
- Collection: `is not empty`, `has unique elements`, `size ==`, `size >=`,
`size <=`
- Cross-field: `< [field]`, `<= [field]`, `> [field]`, `>= [field]`, `==
[field]`, `!= [field]`, `size == [field]`
**`Condition` class** — 27 new static factory methods + defensive
constructor validation (null operator, missing `compareOption` for FIELD ops,
missing `expectValue` for BINARY+LITERAL ops) + circular chain detection in
`and()`/`or()`.
**`OptionRule.Builder`** — 6 new overloads:
| Method | Purpose |
|--------|---------|
| `required(Option, Condition, Condition...)` | Single-field required +
value constraints |
| `required(Option, Option, Condition, Condition...)` | Two-field required +
cross-field constraints |
| `optional(Option, Condition, Condition...)` | Optional + value constraints
(validated when present) |
| `optional(Option, Option, Condition, Condition...)` | Two-field optional +
constraints |
| `conditional(Option, T, Condition, Condition...)` | Conditionally
triggered value constraints |
| `conditional(Option, T, Option, Option, Condition, Condition...)` |
Conditional two-field + constraints |
### Usage example
```java
OptionRule.builder()
.required(PORT,
Condition.greaterOrEqual(PORT, 1)
.and(Condition.lessOrEqual(PORT, 65535)))
.required(HOST, Condition.notBlank(HOST))
.required(START_TS, END_TS,
Condition.lessThanField(START_TS, END_TS))
.optional(MODE)
.conditional(MODE, StartMode.TIMESTAMP,
Condition.greaterThan(TIMESTAMP_VALUE, 0))
.build();
```
## Test Plan
```bash
./mvnw -B -pl seatunnel-api test -Dtest=ConfigValidatorTest
./mvnw -B -pl seatunnel-engine/seatunnel-engine-server test
-Dtest=OptionRulesServiceTest
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]