This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 4e80d25ed47 Added INSTR to Doris parsing support (#31508) (#33289)
4e80d25ed47 is described below
commit 4e80d25ed470b0d507e376068b72cecde346506a
Author: Daniel Giribet <[email protected]>
AuthorDate: Sun Oct 20 13:12:07 2024 +0200
Added INSTR to Doris parsing support (#31508) (#33289)
* Added support for INSTR to Doris parsing
- related to #31508
- includes test
- `mvn spotless:apply -Pcheck` and `mvn test -Dtest=InternalDorisParserIT`
- will update release notes in next commit
- will check if MySQL supports INSTR in next commit
- verified query in Doris
* Updated release notes to reflect #33258
* Added comment markers for INSTR and BIT_XOR
Small additional changes:
- Also moved the java code to match the order in g4 more.
- Added missing import as well.
* Added release notes
Also added missing `// DORIS ADDED BEGIN|END` marker
---
RELEASE-NOTES.md | 2 +
.../src/main/antlr4/imports/doris/BaseRule.g4 | 22 ++++++++++-
.../src/main/antlr4/imports/doris/DorisKeyword.g4 | 9 +++++
.../visitor/statement/DorisStatementVisitor.java | 45 ++++++++++++++++------
.../resources/case/dml/select-special-function.xml | 18 ++++++++-
.../sql/supported/dml/select-special-function.xml | 1 +
6 files changed, 83 insertions(+), 14 deletions(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 028b2d01e87..50bc3459358 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -63,6 +63,8 @@
1. Infra: Support compiling and using ShardingSphere under OpenJDK 23 -
[#33025](https://github.com/apache/shardingsphere/pull/33025)
1. Hive: Support Hive integration module to connect to HiveServer2 4.0.1 -
[#33212](https://github.com/apache/shardingsphere/pull/33212)
1. Infra: Support building Example module with OpenJDK 23 -
[#33224](https://github.com/apache/shardingsphere/pull/33224)
+1. SQL Parser: Support parsing Doris BITXOR -
[#33258](https://github.com/apache/shardingsphere/pull/33258)
+1. SQL Parser: Support parsing Doris INSTR -
[#33289](3325://github.com/apache/shardingsphere/pull/33289)
### Bug Fix
diff --git a/parser/sql/dialect/doris/src/main/antlr4/imports/doris/BaseRule.g4
b/parser/sql/dialect/doris/src/main/antlr4/imports/doris/BaseRule.g4
index 65b93ce7393..48dd6589235 100644
--- a/parser/sql/dialect/doris/src/main/antlr4/imports/doris/BaseRule.g4
+++ b/parser/sql/dialect/doris/src/main/antlr4/imports/doris/BaseRule.g4
@@ -150,7 +150,9 @@ identifierKeywordsUnambiguous
| BEFORE
| BINLOG
| BIT
+ // DORIS ADDED BEGIN
| BITXOR
+ // DORIS ADDED END
| BLOCK
| BOOLEAN
| BOOL
@@ -261,6 +263,9 @@ identifierKeywordsUnambiguous
| INITIAL_SIZE
| INSERT_METHOD
| INSTANCE
+ // DORIS ADDED BEGIN
+ | INSTR
+ // DORIS ADDED END
| INVISIBLE
| INVOKER
| IO
@@ -961,9 +966,11 @@ aggregationFunction
: aggregationFunctionName LP_ distinct? (expr (COMMA_ expr)* | ASTERISK_)?
collateClause? RP_ overClause?
;
+// DORIS ADDED BEGIN
bitwiseFunction
: bitwiseBinaryFunctionName LP_ expr COMMA_ expr RP_
;
+// DORIS ADDED END
jsonFunction
: jsonTableFunction
@@ -998,9 +1005,11 @@ aggregationFunctionName
: MAX | MIN | SUM | COUNT | AVG | BIT_XOR | GROUP_CONCAT
;
+// DORIS ADDED BEGIN
bitwiseBinaryFunctionName
: BITXOR
;
+// DORIS ADDED END
distinct
: DISTINCT
@@ -1033,10 +1042,16 @@ frameBetween
specialFunction
: castFunction
| convertFunction
+ // DORIS ADDED BEGIN
+ | bitwiseFunction
+ // DORIS ADDED END
| currentUserFunction
| charFunction
| extractFunction
| groupConcatFunction
+ // DORIS ADDED BEGIN
+ | instrFunction
+ // DORIS ADDED END
| positionFunction
| substringFunction
| trimFunction
@@ -1045,7 +1060,6 @@ specialFunction
| windowFunction
| groupingFunction
| timeStampDiffFunction
- | bitwiseFunction
;
currentUserFunction
@@ -1064,6 +1078,12 @@ groupConcatFunction
: GROUP_CONCAT LP_ distinct? (expr (COMMA_ expr)* | ASTERISK_)?
(orderByClause)? (SEPARATOR expr)? RP_
;
+// DORIS ADDED BEGIN
+instrFunction
+ : INSTR LP_ expr COMMA_ expr RP_
+ ;
+// DORIS ADDED END
+
windowFunction
: funcName = (ROW_NUMBER | RANK | DENSE_RANK | CUME_DIST | PERCENT_RANK)
LP_ RP_ windowingClause
| funcName = NTILE (simpleExpr) windowingClause
diff --git
a/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4
b/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4
index f4016d023f3..ea4003474cc 100644
--- a/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4
+++ b/parser/sql/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4
@@ -127,9 +127,11 @@ ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS
: A S S I G N UL_ G T I D S UL_ T O UL_ A N O N Y M O U S UL_ T R A N S A
C T I O N S
;
+// DORIS ADDED BEGIN
BITXOR
: B I T X O R
;
+// DORIS ADDED END
BIT_XOR
: B I T UL_ X O R
@@ -1071,6 +1073,13 @@ INSTANCE
: I N S T A N C E
;
+// DORIS ADDED BEOIM
+INSTR
+ : I N S T R
+ ;
+// DORIS ADDED END
+
+
INT
: I N T
;
diff --git
a/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/DorisStatementVisitor.java
b/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/DorisStatementVisitor.java
index 8a26b9c042b..c122e38fa28 100644
---
a/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/DorisStatementVisitor.java
+++
b/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/DorisStatementVisitor.java
@@ -74,6 +74,7 @@ import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.InsertC
import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.InsertIdentifierContext;
import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.InsertSelectClauseContext;
import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.InsertValuesClauseContext;
+import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.InstrFunctionContext;
import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.IntervalExpressionContext;
import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.JoinSpecificationContext;
import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.JoinedTableContext;
@@ -995,12 +996,22 @@ public abstract class DorisStatementVisitor extends
DorisStatementBaseVisitor<AS
if (null != ctx.windowFunction()) {
return visit(ctx.windowFunction());
}
+ // DORIS ADDED BEGIN
+ if (null != ctx.bitwiseFunction()) {
+ return visit(ctx.bitwiseFunction());
+ }
+ // DORIS ADDED END
if (null != ctx.castFunction()) {
return visit(ctx.castFunction());
}
if (null != ctx.convertFunction()) {
return visit(ctx.convertFunction());
}
+ // DORIS ADDED BEGIN
+ if (null != ctx.instrFunction()) {
+ return visit(ctx.instrFunction());
+ }
+ // DORIS ADDED END
if (null != ctx.positionFunction()) {
return visit(ctx.positionFunction());
}
@@ -1028,9 +1039,6 @@ public abstract class DorisStatementVisitor extends
DorisStatementBaseVisitor<AS
if (null != ctx.timeStampDiffFunction()) {
return visit(ctx.timeStampDiffFunction());
}
- if (null != ctx.bitwiseFunction()) {
- return visit(ctx.bitwiseFunction());
- }
return new FunctionSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), getOriginalText(ctx), getOriginalText(ctx));
}
@@ -1044,6 +1052,28 @@ public abstract class DorisStatementVisitor extends
DorisStatementBaseVisitor<AS
return result;
}
+ // DORIS ADDED BEGIN
+ @Override
+ public final ASTNode visitBitwiseFunction(final BitwiseFunctionContext
ctx) {
+ FunctionSegment result = new
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(),
ctx.bitwiseBinaryFunctionName().getText(), getOriginalText(ctx));
+ for (ExprContext each : ctx.expr()) {
+ result.getParameters().add(new
LiteralExpressionSegment(each.getStart().getStartIndex(),
each.getStop().getStopIndex(), each.getText()));
+ }
+ return result;
+ }
+ // DORIS ADDED END
+
+ // DORIS ADDED BEGIN
+ @Override
+ public final ASTNode visitInstrFunction(final InstrFunctionContext ctx) {
+ FunctionSegment result = new
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(),
ctx.INSTR().getText(), getOriginalText(ctx));
+ for (ExprContext each : ctx.expr()) {
+ result.getParameters().add(new
LiteralExpressionSegment(each.getStart().getStartIndex(),
each.getStop().getStopIndex(), each.getText()));
+ }
+ return result;
+ }
+ // DORIS ADDED END
+
@Override
public final ASTNode visitCastFunction(final CastFunctionContext ctx) {
FunctionSegment result = new
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(),
ctx.CAST().getText(), getOriginalText(ctx));
@@ -1182,15 +1212,6 @@ public abstract class DorisStatementVisitor extends
DorisStatementBaseVisitor<AS
return result;
}
- @Override
- public final ASTNode visitBitwiseFunction(final BitwiseFunctionContext
ctx) {
- FunctionSegment result = new
FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(),
ctx.bitwiseBinaryFunctionName().getText(), getOriginalText(ctx));
- for (ExprContext each : ctx.expr()) {
- result.getParameters().add(new
LiteralExpressionSegment(each.getStart().getStartIndex(),
each.getStop().getStopIndex(), each.getText()));
- }
- return result;
- }
-
@Override
public final ASTNode visitRegularFunction(final RegularFunctionContext
ctx) {
return null == ctx.completeRegularFunction() ?
visit(ctx.shorthandRegularFunction()) : visit(ctx.completeRegularFunction());
diff --git
a/test/it/parser/src/main/resources/case/dml/select-special-function.xml
b/test/it/parser/src/main/resources/case/dml/select-special-function.xml
index 32ecc8de766..0739d073c34 100644
--- a/test/it/parser/src/main/resources/case/dml/select-special-function.xml
+++ b/test/it/parser/src/main/resources/case/dml/select-special-function.xml
@@ -4145,7 +4145,7 @@
</function-table>
</from>
</select>
- <select sql-case-id="select_bitxor" db-types="Doris">
+ <select sql-case-id="select_bitxor" db-types="Doris">
<projections start-index="7" stop-index="17">
<expression-projection text="BITXOR(3,5)" start-index="7"
stop-index="17">
<expr>
@@ -4161,4 +4161,20 @@
</expression-projection>
</projections>
</select>
+ <select sql-case-id="select_instr" db-types="Doris">
+ <projections start-index="7" stop-index="27">
+ <expression-projection text="INSTR('foobar','bar')"
start-index="7" stop-index="27">
+ <expr>
+ <function function-name="INSTR" start-index="7"
stop-index="27" text="INSTR('foobar','bar')">
+ <parameter>
+ <literal-expression value="'foobar'"
start-index="13" stop-index="20" />
+ </parameter>
+ <parameter>
+ <literal-expression value="'bar'" start-index="22"
stop-index="26" />
+ </parameter>
+ </function>
+ </expr>
+ </expression-projection>
+ </projections>
+ </select>
</sql-parser-test-cases>
diff --git
a/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
b/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
index a26ed0dd4fe..b9a0a4d7908 100644
---
a/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
+++
b/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml
@@ -240,4 +240,5 @@
<sql-case id="select_st_convexhull" value="SELECT
ST_ConvexHull(ST_GeomFromText('MULTIPOINT(5 0,25 0,15 10,15 25)'))"
db-types="MySQL,Doris" />
<sql-case id="select_st_crosses" value="SELECT
ST_Crosses(ST_GeomFromText('POINT(1 1)'), ST_GeomFromText('POINT(2 2)'))"
db-types="MySQL,Doris" />
<sql-case id="select_bitxor" value="SELECT BITXOR(3,5)" db-types="Doris" />
+ <sql-case id="select_instr" value="SELECT INSTR('foobar','bar')"
db-types="Doris" />
</sql-cases>