This is an automated email from the ASF dual-hosted git repository. chengzhang 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 5736aab5bdf Add WithAvailable interface and encrypt with, combine, insert select support checker (#34175) 5736aab5bdf is described below commit 5736aab5bdfa1b344db4f5f02a8d7616fe5a5fd8 Author: Zhengqiang Duan <duanzhengqi...@apache.org> AuthorDate: Fri Dec 27 13:40:13 2024 +0800 Add WithAvailable interface and encrypt with, combine, insert select support checker (#34175) * Add WithAvailable interface and encrypt with support checker * Add combine and insert select checker * update release note and doc * remove unsupported test case --- RELEASE-NOTES.md | 1 + .../content/features/encrypt/appendix.cn.md | 2 + .../content/features/encrypt/appendix.en.md | 2 + .../sql/EncryptSupportedSQLCheckersBuilder.java | 8 ++- .../EncryptCombineClauseSupportedChecker.java | 63 ++++++++++++++++++++ .../EncryptInsertSelectSupportedChecker.java | 51 ++++++++++++++++ .../with/EncryptWithClauseSupportedChecker.java | 51 ++++++++++++++++ .../EncryptCombineClauseSupportedCheckerTest.java | 67 ++++++++++++++++++++++ .../EncryptInsertSelectSupportedCheckerTest.java | 67 ++++++++++++++++++++++ .../EncryptWithClauseSupportedCheckerTest.java | 67 ++++++++++++++++++++++ .../statement/dml/DeleteStatementContext.java | 14 ++++- .../statement/dml/InsertStatementContext.java | 9 ++- .../statement/dml/SelectStatementContext.java | 19 ++++-- .../statement/dml/UpdateStatementContext.java | 10 +++- .../infra/binder/context/type/WithAvailable.java | 35 +++++++++++ .../dataset/encrypt/insert_select_user_table.xml | 60 ------------------- .../tbl/batch_insert_all_into_order_table.xml | 48 ---------------- .../tbl/batch_insert_into_order_with_select.xml | 51 ---------------- .../tbl/insert_into_order_table_with_select.xml | 50 ---------------- .../test/resources/cases/dml/e2e-dml-insert.xml | 18 +----- 20 files changed, 455 insertions(+), 238 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 37de7afcafb..09a98277429 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -46,6 +46,7 @@ 1. SQL Binder: Support truncate table sql bind and add test case - [#34162](https://github.com/apache/shardingsphere/pull/34162) 1. SQL Binder: Support create view, alter view, drop view sql bind logic - [#34167](https://github.com/apache/shardingsphere/pull/34167) 1. Transaction: Support savepoint/release savepoint TCL statements in jdbc adapter -[#34173](https://github.com/apache/shardingsphere/pull/34173) +1. Kernel: Add WithAvailable interface and encrypt with, combine, insert select support checker - [#34175](https://github.com/apache/shardingsphere/pull/34175) ### Bug Fixes diff --git a/docs/document/content/features/encrypt/appendix.cn.md b/docs/document/content/features/encrypt/appendix.cn.md index 43adc4bce47..c1ab43bb03d 100644 --- a/docs/document/content/features/encrypt/appendix.cn.md +++ b/docs/document/content/features/encrypt/appendix.cn.md @@ -9,6 +9,8 @@ weight = 3 - 加密字段无法支持比较操作,如:大于、小于、ORDER BY、BETWEEN 等; - 加密字段无法支持计算操作,如:AVG、SUM 以及计算表达式; - 不支持子查询中包含加密字段,并且外层投影使用星号的 SQL; +- 不支持 WITH 语句中包含加密列; +- 不支持 INSERT SELECT 语句中包含加密列; - 不支持 UNION、INTERSECT、EXCEPT 等集合运算语句中包含加密列。 其他: diff --git a/docs/document/content/features/encrypt/appendix.en.md b/docs/document/content/features/encrypt/appendix.en.md index a729ee62cc4..e347d56a0e4 100644 --- a/docs/document/content/features/encrypt/appendix.en.md +++ b/docs/document/content/features/encrypt/appendix.en.md @@ -9,6 +9,8 @@ Unsupported SQL: - Comparison operations are not supported for encrypted fields, such as GREATER THAN, LESS THAN, ORDER BY, BETWEEN. - Calculation operations are not supported for encrypted fields, such as AVG, SUM, and computation expressions. - SQL that contains encrypt column in subquery and uses asterisks for outer projection is not supported. +- SQL that contains encrypt column in WITH is not supported. +- SQL that contains encrypt column in INSERT SELECT is not supported. - SQL that contains encrypt column in UNION, INTERSECT, and EXCEPT statements is not supported. Other: diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/EncryptSupportedSQLCheckersBuilder.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/EncryptSupportedSQLCheckersBuilder.java index fce03c66f10..a74b1d0c64d 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/EncryptSupportedSQLCheckersBuilder.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/EncryptSupportedSQLCheckersBuilder.java @@ -17,10 +17,13 @@ package org.apache.shardingsphere.encrypt.checker.sql; +import org.apache.shardingsphere.encrypt.checker.sql.combine.EncryptCombineClauseSupportedChecker; +import org.apache.shardingsphere.encrypt.checker.sql.insert.EncryptInsertSelectSupportedChecker; import org.apache.shardingsphere.encrypt.checker.sql.orderby.EncryptOrderByItemSupportedChecker; import org.apache.shardingsphere.encrypt.checker.sql.predicate.EncryptPredicateColumnSupportedChecker; import org.apache.shardingsphere.encrypt.checker.sql.projection.EncryptInsertSelectProjectionSupportedChecker; import org.apache.shardingsphere.encrypt.checker.sql.projection.EncryptSelectProjectionSupportedChecker; +import org.apache.shardingsphere.encrypt.checker.sql.with.EncryptWithClauseSupportedChecker; import org.apache.shardingsphere.encrypt.constant.EncryptOrder; import org.apache.shardingsphere.encrypt.rule.EncryptRule; import org.apache.shardingsphere.infra.checker.SupportedSQLChecker; @@ -40,7 +43,10 @@ public final class EncryptSupportedSQLCheckersBuilder implements SupportedSQLChe new EncryptSelectProjectionSupportedChecker(), new EncryptInsertSelectProjectionSupportedChecker(), new EncryptPredicateColumnSupportedChecker(), - new EncryptOrderByItemSupportedChecker()); + new EncryptOrderByItemSupportedChecker(), + new EncryptWithClauseSupportedChecker(), + new EncryptCombineClauseSupportedChecker(), + new EncryptInsertSelectSupportedChecker()); } @Override diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/combine/EncryptCombineClauseSupportedChecker.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/combine/EncryptCombineClauseSupportedChecker.java new file mode 100644 index 00000000000..d1ae2995bfb --- /dev/null +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/combine/EncryptCombineClauseSupportedChecker.java @@ -0,0 +1,63 @@ +/* + * 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.encrypt.checker.sql.combine; + +import org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException; +import org.apache.shardingsphere.encrypt.rule.EncryptRule; +import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; +import org.apache.shardingsphere.infra.binder.context.extractor.SQLStatementContextExtractor; +import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; +import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; +import org.apache.shardingsphere.infra.checker.SupportedSQLChecker; +import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; +import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; + +import java.util.Collection; + +/** + * Combine clause supported checker for encrypt. + */ +@HighFrequencyInvocation +public final class EncryptCombineClauseSupportedChecker implements SupportedSQLChecker<SQLStatementContext, EncryptRule> { + + @Override + public boolean isCheck(final SQLStatementContext sqlStatementContext) { + if (isContainsCombine(sqlStatementContext)) { + return true; + } + for (SelectStatementContext each : SQLStatementContextExtractor.getAllSubqueryContexts(sqlStatementContext)) { + if (isContainsCombine(each)) { + return true; + } + } + return false; + } + + private static boolean isContainsCombine(final SQLStatementContext sqlStatementContext) { + return sqlStatementContext instanceof SelectStatementContext && ((SelectStatementContext) sqlStatementContext).isContainsCombine(); + } + + @Override + public void check(final EncryptRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final SQLStatementContext sqlStatementContext) { + Collection<String> tableNames = SQLStatementContextExtractor.getTableNames(database, sqlStatementContext); + for (String each : tableNames) { + ShardingSpherePreconditions.checkState(!rule.findEncryptTable(each).isPresent(), () -> new UnsupportedEncryptSQLException("COMBINE")); + } + } +} diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/insert/EncryptInsertSelectSupportedChecker.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/insert/EncryptInsertSelectSupportedChecker.java new file mode 100644 index 00000000000..a5746d2e3fa --- /dev/null +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/insert/EncryptInsertSelectSupportedChecker.java @@ -0,0 +1,51 @@ +/* + * 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.encrypt.checker.sql.insert; + +import org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException; +import org.apache.shardingsphere.encrypt.rule.EncryptRule; +import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; +import org.apache.shardingsphere.infra.binder.context.extractor.SQLStatementContextExtractor; +import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; +import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; +import org.apache.shardingsphere.infra.checker.SupportedSQLChecker; +import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; +import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; + +import java.util.Collection; + +/** + * Insert select supported checker for encrypt. + */ +@HighFrequencyInvocation +public final class EncryptInsertSelectSupportedChecker implements SupportedSQLChecker<InsertStatementContext, EncryptRule> { + + @Override + public boolean isCheck(final SQLStatementContext sqlStatementContext) { + return sqlStatementContext instanceof InsertStatementContext && ((InsertStatementContext) sqlStatementContext).getSqlStatement().getInsertSelect().isPresent(); + } + + @Override + public void check(final EncryptRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final InsertStatementContext sqlStatementContext) { + Collection<String> tableNames = SQLStatementContextExtractor.getTableNames(database, sqlStatementContext); + for (String each : tableNames) { + ShardingSpherePreconditions.checkState(!rule.findEncryptTable(each).isPresent(), () -> new UnsupportedEncryptSQLException("INSERT ... SELECT ...")); + } + } +} diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/with/EncryptWithClauseSupportedChecker.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/with/EncryptWithClauseSupportedChecker.java new file mode 100644 index 00000000000..7b0687eeaf4 --- /dev/null +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/with/EncryptWithClauseSupportedChecker.java @@ -0,0 +1,51 @@ +/* + * 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.encrypt.checker.sql.with; + +import org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException; +import org.apache.shardingsphere.encrypt.rule.EncryptRule; +import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation; +import org.apache.shardingsphere.infra.binder.context.extractor.SQLStatementContextExtractor; +import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; +import org.apache.shardingsphere.infra.binder.context.type.WithAvailable; +import org.apache.shardingsphere.infra.checker.SupportedSQLChecker; +import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; +import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; + +import java.util.Collection; + +/** + * With clause supported checker for encrypt. + */ +@HighFrequencyInvocation +public final class EncryptWithClauseSupportedChecker implements SupportedSQLChecker<SQLStatementContext, EncryptRule> { + + @Override + public boolean isCheck(final SQLStatementContext sqlStatementContext) { + return sqlStatementContext instanceof WithAvailable && ((WithAvailable) sqlStatementContext).getWith().isPresent(); + } + + @Override + public void check(final EncryptRule rule, final ShardingSphereDatabase database, final ShardingSphereSchema currentSchema, final SQLStatementContext sqlStatementContext) { + Collection<String> tableNames = SQLStatementContextExtractor.getTableNames(database, sqlStatementContext); + for (String each : tableNames) { + ShardingSpherePreconditions.checkState(!rule.findEncryptTable(each).isPresent(), () -> new UnsupportedEncryptSQLException("WITH")); + } + } +} diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/combine/EncryptCombineClauseSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/combine/EncryptCombineClauseSupportedCheckerTest.java new file mode 100644 index 00000000000..58b5bbe032d --- /dev/null +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/combine/EncryptCombineClauseSupportedCheckerTest.java @@ -0,0 +1,67 @@ +/* + * 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.encrypt.checker.sql.combine; + +import org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException; +import org.apache.shardingsphere.encrypt.rewrite.token.generator.fixture.EncryptGeneratorFixtureBuilder; +import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; +import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class EncryptCombineClauseSupportedCheckerTest { + + @Test + void assertIsCheck() { + SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); + when(sqlStatementContext.isContainsCombine()).thenReturn(true); + assertTrue(new EncryptCombineClauseSupportedChecker().isCheck(sqlStatementContext)); + } + + @Test + void assertIsCheckWithoutCombineClause() { + assertFalse(new EncryptCombineClauseSupportedChecker().isCheck(mock(SQLStatementContext.class))); + } + + @Test + void assertCheckWithoutEncryptTable() { + assertDoesNotThrow(() -> new EncryptCombineClauseSupportedChecker() + .check(EncryptGeneratorFixtureBuilder.createEncryptRule(), null, null, mockSelectStatementContext("t_order"))); + } + + @Test + void assertCheckWithEncryptTable() { + assertThrows(UnsupportedEncryptSQLException.class, () -> new EncryptCombineClauseSupportedChecker() + .check(EncryptGeneratorFixtureBuilder.createEncryptRule(), null, null, mockSelectStatementContext("t_user"))); + } + + private SQLStatementContext mockSelectStatementContext(final String tableName) { + SelectStatementContext result = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); + when(result.getTablesContext().getTableNames()).thenReturn(Collections.singleton(tableName)); + return result; + } +} diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/insert/EncryptInsertSelectSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/insert/EncryptInsertSelectSupportedCheckerTest.java new file mode 100644 index 00000000000..fc3dd9beb83 --- /dev/null +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/insert/EncryptInsertSelectSupportedCheckerTest.java @@ -0,0 +1,67 @@ +/* + * 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.encrypt.checker.sql.insert; + +import org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException; +import org.apache.shardingsphere.encrypt.rewrite.token.generator.fixture.EncryptGeneratorFixtureBuilder; +import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; +import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext; +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class EncryptInsertSelectSupportedCheckerTest { + + @Test + void assertIsCheck() { + InsertStatementContext sqlStatementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS); + when(sqlStatementContext.getSqlStatement().getInsertSelect().isPresent()).thenReturn(true); + assertTrue(new EncryptInsertSelectSupportedChecker().isCheck(sqlStatementContext)); + } + + @Test + void assertIsCheckWithoutCombineClause() { + assertFalse(new EncryptInsertSelectSupportedChecker().isCheck(mock(SQLStatementContext.class))); + } + + @Test + void assertCheckWithoutEncryptTable() { + assertDoesNotThrow(() -> new EncryptInsertSelectSupportedChecker() + .check(EncryptGeneratorFixtureBuilder.createEncryptRule(), null, null, mockInsertStatementContext("t_order"))); + } + + @Test + void assertCheckWithEncryptTable() { + assertThrows(UnsupportedEncryptSQLException.class, () -> new EncryptInsertSelectSupportedChecker() + .check(EncryptGeneratorFixtureBuilder.createEncryptRule(), null, null, mockInsertStatementContext("t_user"))); + } + + private InsertStatementContext mockInsertStatementContext(final String tableName) { + InsertStatementContext result = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS); + when(result.getTablesContext().getTableNames()).thenReturn(Collections.singleton(tableName)); + return result; + } +} diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/with/EncryptWithClauseSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/with/EncryptWithClauseSupportedCheckerTest.java new file mode 100644 index 00000000000..31489bebfc4 --- /dev/null +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/with/EncryptWithClauseSupportedCheckerTest.java @@ -0,0 +1,67 @@ +/* + * 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.encrypt.checker.sql.with; + +import org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException; +import org.apache.shardingsphere.encrypt.rewrite.token.generator.fixture.EncryptGeneratorFixtureBuilder; +import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; +import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class EncryptWithClauseSupportedCheckerTest { + + @Test + void assertIsCheck() { + SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); + when(sqlStatementContext.getWith().isPresent()).thenReturn(true); + assertTrue(new EncryptWithClauseSupportedChecker().isCheck(sqlStatementContext)); + } + + @Test + void assertIsCheckWithoutWithAvailable() { + assertFalse(new EncryptWithClauseSupportedChecker().isCheck(mock(SQLStatementContext.class))); + } + + @Test + void assertCheckWithoutEncryptTable() { + assertDoesNotThrow(() -> new EncryptWithClauseSupportedChecker() + .check(EncryptGeneratorFixtureBuilder.createEncryptRule(), null, null, mockSelectStatementContext("t_order"))); + } + + @Test + void assertCheckWithEncryptTable() { + assertThrows(UnsupportedEncryptSQLException.class, () -> new EncryptWithClauseSupportedChecker() + .check(EncryptGeneratorFixtureBuilder.createEncryptRule(), null, null, mockSelectStatementContext("t_user"))); + } + + private SQLStatementContext mockSelectStatementContext(final String tableName) { + SelectStatementContext result = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); + when(result.getTablesContext().getTableNames()).thenReturn(Collections.singleton(tableName)); + return result; + } +} diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContext.java index d5a01ab9b1e..a7bdfb95a38 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContext.java @@ -22,25 +22,28 @@ import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContex import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable; +import org.apache.shardingsphere.infra.binder.context.type.WithAvailable; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.WithSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DeleteStatement; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; +import java.util.Optional; /** * Delete statement context. */ @Getter -public final class DeleteStatementContext extends CommonSQLStatementContext implements TableAvailable, WhereAvailable { +public final class DeleteStatementContext extends CommonSQLStatementContext implements TableAvailable, WhereAvailable, WithAvailable { private final TablesContext tablesContext; @@ -103,4 +106,9 @@ public final class DeleteStatementContext extends CommonSQLStatementContext impl public Collection<BinaryOperationExpression> getJoinConditions() { return joinConditions; } + + @Override + public Optional<WithSegment> getWith() { + return getSqlStatement().getWithSegment(); + } } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContext.java index 4b8de3e31b5..a2a30fbea34 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContext.java @@ -29,6 +29,7 @@ import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContex import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable; +import org.apache.shardingsphere.infra.binder.context.type.WithAvailable; import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.NoDatabaseSelectedException; @@ -48,6 +49,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.Bina import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.WithSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement; @@ -65,7 +67,7 @@ import java.util.concurrent.atomic.AtomicInteger; /** * Insert SQL statement context. */ -public final class InsertStatementContext extends CommonSQLStatementContext implements TableAvailable, ParameterAware, WhereAvailable { +public final class InsertStatementContext extends CommonSQLStatementContext implements TableAvailable, ParameterAware, WhereAvailable, WithAvailable { private final ShardingSphereMetaData metaData; @@ -331,4 +333,9 @@ public final class InsertStatementContext extends CommonSQLStatementContext impl public Collection<BinaryOperationExpression> getJoinConditions() { return null == insertSelectContext ? Collections.emptyList() : insertSelectContext.getSelectStatementContext().getJoinConditions(); } + + @Override + public Optional<WithSegment> getWith() { + return getSqlStatement().getWithSegment(); + } } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java index 36d9a28221d..45540103877 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java @@ -40,6 +40,7 @@ import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContex import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable; +import org.apache.shardingsphere.infra.binder.context.type.WithAvailable; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.NoDatabaseSelectedException; import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.UnknownDatabaseException; @@ -48,6 +49,11 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; import org.apache.shardingsphere.sql.parser.statement.core.enums.ParameterMarkerType; import org.apache.shardingsphere.sql.parser.statement.core.enums.SubqueryType; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.SubqueryExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.WhereExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; @@ -59,17 +65,13 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.ite import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.item.OrderByItemSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.item.TextOrderByItemSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.WithSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.JoinTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SubqueryTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; import org.apache.shardingsphere.sql.parser.statement.core.util.SQLUtils; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.SubqueryExtractor; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.WhereExtractor; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import java.util.Collection; @@ -86,7 +88,7 @@ import java.util.stream.Collectors; */ @Getter @Setter -public final class SelectStatementContext extends CommonSQLStatementContext implements TableAvailable, WhereAvailable, ParameterAware { +public final class SelectStatementContext extends CommonSQLStatementContext implements TableAvailable, WhereAvailable, ParameterAware, WithAvailable { private final TablesContext tablesContext; @@ -419,4 +421,9 @@ public final class SelectStatementContext extends CommonSQLStatementContext impl public void setUpParameters(final List<Object> params) { paginationContext = new PaginationContextEngine(getDatabaseType()).createPaginationContext(getSqlStatement(), projectionsContext, params, whereSegments); } + + @Override + public Optional<WithSegment> getWith() { + return getSqlStatement().getWithSegment(); + } } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContext.java index b8f1ad79bdc..999c576a558 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContext.java @@ -22,23 +22,26 @@ import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContex import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable; +import org.apache.shardingsphere.infra.binder.context.type.WithAvailable; import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.WithSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.UpdateStatement; import java.util.Collection; import java.util.LinkedList; +import java.util.Optional; /** * Update SQL statement context. */ @Getter -public final class UpdateStatementContext extends CommonSQLStatementContext implements TableAvailable, WhereAvailable { +public final class UpdateStatementContext extends CommonSQLStatementContext implements TableAvailable, WhereAvailable, WithAvailable { private final TablesContext tablesContext; @@ -76,4 +79,9 @@ public final class UpdateStatementContext extends CommonSQLStatementContext impl public Collection<ColumnSegment> getColumnSegments() { return columnSegments; } + + @Override + public Optional<WithSegment> getWith() { + return getSqlStatement().getWithSegment(); + } } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/type/WithAvailable.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/type/WithAvailable.java new file mode 100644 index 00000000000..310c7b1380a --- /dev/null +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/type/WithAvailable.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.infra.binder.context.type; + +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.WithSegment; + +import java.util.Optional; + +/** + * With available. + */ +public interface WithAvailable { + + /** + * Get with segement. + * + * @return with segement + */ + Optional<WithSegment> getWith(); +} diff --git a/test/e2e/sql/src/test/resources/cases/dml/dataset/encrypt/insert_select_user_table.xml b/test/e2e/sql/src/test/resources/cases/dml/dataset/encrypt/insert_select_user_table.xml deleted file mode 100644 index f6b7dd5e98a..00000000000 --- a/test/e2e/sql/src/test/resources/cases/dml/dataset/encrypt/insert_select_user_table.xml +++ /dev/null @@ -1,60 +0,0 @@ -<!-- - ~ 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. - --> - -<dataset update-count="1"> - <metadata data-nodes="encrypt.t_user"> - <column name="user_id" type="numeric" /> - <column name="user_name_cipher" type="varchar" /> - <column name="user_name_like" type="varchar" /> - <column name="password_cipher" type="varchar" /> - <column name="email_cipher" type="varchar" /> - <column name="user_telephone_cipher" type="varchar" /> - <column name="user_telephone_like" type="varchar" /> - <column name="creation_date" type="datetime" /> - </metadata> - <row data-node="encrypt.t_user" values="10, sVq8Lmm+j6bZE5EKSilJEQ==, yi`mht`m, aQol0b6th65d0aXe+zFPsQ==, WM0fHOH91JNWnHTkiqBdyNmzk4uJ7CCz4mB1va9Ya1M=, kLjLJIMnfyHT2nA+viaoaQ==, 01454589811, 2017-08-08" /> - <row data-node="encrypt.t_user" values="11, fQ7IzBxKVuNHtUF6h6WSBg==, mhth, wuhmEKgdgrWQYt+Ev0hgGA==, svATu3uWv9KfiloWJeWx3A==, 0kDFxndQdzauFwL/wyCsNQ==, 01454589810, 2017-08-08" /> - <row data-node="encrypt.t_user" values="12, AQRWSlufQPog/b64YRhu6Q==, x`mhxt, x7A+2jq9B6DSOSFtSOibdA==, nHJv9e6NiClIuGHOjHLvCAq2ZLhWcqfQ8/EQnIqMx+g=, a/SzSJLapt5iBXvF2c9ycw==, 01454589811, 2017-08-08" /> - <row data-node="encrypt.t_user" values="13, 5NqS4YvpT+mHBFqZOZ3QDA==, yi`pmht, zi6b4xYRjjV+bBk2R4wB+w==, MLBZczLjriUXvg3aM5QPTxMJbLjNh8yeNrSNBek/VTw=, b6VVhG+F6ujG8IMUZJAIFg==, 01454589814, 2017-08-08" /> - <row data-node="encrypt.t_user" values="14, qeIY9od3u1KwhjihzLQUTQ==, yitph, 51UmlLAC+tUvdOAj8CjWfQ==, JCmeNdPyrKO5BW5zvhAA+g==, f995xinpZdKMVU5J5/yv3w==, 01454589815, 2017-08-08" /> - <row data-node="encrypt.t_user" values="15, VbNUtguwtpeGhHGnPJ3aXg==, mha`, +3/5CVbqoKhg3sqznKTFFQ==, T+X+e3Q3+ZNIXXmg/80uxg==, GETj+S6DrO042E7NuBXLBQ==, 01454589814, 2017-08-08" /> - <row data-node="encrypt.t_user" values="16, U0/Ao/w1u7L5avR3fAH2Og==, x`mhiht, jFfFMYxv02DjaFRuAoCDGw==, RNW/KRq5HeL2YTfAdXSyARMJbLjNh8yeNrSNBek/VTw=, +lbvjJwO7VO4HUKc0Mw0NA==, 01454589815, 2017-08-08" /> - <row data-node="encrypt.t_user" values="17, zb1sgBigoMi7JPSoY4bAVw==, yite`, VFIjocgjujJCJc6waWXqJA==, 1vF/ET3nBxt7T7vVfAndZQ==, wFvs5BH6OikgveBeTEBwsQ==, 01454589818, 2017-08-08" /> - <row data-node="encrypt.t_user" values="18, rJzNIrFEnx296kW+N1YmMw==, ttmdq, LaODSKGyR7vZ1IvmBOe9vA==, 5u4GIQkJsWRmnJHWaHNSjg==, uwqm2O1Lv2tNTraJX1ym7Q==, 01454589819, 2017-08-08" /> - <row data-node="encrypt.t_user" values="19, qHwpQ9kteL8VX6iTUhNdbQ==, yiptt`m, MyOShk4kjRnds7CZfU5NCw==, HmYCo7QBfJ2E0EvaGHBCOBMJbLjNh8yeNrSNBek/VTw=, YLNQuuUPMGA21nhKWPzzsg==, 01454589818, 2017-08-08" /> - <row data-node="encrypt.t_user" values="20, qCCmvf7OWRxbVbtLb0az1g==, upl, fzdTMkzpBvgNYmKSQAp8Fg==, gOoP4Mf0P4ISOJp6A4sRmg==, l4xa4HwOfs/jusoJon9Wzw==, 01454589801, 2017-08-08" /> - <row data-node="encrypt.t_user" values="21, IYJ1COaRQ0gSjWMC/UAeMg==, lpad, 1uEDMeYh2jstbOf6kx/cqw==, tikMAFiQ37u2VgWqUT38Eg==, rGpr30UXfczXjCjdvPN+BA==, 01454589800, 2017-08-08" /> - <row data-node="encrypt.t_user" values="22, 7wvZZ7NVHgk6m1vB/sTC1Q==, idqqx, OirN3gvz9uBnrq88nfa1wQ==, T7K/Uz1O2m+3xvB0+c4nGQ==, 7+fCU+VbQZKgLJXZPTTegA==, 01454589801, 2017-08-08" /> - <row data-node="encrypt.t_user" values="23, SbVQWl8JbnxflCfGJ7KZdA==, i`ldt, hWVVYdkdTUTgm08haeq+tw==, Uk3ju6GteCD1qEHns5ZhKA==, DpnV86FZefwBRmIAVBh2gg==, 01454589804, 2017-08-08" /> - <row data-node="encrypt.t_user" values="24, fx7OfSAYqVpjNa7LoKhXvw==, x`ed, N2W9ijAXNkBxhkvJiIwp0A==, lAAGItVLmb1H69++1MDrIA==, QrE62wAb8B+2cEPcs4Lm1Q==, 01454589805, 2017-08-08" /> - <row data-node="encrypt.t_user" values="25, wH3/LdWShD9aCb8eCIm3Tg==, qptd, GDixtt6NzPOVv6H0dmov5g==, T1yfJSyVxumZUfkDnmUQxA==, iU+AsGczboCRfU+Zr7mcpw==, 01454589804, 2017-08-08" /> - <row data-node="encrypt.t_user" values="26, GgJQTndbxyBZ2tECS8SmqQ==, apti, gLgVFLFIyyKwdQCXaw78Ag==, O+JIn9XZ3yq6RnKElHuqlA==, kwYlbu9aF7ndvMTcj8QBSg==, 01454589805, 2017-08-08" /> - <row data-node="encrypt.t_user" values="27, lv8w8g32kuTXNvSUUypOig==, i`dl, 8i0YH2mn6kXSyvBjM5p+Yg==, gqRoJF5S66SvBalc2RCo1A==, 2ob/3UYqRsZA5VdScnaWxQ==, 01454589808, 2017-08-08" /> - <row data-node="encrypt.t_user" values="28, P9YCbFvWCIhcS99KyKH2zA==, ipqe`m, PRrI4z4FrWwLvcHPx9g4og==, y8q31Jj4PFSyZHiLVIxKEQq2ZLhWcqfQ8/EQnIqMx+g=, kDF2za26uOerlNYWYHRT2Q==, 01454589809, 2017-08-08" /> - <row data-node="encrypt.t_user" values="29, 5wu9XvlJAVtjKijhxt6SQQ==, itmhd, O4pgkLgz34N+C4bIUOQVnA==, UH7ihg16J61Np/EYMQnXIA==, z2hbJQD4dRkVVITNxAac5Q==, 01454589808, 2017-08-08" /> - <row data-node="encrypt.t_user" values="30, i50fpEe3j0VOy/Hbfmr5Bg==, 兹卜, MyOShk4kjRnds7CZfU5NCw==, WM0fHOH91JNWnHTkiqBdyNmzk4uJ7CCz4mB1va9Ya1M=, uRbQGcAhuXmxdIzRsgiy8g==, 09101401454, 2017-08-08" /> - <row data-node="encrypt.t_user" values="31, wLXX1Gs7zl0PkyJRMIxmCQ==, 兹付, fzdTMkzpBvgNYmKSQAp8Fg==, cq1LN85LmWHrEtS4gN/ac9mzk4uJ7CCz4mB1va9Ya1M=, jDL+p5OyKQXfQ4H8JpNKJQ==, 09101401454, 2017-08-08" /> - <row data-node="encrypt.t_user" values="32, 5NNYIZCq4Dxab0uKWXt93A==, 兹咔, 1uEDMeYh2jstbOf6kx/cqw==, rehTd++DbFy3qYqeDJUjRRMJbLjNh8yeNrSNBek/VTw=, 60fpnMdKCWeyKzxkdthn2Q==, 09101401454, 2017-08-08" /> - <row data-node="encrypt.t_user" values="33, 8kgeyqYaHUMq6di5BVt3Ow==, 伴伌, OirN3gvz9uBnrq88nfa1wQ==, svATu3uWv9KfiloWJeWx3A==, 60fpnMdKCWeyKzxkdthn2Q==, 09101401454, 2017-08-08" /> - <row data-node="encrypt.t_user" values="34, THN1NIcHrqnfvPKR92lAKw==, 伴侁, ZSU1lmpj8cugQHD59QxPhQ==, KtMacpLCtRTSl+VeCPYrPwq2ZLhWcqfQ8/EQnIqMx+g=, 60fpnMdKCWeyKzxkdthn2Q==, 09101401454, 2017-08-08" /> - <row data-node="encrypt.t_user" values="35, R3tsv8yeGKXz7WXLYfjkPA==, 伈夸噥, 31jh3gwg1fgDFnd6iYxU+Q==, ZsrMzd0mjJ9H3fxe4UNVfQsU49iKH47f2rb+/uKuo9M=, 60fpnMdKCWeyKzxkdthn2Q==, 09101401454, 2017-08-08" /> - <row data-node="encrypt.t_user" values="36, M2hIFm7Z/s4zGd+rPD1USA==, 伈僘噭, bO/8ha1eS/H8/3DugjdOAQ==, PyO5yO0W8v5cpLPhqASTHA==, 60fpnMdKCWeyKzxkdthn2Q==, 09101401454, 2017-08-08" /> - <row data-node="encrypt.t_user" values="37, aXS0VfnqHIAnOAtDjsF/9Q==, 伈嶱啴, bO/8ha1eS/H8/3DugjdOAQ==, fwyOxfHtLxNuSCFmghYiY0qMsgbpjg5UIo3xmJOLGu0=, 60fpnMdKCWeyKzxkdthn2Q==, 09101401454, 2017-08-08" /> - <row data-node="encrypt.t_user" values="38, 59/68izQEdnwNSueX1lPAA==, 伈乄, ilD/Tk7DUG4+EuznS1bNLg==, 2emhAeiXPr0kHbFrhYlM1dmzk4uJ7CCz4mB1va9Ya1M=, 60fpnMdKCWeyKzxkdthn2Q==, 09101401454, 2017-08-08" /> - <row data-node="encrypt.t_user" values="39, fn9LnNltUAOWO0F0iy0+Jw==, 伈妅, qe/WdUiSPP1RAsSSuejGJw==, zx2omwIbXHpEJeh8ta7HqQq2ZLhWcqfQ8/EQnIqMx+g=, 60fpnMdKCWeyKzxkdthn2Q==, 09101401454, 2017-08-08" /> - <row data-node="encrypt.t_user" values="40, fQ7IzBxKVuNHtUF6h6WSBg==, mhth, wuhmEKgdgrWQYt+Ev0hgGA==, svATu3uWv9KfiloWJeWx3A==, 0kDFxndQdzauFwL/wyCsNQ==, 01454589810, 2017-08-08" /> -</dataset> diff --git a/test/e2e/sql/src/test/resources/cases/dml/dataset/tbl/batch_insert_all_into_order_table.xml b/test/e2e/sql/src/test/resources/cases/dml/dataset/tbl/batch_insert_all_into_order_table.xml deleted file mode 100644 index 0d828f0bbef..00000000000 --- a/test/e2e/sql/src/test/resources/cases/dml/dataset/tbl/batch_insert_all_into_order_table.xml +++ /dev/null @@ -1,48 +0,0 @@ -<!-- - ~ 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. - --> - -<dataset update-count="1"> - <metadata data-nodes="tbl.t_order_${0..9}"> - <column name="order_id" type="numeric" /> - <column name="user_id" type="numeric" /> - <column name="status" type="varchar" /> - <column name="merchant_id" type="numeric" /> - <column name="remark" type="varchar" /> - <column name="creation_date" type="datetime" /> - </metadata> - <row data-node="tbl.t_order_0" values="1000, 10, init, 1, test, 2017-08-08" /> - <row data-node="tbl.t_order_1" values="1001, 10, init, 2, test, 2017-08-08" /> - <row data-node="tbl.t_order_2" values="1002, 10, init, 3, test, 2017-08-08" /> - <row data-node="tbl.t_order_3" values="1003, 10, init, 4, test, 2017-08-08" /> - <row data-node="tbl.t_order_4" values="1004, 10, init, 5, test, 2017-08-08" /> - <row data-node="tbl.t_order_5" values="1005, 10, init, 6, test, 2017-08-08" /> - <row data-node="tbl.t_order_6" values="1006, 10, init, 7, test, 2017-08-08" /> - <row data-node="tbl.t_order_7" values="1007, 10, init, 8, test, 2017-08-08" /> - <row data-node="tbl.t_order_8" values="1008, 10, init, 9, test, 2017-08-08" /> - <row data-node="tbl.t_order_9" values="999, 10, insertALL, 1, test, 2017-08-08" /> - <row data-node="tbl.t_order_9" values="1009, 10, init, 10, test, 2017-08-08" /> - <row data-node="tbl.t_order_0" values="1100, 11, init, 11, test, 2017-08-08" /> - <row data-node="tbl.t_order_1" values="1101, 11, init, 12, test, 2017-08-08" /> - <row data-node="tbl.t_order_2" values="1102, 11, init, 13, test, 2017-08-08" /> - <row data-node="tbl.t_order_3" values="1103, 11, init, 14, test, 2017-08-08" /> - <row data-node="tbl.t_order_4" values="1104, 11, init, 15, test, 2017-08-08" /> - <row data-node="tbl.t_order_5" values="1105, 11, init, 16, test, 2017-08-08" /> - <row data-node="tbl.t_order_6" values="1106, 11, init, 17, test, 2017-08-08" /> - <row data-node="tbl.t_order_7" values="1107, 11, init, 18, test, 2017-08-08" /> - <row data-node="tbl.t_order_8" values="1108, 11, init, 19, test, 2017-08-08" /> - <row data-node="tbl.t_order_9" values="1109, 11, init, 20, test, 2017-08-08" /> -</dataset> diff --git a/test/e2e/sql/src/test/resources/cases/dml/dataset/tbl/batch_insert_into_order_with_select.xml b/test/e2e/sql/src/test/resources/cases/dml/dataset/tbl/batch_insert_into_order_with_select.xml deleted file mode 100644 index 2b8e29be71a..00000000000 --- a/test/e2e/sql/src/test/resources/cases/dml/dataset/tbl/batch_insert_into_order_with_select.xml +++ /dev/null @@ -1,51 +0,0 @@ -<!-- - ~ 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. - --> - -<dataset update-count="2"> - <metadata data-nodes="tbl.t_order_${0..9}"> - <column name="order_id" type="numeric" /> - <column name="user_id" type="numeric" /> - <column name="status" type="varchar" /> - <column name="merchant_id" type="numeric" /> - <column name="remark" type="varchar" /> - <column name="creation_date" type="datetime" /> - </metadata> - <row data-node="tbl.t_order_0" values="1000, 10, init, 1, test, 2017-08-08" /> - <row data-node="tbl.t_order_1" values="1, 1, insert, 1, test, 2017-08-08" /> - <row data-node="tbl.t_order_1" values="1001, 10, init, 2, test, 2017-08-08" /> - <row data-node="tbl.t_order_2" values="2, 2, insert, 2, test, 2017-08-08" /> - <row data-node="tbl.t_order_2" values="1002, 10, init, 3, test, 2017-08-08" /> - <row data-node="tbl.t_order_3" values="1003, 10, init, 4, test, 2017-08-08" /> - <row data-node="tbl.t_order_4" values="1004, 10, init, 5, test, 2017-08-08" /> - <row data-node="tbl.t_order_5" values="1005, 10, init, 6, test, 2017-08-08" /> - <row data-node="tbl.t_order_6" values="1006, 10, init, 7, test, 2017-08-08" /> - <row data-node="tbl.t_order_7" values="1007, 10, init, 8, test, 2017-08-08" /> - <row data-node="tbl.t_order_8" values="1008, 10, init, 9, test, 2017-08-08" /> - <row data-node="tbl.t_order_9" values="1009, 10, init, 10, test, 2017-08-08" /> - <row data-node="tbl.t_order_0" values="1100, 11, init, 11, test, 2017-08-08" /> - <row data-node="tbl.t_order_1" values="1101, 11, init, 12, test, 2017-08-08" /> - <row data-node="tbl.t_order_2" values="1102, 11, init, 13, test, 2017-08-08" /> - <row data-node="tbl.t_order_3" values="1103, 11, init, 14, test, 2017-08-08" /> - <row data-node="tbl.t_order_4" values="1104, 11, init, 15, test, 2017-08-08" /> - <row data-node="tbl.t_order_5" values="1105, 11, init, 16, test, 2017-08-08" /> - <row data-node="tbl.t_order_6" values="1106, 11, init, 17, test, 2017-08-08" /> - <row data-node="tbl.t_order_7" values="1107, 11, init, 18, test, 2017-08-08" /> - <row data-node="tbl.t_order_8" values="1108, 11, init, 19, test, 2017-08-08" /> - <row data-node="tbl.t_order_8" values="998, 10, insertALL, 1, test, 2017-08-08" /> - <row data-node="tbl.t_order_9" values="1109, 11, init, 20, test, 2017-08-08" /> - <row data-node="tbl.t_order_9" values="999, 10, insertALL, 1, test, 2017-08-08" /> -</dataset> diff --git a/test/e2e/sql/src/test/resources/cases/dml/dataset/tbl/insert_into_order_table_with_select.xml b/test/e2e/sql/src/test/resources/cases/dml/dataset/tbl/insert_into_order_table_with_select.xml deleted file mode 100644 index 829a8182455..00000000000 --- a/test/e2e/sql/src/test/resources/cases/dml/dataset/tbl/insert_into_order_table_with_select.xml +++ /dev/null @@ -1,50 +0,0 @@ -<!-- - ~ 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. - --> - -<dataset update-count="2"> - <metadata data-nodes="tbl.t_order_${0..9}"> - <column name="order_id" type="numeric" /> - <column name="user_id" type="numeric" /> - <column name="status" type="varchar" /> - <column name="merchant_id" type="numeric" /> - <column name="remark" type="varchar" /> - <column name="creation_date" type="datetime" /> - </metadata> - <row data-node="tbl.t_order_0" values="1000, 10, init, 1, test, 2017-08-08" /> - <row data-node="tbl.t_order_1" values="1, 1, insert, 1, test, 2017-08-08" /> - <row data-node="tbl.t_order_1" values="1001, 10, init, 2, test, 2017-08-08" /> - <row data-node="tbl.t_order_2" values="2, 2, insert, 2, test, 2017-08-08" /> - <row data-node="tbl.t_order_2" values="1002, 10, init, 3, test, 2017-08-08" /> - <row data-node="tbl.t_order_3" values="1003, 10, init, 4, test, 2017-08-08" /> - <row data-node="tbl.t_order_4" values="1004, 10, init, 5, test, 2017-08-08" /> - <row data-node="tbl.t_order_5" values="1005, 10, init, 6, test, 2017-08-08" /> - <row data-node="tbl.t_order_6" values="1006, 10, init, 7, test, 2017-08-08" /> - <row data-node="tbl.t_order_7" values="1007, 10, init, 8, test, 2017-08-08" /> - <row data-node="tbl.t_order_8" values="1008, 10, init, 9, test, 2017-08-08" /> - <row data-node="tbl.t_order_9" values="1009, 10, init, 10, test, 2017-08-08" /> - <row data-node="tbl.t_order_0" values="1100, 11, init, 11, test, 2017-08-08" /> - <row data-node="tbl.t_order_1" values="1101, 11, init, 12, test, 2017-08-08" /> - <row data-node="tbl.t_order_2" values="1102, 11, init, 13, test, 2017-08-08" /> - <row data-node="tbl.t_order_3" values="1103, 11, init, 14, test, 2017-08-08" /> - <row data-node="tbl.t_order_4" values="1104, 11, init, 15, test, 2017-08-08" /> - <row data-node="tbl.t_order_5" values="1105, 11, init, 16, test, 2017-08-08" /> - <row data-node="tbl.t_order_6" values="1106, 11, init, 17, test, 2017-08-08" /> - <row data-node="tbl.t_order_7" values="1107, 11, init, 18, test, 2017-08-08" /> - <row data-node="tbl.t_order_8" values="1108, 11, init, 19, test, 2017-08-08" /> - <row data-node="tbl.t_order_9" values="1109, 11, init, 20, test, 2017-08-08" /> - <row data-node="tbl.t_order_9" values="999, 10, insertALL, 1, test, 2017-08-08" /> -</dataset> diff --git a/test/e2e/sql/src/test/resources/cases/dml/e2e-dml-insert.xml b/test/e2e/sql/src/test/resources/cases/dml/e2e-dml-insert.xml index 6e7f7a24d3c..d3a30fe3a08 100644 --- a/test/e2e/sql/src/test/resources/cases/dml/e2e-dml-insert.xml +++ b/test/e2e/sql/src/test/resources/cases/dml/e2e-dml-insert.xml @@ -93,26 +93,10 @@ <assertion parameters="1:int, 1:int, 1:int" expected-data-file="insert_with_generate_key_column.xml" /> </test-case> - <test-case sql="INSERT ALL INTO t_order (order_id, user_id, status, merchant_id, remark, creation_date) VALUES (?, ?, ?, 1, 'test', '2017-08-08') SELECT 1 FROM DUAL" db-types="Oracle" scenario-types="tbl"> - <assertion parameters="999:int, 10:int, insertALL:String" expected-data-file="batch_insert_all_into_order_table.xml" /> - </test-case> - - <test-case sql="INSERT INTO t_order (order_id, user_id, status, merchant_id, remark, creation_date) SELECT ?, ?, ?, 1, 'test', '2017-08-08' FROM DUAL" db-types="Oracle" scenario-types="tbl"> - <assertion parameters="999:int, 10:int, insertALL:String" expected-data-file="insert_into_order_table_with_select.xml" /> - </test-case> - - <test-case sql="INSERT INTO t_order (order_id, user_id, status, merchant_id, remark, creation_date) (SELECT ?, ?, ?, 1, 'test', '2017-08-08' UNION ALL SELECT ?, ?, ?, 1, 'test', '2017-08-08' FROM DUAL)" db-types="Oracle" scenario-types="tbl"> - <assertion parameters="999:int, 10:int, insertALL:String, 998:int, 10:int, insertALL:String" expected-data-file="batch_insert_into_order_with_select.xml" /> - </test-case> - - <test-case sql="INSERT INTO t_user (user_id, user_name, password, email, telephone, creation_date) SELECT ?, user_name, password, email, telephone, creation_date FROM t_user where user_name = ? and user_id = ?" scenario-types="encrypt" db-types="MySQL"> - <assertion parameters="40:int, lisi:String, 11:int" expected-data-file="insert_select_user_table.xml" /> - </test-case> - <test-case sql="INSERT INTO t_order_item VALUES (?, ?, 1, 1, '2017-08-08')" scenario-types="db,tbl,dbtbl_with_readwrite_splitting"> <assertion parameters="1:int, 1:int" expected-data-file="insert_without_generate_key_column.xml" expected-generated-key-data-file="insert_without_generate_key_column_generated_key_data.xml" /> </test-case> - + <test-case sql="INSERT INTO t_order_item (order_id, user_id, product_id, quantity, creation_date) VALUES (?, ?, 1, 1, '2017-08-08')" scenario-types="db,tbl,dbtbl_with_readwrite_splitting"> <assertion parameters="1:int, 1:int" expected-data-file="insert_without_generate_key_column.xml" expected-generated-key-data-file="insert_without_generate_key_column_generated_key_data.xml" /> </test-case>