Skip to content

Commit 5e345fb

Browse files
authored
Extract DCL statement to reduce duplicate logic for MySQL and doris (#31771)
1 parent 59433c2 commit 5e345fb

File tree

41 files changed

+370
-190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+370
-190
lines changed

infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ShowTableStatusStatement;
7878
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ShowTablesStatement;
7979
import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.DCLStatement;
80+
import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.DenyUserStatement;
8081
import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.GrantStatement;
8182
import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.RevokeStatement;
8283
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterIndexStatement;
@@ -111,7 +112,6 @@
111112
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLLoadXMLStatement;
112113
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCursorStatement;
113114
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.dml.OracleMergeStatement;
114-
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dcl.SQLServerDenyUserStatement;
115115

116116
import java.util.Collections;
117117
import java.util.List;
@@ -254,8 +254,8 @@ private static SQLStatementContext getDCLStatementContext(final DCLStatement sql
254254
if (sqlStatement instanceof RevokeStatement) {
255255
return new RevokeStatementContext((RevokeStatement) sqlStatement);
256256
}
257-
if (sqlStatement instanceof SQLServerDenyUserStatement) {
258-
return new DenyUserStatementContext((SQLServerDenyUserStatement) sqlStatement);
257+
if (sqlStatement instanceof DenyUserStatement) {
258+
return new DenyUserStatementContext((DenyUserStatement) sqlStatement);
259259
}
260260
return new UnknownSQLStatementContext(sqlStatement);
261261
}

infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContext.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
2222
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
2323
import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
24-
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dcl.SQLServerDenyUserStatement;
24+
import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.DenyUserStatement;
2525

2626
/**
2727
* Deny user statement context.
@@ -31,13 +31,13 @@ public final class DenyUserStatementContext extends CommonSQLStatementContext im
3131

3232
private final TablesContext tablesContext;
3333

34-
public DenyUserStatementContext(final SQLServerDenyUserStatement sqlStatement) {
34+
public DenyUserStatementContext(final DenyUserStatement sqlStatement) {
3535
super(sqlStatement);
3636
tablesContext = new TablesContext(sqlStatement.getTable(), getDatabaseType());
3737
}
3838

3939
@Override
40-
public SQLServerDenyUserStatement getSqlStatement() {
41-
return (SQLServerDenyUserStatement) super.getSqlStatement();
40+
public DenyUserStatement getSqlStatement() {
41+
return (DenyUserStatement) super.getSqlStatement();
4242
}
4343
}

parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/dal/FlushStatement.java

+12
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,22 @@
1717

1818
package org.apache.shardingsphere.sql.parser.sql.common.statement.dal;
1919

20+
import lombok.Getter;
21+
import lombok.Setter;
22+
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
2023
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
2124

25+
import java.util.Collection;
26+
import java.util.LinkedList;
27+
2228
/**
2329
* Flush statement.
2430
*/
31+
@Getter
32+
@Setter
2533
public abstract class FlushStatement extends AbstractSQLStatement implements DALStatement {
34+
35+
private final Collection<SimpleTableSegment> tables = new LinkedList<>();
36+
37+
private boolean flushTable;
2638
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.sql.common.statement.dal;
19+
20+
import lombok.Getter;
21+
import lombok.Setter;
22+
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
23+
24+
/**
25+
* Spool statement.
26+
*/
27+
@Getter
28+
@Setter
29+
public abstract class SpoolStatement extends AbstractSQLStatement implements DALStatement {
30+
31+
private String fileName;
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.sql.common.statement.dcl;
19+
20+
import lombok.Getter;
21+
import lombok.Setter;
22+
import org.apache.shardingsphere.sql.parser.sql.common.segment.dcl.LoginSegment;
23+
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
24+
25+
/**
26+
* Alter login statement.
27+
*/
28+
@Getter
29+
@Setter
30+
public abstract class AlterLoginStatement extends AbstractSQLStatement implements DCLStatement {
31+
32+
private LoginSegment loginSegment;
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.sql.common.statement.dcl;
19+
20+
import lombok.Getter;
21+
import lombok.Setter;
22+
import org.apache.shardingsphere.sql.parser.sql.common.segment.dcl.LoginSegment;
23+
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
24+
25+
/**
26+
* Create login statement.
27+
*/
28+
@Getter
29+
@Setter
30+
public abstract class CreateLoginStatement extends AbstractSQLStatement implements DCLStatement {
31+
32+
private LoginSegment loginSegment;
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.sql.common.statement.dcl;
19+
20+
import lombok.Getter;
21+
import lombok.Setter;
22+
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
23+
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
24+
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
25+
26+
import java.util.Collection;
27+
import java.util.LinkedList;
28+
29+
/**
30+
* Deny user statement.
31+
*/
32+
@Getter
33+
@Setter
34+
public abstract class DenyUserStatement extends AbstractSQLStatement implements DCLStatement {
35+
36+
private SimpleTableSegment table;
37+
38+
private final Collection<ColumnSegment> columns = new LinkedList<>();
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.sql.common.statement.dcl;
19+
20+
import lombok.Getter;
21+
import lombok.Setter;
22+
import org.apache.shardingsphere.sql.parser.sql.common.segment.dcl.LoginSegment;
23+
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
24+
25+
/**
26+
* Drop login statement.
27+
*/
28+
@Getter
29+
@Setter
30+
public abstract class DropLoginStatement extends AbstractSQLStatement implements DCLStatement {
31+
32+
private LoginSegment loginSegment;
33+
}
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.shardingsphere.sql.parser.sql.common.statement.dal;
18+
package org.apache.shardingsphere.sql.parser.sql.common.statement.dcl;
1919

20-
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.doris.DorisStatement;
20+
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
2121

2222
/**
23-
* Use database statement for Doris.
23+
* Rename user statement.
2424
*/
25-
public final class DorisUseStatement extends UseStatement implements DorisStatement {
25+
public abstract class RenameUserStatement extends AbstractSQLStatement implements DCLStatement {
2626
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.sql.common.statement.dcl;
19+
20+
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
21+
22+
/**
23+
* Set default role statement.
24+
*/
25+
public abstract class SetDefaultRoleStatement extends AbstractSQLStatement implements DCLStatement {
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.sql.common.statement.dcl;
19+
20+
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
21+
22+
/**
23+
* Set password statement.
24+
*/
25+
public abstract class SetPasswordStatement extends AbstractSQLStatement implements DCLStatement {
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.sql.common.statement.dcl;
19+
20+
import lombok.Getter;
21+
import lombok.Setter;
22+
import org.apache.shardingsphere.sql.parser.sql.common.segment.dcl.UserSegment;
23+
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
24+
25+
/**
26+
* Set user statement.
27+
*/
28+
@Getter
29+
@Setter
30+
public abstract class SetUserStatement extends AbstractSQLStatement implements DCLStatement {
31+
32+
private UserSegment user;
33+
}

parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/doris/dal/DorisFlushStatement.java

-13
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,11 @@
1717

1818
package org.apache.shardingsphere.sql.parser.sql.dialect.statement.doris.dal;
1919

20-
import lombok.Getter;
21-
import lombok.Setter;
22-
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
2320
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.FlushStatement;
2421
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.doris.DorisStatement;
2522

26-
import java.util.Collection;
27-
import java.util.LinkedList;
28-
2923
/**
3024
* Doris flush statement.
3125
*/
32-
@Getter
33-
@Setter
3426
public final class DorisFlushStatement extends FlushStatement implements DorisStatement {
35-
36-
private final Collection<SimpleTableSegment> tables = new LinkedList<>();
37-
38-
private boolean flushTable;
39-
4027
}

parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/doris/dcl/DorisRenameUserStatement.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717

1818
package org.apache.shardingsphere.sql.parser.sql.dialect.statement.doris.dcl;
1919

20-
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
21-
import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.DCLStatement;
20+
import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.RenameUserStatement;
2221
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.doris.DorisStatement;
2322

2423
/**
2524
* Doris rename user statement.
2625
*/
27-
public final class DorisRenameUserStatement extends AbstractSQLStatement implements DCLStatement, DorisStatement {
26+
public final class DorisRenameUserStatement extends RenameUserStatement implements DorisStatement {
2827
}

0 commit comments

Comments
 (0)