Skip to content

Commit d47c7d6

Browse files
authored
Support for the ALTER CATALOG statement and the RESUME JOB statement (#37491)
* Support for the ALTER CATALOG statement and the RESUME JOB statement * Support for the ALTER CATALOG statement and the RESUME JOB statement
1 parent 5f970d1 commit d47c7d6

26 files changed

Lines changed: 827 additions & 0 deletions

File tree

parser/sql/engine/core/src/main/java/org/apache/shardingsphere/sql/parser/engine/core/database/visitor/SQLVisitorRule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ public enum SQLVisitorRule {
275275

276276
UNLISTEN("Unlisten", SQLStatementType.DDL),
277277

278+
RESUME_JOB("ResumeJob", SQLStatementType.DDL),
279+
280+
ALTER_CATALOG("AlterCatalog", SQLStatementType.DDL),
281+
278282
SET_CONSTRAINTS("SetConstraints", SQLStatementType.TCL),
279283

280284
SET_TRANSACTION("SetTransaction", SQLStatementType.TCL),

parser/sql/engine/dialect/doris/src/main/antlr4/imports/doris/BaseRule.g4

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ identifierKeywordsAmbiguous2Labels
585585
identifierKeywordsAmbiguous3Roles
586586
: EVENT
587587
| FILE
588+
| JOB
588589
| NONE
589590
| PROCESS
590591
| PROXY
@@ -671,6 +672,14 @@ databaseNames
671672
: databaseName (COMMA_ databaseName)*
672673
;
673674

675+
jobName
676+
: identifier
677+
;
678+
679+
catalogName
680+
: identifier
681+
;
682+
674683
charsetName
675684
: textOrIdentifier | BINARY | DEFAULT
676685
;

parser/sql/engine/dialect/doris/src/main/antlr4/imports/doris/DDLStatement.g4

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ alterStatement
2929
| alterLogfileGroup
3030
| alterInstance
3131
| alterServer
32+
| alterCatalog
3233
;
3334

3435
createTable
@@ -266,6 +267,10 @@ dropDatabase
266267
: DROP (DATABASE | SCHEMA) ifExists? databaseName
267268
;
268269

270+
alterCatalog
271+
: ALTER CATALOG catalogName (RENAME identifier | SET PROPERTIES LP_ properties RP_ | MODIFY COMMENT string_)
272+
;
273+
269274
alterInstance
270275
: ALTER INSTANCE instanceAction
271276
;
@@ -899,6 +904,10 @@ signalInformationItem
899904
: conditionInformationItemName EQ_ expr
900905
;
901906

907+
resumeJob
908+
: RESUME JOB WHERE jobName EQ_ stringLiterals
909+
;
910+
902911
prepare
903912
: PREPARE identifier FROM (stringLiterals | userVariable)
904913
;

parser/sql/engine/dialect/doris/src/main/antlr4/imports/doris/DorisKeyword.g4

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,10 @@ JSON_VALUE
12201220
: J S O N UL_ V A L U E
12211221
;
12221222

1223+
JOB
1224+
: J O B
1225+
;
1226+
12231227
KEY
12241228
: K E Y
12251229
;

parser/sql/engine/dialect/doris/src/main/antlr4/org/apache/shardingsphere/sql/parser/autogen/DorisStatement.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ execute
132132
| delimiter
133133
| startReplica
134134
| createMaterializedView
135+
| resumeJob
135136
// TODO consider refactor following sytax to SEMI_? EOF
136137
) (SEMI_ EOF? | EOF)
137138
| EOF

parser/sql/engine/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/engine/doris/visitor/statement/type/DorisDDLStatementVisitor.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
2424
import org.apache.shardingsphere.sql.parser.api.ASTNode;
2525
import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor;
26+
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.AlterCatalogContext;
27+
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.ResumeJobContext;
2628
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.AddColumnContext;
2729
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.AddTableConstraintContext;
2830
import org.apache.shardingsphere.sql.parser.autogen.DorisStatementParser.AlterAlgorithmOptionContext;
@@ -154,6 +156,7 @@
154156
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.ExecuteStatement;
155157
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.PrepareStatement;
156158
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.TruncateStatement;
159+
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.catalog.AlterCatalogStatement;
157160
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.database.AlterDatabaseStatement;
158161
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.database.CreateDatabaseStatement;
159162
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.database.DropDatabaseStatement;
@@ -186,8 +189,10 @@
186189
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.InsertStatement;
187190
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
188191
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.UpdateStatement;
192+
import org.apache.shardingsphere.sql.parser.statement.core.util.SQLUtils;
189193
import org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue;
190194
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
195+
import org.apache.shardingsphere.sql.parser.statement.doris.ddl.DorisResumeJobStatement;
191196
import org.apache.shardingsphere.sql.parser.statement.mysql.ddl.event.MySQLAlterEventStatement;
192197
import org.apache.shardingsphere.sql.parser.statement.mysql.ddl.event.MySQLCreateEventStatement;
193198
import org.apache.shardingsphere.sql.parser.statement.mysql.ddl.event.MySQLDropEventStatement;
@@ -254,6 +259,34 @@ public ASTNode visitDropDatabase(final DropDatabaseContext ctx) {
254259
return new DropDatabaseStatement(getDatabaseType(), new IdentifierValue(ctx.databaseName().getText()).getValue(), null != ctx.ifExists());
255260
}
256261

262+
@Override
263+
public ASTNode visitAlterCatalog(final AlterCatalogContext ctx) {
264+
AlterCatalogStatement result = new AlterCatalogStatement(getDatabaseType());
265+
result.setCatalogName(new IdentifierValue(ctx.catalogName().getText()).getValue());
266+
if (null != ctx.RENAME()) {
267+
result.setNewCatalogName(new IdentifierValue(ctx.identifier().getText()).getValue());
268+
}
269+
if (null != ctx.PROPERTIES()) {
270+
for (int i = 0; i < ctx.properties().property().size(); i++) {
271+
String key = null != ctx.properties().property(i).SINGLE_QUOTED_TEXT()
272+
? SQLUtils.getExactlyValue(ctx.properties().property(i).SINGLE_QUOTED_TEXT().getText())
273+
: SQLUtils.getExactlyValue(ctx.properties().property(i).identifier().getText());
274+
String value = SQLUtils.getExactlyValue(ctx.properties().property(i).literals().getText());
275+
result.getProperties().put(key, value);
276+
}
277+
}
278+
if (null != ctx.COMMENT()) {
279+
result.setComment(SQLUtils.getExactlyValue(ctx.string_().getText()));
280+
}
281+
return result;
282+
}
283+
284+
@Override
285+
public ASTNode visitResumeJob(final ResumeJobContext ctx) {
286+
String jobName = SQLUtils.getExactlyValue(ctx.stringLiterals().getText());
287+
return new DorisResumeJobStatement(getDatabaseType(), jobName);
288+
}
289+
257290
@SuppressWarnings("unchecked")
258291
@Override
259292
public ASTNode visitCreateTable(final CreateTableContext ctx) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.catalog;
19+
20+
import lombok.Getter;
21+
import lombok.Setter;
22+
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
23+
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DDLStatement;
24+
25+
import java.util.LinkedHashMap;
26+
import java.util.Map;
27+
import java.util.Optional;
28+
29+
/**
30+
* Alter catalog statement.
31+
*/
32+
@Getter
33+
@Setter
34+
public final class AlterCatalogStatement extends DDLStatement {
35+
36+
private String catalogName;
37+
38+
private String newCatalogName;
39+
40+
private String comment;
41+
42+
private Map<String, String> properties = new LinkedHashMap<>();
43+
44+
public AlterCatalogStatement(final DatabaseType databaseType) {
45+
super(databaseType);
46+
}
47+
48+
/**
49+
* Get new catalog name.
50+
*
51+
* @return new catalog name
52+
*/
53+
public Optional<String> getNewCatalogName() {
54+
return Optional.ofNullable(newCatalogName);
55+
}
56+
57+
/**
58+
* Get comment.
59+
*
60+
* @return comment
61+
*/
62+
public Optional<String> getComment() {
63+
return Optional.ofNullable(comment);
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.sql.parser.statement.doris.ddl;
19+
20+
import lombok.Getter;
21+
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
22+
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DDLStatement;
23+
24+
/**
25+
* Resume job statement for Doris.
26+
*/
27+
@Getter
28+
public final class DorisResumeJobStatement extends DDLStatement {
29+
30+
private final String jobName;
31+
32+
public DorisResumeJobStatement(final DatabaseType databaseType, final String jobName) {
33+
super(databaseType);
34+
this.jobName = jobName;
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.catalog;
19+
20+
import lombok.AccessLevel;
21+
import lombok.NoArgsConstructor;
22+
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
23+
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.catalog.ExpectedCatalogComment;
24+
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.catalog.ExpectedCatalogProperties;
25+
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.catalog.ExpectedCatalogName;
26+
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.catalog.ExpectedCatalogProperty;
27+
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.catalog.ExpectedRenameCatalog;
28+
29+
import java.util.Map;
30+
31+
import static org.hamcrest.CoreMatchers.is;
32+
import static org.hamcrest.MatcherAssert.assertThat;
33+
34+
/**
35+
* Catalog assert.
36+
*/
37+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
38+
public final class CatalogAssert {
39+
40+
/**
41+
* Assert catalog name is correct with expected catalog name.
42+
*
43+
* @param assertContext assert context
44+
* @param actual actual catalog name
45+
* @param expected expected catalog name
46+
*/
47+
public static void assertCatalogName(final SQLCaseAssertContext assertContext, final String actual, final ExpectedCatalogName expected) {
48+
assertThat(assertContext.getText("Catalog name assertion error: "), actual, is(expected.getName()));
49+
}
50+
51+
/**
52+
* Assert rename catalog is correct with expected rename catalog.
53+
*
54+
* @param assertContext assert context
55+
* @param actual actual new catalog name
56+
* @param expected expected rename catalog
57+
*/
58+
public static void assertRenameCatalog(final SQLCaseAssertContext assertContext, final String actual, final ExpectedRenameCatalog expected) {
59+
assertThat(assertContext.getText("Rename catalog assertion error: "), actual, is(expected.getValue()));
60+
}
61+
62+
/**
63+
* Assert properties are correct with expected properties.
64+
*
65+
* @param assertContext assert context
66+
* @param actual actual properties
67+
* @param expected expected properties
68+
*/
69+
public static void assertProperties(final SQLCaseAssertContext assertContext, final Map<String, String> actual, final ExpectedCatalogProperties expected) {
70+
assertThat(assertContext.getText("Properties size assertion error: "), actual.size(), is(expected.getProperties().size()));
71+
for (ExpectedCatalogProperty each : expected.getProperties()) {
72+
assertProperty(assertContext, actual, each);
73+
}
74+
}
75+
76+
private static void assertProperty(final SQLCaseAssertContext assertContext, final Map<String, String> actual, final ExpectedCatalogProperty expected) {
77+
assertThat(assertContext.getText(String.format("Property key '%s' assertion error: ", expected.getKey())), actual.containsKey(expected.getKey()), is(true));
78+
assertThat(assertContext.getText(String.format("Property value '%s' assertion error: ", expected.getKey())), actual.get(expected.getKey()), is(expected.getValue()));
79+
}
80+
81+
/**
82+
* Assert catalog comment is correct with expected catalog comment.
83+
*
84+
* @param assertContext assert context
85+
* @param actual actual comment
86+
* @param expected expected catalog comment
87+
*/
88+
public static void assertCatalogComment(final SQLCaseAssertContext assertContext, final String actual, final ExpectedCatalogComment expected) {
89+
assertThat(assertContext.getText("Catalog comment assertion error: "), actual, is(expected.getValue()));
90+
}
91+
}

test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/DDLStatementAssert.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import lombok.NoArgsConstructor;
2222
import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.DDLStatement;
2323
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
24+
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ddl.dialect.doris.DorisDDLStatementAssert;
2425
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ddl.dialect.oracle.OracleDDLStatementAssert;
2526
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ddl.dialect.postgresql.PostgreSQLDDLStatementAssert;
2627
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ddl.dialect.sqlserver.SQLServerDDLStatementAssert;
@@ -45,5 +46,6 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final DDLS
4546
PostgreSQLDDLStatementAssert.assertIs(assertContext, actual, expected);
4647
OracleDDLStatementAssert.assertIs(assertContext, actual, expected);
4748
SQLServerDDLStatementAssert.assertIs(assertContext, actual, expected);
49+
DorisDDLStatementAssert.assertIs(assertContext, actual, expected);
4850
}
4951
}

0 commit comments

Comments
 (0)