This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 e93cbff07db Merge DropViewStatementContext and
TableAvailableSQLStatementContext (#35698)
e93cbff07db is described below
commit e93cbff07dbe2a45f19ac6ec306baa0189a4e3a5
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Jun 13 18:02:05 2025 +0800
Merge DropViewStatementContext and TableAvailableSQLStatementContext
(#35698)
---
.../type/unicast/BroadcastUnicastRouteEngine.java | 5 ++-
.../unicast/BroadcastUnicastRouteEngineTest.java | 7 +++-
.../type/unicast/ShardingUnicastRouteEngine.java | 7 ++--
.../statement/SQLStatementContextFactory.java | 3 +-
.../type/ddl/DropViewStatementContext.java | 44 -------------------
.../type/ddl/DropViewStatementContextTest.java | 49 ----------------------
6 files changed, 13 insertions(+), 102 deletions(-)
diff --git
a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/route/engine/type/unicast/BroadcastUnicastRouteEngine.java
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/route/engine/type/unicast/BroadcastUnicastRouteEngine.java
index d06b6aec44a..8bf5b71f992 100644
---
a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/route/engine/type/unicast/BroadcastUnicastRouteEngine.java
+++
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/route/engine/type/unicast/BroadcastUnicastRouteEngine.java
@@ -24,12 +24,12 @@ import
org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterViewStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateViewStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropViewStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropViewStatement;
import java.util.ArrayList;
import java.util.Collection;
@@ -71,7 +71,8 @@ public final class BroadcastUnicastRouteEngine implements
BroadcastRouteEngine {
}
private boolean isViewStatementContext(final SQLStatementContext
sqlStatementContext) {
- return sqlStatementContext instanceof CreateViewStatementContext ||
sqlStatementContext instanceof AlterViewStatementContext || sqlStatementContext
instanceof DropViewStatementContext;
+ return sqlStatementContext instanceof CreateViewStatementContext ||
sqlStatementContext instanceof AlterViewStatementContext
+ || sqlStatementContext.getSqlStatement() instanceof
DropViewStatement;
}
private String getRandomDataSourceName(final Collection<String>
dataSourceNames) {
diff --git
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/type/unicast/BroadcastUnicastRouteEngineTest.java
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/type/unicast/BroadcastUnicastRouteEngineTest.java
index aaa12ede0c4..cf569769612 100644
---
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/type/unicast/BroadcastUnicastRouteEngineTest.java
+++
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/type/unicast/BroadcastUnicastRouteEngineTest.java
@@ -19,13 +19,14 @@ package
org.apache.shardingsphere.broadcast.route.engine.type.unicast;
import org.apache.shardingsphere.broadcast.rule.BroadcastRule;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterViewStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateViewStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropViewStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropViewStatement;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -76,7 +77,9 @@ class BroadcastUnicastRouteEngineTest {
@Test
void assertRouteToFirstDataSourceWithDropViewStatementContext() {
- assertRoute(mock(DropViewStatementContext.class), is("ds_0"));
+ SQLStatementContext sqlStatementContext =
mock(TableAvailableSQLStatementContext.class);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(DropViewStatement.class));
+ assertRoute(sqlStatementContext, is("ds_0"));
}
@Test
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRouteEngine.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRouteEngine.java
index 6eb36962369..fdedb1b1f83 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRouteEngine.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRouteEngine.java
@@ -22,17 +22,17 @@ import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterViewStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateViewStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropViewStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
-import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import
org.apache.shardingsphere.sharding.exception.syntax.DataSourceIntersectionNotFoundException;
import
org.apache.shardingsphere.sharding.route.engine.type.ShardingRouteEngine;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.ShardingTable;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropViewStatement;
import java.util.ArrayList;
import java.util.Collection;
@@ -82,7 +82,8 @@ public final class ShardingUnicastRouteEngine implements
ShardingRouteEngine {
}
private boolean isViewStatementContext(final SQLStatementContext
sqlStatementContext) {
- return sqlStatementContext instanceof CreateViewStatementContext ||
sqlStatementContext instanceof AlterViewStatementContext || sqlStatementContext
instanceof DropViewStatementContext;
+ return sqlStatementContext instanceof CreateViewStatementContext ||
sqlStatementContext instanceof AlterViewStatementContext
+ || sqlStatementContext.getSqlStatement() instanceof
DropViewStatement;
}
private void routeWithMultipleTables(final RouteContext routeContext,
final ShardingRule shardingRule) {
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java
index 6ab074901c9..1da5bbf7c8f 100644
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java
+++
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java
@@ -39,7 +39,6 @@ import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateV
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropIndexStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropTableStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropViewStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.FetchStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.MoveStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.CopyStatementContext;
@@ -214,7 +213,7 @@ public final class SQLStatementContextFactory {
return new AlterViewStatementContext(metaData, databaseType,
params, (AlterViewStatement) sqlStatement, currentDatabaseName);
}
if (sqlStatement instanceof DropViewStatement) {
- return new DropViewStatementContext(databaseType,
(DropViewStatement) sqlStatement);
+ return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((DropViewStatement) sqlStatement).getViews());
}
if (sqlStatement instanceof PrepareStatement) {
return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((PrepareStatement) sqlStatement).getTables());
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropViewStatementContext.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropViewStatementContext.java
deleted file mode 100644
index e5f4f1c7f7b..00000000000
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropViewStatementContext.java
+++ /dev/null
@@ -1,44 +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.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
-
-import lombok.Getter;
-import
org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropViewStatement;
-
-/**
- * Drop view statement context.
- */
-@Getter
-public final class DropViewStatementContext extends CommonSQLStatementContext
implements TableAvailable {
-
- private final TablesContext tablesContext;
-
- public DropViewStatementContext(final DatabaseType databaseType, final
DropViewStatement sqlStatement) {
- super(databaseType, sqlStatement);
- tablesContext = new TablesContext(sqlStatement.getViews());
- }
-
- @Override
- public DropViewStatement getSqlStatement() {
- return (DropViewStatement) super.getSqlStatement();
- }
-}
diff --git
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropViewStatementContextTest.java
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropViewStatementContextTest.java
deleted file mode 100644
index a5297f6ea32..00000000000
---
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropViewStatementContextTest.java
+++ /dev/null
@@ -1,49 +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.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement.type.ddl;
-
-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.DropViewStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class DropViewStatementContextTest {
-
- @Test
- void assertNewInstance() {
- DropViewStatement dropViewStatement = mock(DropViewStatement.class);
- when(dropViewStatement.getViews()).thenReturn(Arrays.asList(new
SimpleTableSegment(createTableNameSegment("foo_tbl")), new
SimpleTableSegment(createTableNameSegment("bar_tbl"))));
- DropViewStatementContext actual = new DropViewStatementContext(mock(),
dropViewStatement);
- assertThat(actual.getSqlStatement(), is(dropViewStatement));
- }
-
- private static TableNameSegment createTableNameSegment(final String
tableName) {
- TableNameSegment result = new TableNameSegment(0, 0, new
IdentifierValue(tableName));
- result.setTableBoundInfo(new TableSegmentBoundInfo(new
IdentifierValue("foo_db"), new IdentifierValue("foo_schema")));
- return result;
- }
-}