This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 774fc26f962 [improve](syntax) compatiable with mysql MOD syntax
(#58432)
774fc26f962 is described below
commit 774fc26f962362dbd051895444e4bbdbedfa58ac
Author: ivin <[email protected]>
AuthorDate: Wed Jan 7 17:39:26 2026 +0800
[improve](syntax) compatiable with mysql MOD syntax (#58432)
### What problem does this PR solve?
This PR improves compatibility with MySQL arithmetic expression syntax,
allow user use `%` and `MOD` to represent modular semantics.
Note that the `MOD` is a non-reserved keyword, can be used in arithmetic
expressions, MOD function name or to represent aliases in as statements.
before:
```sql
SELECT 10 MOD 3 as mod;
ERROR 1105 (HY000): errCode = 2, detailMessage =
mismatched input '3' expecting {<EOF>, ';'}(line 1, pos 19)
```
after:
```sql
mysql> SELECT 10 MOD 3 as mod;
+------+
| mod |
+------+
| 1 |
+------+
```
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [x] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
---
.../src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 | 1 +
.../src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 | 3 ++-
.../org/apache/doris/nereids/parser/LogicalPlanBuilder.java | 2 ++
.../data/nereids_p0/operator/test_arithmetic_operators.out | 10 ++++++++++
.../nereids_p0/operator/test_arithmetic_operators.groovy | 3 +++
5 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
index 33282dc4a6b..7ac1559c6d5 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
@@ -614,6 +614,7 @@ SUBTRACT: '-';
ASTERISK: '*';
SLASH: '/';
MOD: '%';
+MOD_ALT: 'MOD';
TILDE: '~';
AMPERSAND: '&';
LOGICALAND: '&&';
diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index d9166264206..de1d6f0b1cb 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -1598,7 +1598,7 @@ valueExpression
| operator=(SUBTRACT | PLUS | TILDE) valueExpression
#arithmeticUnary
// split arithmeticBinary from 1 to 5 due to they have different operator
precedence
| left=valueExpression operator=HAT right=valueExpression
#arithmeticBinary
- | left=valueExpression operator=(ASTERISK | SLASH | MOD | DIV)
right=valueExpression #arithmeticBinary
+ | left=valueExpression operator=(ASTERISK | SLASH | MOD | MOD_ALT | DIV)
right=valueExpression #arithmeticBinary
| left=valueExpression operator=(PLUS | SUBTRACT) right=valueExpression
#arithmeticBinary
| left=valueExpression operator=AMPERSAND right=valueExpression
#arithmeticBinary
| left=valueExpression operator=PIPE right=valueExpression
#arithmeticBinary
@@ -2102,6 +2102,7 @@ nonReserved
| MIN
| MINUTE
| MINUTES
+ | MOD_ALT
| MODIFY
| MONTH
| MTMV
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index fe02442ee2a..0a20bc1d167 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -3035,6 +3035,8 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
return new Divide(left, right);
case DorisParser.MOD:
return new Mod(left, right);
+ case DorisParser.MOD_ALT:
+ return new Mod(left, right);
case DorisParser.PLUS:
return new Add(left, right);
case DorisParser.SUBTRACT:
diff --git
a/regression-test/data/nereids_p0/operator/test_arithmetic_operators.out
b/regression-test/data/nereids_p0/operator/test_arithmetic_operators.out
index 218d2376ddd..8e841fe2e54 100644
--- a/regression-test/data/nereids_p0/operator/test_arithmetic_operators.out
+++ b/regression-test/data/nereids_p0/operator/test_arithmetic_operators.out
@@ -290,3 +290,13 @@
\N \N \N
\N \N \N
+-- !arith_op30 --
+0.123 0.1 0.3330001831054688
+1.500 0.2680000000000007 0.25
+0.325 1 0
+
+-- !arith_op31 --
+0.123 0.1 0.3330001831054688
+1.500 0.2680000000000007 0.25
+0.325 1 0
+
diff --git
a/regression-test/suites/nereids_p0/operator/test_arithmetic_operators.groovy
b/regression-test/suites/nereids_p0/operator/test_arithmetic_operators.groovy
index 1cec22cbe4c..3fbd15bd3bb 100644
---
a/regression-test/suites/nereids_p0/operator/test_arithmetic_operators.groovy
+++
b/regression-test/suites/nereids_p0/operator/test_arithmetic_operators.groovy
@@ -76,4 +76,7 @@ suite("test_arithmetic_operators", "query,p0") {
qt_arith_op27 "select -10.2 / 0.0, -10.2 / 0, -10.2 % 0.0, -10.2 % 0"
qt_arith_op28 "select k5 / 0, k8 / 0, k9 / 0 from ${tableName} order by
k1,k2,k3,k4"
qt_arith_op29 "select k5 % 0, k8 % 0, k9 % 0 from ${tableName} order by
k1,k2,k3,k4"
+
+ qt_arith_op30 "select k5 MOD 3, k8 mod 2, k9 Mod 1 from ${tableName} order
by k1,k2,k3,k4"
+ qt_arith_op31 "select k5 MOD 3, MOD(k8, 2), (k9 MOD 1) as MOD from
${tableName} order by k1,k2,k3,k4"
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]