From 1ead8033e863de811a12ebedd4ba1a6ae0c19198 Mon Sep 17 00:00:00 2001 From: xiaosaxiaozai Date: Mon, 15 Dec 2025 20:50:36 +0800 Subject: [PATCH 1/3] Support for the ALTER RESOURCE statement --- .../core/database/visitor/SQLVisitorRule.java | 2 + parser/sql/engine/dialect/doris/pom.xml | 5 ++ .../main/antlr4/imports/doris/DALStatement.g4 | 12 +++++ .../sql/parser/autogen/DorisStatement.g4 | 1 + .../type/DorisDALStatementVisitor.java | 16 ++++++ parser/sql/statement/dialect/doris/pom.xml | 36 ++++++++++++++ .../dal/DorisAlterResourceStatement.java | 44 +++++++++++++++++ parser/sql/statement/dialect/pom.xml | 1 + .../statement/dal/DALStatementAssert.java | 2 + .../doris/DorisDALStatementAssert.java | 47 ++++++++++++++++++ .../DorisAlterResourceStatementAssert.java | 49 +++++++++++++++++++ .../parser/jaxb/RootSQLParserTestCases.java | 4 ++ .../DorisAlterResourceStatementTestCase.java | 35 +++++++++++++ .../src/main/resources/case/dal/alter.xml | 3 ++ .../resources/sql/supported/dal/alter.xml | 1 + 15 files changed, 258 insertions(+) create mode 100644 parser/sql/statement/dialect/doris/pom.xml create mode 100644 parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisAlterResourceStatement.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/DorisDALStatementAssert.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisAlterResourceStatementAssert.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisAlterResourceStatementTestCase.java 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 a9a7f8dbb870d..99162f1e29e8d 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 @@ -473,6 +473,8 @@ public enum SQLVisitorRule { ALTER_RESOURCE_GROUP("AlterResourceGroup", SQLStatementType.DAL), + ALTER_RESOURCE("AlterResource", SQLStatementType.DAL), + DELIMITER("Delimiter", SQLStatementType.DAL), CALL("Call", SQLStatementType.DML), diff --git a/parser/sql/engine/dialect/doris/pom.xml b/parser/sql/engine/dialect/doris/pom.xml index 271507567e36a..99db7b40e92e4 100644 --- a/parser/sql/engine/dialect/doris/pom.xml +++ b/parser/sql/engine/dialect/doris/pom.xml @@ -41,5 +41,10 @@ shardingsphere-parser-sql-statement-mysql ${project.version} + + org.apache.shardingsphere + shardingsphere-parser-sql-statement-doris + ${project.version} + 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 5bc5062c33c8f..c3d52b43b62c8 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 @@ -329,6 +329,18 @@ alterResourceGroup (ENABLE | DISABLE FORCE?)? ; +alterResource + : ALTER RESOURCE string_ PROPERTIES LP_ propertyAssignments RP_ + ; + +propertyAssignments + : propertyAssignment (COMMA_ propertyAssignment)* + ; + +propertyAssignment + : string_ EQ_ string_ + ; + vcpuSpec : NUMBER_ | NUMBER_ MINUS_ NUMBER_ ; 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 70f5965ed6d79..b41b1ebe08dcc 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 @@ -51,6 +51,7 @@ execute | createTrigger | dropTrigger | alterResourceGroup + | alterResource | createResourceGroup | dropResourceGroup | prepare 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 776d14ab06845..013c04849001d 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 @@ -120,6 +120,8 @@ import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.UninstallComponentContext; import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.UninstallPluginContext; import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.UseContext; +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.AlterResourceContext; +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PropertyAssignmentContext; 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; @@ -153,6 +155,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NumberLiteralValue; import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.StringLiteralValue; +import org.apache.shardingsphere.sql.parser.statement.doris.dal.DorisAlterResourceStatement; 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; @@ -233,6 +236,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Optional; +import java.util.Properties; import java.util.stream.Collectors; /** @@ -902,6 +906,18 @@ public ASTNode visitAlterResourceGroup(final AlterResourceGroupContext ctx) { return new MySQLAlterResourceGroupStatement(getDatabaseType(), ((IdentifierValue) visit(ctx.groupName())).getValue()); } + @Override + public ASTNode visitAlterResource(final AlterResourceContext ctx) { + String resourceName = ((StringLiteralValue) visit(ctx.string_())).getValue(); + Properties properties = new Properties(); + for (PropertyAssignmentContext each : ctx.propertyAssignments().propertyAssignment()) { + String key = ((StringLiteralValue) visit(each.string_(0))).getValue(); + String value = ((StringLiteralValue) visit(each.string_(1))).getValue(); + properties.setProperty(key, value); + } + return new DorisAlterResourceStatement(getDatabaseType(), resourceName, properties); + } + @Override public ASTNode visitChangeMasterTo(final ChangeMasterToContext ctx) { return new MySQLChangeMasterStatement(getDatabaseType()); diff --git a/parser/sql/statement/dialect/doris/pom.xml b/parser/sql/statement/dialect/doris/pom.xml new file mode 100644 index 0000000000000..5560276e84f8f --- /dev/null +++ b/parser/sql/statement/dialect/doris/pom.xml @@ -0,0 +1,36 @@ + + + + + 4.0.0 + + org.apache.shardingsphere + shardingsphere-parser-sql-statement-dialect + 5.5.3-SNAPSHOT + + shardingsphere-parser-sql-statement-doris + ${project.artifactId} + + + + org.apache.shardingsphere + shardingsphere-parser-sql-statement-core + ${project.version} + + + diff --git a/parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisAlterResourceStatement.java b/parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisAlterResourceStatement.java new file mode 100644 index 0000000000000..65e0e282e2135 --- /dev/null +++ b/parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisAlterResourceStatement.java @@ -0,0 +1,44 @@ +/* + * 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.sql.parser.statement.doris.dal; + +import lombok.Getter; +import org.apache.shardingsphere.database.connector.core.type.DatabaseType; +import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement; + +import java.util.Properties; + +/** + * Alter resource statement for Doris. + */ +@Getter +public final class DorisAlterResourceStatement extends DALStatement { + + private final DatabaseType databaseType; + + private final String resourceName; + + private final Properties properties; + + public DorisAlterResourceStatement(final DatabaseType databaseType, final String resourceName, final Properties properties) { + super(databaseType); + this.databaseType = databaseType; + this.resourceName = resourceName; + this.properties = properties; + } +} diff --git a/parser/sql/statement/dialect/pom.xml b/parser/sql/statement/dialect/pom.xml index 42dda4bd6fe65..1e1dab49f1e61 100644 --- a/parser/sql/statement/dialect/pom.xml +++ b/parser/sql/statement/dialect/pom.xml @@ -33,5 +33,6 @@ sqlserver oracle hive + doris diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/DALStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/DALStatementAssert.java index d9ca26e2e2995..ba9aca8f87f7c 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/DALStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/DALStatementAssert.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.mysql.MySQLDALStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.oracle.OracleDALStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.postgresql.PostgreSQLDALStatementAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.dialect.doris.DorisDALStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.dal.standard.StandardDALStatementAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; @@ -45,5 +46,6 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final DALS MySQLDALStatementAssert.assertIs(assertContext, actual, expected); PostgreSQLDALStatementAssert.assertIs(assertContext, actual, expected); OracleDALStatementAssert.assertIs(assertContext, actual, expected); + DorisDALStatementAssert.assertIs(assertContext, actual, 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/DorisDALStatementAssert.java new file mode 100644 index 0000000000000..23c4bd3799a81 --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/DorisDALStatementAssert.java @@ -0,0 +1,47 @@ +/* + * 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; + +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.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; + +/** + * DAL statement assert for Doris. + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class DorisDALStatementAssert { + + /** + * Assert DAL statement is correct with expected parser result. + * + * @param assertContext assert context + * @param actual actual DAL statement + * @param expected expected DAL 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); + } + } +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisAlterResourceStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisAlterResourceStatementAssert.java new file mode 100644 index 0000000000000..b90d995af29ae --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisAlterResourceStatementAssert.java @@ -0,0 +1,49 @@ +/* + * 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.doris.dal.DorisAlterResourceStatement; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.doris.DorisAlterResourceStatementTestCase; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * Alter resource statement assert for Doris. + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class DorisAlterResourceStatementAssert { + + /** + * Assert alter resource statement is correct with expected parser result. + * + * @param assertContext assert context + * @param actual actual alter resource statement + * @param expected expected alter resource statement test case + */ + public static void assertIs(final SQLCaseAssertContext assertContext, final DorisAlterResourceStatement actual, final DorisAlterResourceStatementTestCase expected) { + if (null != expected.getResourceName()) { + assertThat(assertContext.getText("resource name does not match: "), actual.getResourceName(), is(expected.getResourceName())); + } + assertNotNull(actual.getProperties(), assertContext.getText("properties should not be null")); + } +} 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 acbe5468e9d25..e76a915e849f9 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 @@ -72,6 +72,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.mysql.table.MySQLChecksumTableStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.mysql.table.MySQLOptimizeTableStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.mysql.table.MySQLRepairTableStatementTestCase; +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.oracle.OracleSpoolStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.dialect.postgresql.PostgreSQLResetParameterStatementTestCase; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dal.standard.EmptyStatementTestCase; @@ -649,6 +650,9 @@ public final class RootSQLParserTestCases { @XmlElement(name = "alter-resource-group") private final List alterResourceGroupTestCases = new LinkedList<>(); + @XmlElement(name = "alter-resource") + private final List alterResourceTestCases = new LinkedList<>(); + @XmlElement(name = "create-resource-group") private final List createResourceGroupTestCases = 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/DorisAlterResourceStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisAlterResourceStatementTestCase.java new file mode 100644 index 0000000000000..ab4b5953603a7 --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisAlterResourceStatementTestCase.java @@ -0,0 +1,35 @@ +/* + * 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.cases.parser.jaxb.statement.dal.dialect.doris; + +import lombok.Getter; +import lombok.Setter; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; + +import javax.xml.bind.annotation.XmlElement; + +/** + * Alter resource statement test case for Doris. + */ +@Getter +@Setter +public final class DorisAlterResourceStatementTestCase extends SQLParserTestCase { + + @XmlElement(name = "resource-name") + private String resourceName; +} 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 87f9a332d2e34..b496bc81edad8 100644 --- a/test/it/parser/src/main/resources/case/dal/alter.xml +++ b/test/it/parser/src/main/resources/case/dal/alter.xml @@ -22,4 +22,7 @@ + + remote_s3 + 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 2a15133ec145a..a7b46ef0622c2 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 @@ -20,4 +20,5 @@ + From 314323dbe589beaa89ab1ccb66bbece46871690c Mon Sep 17 00:00:00 2001 From: xiaosaxiaozai Date: Tue, 16 Dec 2025 11:01:14 +0800 Subject: [PATCH 2/3] Support for the ALTER RESOURCE statement --- .../main/antlr4/imports/doris/DALStatement.g4 | 16 +++++++- .../type/DorisDALStatementVisitor.java | 37 +++++++++++++++-- .../dal/DorisAlterResourceStatement.java | 3 -- .../DorisAlterResourceStatementAssert.java | 8 ++++ .../DorisAlterResourceStatementTestCase.java | 8 ++++ .../dal/dialect/doris/PropertyTestCase.java | 40 +++++++++++++++++++ .../src/main/resources/case/dal/alter.xml | 14 +++++++ .../resources/sql/supported/dal/alter.xml | 3 ++ 8 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java 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 c3d52b43b62c8..4aa436fbba3d6 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 @@ -330,7 +330,11 @@ alterResourceGroup ; alterResource - : ALTER RESOURCE string_ PROPERTIES LP_ propertyAssignments RP_ + : ALTER RESOURCE resourceName PROPERTIES LP_ propertyAssignments RP_ + ; + +resourceName + : identifier | string_ ; propertyAssignments @@ -338,7 +342,15 @@ propertyAssignments ; propertyAssignment - : string_ EQ_ string_ + : propertyKey EQ_ propertyValue + ; + +propertyKey + : identifier | string_ + ; + +propertyValue + : literals | identifier ; vcpuSpec 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 013c04849001d..13a3ec2971c53 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 @@ -122,6 +122,9 @@ import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.UseContext; import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.AlterResourceContext; import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PropertyAssignmentContext; +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.ResourceNameContext; +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PropertyKeyContext; +import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.PropertyValueContext; 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; @@ -908,16 +911,44 @@ public ASTNode visitAlterResourceGroup(final AlterResourceGroupContext ctx) { @Override public ASTNode visitAlterResource(final AlterResourceContext ctx) { - String resourceName = ((StringLiteralValue) visit(ctx.string_())).getValue(); + String resourceName = getResourceName(ctx.resourceName()); Properties properties = new Properties(); for (PropertyAssignmentContext each : ctx.propertyAssignments().propertyAssignment()) { - String key = ((StringLiteralValue) visit(each.string_(0))).getValue(); - String value = ((StringLiteralValue) visit(each.string_(1))).getValue(); + String key = getPropertyKey(each.propertyKey()); + String value = getPropertyValue(each.propertyValue()); properties.setProperty(key, value); } return new DorisAlterResourceStatement(getDatabaseType(), resourceName, properties); } + private String getResourceName(final ResourceNameContext ctx) { + if (null != ctx.identifier()) { + return ((IdentifierValue) visit(ctx.identifier())).getValue(); + } + return ((StringLiteralValue) visit(ctx.string_())).getValue(); + } + + private String getPropertyKey(final PropertyKeyContext ctx) { + if (null != ctx.identifier()) { + return ((IdentifierValue) visit(ctx.identifier())).getValue(); + } + return ((StringLiteralValue) visit(ctx.string_())).getValue(); + } + + private String getPropertyValue(final PropertyValueContext ctx) { + if (null != ctx.identifier()) { + return ((IdentifierValue) visit(ctx.identifier())).getValue(); + } + ASTNode result = visit(ctx.literals()); + if (result instanceof StringLiteralValue) { + return ((StringLiteralValue) result).getValue(); + } + if (result instanceof NumberLiteralValue) { + return ((NumberLiteralValue) result).getValue().toString(); + } + return result.toString(); + } + @Override public ASTNode visitChangeMasterTo(final ChangeMasterToContext ctx) { return new MySQLChangeMasterStatement(getDatabaseType()); diff --git a/parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisAlterResourceStatement.java b/parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisAlterResourceStatement.java index 65e0e282e2135..14e4586d934a0 100644 --- a/parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisAlterResourceStatement.java +++ b/parser/sql/statement/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/dal/DorisAlterResourceStatement.java @@ -29,15 +29,12 @@ @Getter public final class DorisAlterResourceStatement extends DALStatement { - private final DatabaseType databaseType; - private final String resourceName; private final Properties properties; public DorisAlterResourceStatement(final DatabaseType databaseType, final String resourceName, final Properties properties) { super(databaseType); - this.databaseType = databaseType; this.resourceName = resourceName; this.properties = properties; } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisAlterResourceStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisAlterResourceStatementAssert.java index b90d995af29ae..b121c7b605a3f 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisAlterResourceStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dal/dialect/doris/type/DorisAlterResourceStatementAssert.java @@ -45,5 +45,13 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final Dori assertThat(assertContext.getText("resource name does not match: "), actual.getResourceName(), is(expected.getResourceName())); } assertNotNull(actual.getProperties(), assertContext.getText("properties should not be null")); + if (!expected.getProperties().isEmpty()) { + assertThat(assertContext.getText("properties size does not match: "), actual.getProperties().size(), is(expected.getProperties().size())); + expected.getProperties().forEach(property -> { + String actualValue = actual.getProperties().getProperty(property.getKey()); + assertNotNull(actualValue, assertContext.getText("property key '" + property.getKey() + "' should exist")); + assertThat(assertContext.getText("property value for key '" + property.getKey() + "' does not match: "), actualValue, is(property.getValue())); + }); + } } } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisAlterResourceStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisAlterResourceStatementTestCase.java index ab4b5953603a7..4c7fe43506ceb 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisAlterResourceStatementTestCase.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/DorisAlterResourceStatementTestCase.java @@ -21,15 +21,23 @@ 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.XmlElement; +import java.util.LinkedList; +import java.util.List; /** * Alter resource statement test case for Doris. */ +@XmlAccessorType(XmlAccessType.FIELD) @Getter @Setter public final class DorisAlterResourceStatementTestCase extends SQLParserTestCase { @XmlElement(name = "resource-name") private String resourceName; + + @XmlElement(name = "property") + private final List 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 new file mode 100644 index 0000000000000..b0a27509ca628 --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dal/dialect/doris/PropertyTestCase.java @@ -0,0 +1,40 @@ +/* + * 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.cases.parser.jaxb.statement.dal.dialect.doris; + +import lombok.Getter; +import lombok.Setter; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +/** + * Property test case for Doris. + */ +@XmlAccessorType(XmlAccessType.FIELD) +@Getter +@Setter +public final class PropertyTestCase { + + @XmlAttribute + private String key; + + @XmlAttribute + private String value; +} 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 b496bc81edad8..504c62209f8bc 100644 --- a/test/it/parser/src/main/resources/case/dal/alter.xml +++ b/test/it/parser/src/main/resources/case/dal/alter.xml @@ -24,5 +24,19 @@ remote_s3 + + + + remote_s3 + + + + remote_s3 + + + + remote_s3 + + 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 a7b46ef0622c2..f469cd7fb448e 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 @@ -21,4 +21,7 @@ + + + From ed09e8dfcf078af84acd496d4dbf74faea66d907 Mon Sep 17 00:00:00 2001 From: xiaosaxiaozai Date: Tue, 16 Dec 2025 12:45:39 +0800 Subject: [PATCH 3/3] Support for the ALTER RESOURCE statement --- .../type/DorisDALStatementVisitor.java | 38 ++++++++++++++++--- .../src/main/resources/case/dal/alter.xml | 14 +++++++ .../resources/sql/supported/dal/alter.xml | 3 ++ 3 files changed, 50 insertions(+), 5 deletions(-) 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 13a3ec2971c53..0e325acfe932d 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 @@ -158,6 +158,12 @@ import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NumberLiteralValue; import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.StringLiteralValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.LiteralValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.BooleanLiteralValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.DateTimeLiteralValue; +import org.apache.shardingsphere.sql.parser.statement.core.value.literal.impl.NullLiteralValue; +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.mysql.dal.MySQLCloneStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCreateLoadableFunctionStatement; @@ -940,15 +946,37 @@ private String getPropertyValue(final PropertyValueContext ctx) { return ((IdentifierValue) visit(ctx.identifier())).getValue(); } ASTNode result = visit(ctx.literals()); - if (result instanceof StringLiteralValue) { - return ((StringLiteralValue) result).getValue(); - } - if (result instanceof NumberLiteralValue) { - return ((NumberLiteralValue) result).getValue().toString(); + if (result instanceof LiteralValue) { + return getLiteralValueAsString((LiteralValue) result); } return result.toString(); } + private String getLiteralValueAsString(final LiteralValue literalValue) { + if (literalValue instanceof StringLiteralValue) { + return ((StringLiteralValue) literalValue).getValue(); + } + if (literalValue instanceof NumberLiteralValue) { + return ((NumberLiteralValue) literalValue).getValue().toString(); + } + if (literalValue instanceof BooleanLiteralValue) { + return String.valueOf(((BooleanLiteralValue) literalValue).getValue()); + } + if (literalValue instanceof NullLiteralValue) { + return "NULL"; + } + if (literalValue instanceof DateTimeLiteralValue) { + return ((DateTimeLiteralValue) literalValue).getValue(); + } + if (literalValue instanceof TemporalLiteralValue) { + return ((TemporalLiteralValue) literalValue).getValue(); + } + if (literalValue instanceof OtherLiteralValue) { + return String.valueOf(((OtherLiteralValue) literalValue).getValue()); + } + return String.valueOf(literalValue.getValue()); + } + @Override public ASTNode visitChangeMasterTo(final ChangeMasterToContext ctx) { return new MySQLChangeMasterStatement(getDatabaseType()); 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 504c62209f8bc..13f0c9bbfb8bc 100644 --- a/test/it/parser/src/main/resources/case/dal/alter.xml +++ b/test/it/parser/src/main/resources/case/dal/alter.xml @@ -39,4 +39,18 @@ + + remote_s3 + + + + remote_s3 + + + + remote_s3 + + + + 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 f469cd7fb448e..04e8be96087aa 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 @@ -24,4 +24,7 @@ + + +