Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added INSTR to Doris parsing support (#31508) #33289

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ identifierKeywordsUnambiguous
| BEFORE
| BINLOG
| BIT
// DORIS ADDED BEGIN
| BITXOR
// DORIS ADDED END
| BLOCK
| BOOLEAN
| BOOL
Expand Down Expand Up @@ -261,6 +263,9 @@ identifierKeywordsUnambiguous
| INITIAL_SIZE
| INSERT_METHOD
| INSTANCE
// DORIS ADDED BEGIN
| INSTR
// DORIS ADDED END
| INVISIBLE
| INVOKER
| IO
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -998,9 +1005,11 @@ aggregationFunctionName
: MAX | MIN | SUM | COUNT | AVG | BIT_XOR | GROUP_CONCAT
;

// DORIS ADDED BEGIN
bitwiseBinaryFunctionName
: BITXOR
;
// DORIS ADDED END

distinct
: DISTINCT
Expand Down Expand Up @@ -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
Expand All @@ -1045,7 +1060,6 @@ specialFunction
| windowFunction
| groupingFunction
| timeStampDiffFunction
| bitwiseFunction
;

currentUserFunction
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
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;
Expand Down Expand Up @@ -995,12 +996,22 @@ public final ASTNode visitSpecialFunction(final SpecialFunctionContext ctx) {
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());
}
Expand Down Expand Up @@ -1028,9 +1039,6 @@ public final ASTNode visitSpecialFunction(final SpecialFunctionContext ctx) {
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));
}

Expand All @@ -1044,6 +1052,28 @@ public final ASTNode visitGroupConcatFunction(final GroupConcatFunctionContext c
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));
Expand Down Expand Up @@ -1182,15 +1212,6 @@ public ASTNode visitTimeStampDiffFunction(final TimeStampDiffFunctionContext ctx
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>