Skip to content
Open
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
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
1. SQL Parser: Fix error parsing \l command SQL statement when front-end protocol is og - [#37953](https://github.com/apache/shardingsphere/pull/37953)
1. SQL Parser: Fix SQLParsingException when using reserved word `order` in ORDER BY clause - [#37958](https://github.com/apache/shardingsphere/pull/37958)
1. SQL Parser: Fix parsing error for SQLServer session `SET QUOTED_IDENTIFIER` and `SET TEXTSIZE` statements - [#38005](https://github.com/apache/shardingsphere/pull/38005)
1. SQL Parser: Fix can not accept sql type 'TerminalNodeImpl' when parsing /*! MySQL-specific code */ - [#38032](https://github.com/apache/shardingsphere/pull/38032)
1. SQL Parser: Support '2'::int statement in PostgreSQL and openGauss - [#37962](https://github.com/apache/shardingsphere/pull/37962)
1. SQL Parser: Support range type constructor functions in PostgreSQL without quotes - [#37994](https://github.com/apache/shardingsphere/pull/37994)
1. SQL Parser: Support parsing MySQL stored procedure syntax - [#38017](https://github.com/apache/shardingsphere/pull/38017)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

package org.apache.shardingsphere.sql.parser.engine.mysql.parser;

import java.nio.CharBuffer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CodePointBuffer;
import org.antlr.v4.runtime.CodePointCharStream;
import org.antlr.v4.runtime.misc.Interval;
import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementLexer;

Expand All @@ -27,6 +31,27 @@
public final class MySQLLexer extends MySQLStatementLexer implements SQLLexer {

public MySQLLexer(final CharStream input) {
super(input);
super(stripExecutableComment(input));
}

private static CharStream stripExecutableComment(final CharStream input) {
String sql = input.getText(Interval.of(0, input.size() - 1));
String trimmed = sql.trim();
if (trimmed.endsWith(";")) {
trimmed = trimmed.substring(0, trimmed.length() - 1).trim();
}
if (!trimmed.startsWith("/*!") || !trimmed.endsWith("*/")) {
return input;
}
String content = trimmed.substring(3, trimmed.length() - 2);
int index = 0;
while (index < content.length() && content.charAt(index) >= '0' && content.charAt(index) <= '9') {
index++;
}
String innerSQL = content.substring(index).trim();
if (innerSQL.isEmpty()) {
return input;
}
return CodePointCharStream.fromBuffer(CodePointBuffer.withChars(CharBuffer.wrap(innerSQL.toCharArray())));
}
}
10 changes: 10 additions & 0 deletions test/it/parser/src/main/resources/case/dal/set.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,14 @@
<parameter name="time_zone" scope="PERSIST_ONLY" />
</parameter-assign>
</set-parameter>
<set-parameter sql-case-id="set_mysql_version_comment">
<parameter-assign value="123">
<parameter name="max_connections" scope="GLOBAL" />
</parameter-assign>
</set-parameter>
<set-parameter sql-case-id="set_mysql_version_comment_with_version">
<parameter-assign value="456">
<parameter name="max_connections" scope="GLOBAL" />
</parameter-assign>
</set-parameter>
</sql-parser-test-cases>
2 changes: 2 additions & 0 deletions test/it/parser/src/main/resources/sql/supported/dal/set.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@
<sql-case id="set_session_authorization" value="SET SESSION AUTHORIZATION user1 PASSWORD 'password'" db-types="openGauss" />
<sql-case id="set_persist_system_variable_doris" value="SET PERSIST max_connections = 200" db-types="Doris" />
<sql-case id="set_persist_only_system_variable_doris" value="SET PERSIST_ONLY time_zone = '+08:00'" db-types="Doris" />
<sql-case id="set_mysql_version_comment" value="/*! SET GLOBAL max_connections=123 */" db-types="MySQL" />
<sql-case id="set_mysql_version_comment_with_version" value="/*!80029 SET GLOBAL max_connections=456 */" db-types="MySQL" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add parse comment into SQLStatement comments? And add assert for comments field.

</sql-cases>
Loading