This is an automated email from the ASF dual-hosted git repository.

terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 88139b7249e Fix MySQL NOT sign precedence in SQL Federation (#39744)
88139b7249e is described below

commit 88139b7249eaf0b64c85d52939df704bbff174a1
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Sep 6 11:28:21 2026 +0800

    Fix MySQL NOT sign precedence in SQL Federation (#39744)
---
 .../operator/common/SQLExtensionOperatorTable.java |  2 +-
 .../impl/NotExpressionConverterTest.java           | 28 +++++++++++++++-------
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git 
a/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/operator/common/SQLExtensionOperatorTable.java
 
b/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/operator/common/SQLExtensionOperatorTable.java
index dd9b895a870..95cca78c4aa 100644
--- 
a/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/operator/common/SQLExtensionOperatorTable.java
+++ 
b/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/operator/common/SQLExtensionOperatorTable.java
@@ -47,7 +47,7 @@ public final class SQLExtensionOperatorTable {
     
     public static final SqlBinaryOperator SIGNED_RIGHT_SHIFT = new 
SqlBinaryOperator(">>", SqlKind.OTHER, 30, true, null, null, null);
     
-    public static final SqlPrefixOperator NOT_SIGN = new 
SqlPrefixOperator("!", SqlKind.OTHER, 26, null, null, null);
+    public static final SqlPrefixOperator NOT_SIGN = new 
SqlPrefixOperator("!", SqlKind.OTHER, 80, null, null, null);
     
     public static final SqlBinaryOperator XOR = new SqlBinaryOperator("XOR", 
SqlKind.OTHER, 30, true, null, null, null);
     
diff --git 
a/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/expression/impl/NotExpressionConverterTest.java
 
b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/expression/impl/NotExpressionConverterTest.java
index f207f5d0c84..ccff57be3d7 100644
--- 
a/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/expression/impl/NotExpressionConverterTest.java
+++ 
b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/ast/converter/segment/expression/impl/NotExpressionConverterTest.java
@@ -18,10 +18,13 @@
 package 
org.apache.shardingsphere.sqlfederation.compiler.sql.ast.converter.segment.expression.impl;
 
 import org.apache.calcite.sql.SqlBasicCall;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlLiteral;
 import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParserPos;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.NotExpression;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment;
-import 
org.apache.shardingsphere.sqlfederation.compiler.sql.ast.converter.operator.common.SQLExtensionOperatorTable;
 import 
org.apache.shardingsphere.sqlfederation.compiler.sql.ast.converter.segment.expression.ExpressionConverter;
 import 
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
 import 
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
@@ -32,7 +35,6 @@ import java.util.Optional;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
-import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 @ExtendWith(AutoMockExtension.class)
@@ -40,21 +42,29 @@ import static org.mockito.Mockito.when;
 class NotExpressionConverterTest {
     
     @Test
-    void assertConvertNotSignTrue() {
+    void assertConvertNotSignWithBinaryExpression() {
         LiteralExpressionSegment expression = new LiteralExpressionSegment(0, 
0, 1);
-        SqlNode expressionNode = mock(SqlNode.class);
+        SqlNode expressionNode = 
SqlStdOperatorTable.MINUS.createCall(SqlParserPos.ZERO, new 
SqlIdentifier("order_id", SqlParserPos.ZERO), 
SqlLiteral.createExactNumeric("1000", SqlParserPos.ZERO));
         
when(ExpressionConverter.convert(expression)).thenReturn(Optional.of(expressionNode));
         SqlBasicCall actual = NotExpressionConverter.convert(new 
NotExpression(0, 0, expression, true));
-        assertThat(actual.getOperator(), 
is(SQLExtensionOperatorTable.NOT_SIGN));
-        assertThat(actual.getOperandList().get(0), is(expressionNode));
+        assertThat(actual.toSqlString(config -> 
config.withQuoteAllIdentifiers(false)).getSql(), is("! (order_id - 1000)"));
     }
     
     @Test
-    void assertConvertNotSignFalse() {
+    void assertConvertNotSignWithSimpleExpression() {
         LiteralExpressionSegment expression = new LiteralExpressionSegment(0, 
0, 1);
-        SqlNode expressionNode = mock(SqlNode.class);
+        SqlNode expressionNode = new SqlIdentifier("order_id", 
SqlParserPos.ZERO);
+        
when(ExpressionConverter.convert(expression)).thenReturn(Optional.of(expressionNode));
+        SqlBasicCall actual = NotExpressionConverter.convert(new 
NotExpression(0, 0, expression, true));
+        assertThat(actual.toSqlString(config -> 
config.withQuoteAllIdentifiers(false)).getSql(), is("! order_id"));
+    }
+    
+    @Test
+    void assertConvertNotWithBinaryExpression() {
+        LiteralExpressionSegment expression = new LiteralExpressionSegment(0, 
0, 1);
+        SqlNode expressionNode = 
SqlStdOperatorTable.MINUS.createCall(SqlParserPos.ZERO, new 
SqlIdentifier("order_id", SqlParserPos.ZERO), 
SqlLiteral.createExactNumeric("1000", SqlParserPos.ZERO));
         
when(ExpressionConverter.convert(expression)).thenReturn(Optional.of(expressionNode));
         SqlBasicCall actual = NotExpressionConverter.convert(new 
NotExpression(0, 0, expression, false));
-        assertThat(actual.getOperator(), is(SQLExtensionOperatorTable.NOT));
+        assertThat(actual.toSqlString(config -> 
config.withQuoteAllIdentifiers(false)).getSql(), is("NOT order_id - 1000"));
     }
 }

Reply via email to