This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang 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 ea50147be7d Support deny user SQL bind and add test case (#34279)
ea50147be7d is described below

commit ea50147be7d2c8d4f2b0ba03f64ddc682e24e3ec
Author: Chakkk <[email protected]>
AuthorDate: Wed Jan 8 19:26:49 2025 +0800

    Support deny user SQL bind and add test case (#34279)
    
    * support deny user SQL bind and add test case
    
    * update release note
    
    * fix checkstyle
    
    * format license
---
 RELEASE-NOTES.md                                   |  1 +
 .../infra/binder/engine/SQLBindEngine.java         |  5 ++
 .../statement/dcl/DenyUserStatementBinder.java     | 56 ++++++++++++++++++++++
 .../binder/engine/type/DCLStatementBindEngine.java | 53 ++++++++++++++++++++
 .../src/test/resources/cases/dcl/deny-user.xml     | 28 +++++++++++
 .../src/test/resources/sqls/dcl/deny-user.xml      | 21 ++++++++
 6 files changed, 164 insertions(+)

diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index ad0678561db..88d548aa125 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -53,6 +53,7 @@
 1. SQL Binder: Support optimize table sql bind and add test case - 
[#34242](https://github.com/apache/shardingsphere/pull/34242)
 1. SQL Binder: Support show create table, show columns, show index statement 
bind - [#34271](https://github.com/apache/shardingsphere/pull/34271)
 1. SQL Parser: Enhance create view, alter view, drop view sql parser - 
[#34283](https://github.com/apache/shardingsphere/pull/34283)
+1. SQL Binder: Support deny user sql bind and add test case - 
[#34279](https://github.com/apache/shardingsphere/pull/34279)
 
 ### Bug Fixes
 
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/SQLBindEngine.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/SQLBindEngine.java
index 57dedf85d83..934cfc835d6 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/SQLBindEngine.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/SQLBindEngine.java
@@ -21,6 +21,7 @@ import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
 import 
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContextFactory;
 import 
org.apache.shardingsphere.infra.binder.engine.type.DALStatementBindEngine;
+import 
org.apache.shardingsphere.infra.binder.engine.type.DCLStatementBindEngine;
 import 
org.apache.shardingsphere.infra.binder.engine.type.DDLStatementBindEngine;
 import 
org.apache.shardingsphere.infra.binder.engine.type.DMLStatementBindEngine;
 import org.apache.shardingsphere.infra.hint.HintManager;
@@ -28,6 +29,7 @@ import org.apache.shardingsphere.infra.hint.HintValueContext;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.DALStatement;
+import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.DCLStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DMLStatement;
 
@@ -71,6 +73,9 @@ public final class SQLBindEngine {
         if (statement instanceof DALStatement) {
             return new DALStatementBindEngine(metaData, currentDatabaseName, 
hintValueContext).bind((DALStatement) statement);
         }
+        if (statement instanceof DCLStatement) {
+            return new DCLStatementBindEngine(metaData, currentDatabaseName, 
hintValueContext).bind((DCLStatement) statement);
+        }
         return statement;
     }
 }
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/dcl/DenyUserStatementBinder.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/dcl/DenyUserStatementBinder.java
new file mode 100644
index 00000000000..7aebdd1bc25
--- /dev/null
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/dcl/DenyUserStatementBinder.java
@@ -0,0 +1,56 @@
+/*
+ * 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.infra.binder.engine.statement.dcl;
+
+import com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString;
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Multimap;
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.infra.binder.engine.segment.SegmentType;
+import 
org.apache.shardingsphere.infra.binder.engine.segment.dml.expression.type.ColumnSegmentBinder;
+import 
org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.TableSegmentBinderContext;
+import 
org.apache.shardingsphere.infra.binder.engine.segment.dml.from.type.SimpleTableSegmentBinder;
+import 
org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinder;
+import 
org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
+import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.DenyUserStatement;
+
+/**
+ * Deny user statement binder.
+ */
+public final class DenyUserStatementBinder implements 
SQLStatementBinder<DenyUserStatement> {
+    
+    @Override
+    public DenyUserStatement bind(final DenyUserStatement sqlStatement, final 
SQLStatementBinderContext binderContext) {
+        DenyUserStatement result = copy(sqlStatement);
+        Multimap<CaseInsensitiveString, TableSegmentBinderContext> 
tableBinderContexts = LinkedHashMultimap.create();
+        result.setTable(SimpleTableSegmentBinder.bind(sqlStatement.getTable(), 
binderContext, tableBinderContexts));
+        sqlStatement.getColumns()
+                .forEach(each -> 
result.getColumns().add(ColumnSegmentBinder.bind(each, 
SegmentType.DEFINITION_COLUMNS, binderContext, tableBinderContexts, 
LinkedHashMultimap.create())));
+        return result;
+    }
+    
+    @SneakyThrows(ReflectiveOperationException.class)
+    private static DenyUserStatement copy(final DenyUserStatement 
sqlStatement) {
+        DenyUserStatement result = 
sqlStatement.getClass().getDeclaredConstructor().newInstance();
+        result.setTable(sqlStatement.getTable());
+        
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments());
+        result.getCommentSegments().addAll(sqlStatement.getCommentSegments());
+        result.getVariableNames().addAll(sqlStatement.getVariableNames());
+        return result;
+    }
+}
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DCLStatementBindEngine.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DCLStatementBindEngine.java
new file mode 100644
index 00000000000..fa0d8f0aabe
--- /dev/null
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DCLStatementBindEngine.java
@@ -0,0 +1,53 @@
+/*
+ * 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.infra.binder.engine.type;
+
+import lombok.RequiredArgsConstructor;
+import 
org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
+import 
org.apache.shardingsphere.infra.binder.engine.statement.dcl.DenyUserStatementBinder;
+import org.apache.shardingsphere.infra.hint.HintValueContext;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.DCLStatement;
+import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.DenyUserStatement;
+
+/**
+ * DCL statement bind engine.
+ */
+@RequiredArgsConstructor
+public final class DCLStatementBindEngine {
+    
+    private final ShardingSphereMetaData metaData;
+    
+    private final String currentDatabaseName;
+    
+    private final HintValueContext hintValueContext;
+    
+    /**
+     * Bind DCL statement.
+     *
+     * @param statement to be bound DCL statement
+     * @return bound DCL statement
+     */
+    public DCLStatement bind(final DCLStatement statement) {
+        SQLStatementBinderContext binderContext = new 
SQLStatementBinderContext(metaData, currentDatabaseName, hintValueContext, 
statement);
+        if (statement instanceof DenyUserStatement) {
+            return new DenyUserStatementBinder().bind((DenyUserStatement) 
statement, binderContext);
+        }
+        return statement;
+    }
+}
diff --git a/test/it/binder/src/test/resources/cases/dcl/deny-user.xml 
b/test/it/binder/src/test/resources/cases/dcl/deny-user.xml
new file mode 100644
index 00000000000..2c15b8a5197
--- /dev/null
+++ b/test/it/binder/src/test/resources/cases/dcl/deny-user.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<sql-parser-test-cases>
+    <deny-user sql-case-id="deny_user">
+        <table name="t_order" start-index="15" stop-index="21">
+            <table-bound>
+                <original-database name="foo_db_1" />
+                <original-schema name="dbo" />
+            </table-bound>
+        </table>
+    </deny-user>
+</sql-parser-test-cases>
diff --git a/test/it/binder/src/test/resources/sqls/dcl/deny-user.xml 
b/test/it/binder/src/test/resources/sqls/dcl/deny-user.xml
new file mode 100644
index 00000000000..c741bc71445
--- /dev/null
+++ b/test/it/binder/src/test/resources/sqls/dcl/deny-user.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<sql-cases>
+    <sql-case id="deny_user" value="DENY UPDATE ON t_order TO user_dev" 
db-types="SQLServer" />
+</sql-cases>

Reply via email to