This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 b281fb89fc2 Support for the ALTER SYSTEM statement and the CREATE
SQL_BLOCK_RULE statement (#37552)
b281fb89fc2 is described below
commit b281fb89fc2959467cb9d0f90057f8753b429198
Author: cxy <[email protected]>
AuthorDate: Sat Dec 27 22:19:13 2025 +0800
Support for the ALTER SYSTEM statement and the CREATE SQL_BLOCK_RULE
statement (#37552)
---
.../core/database/visitor/SQLVisitorRule.java | 4 ++
.../src/main/antlr4/imports/doris/DALStatement.g4 | 31 ++++++++++
.../src/main/antlr4/imports/doris/DorisKeyword.g4 | 12 ++++
.../sql/parser/autogen/DorisStatement.g4 | 2 +
.../statement/type/DorisDALStatementVisitor.java | 66 ++++++++++++++++++++++
.../doris/dal/DorisAlterSystemStatement.java | 27 +++++----
.../dal/DorisCreateSqlBlockRuleStatement.java | 24 ++++----
.../dal/dialect/doris/DorisDALStatementAssert.java | 10 ++++
.../DorisAlterSystemStatementAssert.java} | 31 +++++-----
.../DorisCreateSqlBlockRuleStatementAssert.java | 64 +++++++++++++++++++++
.../cases/parser/jaxb/RootSQLParserTestCases.java | 8 +++
...java => DorisAlterSystemStatementTestCase.java} | 15 ++---
... DorisCreateSqlBlockRuleStatementTestCase.java} | 17 +++---
.../dal/dialect/doris/PropertyTestCase.java | 3 +-
.../parser/src/main/resources/case/dal/alter.xml | 16 ++++++
.../parser/src/main/resources/case/dal/create.xml | 27 +++++++++
.../src/main/resources/sql/supported/dal/alter.xml | 4 ++
.../main/resources/sql/supported/dal/create.xml | 5 ++
18 files changed, 311 insertions(+), 55 deletions(-)
diff --git
a/parser/sql/engine/core/src/main/java/org/apache/shardingsphere/sql/parser/engine/core/database/visitor/SQLVisitorRule.java
b/parser/sql/engine/core/src/main/java/org/apache/shardingsphere/sql/parser/engine/core/database/visitor/SQLVisitorRule.java
index bbcf93ca83f..c4dcca230a1 100644
---
a/parser/sql/engine/core/src/main/java/org/apache/shardingsphere/sql/parser/engine/core/database/visitor/SQLVisitorRule.java
+++
b/parser/sql/engine/core/src/main/java/org/apache/shardingsphere/sql/parser/engine/core/database/visitor/SQLVisitorRule.java
@@ -481,6 +481,10 @@ public enum SQLVisitorRule {
ALTER_RESOURCE("AlterResource", SQLStatementType.DAL),
+ DORIS_ALTER_SYSTEM("DorisAlterSystem", SQLStatementType.DAL),
+
+ CREATE_SQL_BLOCK_RULE("CreateSqlBlockRule", SQLStatementType.DAL),
+
DELIMITER("Delimiter", SQLStatementType.DAL),
CALL("Call", SQLStatementType.DML),
diff --git
a/parser/sql/engine/dialect/doris/src/main/antlr4/imports/doris/DALStatement.g4
b/parser/sql/engine/dialect/doris/src/main/antlr4/imports/doris/DALStatement.g4
index 38badae1a10..7bfdb72a776 100644
---
a/parser/sql/engine/dialect/doris/src/main/antlr4/imports/doris/DALStatement.g4
+++
b/parser/sql/engine/dialect/doris/src/main/antlr4/imports/doris/DALStatement.g4
@@ -373,6 +373,37 @@ propertyValue
: literals | identifier
;
+dorisAlterSystem
+ : ALTER SYSTEM dorisAlterSystemAction
+ ;
+
+dorisAlterSystemAction
+ : ADD FOLLOWER string_
+ | ADD OBSERVER string_
+ | DROP FOLLOWER string_
+ | DROP OBSERVER string_
+ ;
+
+createSqlBlockRule
+ : CREATE SQL_BLOCK_RULE ruleName propertiesClause
+ ;
+
+ruleName
+ : identifier
+ ;
+
+propertiesClause
+ : PROPERTIES LP_ properties RP_
+ ;
+
+properties
+ : property (COMMA_ property)*
+ ;
+
+property
+ : (identifier | SINGLE_QUOTED_TEXT | DOUBLE_QUOTED_TEXT) EQ_? literals
+ ;
+
vcpuSpec
: NUMBER_ | NUMBER_ MINUS_ NUMBER_
;
diff --git
a/parser/sql/engine/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4
b/parser/sql/engine/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4
index d5ba02b561b..b8f8e87fe74 100644
---
a/parser/sql/engine/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4
+++
b/parser/sql/engine/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4
@@ -899,6 +899,10 @@ FOUND
: F O U N D
;
+FOLLOWER
+ : F O L L O W E R
+ ;
+
FROM
: F R O M
;
@@ -1862,6 +1866,10 @@ OWNER
: O W N E R
;
+OBSERVER
+ : O B S E R V E R
+ ;
+
PACK_KEYS
: P A C K UL_ K E Y S
;
@@ -2524,6 +2532,10 @@ SQL_BUFFER_RESULT
: S Q L UL_ B U F F E R UL_ R E S U L T
;
+SQL_BLOCK_RULE
+ : S Q L UL_ B L O C K UL_ R U L E
+ ;
+
SQL_CALC_FOUND_ROWS
: S Q L UL_ C A L C UL_ F O U N D UL_ R O W S
;
diff --git
a/parser/sql/engine/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4
b/parser/sql/engine/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4
index a4a928d7c73..c90e153f7fe 100644
---
a/parser/sql/engine/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4
+++
b/parser/sql/engine/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4
@@ -133,6 +133,8 @@ execute
| startReplica
| createMaterializedView
| resumeJob
+ | dorisAlterSystem
+ | createSqlBlockRule
// TODO consider refactor following sytax to SEMI_? EOF
) (SEMI_ EOF? | EOF)
| EOF
diff --git
a/parser/sql/engine/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/engine/doris/visitor/statement/type/DorisDALStatementVisitor.java
b/parser/sql/engine/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/engine/doris/visitor/statement/type/DorisDALStatementVisitor.java
index 11cb7e4f1ed..a66bea827f2 100644
---
a/parser/sql/engine/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/engine/doris/visitor/statement/type/DorisDALStatementVisitor.java
+++
b/parser/sql/engine/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/engine/doris/visitor/statement/type/DorisDALStatementVisitor.java
@@ -130,6 +130,11 @@ import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PluginP
import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PluginPropertyContext;
import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PluginPropertyKeyContext;
import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PluginPropertyValueContext;
+import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.DorisAlterSystemContext;
+import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.CreateSqlBlockRuleContext;
+import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PropertiesClauseContext;
+import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PropertyContext;
+import
org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.DorisAlterSystemActionContext;
import
org.apache.shardingsphere.sql.parser.engine.doris.visitor.statement.DorisStatementVisitor;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dal.CacheTableIndexSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dal.CloneActionSegment;
@@ -147,6 +152,8 @@ import
org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ShowLikeS
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dal.VariableAssignSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dal.VariableSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.property.PropertiesSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.property.PropertySegment;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment;
@@ -159,6 +166,7 @@ import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.An
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.ExplainStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.RefreshStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.SetStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.util.SQLUtils;
import
org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue;
import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import
org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NumberLiteralValue;
@@ -170,6 +178,8 @@ import
org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.Nu
import
org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.OtherLiteralValue;
import
org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.TemporalLiteralValue;
import
org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisAlterResourceStatement;
+import
org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisAlterSystemStatement;
+import
org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisCreateSqlBlockRuleStatement;
import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCloneStatement;
import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCreateLoadableFunctionStatement;
import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLDelimiterStatement;
@@ -1024,6 +1034,62 @@ public final class DorisDALStatementVisitor extends
DorisStatementVisitor implem
return String.valueOf(literalValue.getValue());
}
+ @Override
+ public ASTNode visitDorisAlterSystem(final DorisAlterSystemContext ctx) {
+ return visit(ctx.dorisAlterSystemAction());
+ }
+
+ @Override
+ public ASTNode visitDorisAlterSystemAction(final
DorisAlterSystemActionContext ctx) {
+ String action = getDorisAlterSystemAction(ctx);
+ String target = SQLUtils.getExactlyValue(ctx.string_().getText());
+ return new DorisAlterSystemStatement(getDatabaseType(), action,
target);
+ }
+
+ private String getDorisAlterSystemAction(final
DorisAlterSystemActionContext ctx) {
+ if (null != ctx.FOLLOWER()) {
+ return null != ctx.ADD() ? "ADD FOLLOWER" : "DROP FOLLOWER";
+ }
+ if (null != ctx.OBSERVER()) {
+ return null != ctx.ADD() ? "ADD OBSERVER" : "DROP OBSERVER";
+ }
+ return "";
+ }
+
+ @Override
+ public ASTNode visitCreateSqlBlockRule(final CreateSqlBlockRuleContext
ctx) {
+ DorisCreateSqlBlockRuleStatement result = new
DorisCreateSqlBlockRuleStatement(getDatabaseType());
+ result.setRuleName(((IdentifierValue)
visit(ctx.ruleName())).getValue());
+ result.setProperties(extractPropertiesSegment(ctx.propertiesClause()));
+ return result;
+ }
+
+ private PropertiesSegment extractPropertiesSegment(final
PropertiesClauseContext ctx) {
+ PropertiesSegment result = new
PropertiesSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex());
+ for (PropertyContext each : ctx.properties().property()) {
+ String key = getPropertyKeyFromProperty(each);
+ String value = getPropertyValueFromProperty(each);
+ PropertySegment propertySegment = new
PropertySegment(each.getStart().getStartIndex(), each.getStop().getStopIndex(),
key, value);
+ result.getProperties().add(propertySegment);
+ }
+ return result;
+ }
+
+ private String getPropertyKeyFromProperty(final PropertyContext ctx) {
+ if (null != ctx.identifier()) {
+ return ((IdentifierValue) visit(ctx.identifier())).getValue();
+ }
+ if (null != ctx.SINGLE_QUOTED_TEXT()) {
+ return
SQLUtils.getExactlyValue(ctx.SINGLE_QUOTED_TEXT().getText());
+ }
+ return SQLUtils.getExactlyValue(ctx.DOUBLE_QUOTED_TEXT().getText());
+ }
+
+ private String getPropertyValueFromProperty(final PropertyContext ctx) {
+ String exactValue = SQLUtils.getExactlyValue(ctx.literals().getText());
+ return exactValue.replace("\\\\", "\\").replace("\\\"",
"\"").replace("\\'", "'");
+ }
+
@Override
public ASTNode visitChangeMasterTo(final ChangeMasterToContext ctx) {
return new MySQLChangeMasterStatement(getDatabaseType());
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
b/parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisAlterSystemStatement.java
similarity index 58%
copy from
test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
copy to
parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisAlterSystemStatement.java
index b0a27509ca6..266f43fd47d 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
+++
b/parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisAlterSystemStatement.java
@@ -15,26 +15,25 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris;
+package org.apache.shardingsphere.sql.parser.statement.doris.dal;
import lombok.Getter;
-import lombok.Setter;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement;
/**
- * Property test case for Doris.
+ * Alter system statement for Doris.
*/
-@XmlAccessorType(XmlAccessType.FIELD)
@Getter
-@Setter
-public final class PropertyTestCase {
+public final class DorisAlterSystemStatement extends DALStatement {
+
+ private final String action;
- @XmlAttribute
- private String key;
+ private final String target;
- @XmlAttribute
- private String value;
+ public DorisAlterSystemStatement(final DatabaseType databaseType, final
String action, final String target) {
+ super(databaseType);
+ this.action = action;
+ this.target = target;
+ }
}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
b/parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisCreateSqlBlockRuleStatement.java
similarity index 57%
copy from
test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
copy to
parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisCreateSqlBlockRuleStatement.java
index b0a27509ca6..699487bc4bb 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
+++
b/parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisCreateSqlBlockRuleStatement.java
@@ -15,26 +15,26 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris;
+package org.apache.shardingsphere.sql.parser.statement.doris.dal;
import lombok.Getter;
import lombok.Setter;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.property.PropertiesSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement;
/**
- * Property test case for Doris.
+ * Create SQL block rule statement for Doris.
*/
-@XmlAccessorType(XmlAccessType.FIELD)
@Getter
@Setter
-public final class PropertyTestCase {
+public final class DorisCreateSqlBlockRuleStatement extends DALStatement {
+
+ private String ruleName;
- @XmlAttribute
- private String key;
+ private PropertiesSegment properties;
- @XmlAttribute
- private String value;
+ public DorisCreateSqlBlockRuleStatement(final DatabaseType databaseType) {
+ super(databaseType);
+ }
}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/DorisDALStatementAssert.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/DorisDALStatementAssert.java
index 23c4bd3799a..16ee0ba71e7 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/DorisDALStatementAssert.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/DorisDALStatementAssert.java
@@ -21,10 +21,16 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement;
import
org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisAlterResourceStatement;
+import
org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisAlterSystemStatement;
+import
org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisCreateSqlBlockRuleStatement;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.doris.type.DorisAlterResourceStatementAssert;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.doris.type.DorisAlterSystemStatementAssert;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.doris.type.DorisCreateSqlBlockRuleStatementAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.DorisAlterResourceStatementTestCase;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.DorisAlterSystemStatementTestCase;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.DorisCreateSqlBlockRuleStatementTestCase;
/**
* DAL statement assert for Doris.
@@ -42,6 +48,10 @@ public final class DorisDALStatementAssert {
public static void assertIs(final SQLCaseAssertContext assertContext,
final DALStatement actual, final SQLParserTestCase expected) {
if (actual instanceof DorisAlterResourceStatement) {
DorisAlterResourceStatementAssert.assertIs(assertContext,
(DorisAlterResourceStatement) actual, (DorisAlterResourceStatementTestCase)
expected);
+ } else if (actual instanceof DorisAlterSystemStatement) {
+ DorisAlterSystemStatementAssert.assertIs(assertContext,
(DorisAlterSystemStatement) actual, (DorisAlterSystemStatementTestCase)
expected);
+ } else if (actual instanceof DorisCreateSqlBlockRuleStatement) {
+ DorisCreateSqlBlockRuleStatementAssert.assertIs(assertContext,
(DorisCreateSqlBlockRuleStatement) actual,
(DorisCreateSqlBlockRuleStatementTestCase) expected);
}
}
}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/DorisDALStatementAssert.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisAlterSystemStatementAssert.java
similarity index 57%
copy from
test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/DorisDALStatementAssert.java
copy to
test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisAlterSystemStatementAssert.java
index 23c4bd3799a..dc3d3e175cf 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/DorisDALStatementAssert.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisAlterSystemStatementAssert.java
@@ -15,33 +15,36 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.doris;
+package
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.doris.type;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement;
-import
org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisAlterResourceStatement;
+import
org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisAlterSystemStatement;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
-import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.doris.type.DorisAlterResourceStatementAssert;
-import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
-import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.DorisAlterResourceStatementTestCase;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.DorisAlterSystemStatementTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
/**
- * DAL statement assert for Doris.
+ * Alter system statement assert for Doris.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DorisDALStatementAssert {
+public final class DorisAlterSystemStatementAssert {
/**
- * Assert DAL statement is correct with expected parser result.
+ * Assert alter system statement is correct with expected parser result.
*
* @param assertContext assert context
- * @param actual actual DAL statement
- * @param expected expected DAL statement test case
+ * @param actual actual alter system statement
+ * @param expected expected alter system statement test case
*/
- public static void assertIs(final SQLCaseAssertContext assertContext,
final DALStatement actual, final SQLParserTestCase expected) {
- if (actual instanceof DorisAlterResourceStatement) {
- DorisAlterResourceStatementAssert.assertIs(assertContext,
(DorisAlterResourceStatement) actual, (DorisAlterResourceStatementTestCase)
expected);
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final DorisAlterSystemStatement actual, final DorisAlterSystemStatementTestCase
expected) {
+ if (null != expected.getAction()) {
+ assertThat(assertContext.getText("action does not match: "),
actual.getAction(), is(expected.getAction()));
+ }
+ if (null != expected.getTarget()) {
+ assertThat(assertContext.getText("target does not match: "),
actual.getTarget(), is(expected.getTarget()));
}
}
}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisCreateSqlBlockRuleStatementAssert.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisCreateSqlBlockRuleStatementAssert.java
new file mode 100644
index 00000000000..173822d8426
--- /dev/null
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisCreateSqlBlockRuleStatementAssert.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.doris.type;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.property.PropertySegment;
+import
org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisCreateSqlBlockRuleStatement;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.SQLSegmentAssert;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.DorisCreateSqlBlockRuleStatementTestCase;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.PropertyTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Create SQL block rule statement assert for Doris.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DorisCreateSqlBlockRuleStatementAssert {
+
+ /**
+ * Assert create SQL block rule statement is correct with expected parser
result.
+ *
+ * @param assertContext assert context
+ * @param actual actual create SQL block rule statement
+ * @param expected expected create SQL block rule statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final DorisCreateSqlBlockRuleStatement actual, final
DorisCreateSqlBlockRuleStatementTestCase expected) {
+ if (null != expected.getRuleName()) {
+ assertThat(assertContext.getText("Rule name does not match: "),
actual.getRuleName(), is(expected.getRuleName()));
+ }
+ assertNotNull(actual.getProperties(),
assertContext.getText("Properties should not be null"));
+ if (!expected.getProperties().isEmpty()) {
+ assertThat(assertContext.getText("Properties size does not match:
"), actual.getProperties().getProperties().size(),
is(expected.getProperties().size()));
+ for (int i = 0; i < expected.getProperties().size(); i++) {
+ assertProperty(assertContext,
actual.getProperties().getProperties().get(i), expected.getProperties().get(i));
+ }
+ }
+ }
+
+ private static void assertProperty(final SQLCaseAssertContext
assertContext, final PropertySegment actual, final PropertyTestCase expected) {
+ assertThat(assertContext.getText(String.format("Property key '%s'
assertion error: ", expected.getKey())), actual.getKey(),
is(expected.getKey()));
+ assertThat(assertContext.getText(String.format("Property value for key
'%s' assertion error: ", expected.getKey())), actual.getValue(),
is(expected.getValue()));
+ SQLSegmentAssert.assertIs(assertContext, actual, expected);
+ }
+}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
index d5534219f0f..7ea516342f1 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
@@ -21,6 +21,8 @@ import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.SneakyThrows;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.CommonStatementTestCase;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.DorisAlterSystemStatementTestCase;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.DorisCreateSqlBlockRuleStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.dialect.doris.DorisAlterStoragePolicyStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.dialect.doris.DorisResumeJobStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.standard.catalog.AlterCatalogStatementTestCase;
@@ -605,6 +607,12 @@ public final class RootSQLParserTestCases {
@XmlElement(name = "drop-role")
private final List<DropRoleStatementTestCase> dropRoleTestCases = new
LinkedList<>();
+ @XmlElement(name = "doris-alter-system")
+ private final List<DorisAlterSystemStatementTestCase>
dorisAlterSystemTestCases = new LinkedList<>();
+
+ @XmlElement(name = "create-sql-block-rule")
+ private final List<DorisCreateSqlBlockRuleStatementTestCase>
createSqlBlockRuleTestCases = new LinkedList<>();
+
@XmlElement(name = "set-default-role")
private final List<MySQLSetDefaultRoleStatementTestCase>
setDefaultRoleTestCases = new LinkedList<>();
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisAlterSystemStatementTestCase.java
similarity index 76%
copy from
test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
copy to
test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisAlterSystemStatementTestCase.java
index b0a27509ca6..07243c62f80 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisAlterSystemStatementTestCase.java
@@ -19,22 +19,23 @@ package
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.
import lombok.Getter;
import lombok.Setter;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
/**
- * Property test case for Doris.
+ * Alter system statement test case for Doris.
*/
@XmlAccessorType(XmlAccessType.FIELD)
@Getter
@Setter
-public final class PropertyTestCase {
+public final class DorisAlterSystemStatementTestCase extends SQLParserTestCase
{
- @XmlAttribute
- private String key;
+ @XmlElement
+ private String action;
- @XmlAttribute
- private String value;
+ @XmlElement
+ private String target;
}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisCreateSqlBlockRuleStatementTestCase.java
similarity index 68%
copy from
test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
copy to
test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisCreateSqlBlockRuleStatementTestCase.java
index b0a27509ca6..edbc6f784c4 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisCreateSqlBlockRuleStatementTestCase.java
@@ -19,22 +19,25 @@ package
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.
import lombok.Getter;
import lombok.Setter;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import java.util.LinkedList;
+import java.util.List;
/**
- * Property test case for Doris.
+ * Create SQL block rule statement test case for Doris.
*/
@XmlAccessorType(XmlAccessType.FIELD)
@Getter
@Setter
-public final class PropertyTestCase {
+public final class DorisCreateSqlBlockRuleStatementTestCase extends
SQLParserTestCase {
- @XmlAttribute
- private String key;
+ @XmlElement(name = "rule-name")
+ private String ruleName;
- @XmlAttribute
- private String value;
+ @XmlElement(name = "property")
+ private final List<PropertyTestCase> properties = new LinkedList<>();
}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
index b0a27509ca6..bb78adf4fdb 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.
import lombok.Getter;
import lombok.Setter;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.AbstractExpectedSQLSegment;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -30,7 +31,7 @@ import javax.xml.bind.annotation.XmlAttribute;
@XmlAccessorType(XmlAccessType.FIELD)
@Getter
@Setter
-public final class PropertyTestCase {
+public final class PropertyTestCase extends AbstractExpectedSQLSegment {
@XmlAttribute
private String key;
diff --git a/test/it/parser/src/main/resources/case/dal/alter.xml
b/test/it/parser/src/main/resources/case/dal/alter.xml
index 13f0c9bbfb8..9974801f417 100644
--- a/test/it/parser/src/main/resources/case/dal/alter.xml
+++ b/test/it/parser/src/main/resources/case/dal/alter.xml
@@ -53,4 +53,20 @@
<property key="s3.connection.timeout" value="1000" />
<property key="s3.use_path_style" value="false" />
</alter-resource>
+ <doris-alter-system sql-case-id="alter_system_add_follower">
+ <action>ADD FOLLOWER</action>
+ <target>192.168.1.100:9010</target>
+ </doris-alter-system>
+ <doris-alter-system sql-case-id="alter_system_add_observer">
+ <action>ADD OBSERVER</action>
+ <target>192.168.1.101:9010</target>
+ </doris-alter-system>
+ <doris-alter-system sql-case-id="alter_system_drop_follower">
+ <action>DROP FOLLOWER</action>
+ <target>192.168.1.100:9010</target>
+ </doris-alter-system>
+ <doris-alter-system sql-case-id="alter_system_drop_observer">
+ <action>DROP OBSERVER</action>
+ <target>192.168.1.101:9010</target>
+ </doris-alter-system>
</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/case/dal/create.xml
b/test/it/parser/src/main/resources/case/dal/create.xml
index d96e28d0e1c..2cec4607ac2 100644
--- a/test/it/parser/src/main/resources/case/dal/create.xml
+++ b/test/it/parser/src/main/resources/case/dal/create.xml
@@ -23,4 +23,31 @@
<create-resource-group
sql-case-id="create_resource_group_with_system_type_and_thread_priority">
<group name="rg2" start-index="23" stop-index="25"/>
</create-resource-group>
+ <create-sql-block-rule sql-case-id="create_sql_block_rule_with_sql">
+ <rule-name start-index="24" stop-index="32">test_rule</rule-name>
+ <property key="sql" value="select \* from order_analysis"
start-index="43" stop-index="80" />
+ <property key="global" value="true" start-index="82" stop-index="96" />
+ <property key="enable" value="true" start-index="98" stop-index="112"
/>
+ </create-sql-block-rule>
+ <create-sql-block-rule sql-case-id="create_sql_block_rule_with_sqlhash">
+ <rule-name start-index="24"
stop-index="42">block_rule_sqlhash</rule-name>
+ <property key="sqlHash" value="0e5491b37dbea5e8" start-index="52"
stop-index="79" />
+ <property key="enable" value="true" start-index="81" stop-index="95" />
+ </create-sql-block-rule>
+ <create-sql-block-rule
sql-case-id="create_sql_block_rule_with_partition_num">
+ <rule-name start-index="24"
stop-index="43">limit_partition_rule</rule-name>
+ <property key="partition_num" value="30" start-index="54"
stop-index="73" />
+ <property key="global" value="true" start-index="75" stop-index="89" />
+ </create-sql-block-rule>
+ <create-sql-block-rule
sql-case-id="create_sql_block_rule_with_cardinality">
+ <rule-name start-index="24"
stop-index="47">limit_cardinality_rule</rule-name>
+ <property key="cardinality" value="10000000000" start-index="56"
stop-index="82" />
+ <property key="tablet_num" value="100" start-index="84"
stop-index="101" />
+ </create-sql-block-rule>
+ <create-sql-block-rule
sql-case-id="create_sql_block_rule_mixed_properties">
+ <rule-name start-index="24" stop-index="35">complex_rule</rule-name>
+ <property key="sql" value="\s*select\s*\*\s*from order_\w*\s*"
start-index="46" stop-index="93" />
+ <property key="global" value="false" start-index="95" stop-index="110"
/>
+ <property key="enable" value="true" start-index="112" stop-index="126"
/>
+ </create-sql-block-rule>
</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/dal/alter.xml
b/test/it/parser/src/main/resources/sql/supported/dal/alter.xml
index 04e8be96087..af36fb0734c 100644
--- a/test/it/parser/src/main/resources/sql/supported/dal/alter.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dal/alter.xml
@@ -27,4 +27,8 @@
<sql-case id="alter_resource_with_boolean" value="ALTER RESOURCE
'remote_s3' PROPERTIES ("s3.use_path_style" = true);"
db-types="Doris" />
<sql-case id="alter_resource_with_null" value="ALTER RESOURCE 'remote_s3'
PROPERTIES ("s3.session_token" = NULL);" db-types="Doris" />
<sql-case id="alter_resource_mixed_types" value="ALTER RESOURCE
'remote_s3' PROPERTIES ("s3.connection.maximum" = "100",
"s3.connection.timeout" = 1000, "s3.use_path_style" =
false);" db-types="Doris" />
+ <sql-case id="alter_system_add_follower" value="ALTER SYSTEM ADD FOLLOWER
"192.168.1.100:9010"" db-types="Doris" />
+ <sql-case id="alter_system_add_observer" value="ALTER SYSTEM ADD OBSERVER
"192.168.1.101:9010"" db-types="Doris" />
+ <sql-case id="alter_system_drop_follower" value="ALTER SYSTEM DROP
FOLLOWER "192.168.1.100:9010"" db-types="Doris" />
+ <sql-case id="alter_system_drop_observer" value="ALTER SYSTEM DROP
OBSERVER "192.168.1.101:9010"" db-types="Doris" />
</sql-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/dal/create.xml
b/test/it/parser/src/main/resources/sql/supported/dal/create.xml
index 15da635450d..18835190798 100644
--- a/test/it/parser/src/main/resources/sql/supported/dal/create.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dal/create.xml
@@ -19,4 +19,9 @@
<sql-cases>
<sql-case id="create_resource_group" value="CREATE RESOURCE GROUP rg type
= user" db-types="MySQL" />
<sql-case id="create_resource_group_with_system_type_and_thread_priority"
value="CREATE RESOURCE GROUP rg2 TYPE = SYSTEM THREAD_PRIORITY = -20 DISABLE"
db-types="MySQL"/>
+ <sql-case id="create_sql_block_rule_with_sql" value="CREATE SQL_BLOCK_RULE
test_rule PROPERTIES("sql"="select \\* from
order_analysis","global"="true","enable"="true")"
db-types="Doris" />
+ <sql-case id="create_sql_block_rule_with_sqlhash" value="CREATE
SQL_BLOCK_RULE block_rule_sqlhash
PROPERTIES("sqlHash"="0e5491b37dbea5e8","enable"="true")"
db-types="Doris" />
+ <sql-case id="create_sql_block_rule_with_partition_num" value="CREATE
SQL_BLOCK_RULE limit_partition_rule
PROPERTIES("partition_num"="30","global"="true")"
db-types="Doris" />
+ <sql-case id="create_sql_block_rule_with_cardinality" value="CREATE
SQL_BLOCK_RULE limit_cardinality_rule
PROPERTIES("cardinality"="10000000000","tablet_num"="100")"
db-types="Doris" />
+ <sql-case id="create_sql_block_rule_mixed_properties" value="CREATE
SQL_BLOCK_RULE complex_rule
PROPERTIES("sql"="\\s*select\\s*\\*\\s*from
order_\\w*\\s*","global"="false","enable"="true")"
db-types="Doris" />
</sql-cases>