seatunnel icon indicating copy to clipboard operation
seatunnel copied to clipboard

[Feature][API] Simplify condition chain model by removing (Expression)

Open nzw921rx opened this issue 5 months ago • 5 comments

Search before asking

  • [x] I had searched in the feature and found no similar feature requirement.

Description

Problem statement

Today we maintain two abstractions for the same concept:

  • Condition<?> already supports linked condition chains via .and() / .or()
  • Expression wraps a Condition<?> and re-implements chain composition

As a result, internal code frequently does:

  1. build a Condition chain
  2. wrap it as Expression
  3. immediately unwrap it again (getExpression()) before evaluation or rendering

This indirection increases API surface and maintenance cost without adding semantics.

Goal

Use Condition<?> as the single representation of condition chains.

Non-goals

  • No new precedence rule is introduced (reuse Condition's existing AND/OR evaluation logic)
  • No behavior change in error messages
  • No behavior change in REST metadata rendering
  • No change to connector-facing OptionRule.builder() usage patterns

Proposed API model

Current Proposed
Expression.of(Condition.of(option, value)) Condition.of(option, value)
Expression::or / Expression::and Condition::or / Condition::and
ConditionRule.expression: Expression ConditionRule.condition: Condition<?>
ConditionalRequiredOptions.expression: Expression ConditionalRequiredOptions.condition: Condition<?>
Map<Expression, OptionRule> Map<Condition<?>, OptionRule>
ConfigValidator.validate(Expression) ConfigValidator.validate(Condition<?>)

Compatibility strategy

Two rollout options:

Option 1: Deprecate first, remove later

  • Keep Expression in the current release and mark it as @Deprecated
  • Migrate all in-repo usages to Condition<?>
  • Remove Expression in the next API cleanup window

When to use: if maintainers want a transition window for potential downstream usage.

Option 2: Remove directly in this PR

  • Delete Expression.java directly
  • Replace all in-repo usages with Condition<?>
  • Remove all Expression entrypoints in ConfigValidator in the same PR

When to use: if maintainers confirm external usage is minimal and want to reduce model complexity immediately.

Impact scope (direct changes)

  • Expression.java: delete
  • OptionRule.java: remove Expression construction path, use Condition<?> directly
  • ConditionRule.java: field type changes from Expression to Condition<?>
  • RequiredOption.java: ConditionalRequiredOptions changes from Expression to Condition<?>
  • ConfigValidator.java: remove all Expression entrypoints (including constructor/overload), evaluate via Condition<?> only
  • OptionRulesService.java: replace getExpression() with getCondition()
  • MetadataExportCommand.java: switch export path from Expression to Condition
  • tests: replace all Expression-related assertions and builders

Questions to confirm

  1. Should we choose Option 1 (deprecate first) or Option 2 (direct removal in this PR)?
  2. Is it acceptable to update seatunnel-engine and seatunnel-core call paths in this PR (OptionRulesService / MetadataExportCommand)?
  3. Can we remove all Expression-typed constructors/overloads in ConfigValidator without keeping compatibility shims?
  4. Should this change be treated as API cleanup and explicitly called out in PR notes/changelog for downstream users that may import `Expression

Usage Scenario

No response

Related issues

No response

Are you willing to submit a PR?

  • [x] Yes I am willing to submit a PR!

Code of Conduct

nzw921rx avatar Jun 10 '26 10:06 nzw921rx

@davidzollo PTAL and please help confirm. Thanks in advance😄

nzw921rx avatar Jun 10 '26 10:06 nzw921rx

Thanks for writing this up so concretely.

I agree this is a larger API-cleanup / compatibility topic, not just a local refactor.

I would not remove Expression directly in the first PR. My preference is Option 1: deprecate first, migrate in-repo usages, and keep compatibility shims for one release cycle.

The main reason is that Expression is still a public seatunnel-api type today, and it is not only an internal wrapper. RequiredOption.ConditionalRequiredOptions still stores an Expression, and ConfigValidator still validates through Expression. Even if all in-repo call sites are migrated in one PR, deleting it immediately would still be a source-level breaking change for downstream extensions that may already import it.

My suggested scope is:

  1. keep Condition<?> as the long-term single model
  2. migrate the internal evaluation / rendering path toward Condition<?>
  3. keep deprecated Expression entrypoints / constructors / accessors as forwarding compatibility shims for now
  4. keep behavior and error-message rendering unchanged in this step

It is fine to update the seatunnel-engine and seatunnel-core call paths in the same PR if the observable behavior stays identical. What I would avoid in the first change is removing all Expression-typed APIs from ConfigValidator and RequiredOption at once.

So from my side: yes to the cleanup direction, but deprecate-first is the safer path here.

DanielLeens avatar Jun 10 '26 15:06 DanielLeens

I think your point makes sense. Let's hear from the other guys

davidzollo avatar Jun 11 '26 13:06 davidzollo

Thanks for the well-structured proposal. Since Expression is part of the public API in seatunnel-api, Option 1 (deprecate first, remove in a later API cleanup window) seems safer for potential downstream/connector authors. Could a committer confirm the preferred rollout path before implementation starts?

Please confirm the scope of in-repo migration: a quick audit of all usages of Expression (e.g., ConditionRule, ConditionalRequiredOptions, ConfigValidator, REST metadata rendering, Map<Expression, OptionRule> keys) with a checklist in this issue would help track the change and verify the stated non-goals (no behavior/message/rendering changes).

If you plan to work on this, please note that Condition will be used as a map key after the change — verify its equals/hashCode semantics match what Expression provided today, and add tests covering AND/OR chain equality to avoid subtle regressions.

SEZ9 avatar Aug 20 '26 15:08 SEZ9

Thanks @DanielLeens for the detailed analysis, and @davidzollo for confirming the direction.

I agree with Option 1 (deprecate-first) rather than removing Expression outright. Since Expression is still a public seatunnel-api type — stored in RequiredOption.ConditionalRequiredOptions and validated through ConfigValidator — deleting it immediately would be a source-level breaking change for downstream extensions, even if all in-repo usages are migrated in one PR.

So let's lock the first PR's scope to what @DanielLeens outlined:

  1. Keep Condition<?> as the long-term single model.
  2. Migrate the internal evaluation / rendering path toward Condition<?>.
  3. Keep deprecated Expression entrypoints / constructors / accessors as forwarding compatibility shims for one release cycle.
  4. Keep behavior and error-message rendering unchanged in this step.

Updating the seatunnel-engine and seatunnel-core call paths in the same PR is fine as long as observable behavior stays identical, and the Expression-typed APIs in ConfigValidator and RequiredOption should not be removed in this first change.

@nzw921rx, can you confirm you're OK taking this on with the deprecate-first scope above? Thanks all — looking forward to the PR.

SEZ9 avatar Aug 21 '26 06:08 SEZ9