From c5d644bb222055eb7098590cbc65169b48f0ff10 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Wed, 25 Dec 2024 19:32:05 +0800 Subject: [PATCH 1/9] Support sql bind for select with current select projection reference --- .../expression/type/ColumnSegmentBinder.java | 8 ++-- .../projection/ProjectionsSegmentBinder.java | 34 +++++++++++++++-- .../type/ColumnProjectionSegmentBinder.java | 9 +++-- .../driver/jdbc/JDBCExecutorCallback.java | 12 ++++-- .../driver/DriverExecutionPrepareEngine.java | 3 +- .../src/test/resources/cases/dml/select.xml | 37 +++++++++++++++++++ .../src/test/resources/sqls/dml/select.xml | 1 + 7 files changed, 88 insertions(+), 16 deletions(-) diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinder.java index 6020cc3f1bbdf..ab598c4f58fcb 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinder.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.engine.segment.expression.type; import com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString; +import com.cedarsoftware.util.CaseInsensitiveSet; import com.google.common.base.Strings; import com.google.common.collect.Multimap; import lombok.AccessLevel; @@ -43,7 +44,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.LinkedHashSet; import java.util.List; import java.util.ListIterator; import java.util.Map; @@ -56,7 +56,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ColumnSegmentBinder { - private static final Collection EXCLUDE_BIND_COLUMNS = new LinkedHashSet<>(Arrays.asList( + private static final Collection EXCLUDE_BIND_COLUMNS = new CaseInsensitiveSet<>(Arrays.asList( "ROWNUM", "ROW_NUMBER", "ROWNUM_", "ROWID", "SYSDATE", "SYSTIMESTAMP", "CURRENT_TIMESTAMP", "LOCALTIMESTAMP", "UID", "USER", "NEXTVAL", "LEVEL")); private static final Map SEGMENT_TYPE_MESSAGES = Maps.of(SegmentType.PROJECTION, "field list", SegmentType.JOIN_ON, "on clause", SegmentType.JOIN_USING, "from clause", @@ -77,7 +77,7 @@ public final class ColumnSegmentBinder { public static ColumnSegment bind(final ColumnSegment segment, final SegmentType parentSegmentType, final SQLStatementBinderContext binderContext, final Multimap tableBinderContexts, final Multimap outerTableBinderContexts) { - if (EXCLUDE_BIND_COLUMNS.contains(segment.getIdentifier().getValue().toUpperCase())) { + if (EXCLUDE_BIND_COLUMNS.contains(segment.getIdentifier().getValue())) { return segment; } ColumnSegment result = copy(segment); @@ -116,7 +116,7 @@ private static Collection getTableSegmentBinderContex if (!binderContext.getJoinTableProjectionSegments().isEmpty() && isNeedUseJoinTableProjectionBind(segment, parentSegmentType, binderContext)) { return Collections.singleton(new SimpleTableSegmentBinderContext(binderContext.getJoinTableProjectionSegments())); } - return tableBinderContexts.values(); + return tableBinderContexts.values().isEmpty() ? outerTableBinderContexts.values() : tableBinderContexts.values(); } private static Collection getTableBinderContextByOwner(final String owner, final Multimap tableBinderContexts, diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/projection/ProjectionsSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/projection/ProjectionsSegmentBinder.java index 83557beb1f937..9b3c92a48577b 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/projection/ProjectionsSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/projection/ProjectionsSegmentBinder.java @@ -25,10 +25,13 @@ import org.apache.shardingsphere.infra.binder.engine.segment.SegmentType; import org.apache.shardingsphere.infra.binder.engine.segment.expression.ExpressionSegmentBinder; import org.apache.shardingsphere.infra.binder.engine.segment.from.context.TableSegmentBinderContext; +import org.apache.shardingsphere.infra.binder.engine.segment.from.context.type.SimpleTableSegmentBinderContext; import org.apache.shardingsphere.infra.binder.engine.segment.projection.type.ColumnProjectionSegmentBinder; import org.apache.shardingsphere.infra.binder.engine.segment.projection.type.ShorthandProjectionSegmentBinder; import org.apache.shardingsphere.infra.binder.engine.segment.projection.type.SubqueryProjectionSegmentBinder; import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext; +import org.apache.shardingsphere.infra.binder.engine.util.SubqueryTableBindUtils; +import org.apache.shardingsphere.infra.exception.kernel.metadata.ColumnNotFoundException; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.AggregationDistinctProjectionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.AggregationProjectionSegment; @@ -39,8 +42,9 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ShorthandProjectionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableSegment; +import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; -import java.util.stream.Collectors; +import java.util.Collection; /** * Projections segment binder. @@ -63,16 +67,30 @@ public static ProjectionsSegment bind(final ProjectionsSegment segment, final SQ final Multimap outerTableBinderContexts) { ProjectionsSegment result = new ProjectionsSegment(segment.getStartIndex(), segment.getStopIndex()); result.setDistinctRow(segment.isDistinctRow()); - result.getProjections().addAll(segment.getProjections().stream() - .map(each -> bind(each, binderContext, boundTableSegment, tableBinderContexts, outerTableBinderContexts)).collect(Collectors.toList())); + for (ProjectionSegment each : segment.getProjections()) { + Multimap currentTableBinderContexts = createCurrentTableBinderContexts(binderContext, result.getProjections()); + result.getProjections().add(bind(binderContext, boundTableSegment, currentTableBinderContexts, tableBinderContexts, outerTableBinderContexts, each)); + } return result; } + private static ProjectionSegment bind(final SQLStatementBinderContext binderContext, final TableSegment boundTableSegment, + final Multimap currentTableBinderContexts, + final Multimap tableBinderContexts, + final Multimap outerTableBinderContexts, + final ProjectionSegment projectionSegment) { + try { + return bind(projectionSegment, binderContext, boundTableSegment, tableBinderContexts, outerTableBinderContexts); + } catch (final ColumnNotFoundException ignored) { + return bind(projectionSegment, binderContext, boundTableSegment, currentTableBinderContexts, outerTableBinderContexts); + } + } + private static ProjectionSegment bind(final ProjectionSegment projectionSegment, final SQLStatementBinderContext binderContext, final TableSegment boundTableSegment, final Multimap tableBinderContexts, final Multimap outerTableBinderContexts) { if (projectionSegment instanceof ColumnProjectionSegment) { - return ColumnProjectionSegmentBinder.bind((ColumnProjectionSegment) projectionSegment, binderContext, tableBinderContexts); + return ColumnProjectionSegmentBinder.bind((ColumnProjectionSegment) projectionSegment, binderContext, tableBinderContexts, outerTableBinderContexts); } if (projectionSegment instanceof ShorthandProjectionSegment) { return ShorthandProjectionSegmentBinder.bind((ShorthandProjectionSegment) projectionSegment, boundTableSegment, tableBinderContexts); @@ -125,4 +143,12 @@ private static AggregationProjectionSegment bindAggregationProjection(final Aggr aggregationSegment.getAliasSegment().ifPresent(result::setAlias); return result; } + + private static Multimap createCurrentTableBinderContexts(final SQLStatementBinderContext binderContext, + final Collection projections) { + Multimap result = LinkedHashMultimap.create(); + Collection subqueryProjections = SubqueryTableBindUtils.createSubqueryProjections(projections, new IdentifierValue(""), binderContext.getSqlStatement().getDatabaseType()); + result.put(new CaseInsensitiveString(""), new SimpleTableSegmentBinderContext(subqueryProjections)); + return result; + } } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/projection/type/ColumnProjectionSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/projection/type/ColumnProjectionSegmentBinder.java index 371105638533c..3dd3cff32cca2 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/projection/type/ColumnProjectionSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/projection/type/ColumnProjectionSegmentBinder.java @@ -18,7 +18,6 @@ package org.apache.shardingsphere.infra.binder.engine.segment.projection.type; import com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString; -import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -41,11 +40,13 @@ public final class ColumnProjectionSegmentBinder { * @param segment table segment * @param binderContext SQL statement binder context * @param tableBinderContexts table binder contexts + * @param outerTableBinderContexts outer table binder contexts * @return bound column projection segment */ - public static ColumnProjectionSegment bind(final ColumnProjectionSegment segment, - final SQLStatementBinderContext binderContext, final Multimap tableBinderContexts) { - ColumnSegment boundColumn = ColumnSegmentBinder.bind(segment.getColumn(), SegmentType.PROJECTION, binderContext, tableBinderContexts, LinkedHashMultimap.create()); + public static ColumnProjectionSegment bind(final ColumnProjectionSegment segment, final SQLStatementBinderContext binderContext, + final Multimap tableBinderContexts, + final Multimap outerTableBinderContexts) { + ColumnSegment boundColumn = ColumnSegmentBinder.bind(segment.getColumn(), SegmentType.PROJECTION, binderContext, tableBinderContexts, outerTableBinderContexts); ColumnProjectionSegment result = new ColumnProjectionSegment(boundColumn); segment.getAliasSegment().ifPresent(result::setAlias); result.setVisible(segment.isVisible()); diff --git a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java index f2451cd99be68..df54c8aa51575 100644 --- a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java +++ b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java @@ -29,6 +29,7 @@ import org.apache.shardingsphere.infra.executor.sql.hook.SQLExecutionHook; import org.apache.shardingsphere.infra.executor.sql.process.ProcessEngine; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; import java.sql.SQLException; @@ -76,12 +77,17 @@ public final Collection execute(final Collection execution */ private T execute(final JDBCExecutionUnit jdbcExecutionUnit, final boolean isTrunkThread, final String processId) throws SQLException { SQLExecutorExceptionHandler.setExceptionThrown(isExceptionThrown); - DatabaseType storageType = resourceMetaData.getStorageUnits().get(jdbcExecutionUnit.getExecutionUnit().getDataSourceName()).getStorageType(); - ConnectionProperties connectionProps = resourceMetaData.getStorageUnits().get(jdbcExecutionUnit.getExecutionUnit().getDataSourceName()).getConnectionProperties(); + String dataSourceName = jdbcExecutionUnit.getExecutionUnit().getDataSourceName(); + // TODO use metadata to replace storageUnits to support multiple logic databases + StorageUnit storageUnit = resourceMetaData.getStorageUnits().containsKey(dataSourceName) + ? resourceMetaData.getStorageUnits().get(dataSourceName) + : resourceMetaData.getStorageUnits().values().iterator().next(); + DatabaseType storageType = storageUnit.getStorageType(); + ConnectionProperties connectionProps = storageUnit.getConnectionProperties(); SQLExecutionHook sqlExecutionHook = new SPISQLExecutionHook(); try { SQLUnit sqlUnit = jdbcExecutionUnit.getExecutionUnit().getSqlUnit(); - sqlExecutionHook.start(jdbcExecutionUnit.getExecutionUnit().getDataSourceName(), sqlUnit.getSql(), sqlUnit.getParameters(), connectionProps, isTrunkThread); + sqlExecutionHook.start(dataSourceName, sqlUnit.getSql(), sqlUnit.getParameters(), connectionProps, isTrunkThread); T result = executeSQL(sqlUnit.getSql(), jdbcExecutionUnit.getStorageResource(), jdbcExecutionUnit.getConnectionMode(), storageType); sqlExecutionHook.finishSuccess(); processEngine.completeSQLUnitExecution(jdbcExecutionUnit, processId); diff --git a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java index 17dd4851ea175..463404ec0e312 100644 --- a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java +++ b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java @@ -102,7 +102,8 @@ protected List> group(final String databaseName, final String @SuppressWarnings("unchecked") private ExecutionGroup createExecutionGroup(final String dataSourceName, final List executionUnits, final C connection, final ConnectionMode connectionMode) throws SQLException { List inputs = new LinkedList<>(); - DatabaseType databaseType = storageUnits.get(dataSourceName).getStorageType(); + // TODO use metadata to replace storageUnits to support multiple logic databases + DatabaseType databaseType = storageUnits.containsKey(dataSourceName) ? storageUnits.get(dataSourceName).getStorageType() : storageUnits.values().iterator().next().getStorageType(); for (ExecutionUnit each : executionUnits) { inputs.add((T) sqlExecutionUnitBuilder.build(each, statementManager, connection, connectionMode, option, databaseType)); } diff --git a/test/it/binder/src/test/resources/cases/dml/select.xml b/test/it/binder/src/test/resources/cases/dml/select.xml index 8caabdcb4d972..da40c0135de82 100644 --- a/test/it/binder/src/test/resources/cases/dml/select.xml +++ b/test/it/binder/src/test/resources/cases/dml/select.xml @@ -293,4 +293,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/it/binder/src/test/resources/sqls/dml/select.xml b/test/it/binder/src/test/resources/sqls/dml/select.xml index cca532f1c5f25..ced2c64e8b23a 100644 --- a/test/it/binder/src/test/resources/sqls/dml/select.xml +++ b/test/it/binder/src/test/resources/sqls/dml/select.xml @@ -20,4 +20,5 @@ + From e285e18388244373b4a0e2df57cb6dd37c5cf59f Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Wed, 25 Dec 2024 19:33:24 +0800 Subject: [PATCH 2/9] update release note --- RELEASE-NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 37fad67b25538..5e23492b00dc3 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -39,6 +39,7 @@ 1. SQL Parser: Support MySQL update with statement parse - [#34126](https://github.com/apache/shardingsphere/pull/34126) 1. SQL Binder: Remove TablesContext#findTableNames method and implement select order by, group by bind logic - [#34123](https://github.com/apache/shardingsphere/pull/34123) 1. SQL Binder: Support select with statement sql bind and add bind test case - [#34141](https://github.com/apache/shardingsphere/pull/34141) +1. SQL Binder: Support sql bind for select with current select projection reference - [#34151](https://github.com/apache/shardingsphere/pull/34151) ### Bug Fixes From c282000c7ccab6432b0137cc09dc66f5c70b527a Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Thu, 26 Dec 2024 08:00:56 +0800 Subject: [PATCH 3/9] fix unit test --- .../engine/segment/expression/type/ColumnSegmentBinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinder.java index ab598c4f58fcb..d4f9cdeecbcb3 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinder.java @@ -116,7 +116,7 @@ private static Collection getTableSegmentBinderContex if (!binderContext.getJoinTableProjectionSegments().isEmpty() && isNeedUseJoinTableProjectionBind(segment, parentSegmentType, binderContext)) { return Collections.singleton(new SimpleTableSegmentBinderContext(binderContext.getJoinTableProjectionSegments())); } - return tableBinderContexts.values().isEmpty() ? outerTableBinderContexts.values() : tableBinderContexts.values(); + return tableBinderContexts.values(); } private static Collection getTableBinderContextByOwner(final String owner, final Multimap tableBinderContexts, From 8720f9b62a6d17d757490f6b5a2b4776291cdef5 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Thu, 26 Dec 2024 08:17:53 +0800 Subject: [PATCH 4/9] fix unit test --- .../text/query/MySQLMultiStatementsHandlerTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java index 7d3e282e0796e..3fb046a90bdef 100644 --- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java +++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java @@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode; import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption; +import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; @@ -155,6 +156,7 @@ void assertExecuteWithMultiInsertOnDuplicateKey() throws SQLException { private ConnectionSession mockConnectionSession() throws SQLException { ConnectionSession result = mock(ConnectionSession.class, RETURNS_DEEP_STUBS); when(result.getCurrentDatabaseName()).thenReturn("foo_db"); + when(result.getUsedDatabaseName()).thenReturn("foo_db"); Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS); when(connection.getMetaData().getURL()).thenReturn("jdbc:mysql://127.0.0.1/db"); Statement statement = mock(Statement.class); @@ -171,11 +173,12 @@ private ConnectionSession mockConnectionSession() throws SQLException { private ContextManager mockContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); - when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData().getAllInstanceDataSourceNames()).thenReturn(Collections.singletonList("foo_ds")); + ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); + when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData()).thenReturn(resourceMetaData); + when(resourceMetaData.getAllInstanceDataSourceNames()).thenReturn(Collections.singletonList("foo_ds")); StorageUnit storageUnit = mock(StorageUnit.class, RETURNS_DEEP_STUBS); when(storageUnit.getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); - when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData().getStorageUnits()) - .thenReturn(Collections.singletonMap("foo_ds", storageUnit)); + when(resourceMetaData.getStorageUnits()).thenReturn(Collections.singletonMap("foo_ds", storageUnit)); when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "MySQL")); when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").getRuleMetaData()) .thenReturn(new RuleMetaData(Collections.emptyList())); From 8a374fb5b323b9b37638dde5f78148502114bafc Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Thu, 26 Dec 2024 08:19:52 +0800 Subject: [PATCH 5/9] fix unit test --- ...PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java | 1 + .../query/extended/PostgreSQLBatchedStatementsExecutorTest.java | 1 + 2 files changed, 2 insertions(+) diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java index cb813d381c6d9..d2f3445f4bd9c 100644 --- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java +++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java @@ -114,6 +114,7 @@ private ConnectionSession mockConnectionSession() throws SQLException { SQLStatementContext sqlStatementContext = mock(InsertStatementContext.class); when(sqlStatementContext.getSqlStatement()).thenReturn(parserEngine.parse(SQL, false)); when(result.getCurrentDatabaseName()).thenReturn("foo_db"); + when(result.getUsedDatabaseName()).thenReturn("foo_db"); ConnectionContext connectionContext = new ConnectionContext(Collections::emptySet); connectionContext.setCurrentDatabaseName("foo_db"); when(result.getConnectionContext()).thenReturn(connectionContext); diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java index 81943995dae02..5d7f1aa257b9d 100644 --- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java +++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java @@ -154,6 +154,7 @@ private ContextManager mockContextManager() { private ConnectionSession mockConnectionSession() { ConnectionSession result = mock(ConnectionSession.class); when(result.getCurrentDatabaseName()).thenReturn("db"); + when(result.getUsedDatabaseName()).thenReturn("db"); when(result.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager); when(result.getStatementManager()).thenReturn(backendStatement); ConnectionContext connectionContext = new ConnectionContext(Collections::emptySet); From 342421b59aed0e6ffbbc553aef8ee79c1a60c07f Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Thu, 26 Dec 2024 08:26:15 +0800 Subject: [PATCH 6/9] fix unit test --- .../query/extended/bind/OpenGaussComBatchBindExecutorTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java index bfe13d152b8d6..88f942dd632c0 100644 --- a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java +++ b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java @@ -106,6 +106,7 @@ private ConnectionSession mockConnectionSession() throws SQLException { ConnectionSession result = mock(ConnectionSession.class); when(result.getConnectionContext()).thenReturn(new ConnectionContext(Collections::emptySet)); when(result.getCurrentDatabaseName()).thenReturn("foo_db"); + when(result.getUsedDatabaseName()).thenReturn("foo_db"); ConnectionContext connectionContext = mockConnectionContext(); when(result.getConnectionContext()).thenReturn(connectionContext); ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class); From 2c57a35875eac3654da241cdad560c0dffc4ec61 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Thu, 26 Dec 2024 10:51:18 +0800 Subject: [PATCH 7/9] Support alter table, drop table sql bind and add test case --- ...ShardingDropTableSupportedCheckerTest.java | 2 +- ...rdingDropTableRouteContextCheckerTest.java | 8 +- .../from/type/SimpleTableSegmentBinder.java | 14 ++ .../ddl/AlterTableStatementBinder.java | 66 +++++++++ .../ddl/DropTableStatementBinder.java | 53 +++++++ .../engine/type/DDLStatementBindEngine.java | 10 ++ .../type/DorisDDLStatementVisitor.java | 3 +- .../type/MySQLDDLStatementVisitor.java | 3 +- .../type/OpenGaussDDLStatementVisitor.java | 4 +- .../type/PostgreSQLDDLStatementVisitor.java | 4 +- .../type/PrestoDDLStatementVisitor.java | 3 +- .../type/SQLServerDDLStatementVisitor.java | 3 +- .../statement/ddl/AlterTableStatement.java | 8 + .../statement/ddl/DropTableStatement.java | 16 ++ .../doris/ddl/DorisDropTableStatement.java | 4 +- .../mysql/ddl/MySQLDropTableStatement.java | 4 +- .../ddl/OpenGaussDropTableStatement.java | 6 +- .../ddl/PostgreSQLDropTableStatement.java | 6 +- .../presto/ddl/PrestoDropTableStatement.java | 4 +- .../ddl/SQLServerDropTableStatement.java | 4 +- .../MySQLComStmtPrepareCheckerTest.java | 3 +- .../binder/dialect/doris/DorisBinderIT.java | 25 ++++ .../test/resources/cases/ddl/alter-table.xml | 50 +++++++ .../test/resources/cases/ddl/create-table.xml | 139 ++++++++++++++++++ .../test/resources/cases/ddl/drop-table.xml | 49 ++++++ .../test/resources/sqls/ddl/alter-table.xml | 22 +++ .../test/resources/sqls/ddl/create-table.xml | 2 + .../test/resources/sqls/ddl/drop-table.xml | 22 +++ 28 files changed, 516 insertions(+), 21 deletions(-) create mode 100644 infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/AlterTableStatementBinder.java create mode 100644 infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/DropTableStatementBinder.java create mode 100644 test/it/binder/src/test/java/org/apache/shardingsphere/test/it/sql/binder/dialect/doris/DorisBinderIT.java create mode 100644 test/it/binder/src/test/resources/cases/ddl/alter-table.xml create mode 100644 test/it/binder/src/test/resources/cases/ddl/drop-table.xml create mode 100644 test/it/binder/src/test/resources/sqls/ddl/alter-table.xml create mode 100644 test/it/binder/src/test/resources/sqls/ddl/drop-table.xml diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java index 5223b63b3747d..35726fd7e225c 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java @@ -62,7 +62,7 @@ void init() { @Test void assertCheckForMySQL() { - MySQLDropTableStatement sqlStatement = new MySQLDropTableStatement(false); + MySQLDropTableStatement sqlStatement = new MySQLDropTableStatement(); sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_item")))); DropTableStatementContext sqlStatementContext = new DropTableStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java index 4a26cb3d8aff9..4c57935c353cf 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java @@ -80,7 +80,7 @@ void init() { @Test void assertCheckWhenDropTableInUsedForMySQL() { - MySQLDropTableStatement sqlStatement = new MySQLDropTableStatement(false); + MySQLDropTableStatement sqlStatement = new MySQLDropTableStatement(); sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_item")))); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(database.getName()).thenReturn("db_schema"); @@ -119,7 +119,7 @@ void clean() { @Test void assertCheckWithSameRouteResultShardingTableForPostgreSQL() { - PostgreSQLDropTableStatement sqlStatement = new PostgreSQLDropTableStatement(false, false); + PostgreSQLDropTableStatement sqlStatement = new PostgreSQLDropTableStatement(); sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); when(shardingRule.isShardingTable("t_order")).thenReturn(true); when(shardingRule.getShardingTable("t_order")).thenReturn(new ShardingTable(Arrays.asList("ds_0", "ds_1"), "t_order")); @@ -134,7 +134,7 @@ void assertCheckWithSameRouteResultShardingTableForPostgreSQL() { @Test void assertCheckWithDifferentRouteResultShardingTableForPostgreSQL() { - PostgreSQLDropTableStatement sqlStatement = new PostgreSQLDropTableStatement(false, false); + PostgreSQLDropTableStatement sqlStatement = new PostgreSQLDropTableStatement(); sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); when(shardingRule.isShardingTable("t_order")).thenReturn(true); when(shardingRule.getShardingTable("t_order")).thenReturn(new ShardingTable(Arrays.asList("ds_0", "ds_1"), "t_order")); @@ -148,7 +148,7 @@ void assertCheckWithDifferentRouteResultShardingTableForPostgreSQL() { @Test void assertCheckWithSameRouteResultBroadcastTableForPostgreSQL() { - PostgreSQLDropTableStatement sqlStatement = new PostgreSQLDropTableStatement(false, false); + PostgreSQLDropTableStatement sqlStatement = new PostgreSQLDropTableStatement(); sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_config")))); when(shardingRule.getShardingTable("t_config")).thenReturn(new ShardingTable(Arrays.asList("ds_0", "ds_1"), "t_config")); Collection routeUnits = new LinkedList<>(); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java index d471cb8cf0105..a7b9198874780 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java @@ -49,7 +49,9 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterTableStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateTableStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import java.util.Collection; @@ -130,6 +132,14 @@ private static void checkTableExists(final SQLStatementBinderContext binderConte || ((CreateTableStatement) binderContext.getSqlStatement()).isIfNotExists() || !schema.containsTable(tableName), () -> new TableExistsException(tableName)); return; } + if (binderContext.getSqlStatement() instanceof AlterTableStatement && isRenameTable((AlterTableStatement) binderContext.getSqlStatement(), tableName)) { + ShardingSpherePreconditions.checkState(binderContext.getHintValueContext().isSkipMetadataValidate() || !schema.containsTable(tableName), () -> new TableExistsException(tableName)); + return; + } + if (binderContext.getSqlStatement() instanceof DropTableStatement) { + ShardingSpherePreconditions.checkState(((DropTableStatement) binderContext.getSqlStatement()).isIfExists() || schema.containsTable(tableName), () -> new TableNotFoundException(tableName)); + return; + } if ("DUAL".equalsIgnoreCase(tableName)) { return; } @@ -142,6 +152,10 @@ private static void checkTableExists(final SQLStatementBinderContext binderConte ShardingSpherePreconditions.checkState(schema.containsTable(tableName), () -> new TableNotFoundException(tableName)); } + private static boolean isRenameTable(final AlterTableStatement alterTableStatement, final String tableName) { + return alterTableStatement.getRenameTable().isPresent() && alterTableStatement.getRenameTable().get().getTableName().getIdentifier().getValue().equalsIgnoreCase(tableName); + } + private static SimpleTableSegmentBinderContext createSimpleTableBinderContext(final SimpleTableSegment segment, final ShardingSphereSchema schema, final IdentifierValue databaseName, final IdentifierValue schemaName, final SQLStatementBinderContext binderContext) { IdentifierValue tableName = segment.getTableName().getIdentifier(); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/AlterTableStatementBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/AlterTableStatementBinder.java new file mode 100644 index 0000000000000..4a3f1e31b1292 --- /dev/null +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/AlterTableStatementBinder.java @@ -0,0 +1,66 @@ +/* + * 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.ddl; + +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.from.context.TableSegmentBinderContext; +import org.apache.shardingsphere.infra.binder.engine.segment.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.ddl.AlterTableStatement; + +/** + * Alter table statement binder. + */ +public final class AlterTableStatementBinder implements SQLStatementBinder { + + @Override + public AlterTableStatement bind(final AlterTableStatement sqlStatement, final SQLStatementBinderContext binderContext) { + AlterTableStatement result = copy(sqlStatement); + Multimap tableBinderContexts = LinkedHashMultimap.create(); + result.setTable(SimpleTableSegmentBinder.bind(sqlStatement.getTable(), binderContext, tableBinderContexts)); + sqlStatement.getRenameTable().ifPresent(optional -> result.setRenameTable(SimpleTableSegmentBinder.bind(optional, binderContext, tableBinderContexts))); + return result; + } + + @SneakyThrows(ReflectiveOperationException.class) + private static AlterTableStatement copy(final AlterTableStatement sqlStatement) { + AlterTableStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); + // TODO bind column and reference table if kernel need use them + sqlStatement.getConvertTableDefinition().ifPresent(result::setConvertTableDefinition); + result.getAddColumnDefinitions().addAll(sqlStatement.getAddColumnDefinitions()); + result.getModifyColumnDefinitions().addAll(sqlStatement.getModifyColumnDefinitions()); + result.getChangeColumnDefinitions().addAll(sqlStatement.getChangeColumnDefinitions()); + result.getDropColumnDefinitions().addAll(sqlStatement.getDropColumnDefinitions()); + result.getAddConstraintDefinitions().addAll(sqlStatement.getAddConstraintDefinitions()); + result.getValidateConstraintDefinitions().addAll(sqlStatement.getValidateConstraintDefinitions()); + result.getModifyConstraintDefinitions().addAll(sqlStatement.getModifyConstraintDefinitions()); + result.getDropConstraintDefinitions().addAll(sqlStatement.getDropConstraintDefinitions()); + result.getDropIndexDefinitions().addAll(sqlStatement.getDropIndexDefinitions()); + result.getRenameColumnDefinitions().addAll(sqlStatement.getRenameColumnDefinitions()); + result.getRenameIndexDefinitions().addAll(sqlStatement.getRenameIndexDefinitions()); + sqlStatement.getModifyCollectionRetrieval().ifPresent(result::setModifyCollectionRetrieval); + 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/statement/ddl/DropTableStatementBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/DropTableStatementBinder.java new file mode 100644 index 0000000000000..c54d2ce00bdeb --- /dev/null +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/ddl/DropTableStatementBinder.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.statement.ddl; + +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.from.context.TableSegmentBinderContext; +import org.apache.shardingsphere.infra.binder.engine.segment.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.ddl.DropTableStatement; + +/** + * Drop table statement binder. + */ +public final class DropTableStatementBinder implements SQLStatementBinder { + + @Override + public DropTableStatement bind(final DropTableStatement sqlStatement, final SQLStatementBinderContext binderContext) { + DropTableStatement result = copy(sqlStatement); + Multimap tableBinderContexts = LinkedHashMultimap.create(); + sqlStatement.getTables().forEach(each -> result.getTables().add(SimpleTableSegmentBinder.bind(each, binderContext, tableBinderContexts))); + return result; + } + + @SneakyThrows(ReflectiveOperationException.class) + private static DropTableStatement copy(final DropTableStatement sqlStatement) { + DropTableStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); + result.setIfExists(sqlStatement.isIfExists()); + result.setContainsCascade(sqlStatement.isContainsCascade()); + 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/DDLStatementBindEngine.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DDLStatementBindEngine.java index 6665fc27ec50e..2792f3fc62c44 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DDLStatementBindEngine.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DDLStatementBindEngine.java @@ -19,15 +19,19 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext; +import org.apache.shardingsphere.infra.binder.engine.statement.ddl.AlterTableStatementBinder; import org.apache.shardingsphere.infra.binder.engine.statement.ddl.CreateIndexStatementBinder; import org.apache.shardingsphere.infra.binder.engine.statement.ddl.CreateTableStatementBinder; import org.apache.shardingsphere.infra.binder.engine.statement.ddl.CursorStatementBinder; +import org.apache.shardingsphere.infra.binder.engine.statement.ddl.DropTableStatementBinder; import org.apache.shardingsphere.infra.hint.HintValueContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterTableStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateIndexStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateTableStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CursorStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement; /** * DDL statement bind engine. @@ -55,6 +59,12 @@ public DDLStatement bind(final DDLStatement statement) { if (statement instanceof CreateTableStatement) { return new CreateTableStatementBinder().bind((CreateTableStatement) statement, binderContext); } + if (statement instanceof AlterTableStatement) { + return new AlterTableStatementBinder().bind((AlterTableStatement) statement, binderContext); + } + if (statement instanceof DropTableStatement) { + return new DropTableStatementBinder().bind((DropTableStatement) statement, binderContext); + } if (statement instanceof CreateIndexStatement) { return new CreateIndexStatementBinder().bind((CreateIndexStatement) statement, binderContext); } diff --git a/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDDLStatementVisitor.java b/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDDLStatementVisitor.java index 70609a7173230..9c18804dcf91d 100644 --- a/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDDLStatementVisitor.java +++ b/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDDLStatementVisitor.java @@ -664,7 +664,8 @@ public ASTNode visitPlace(final PlaceContext ctx) { @SuppressWarnings("unchecked") @Override public ASTNode visitDropTable(final DropTableContext ctx) { - DorisDropTableStatement result = new DorisDropTableStatement(null != ctx.ifExists()); + DorisDropTableStatement result = new DorisDropTableStatement(); + result.setIfExists(null != ctx.ifExists()); result.getTables().addAll(((CollectionValue) visit(ctx.tableList())).getValue()); return result; } diff --git a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDDLStatementVisitor.java b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDDLStatementVisitor.java index 97188a7353d38..9f6e311a4b56b 100644 --- a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDDLStatementVisitor.java +++ b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDDLStatementVisitor.java @@ -671,7 +671,8 @@ public ASTNode visitPlace(final PlaceContext ctx) { @SuppressWarnings("unchecked") @Override public ASTNode visitDropTable(final DropTableContext ctx) { - MySQLDropTableStatement result = new MySQLDropTableStatement(null != ctx.ifExists()); + MySQLDropTableStatement result = new MySQLDropTableStatement(); + result.setIfExists(null != ctx.ifExists()); result.getTables().addAll(((CollectionValue) visit(ctx.tableList())).getValue()); return result; } diff --git a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java index f0940ad4a0d17..7fad41cc99f7a 100644 --- a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java +++ b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java @@ -512,7 +512,9 @@ public ASTNode visitRenameColumnSpecification(final RenameColumnSpecificationCon @Override public ASTNode visitDropTable(final DropTableContext ctx) { boolean containsCascade = null != ctx.dropTableOpt() && null != ctx.dropTableOpt().CASCADE(); - OpenGaussDropTableStatement result = new OpenGaussDropTableStatement(null != ctx.ifExists(), containsCascade); + OpenGaussDropTableStatement result = new OpenGaussDropTableStatement(); + result.setIfExists(null != ctx.ifExists()); + result.setContainsCascade(containsCascade); result.getTables().addAll(((CollectionValue) visit(ctx.tableNames())).getValue()); return result; } diff --git a/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDDLStatementVisitor.java b/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDDLStatementVisitor.java index 6a23b13361f77..5bf935cb3ff88 100644 --- a/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDDLStatementVisitor.java +++ b/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDDLStatementVisitor.java @@ -627,7 +627,9 @@ public ASTNode visitRenameColumnSpecification(final RenameColumnSpecificationCon @Override public ASTNode visitDropTable(final DropTableContext ctx) { boolean containsCascade = null != ctx.dropTableOpt() && null != ctx.dropTableOpt().CASCADE(); - PostgreSQLDropTableStatement result = new PostgreSQLDropTableStatement(null != ctx.ifExists(), containsCascade); + PostgreSQLDropTableStatement result = new PostgreSQLDropTableStatement(); + result.setIfExists(null != ctx.ifExists()); + result.setContainsCascade(containsCascade); result.getTables().addAll(((CollectionValue) visit(ctx.tableNames())).getValue()); return result; } diff --git a/parser/sql/dialect/presto/src/main/java/org/apache/shardingsphere/sql/parser/presto/visitor/statement/type/PrestoDDLStatementVisitor.java b/parser/sql/dialect/presto/src/main/java/org/apache/shardingsphere/sql/parser/presto/visitor/statement/type/PrestoDDLStatementVisitor.java index 2fe88595fb6f2..d2b73e1c0be67 100644 --- a/parser/sql/dialect/presto/src/main/java/org/apache/shardingsphere/sql/parser/presto/visitor/statement/type/PrestoDDLStatementVisitor.java +++ b/parser/sql/dialect/presto/src/main/java/org/apache/shardingsphere/sql/parser/presto/visitor/statement/type/PrestoDDLStatementVisitor.java @@ -119,7 +119,8 @@ private String getText(final ParserRuleContext ctx) { @SuppressWarnings("unchecked") @Override public ASTNode visitDropTable(final DropTableContext ctx) { - PrestoDropTableStatement result = new PrestoDropTableStatement(null != ctx.ifExists()); + PrestoDropTableStatement result = new PrestoDropTableStatement(); + result.setIfExists(null != ctx.ifExists()); result.getTables().addAll(((CollectionValue) visit(ctx.tableList())).getValue()); return result; } diff --git a/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/type/SQLServerDDLStatementVisitor.java b/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/type/SQLServerDDLStatementVisitor.java index 0180b750bf390..59841bf11bc59 100644 --- a/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/type/SQLServerDDLStatementVisitor.java +++ b/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/type/SQLServerDDLStatementVisitor.java @@ -309,7 +309,8 @@ public ASTNode visitDropColumnSpecification(final DropColumnSpecificationContext @SuppressWarnings("unchecked") @Override public ASTNode visitDropTable(final DropTableContext ctx) { - SQLServerDropTableStatement result = new SQLServerDropTableStatement(null != ctx.ifExists()); + SQLServerDropTableStatement result = new SQLServerDropTableStatement(); + result.setContainsCascade(null != ctx.ifExists()); result.getTables().addAll(((CollectionValue) visit(ctx.tableNames())).getValue()); return result; } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/AlterTableStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/AlterTableStatement.java index f7fec12bc6a76..400345f579200 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/AlterTableStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/AlterTableStatement.java @@ -92,6 +92,14 @@ public Optional getConvertTableDefinition() { return Optional.ofNullable(convertTableDefinition); } + /** + * Set modify collection retrieval. + * + * @param modifyCollectionRetrieval modify collection retrieval + */ + public void setModifyCollectionRetrieval(final ModifyCollectionRetrievalSegment modifyCollectionRetrieval) { + } + /** * Get modify collection retrieval. * diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/DropTableStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/DropTableStatement.java index c82b5b323a92c..933f46bb5504d 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/DropTableStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/DropTableStatement.java @@ -32,6 +32,14 @@ public abstract class DropTableStatement extends AbstractSQLStatement implements private final Collection tables = new LinkedList<>(); + /** + * Set if exists. + * + * @param ifExists if exists or not + */ + public void setIfExists(final boolean ifExists) { + } + /** * Judge whether contains if exists. * @@ -41,6 +49,14 @@ public boolean isIfExists() { return false; } + /** + * Set contains cascade. + * + * @param containsCascade contains cascade or not + */ + public void setContainsCascade(final boolean containsCascade) { + } + /** * Judge whether contains cascade. * diff --git a/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/ddl/DorisDropTableStatement.java b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/ddl/DorisDropTableStatement.java index 8a12cd4ff5a87..7c9ba41ddcfff 100644 --- a/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/ddl/DorisDropTableStatement.java +++ b/parser/sql/statement/type/doris/src/main/java/org/apache/shardingsphere/sql/parser/statement/doris/ddl/DorisDropTableStatement.java @@ -19,6 +19,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement; import org.apache.shardingsphere.sql.parser.statement.doris.DorisStatement; @@ -27,7 +28,8 @@ */ @RequiredArgsConstructor @Getter +@Setter public final class DorisDropTableStatement extends DropTableStatement implements DorisStatement { - private final boolean ifExists; + private boolean ifExists; } diff --git a/parser/sql/statement/type/mysql/src/main/java/org/apache/shardingsphere/sql/parser/statement/mysql/ddl/MySQLDropTableStatement.java b/parser/sql/statement/type/mysql/src/main/java/org/apache/shardingsphere/sql/parser/statement/mysql/ddl/MySQLDropTableStatement.java index 40ece242d7e5f..289e86eeaf7c4 100644 --- a/parser/sql/statement/type/mysql/src/main/java/org/apache/shardingsphere/sql/parser/statement/mysql/ddl/MySQLDropTableStatement.java +++ b/parser/sql/statement/type/mysql/src/main/java/org/apache/shardingsphere/sql/parser/statement/mysql/ddl/MySQLDropTableStatement.java @@ -19,6 +19,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.MySQLStatement; @@ -27,7 +28,8 @@ */ @RequiredArgsConstructor @Getter +@Setter public final class MySQLDropTableStatement extends DropTableStatement implements MySQLStatement { - private final boolean ifExists; + private boolean ifExists; } diff --git a/parser/sql/statement/type/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/statement/opengauss/ddl/OpenGaussDropTableStatement.java b/parser/sql/statement/type/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/statement/opengauss/ddl/OpenGaussDropTableStatement.java index c10040398d8a3..d9d36b5ce497f 100644 --- a/parser/sql/statement/type/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/statement/opengauss/ddl/OpenGaussDropTableStatement.java +++ b/parser/sql/statement/type/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/statement/opengauss/ddl/OpenGaussDropTableStatement.java @@ -19,6 +19,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement; import org.apache.shardingsphere.sql.parser.statement.opengauss.OpenGaussStatement; @@ -27,9 +28,10 @@ */ @RequiredArgsConstructor @Getter +@Setter public final class OpenGaussDropTableStatement extends DropTableStatement implements OpenGaussStatement { - private final boolean ifExists; + private boolean ifExists; - private final boolean containsCascade; + private boolean containsCascade; } diff --git a/parser/sql/statement/type/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/statement/postgresql/ddl/PostgreSQLDropTableStatement.java b/parser/sql/statement/type/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/statement/postgresql/ddl/PostgreSQLDropTableStatement.java index 917e24e814660..983761915bdab 100644 --- a/parser/sql/statement/type/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/statement/postgresql/ddl/PostgreSQLDropTableStatement.java +++ b/parser/sql/statement/type/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/statement/postgresql/ddl/PostgreSQLDropTableStatement.java @@ -19,6 +19,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement; import org.apache.shardingsphere.sql.parser.statement.postgresql.PostgreSQLStatement; @@ -27,9 +28,10 @@ */ @RequiredArgsConstructor @Getter +@Setter public final class PostgreSQLDropTableStatement extends DropTableStatement implements PostgreSQLStatement { - private final boolean ifExists; + private boolean ifExists; - private final boolean containsCascade; + private boolean containsCascade; } diff --git a/parser/sql/statement/type/presto/src/main/java/org/apache/shardingsphere/sql/parser/statement/presto/ddl/PrestoDropTableStatement.java b/parser/sql/statement/type/presto/src/main/java/org/apache/shardingsphere/sql/parser/statement/presto/ddl/PrestoDropTableStatement.java index 0df13bf5aa4f1..9170d0693193f 100644 --- a/parser/sql/statement/type/presto/src/main/java/org/apache/shardingsphere/sql/parser/statement/presto/ddl/PrestoDropTableStatement.java +++ b/parser/sql/statement/type/presto/src/main/java/org/apache/shardingsphere/sql/parser/statement/presto/ddl/PrestoDropTableStatement.java @@ -19,6 +19,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement; import org.apache.shardingsphere.sql.parser.statement.presto.PrestoStatement; @@ -27,7 +28,8 @@ */ @RequiredArgsConstructor @Getter +@Setter public final class PrestoDropTableStatement extends DropTableStatement implements PrestoStatement { - private final boolean ifExists; + private boolean ifExists; } diff --git a/parser/sql/statement/type/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/statement/sqlserver/ddl/SQLServerDropTableStatement.java b/parser/sql/statement/type/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/statement/sqlserver/ddl/SQLServerDropTableStatement.java index 436fe796b1f85..9036747d79209 100644 --- a/parser/sql/statement/type/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/statement/sqlserver/ddl/SQLServerDropTableStatement.java +++ b/parser/sql/statement/type/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/statement/sqlserver/ddl/SQLServerDropTableStatement.java @@ -19,6 +19,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement; import org.apache.shardingsphere.sql.parser.statement.sqlserver.SQLServerStatement; @@ -27,7 +28,8 @@ */ @RequiredArgsConstructor @Getter +@Setter public final class SQLServerDropTableStatement extends DropTableStatement implements SQLServerStatement { - private final boolean ifExists; + private boolean ifExists; } diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareCheckerTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareCheckerTest.java index 223001a592daf..29223c817c90a 100644 --- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareCheckerTest.java +++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareCheckerTest.java @@ -85,12 +85,11 @@ class MySQLComStmtPrepareCheckerTest { @Test void assertIsStatementAllowed() { MySQLCreateTableStatement createTableStatement = new MySQLCreateTableStatement(); - createTableStatement.setIfNotExists(false); Collection sqlStatements = Arrays.asList( new MySQLAlterTableStatement(), new MySQLAlterUserStatement(), new MySQLAnalyzeTableStatement(), new MySQLCacheIndexStatement(), new MySQLCallStatement(), new MySQLChangeMasterStatement(), new MySQLChecksumTableStatement(), new MySQLCommitStatement(), new MySQLCreateIndexStatement(), new MySQLDropIndexStatement(), new MySQLCreateDatabaseStatement(), new MySQLDropDatabaseStatement(), createTableStatement, - new MySQLDropTableStatement(false), new MySQLCreateUserStatement(), new MySQLRenameUserStatement(), new MySQLDropUserStatement(), + new MySQLDropTableStatement(), new MySQLCreateUserStatement(), new MySQLRenameUserStatement(), new MySQLDropUserStatement(), new MySQLCreateViewStatement(), new MySQLDropViewStatement(), new MySQLDeleteStatement(), new MySQLDoStatement(), new MySQLFlushStatement(), new MySQLGrantStatement(), new MySQLInsertStatement(), new MySQLInstallPluginStatement(), new MySQLKillStatement(), new MySQLLoadIndexInfoStatement(), new MySQLOptimizeTableStatement(), new MySQLRenameTableStatement(), new MySQLRepairTableStatement(), diff --git a/test/it/binder/src/test/java/org/apache/shardingsphere/test/it/sql/binder/dialect/doris/DorisBinderIT.java b/test/it/binder/src/test/java/org/apache/shardingsphere/test/it/sql/binder/dialect/doris/DorisBinderIT.java new file mode 100644 index 0000000000000..18adc1a3b6af9 --- /dev/null +++ b/test/it/binder/src/test/java/org/apache/shardingsphere/test/it/sql/binder/dialect/doris/DorisBinderIT.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.test.it.sql.binder.dialect.doris; + +import org.apache.shardingsphere.test.it.sql.binder.SQLBinderIT; +import org.apache.shardingsphere.test.it.sql.binder.SQLBinderITSettings; + +@SQLBinderITSettings("Doris") +class DorisBinderIT extends SQLBinderIT { +} diff --git a/test/it/binder/src/test/resources/cases/ddl/alter-table.xml b/test/it/binder/src/test/resources/cases/ddl/alter-table.xml new file mode 100644 index 0000000000000..01ad10052f12f --- /dev/null +++ b/test/it/binder/src/test/resources/cases/ddl/alter-table.xml @@ -0,0 +1,50 @@ + + + + + + + + + + +
+ + + + + + +
+ + + + + + + + +
+ + + + + + +
+
diff --git a/test/it/binder/src/test/resources/cases/ddl/create-table.xml b/test/it/binder/src/test/resources/cases/ddl/create-table.xml index 59815b36015b0..7d9a3c1e94feb 100644 --- a/test/it/binder/src/test/resources/cases/ddl/create-table.xml +++ b/test/it/binder/src/test/resources/cases/ddl/create-table.xml @@ -85,4 +85,143 @@ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/test/it/binder/src/test/resources/cases/ddl/drop-table.xml b/test/it/binder/src/test/resources/cases/ddl/drop-table.xml new file mode 100644 index 0000000000000..b4c6b8a295860 --- /dev/null +++ b/test/it/binder/src/test/resources/cases/ddl/drop-table.xml @@ -0,0 +1,49 @@ + + + + + + + + + + +
+ + + + + +
+
+ + + + + + + +
+ + + + + +
+
+
diff --git a/test/it/binder/src/test/resources/sqls/ddl/alter-table.xml b/test/it/binder/src/test/resources/sqls/ddl/alter-table.xml new file mode 100644 index 0000000000000..85facde2b0327 --- /dev/null +++ b/test/it/binder/src/test/resources/sqls/ddl/alter-table.xml @@ -0,0 +1,22 @@ + + + + + + + diff --git a/test/it/binder/src/test/resources/sqls/ddl/create-table.xml b/test/it/binder/src/test/resources/sqls/ddl/create-table.xml index 35e75c68f6121..901b5bd167fba 100644 --- a/test/it/binder/src/test/resources/sqls/ddl/create-table.xml +++ b/test/it/binder/src/test/resources/sqls/ddl/create-table.xml @@ -18,4 +18,6 @@ + + diff --git a/test/it/binder/src/test/resources/sqls/ddl/drop-table.xml b/test/it/binder/src/test/resources/sqls/ddl/drop-table.xml new file mode 100644 index 0000000000000..7ee357740b8ee --- /dev/null +++ b/test/it/binder/src/test/resources/sqls/ddl/drop-table.xml @@ -0,0 +1,22 @@ + + + + + + + From 9759b5955171c92a86c26313747cdb63061d3107 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Thu, 26 Dec 2024 10:53:24 +0800 Subject: [PATCH 8/9] update release note --- RELEASE-NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 5e23492b00dc3..0db9cb1685ab7 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -40,6 +40,7 @@ 1. SQL Binder: Remove TablesContext#findTableNames method and implement select order by, group by bind logic - [#34123](https://github.com/apache/shardingsphere/pull/34123) 1. SQL Binder: Support select with statement sql bind and add bind test case - [#34141](https://github.com/apache/shardingsphere/pull/34141) 1. SQL Binder: Support sql bind for select with current select projection reference - [#34151](https://github.com/apache/shardingsphere/pull/34151) +1. SQL Binder: Support alter table, drop table sql bind and add test case - [#34154](https://github.com/apache/shardingsphere/pull/34154) ### Bug Fixes From db9a1d70abc7c5c5b46781bc9ac4b8d0ca612dc9 Mon Sep 17 00:00:00 2001 From: duanzhengqiang Date: Thu, 26 Dec 2024 11:13:12 +0800 Subject: [PATCH 9/9] fix rewrite it --- .../it/rewrite/engine/scenario/ShardingSQLRewriterIT.java | 7 +++++++ .../resources/scenario/sharding/case/ddl/alter-table.xml | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java index 0c939beff9665..29164a346a4a5 100644 --- a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java +++ b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java @@ -103,6 +103,13 @@ protected Collection mockSchemas(final String schemaName) tables.add(new ShardingSphereTable("t_account_view", Arrays.asList( new ShardingSphereColumn("id", Types.INTEGER, false, false, false, true, false, false), new ShardingSphereColumn("account_id", Types.INTEGER, false, false, false, true, false, false)), Collections.emptyList(), Collections.emptyList())); + tables.add(new ShardingSphereTable("t_order", Arrays.asList( + new ShardingSphereColumn("order_id", Types.BIGINT, true, false, false, true, false, false), + new ShardingSphereColumn("user_id", Types.INTEGER, false, false, false, true, false, false), + new ShardingSphereColumn("status", Types.VARCHAR, false, false, false, true, false, false), + new ShardingSphereColumn("merchant_id", Types.INTEGER, false, false, false, true, false, true), + new ShardingSphereColumn("remark", Types.VARCHAR, false, false, false, true, false, false), + new ShardingSphereColumn("creation_date", Types.DATE, false, false, false, true, false, false)), Collections.emptyList(), Collections.emptyList())); return Collections.singleton(new ShardingSphereSchema(schemaName, tables, Collections.emptyList())); } diff --git a/test/it/rewriter/src/test/resources/scenario/sharding/case/ddl/alter-table.xml b/test/it/rewriter/src/test/resources/scenario/sharding/case/ddl/alter-table.xml index 3e78878bc497f..e33dcd23c75cd 100644 --- a/test/it/rewriter/src/test/resources/scenario/sharding/case/ddl/alter-table.xml +++ b/test/it/rewriter/src/test/resources/scenario/sharding/case/ddl/alter-table.xml @@ -70,8 +70,8 @@ - - + +