pbottine opened a new issue, #40296:
URL: https://github.com/apache/shardingsphere/issues/40296
## Reproduction
With Java 17 and Maven dependencies
`shardingsphere-parser-sql-engine-mysql:5.5.3`,
`shardingsphere-parser-sql-engine-sqlserver:5.5.3`, and
`shardingsphere-sql-federation-compiler:5.5.3`, run:
```java
import org.apache.shardingsphere.sql.parser.engine.api.*;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.*;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
import
org.apache.shardingsphere.sqlfederation.compiler.sql.ast.converter.segment.expression.ExpressionConverter;
public class Repro {
static String shape(ExpressionSegment e) {
if (e instanceof BinaryOperationExpression b)
return "(" + shape(b.getLeft()) + " " + b.getOperator() + " " +
shape(b.getRight()) + ")";
return e.getText();
}
static void test(String dialect, String where) {
var parser = new SQLParserEngine(dialect, new CacheOption(128, 1024L));
var visitor = new SQLStatementVisitorEngine(dialect);
var statement = (SelectStatement) visitor.visit(parser.parse(
"SELECT * FROM t WHERE " + where, false));
var e = statement.getWhere().orElseThrow().getExpr();
System.out.println(dialect + " " + where + " -> " + shape(e));
System.out.println("Federation: " +
ExpressionConverter.convert(e).orElseThrow());
}
public static void main(String[] args) {
test("MySQL", "1 + 2 * 3 = 7");
test("MySQL", "4 | 1 & 2 = 4");
test("SQLServer", "1 + 2 * 3 = 9");
}
}
```
Observed on 2026-10-16: the MySQL ASTs group `((1 + 2) * 3) = 7` and `((4 |
1) & 2) = 4`; the SQL Server AST groups `((1 + 2) * 3) = 9`.
[MySQL](https://dev.mysql.com/doc/refman/8.4/en/operator-precedence.html) and
[SQL
Server](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/operator-precedence-transact-sql)
require multiplication before addition. MySQL also requires `&` before `|`.
The MySQL arithmetic Federation node retains explicit wrong grouping. For the
bitwise case, the MySQL AST records the wrong grouping while the printed
Federation SQL drops explicit parentheses.
The released [MySQL
grammar](https://github.com/apache/shardingsphere/blob/5.5.3/parser/sql/engine/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4#L390-L455)
and [SQL Server
grammar](https://github.com/apache/shardingsphere/blob/5.5.3/parser/sql/engine/dialect/sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4#L275-L286)
put these alternatives in the wrong order. This is distinct from the OR/XOR
grammar case and [PR
#39744](https://github.com/apache/shardingsphere/pull/39744).
--
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]