fudianchn opened a new pull request, #39243: URL: https://github.com/apache/shardingsphere/pull/39243
### What Refines the rewrite for the `BINARY` operator as a sharding condition, as left open by #35621. Fixes #35623. ### Root cause `ConditionValueCompareOperatorGenerator.generate` chose the value side with `predicate.getLeft() instanceof ColumnSegment ? predicate.getRight() : predicate.getLeft()`. For `BINARY account_id = 100` (and `account_id = BINARY 100`), the column/value is wrapped in a `UnaryOperationExpression(BINARY, …)`, so it is **not** a `ColumnSegment`. The generator then picked the `BINARY` unary as the value side, `ConditionValue.getValue()` could not extract a value from it → `Optional.empty()` → no sharding condition → full-route broadcast. (Column extraction is unaffected — `ColumnExtractor` already unwraps `UnaryOperationExpression`, so `findShardingColumn` still matches.) This is exactly the 4 cases left as `<!-- FIXME -->` in `test/it/rewriter/src/test/resources/scenario/sharding/case/dml/select.xml:532-551` (each expecting a single `t_account_0`). ### Fix Strip a leading `BINARY` unary from both sides before selecting the value side (new `unwrapBinaryOperator` helper). Only `BINARY` is unwrapped — not `-`/`+`/`~` — so routing of signed/negative values is unchanged. One method touched plus a small private helper. ### Tests Added two cases to `ConditionValueCompareOperatorGeneratorTest`: - `assertGenerateConditionValueWithBinaryOperatorPrefix` — `BINARY col = 100`. - `assertGenerateConditionValueWithBinaryOperatorValue` — `col = BINARY 100`. Both fail before the change (generator returns empty) and pass after. ### Verification - `./mvnw -pl features/sharding/core -am install -DskipTests` — BUILD SUCCESS. - `./mvnw -pl features/sharding/core test -Dtest=ConditionValueCompareOperatorGeneratorTest` — 14/14 green. - Style gates (Spotless / Checkstyle / PMD / SpotBugs) pass on `features/sharding/core`. The 4 `BINARY` FIXME blocks in `select.xml` are the end-to-end acceptance cases for this fix and can be uncommented once this lands (kept out of this PR to stay focused on the generator). Fixes #35623 -- 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]
