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 e62db267d32 Add TablelessDataSourceBroadcastRouteSQLStatementAttribute (#35788) e62db267d32 is described below commit e62db267d32172515376f2ed143e167e3476fed8 Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Wed Jun 25 16:02:31 2025 +0800 Add TablelessDataSourceBroadcastRouteSQLStatementAttribute (#35788) * Add TablelessDataSourceBroadcastRouteSQLStatementAttribute * Add TablelessDataSourceBroadcastRouteSQLStatementAttribute * Add TablelessDataSourceBroadcastRouteSQLStatementAttribute --- .../tableless/TablelessRouteEngineFactory.java | 9 +++----- .../tableless/TablelessRouteEngineFactoryTest.java | 24 +++++++++++++--------- ...SourceBroadcastRouteSQLStatementAttribute.java} | 23 ++++----------------- .../statement/type/dal/ShowDatabasesStatement.java | 7 +++++++ .../type/dal/ShowTableStatusStatement.java | 4 +++- .../statement/type/dal/ShowTablesStatement.java | 4 +++- 6 files changed, 34 insertions(+), 37 deletions(-) diff --git a/infra/route/core/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactory.java b/infra/route/core/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactory.java index e4e2d377206..fc66b9aef61 100644 --- a/infra/route/core/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactory.java +++ b/infra/route/core/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactory.java @@ -19,9 +19,9 @@ package org.apache.shardingsphere.infra.route.engine.tableless; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.apache.shardingsphere.infra.binder.context.available.CursorContextAvailable; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.binder.context.available.CursorContextAvailable; import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.exception.generic.NoTablelessRouteInfoException; @@ -31,11 +31,9 @@ import org.apache.shardingsphere.infra.route.engine.tableless.type.broadcast.Tab import org.apache.shardingsphere.infra.route.engine.tableless.type.unicast.TablelessDataSourceUnicastRouteEngine; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; +import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TablelessDataSourceBroadcastRouteSQLStatementAttribute; import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.SetStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.ShowDatabasesStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.ShowTableStatusStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.ShowTablesStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.AlterFunctionStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.AlterSchemaStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.AlterTablespaceStatement; @@ -122,8 +120,7 @@ public final class TablelessRouteEngineFactory { } private static TablelessRouteEngine getDALRouteEngine(final DALStatement sqlStatement, final ShardingSphereDatabase database, final DatabaseType databaseType) { - if (sqlStatement instanceof ShowTablesStatement || sqlStatement instanceof ShowTableStatusStatement || sqlStatement instanceof ShowDatabasesStatement - || sqlStatement instanceof SetStatement) { + if (sqlStatement instanceof SetStatement || sqlStatement.getAttributes().findAttribute(TablelessDataSourceBroadcastRouteSQLStatementAttribute.class).isPresent()) { return new TablelessDataSourceBroadcastRouteEngine(); } Optional<DialectDALStatementBroadcastRouteDecider> dialectDALStatementBroadcastRouteDecider = DatabaseTypedSPILoader.findService(DialectDALStatementBroadcastRouteDecider.class, databaseType); diff --git a/infra/route/core/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactoryTest.java b/infra/route/core/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactoryTest.java index 4eaaa203a8c..6e27b903d49 100644 --- a/infra/route/core/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactoryTest.java +++ b/infra/route/core/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactoryTest.java @@ -32,9 +32,10 @@ import org.apache.shardingsphere.infra.route.engine.tableless.type.unicast.Table import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes; +import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TablelessDataSourceBroadcastRouteSQLStatementAttribute; import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.DALStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.SetStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.ShowDatabasesStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.AlterSchemaStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.CloseStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.CreateSchemaStatement; @@ -90,27 +91,28 @@ class TablelessRouteEngineFactoryTest { } @Test - void assertNewInstanceForDALShow() { - DALStatement dalStatement = mock(ShowDatabasesStatement.class); - when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement); + void assertNewInstanceForSetStatement() { + SetStatement setStatement = mock(SetStatement.class); + when(sqlStatementContext.getSqlStatement()).thenReturn(setStatement); QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class)); TablelessRouteEngine actual = TablelessRouteEngineFactory.newInstance(queryContext, database); assertThat(actual, instanceOf(TablelessDataSourceBroadcastRouteEngine.class)); } @Test - void assertNewInstanceForTCL() { - TCLStatement tclStatement = mock(TCLStatement.class); - when(sqlStatementContext.getSqlStatement()).thenReturn(tclStatement); + void assertNewInstanceForTablelessDataSourceBroadcastRouteSQLStatementAttribute() { + DALStatement dalStatement = mock(DALStatement.class); + when(dalStatement.getAttributes()).thenReturn(new SQLStatementAttributes(new TablelessDataSourceBroadcastRouteSQLStatementAttribute())); + when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement); QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class)); TablelessRouteEngine actual = TablelessRouteEngineFactory.newInstance(queryContext, database); assertThat(actual, instanceOf(TablelessDataSourceBroadcastRouteEngine.class)); } @Test - void assertNewInstanceForSetStatement() { - SetStatement setStatement = mock(SetStatement.class); - when(sqlStatementContext.getSqlStatement()).thenReturn(setStatement); + void assertNewInstanceForTCL() { + TCLStatement tclStatement = mock(TCLStatement.class); + when(sqlStatementContext.getSqlStatement()).thenReturn(tclStatement); QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class)); TablelessRouteEngine actual = TablelessRouteEngineFactory.newInstance(queryContext, database); assertThat(actual, instanceOf(TablelessDataSourceBroadcastRouteEngine.class)); @@ -119,6 +121,7 @@ class TablelessRouteEngineFactoryTest { @Test void assertNewInstanceForDataSourceBroadcastRoute() { DALStatement sqlStatement = mock(DALStatement.class); + when(sqlStatement.getAttributes()).thenReturn(new SQLStatementAttributes()); DialectDALStatementBroadcastRouteDecider dialectDALStatementBroadcastRouteDecider = mock(DialectDALStatementBroadcastRouteDecider.class); when(dialectDALStatementBroadcastRouteDecider.isDataSourceBroadcastRoute(sqlStatement)).thenReturn(true); when(DatabaseTypedSPILoader.findService(DialectDALStatementBroadcastRouteDecider.class, databaseType)).thenReturn(Optional.of(dialectDALStatementBroadcastRouteDecider)); @@ -131,6 +134,7 @@ class TablelessRouteEngineFactoryTest { @Test void assertNewInstanceForInstanceBroadcastRoute() { DALStatement sqlStatement = mock(DALStatement.class); + when(sqlStatement.getAttributes()).thenReturn(new SQLStatementAttributes()); DialectDALStatementBroadcastRouteDecider dialectDALStatementBroadcastRouteDecider = mock(DialectDALStatementBroadcastRouteDecider.class); when(dialectDALStatementBroadcastRouteDecider.isInstanceBroadcastRoute(sqlStatement)).thenReturn(true); when(DatabaseTypedSPILoader.findService(DialectDALStatementBroadcastRouteDecider.class, databaseType)).thenReturn(Optional.of(dialectDALStatementBroadcastRouteDecider)); diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowDatabasesStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/attribute/type/TablelessDataSourceBroadcastRouteSQLStatementAttribute.java similarity index 62% copy from parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowDatabasesStatement.java copy to parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/attribute/type/TablelessDataSourceBroadcastRouteSQLStatementAttribute.java index 27e4b4df127..39bdb799558 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowDatabasesStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/attribute/type/TablelessDataSourceBroadcastRouteSQLStatementAttribute.java @@ -15,27 +15,12 @@ * limitations under the License. */ -package org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal; +package org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type; -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ShowFilterSegment; - -import java.util.Optional; +import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttribute; /** - * Show databases statement. + * Tableless data source broadcast route SQL statement attribute. */ -@RequiredArgsConstructor -public final class ShowDatabasesStatement extends DALStatement { - - private final ShowFilterSegment filter; - - /** - * Get filter segment. - * - * @return filter segment - */ - public Optional<ShowFilterSegment> getFilter() { - return Optional.ofNullable(filter); - } +public final class TablelessDataSourceBroadcastRouteSQLStatementAttribute implements SQLStatementAttribute { } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowDatabasesStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowDatabasesStatement.java index 27e4b4df127..6303667ccd6 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowDatabasesStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowDatabasesStatement.java @@ -19,6 +19,8 @@ package org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ShowFilterSegment; +import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes; +import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TablelessDataSourceBroadcastRouteSQLStatementAttribute; import java.util.Optional; @@ -38,4 +40,9 @@ public final class ShowDatabasesStatement extends DALStatement { public Optional<ShowFilterSegment> getFilter() { return Optional.ofNullable(filter); } + + @Override + public SQLStatementAttributes getAttributes() { + return new SQLStatementAttributes(new TablelessDataSourceBroadcastRouteSQLStatementAttribute()); + } } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowTableStatusStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowTableStatusStatement.java index 0c81c60f0cd..c18c1b68697 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowTableStatusStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowTableStatusStatement.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ShowFilte import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes; import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.DatabaseSelectRequiredSQLStatementAttribute; import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.FromDatabaseSQLStatementAttribute; +import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TablelessDataSourceBroadcastRouteSQLStatementAttribute; import java.util.Optional; @@ -58,6 +59,7 @@ public final class ShowTableStatusStatement extends DALStatement { @Override public SQLStatementAttributes getAttributes() { - return new SQLStatementAttributes(new DatabaseSelectRequiredSQLStatementAttribute(), new FromDatabaseSQLStatementAttribute(fromDatabase)); + return new SQLStatementAttributes( + new DatabaseSelectRequiredSQLStatementAttribute(), new FromDatabaseSQLStatementAttribute(fromDatabase), new TablelessDataSourceBroadcastRouteSQLStatementAttribute()); } } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowTablesStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowTablesStatement.java index 6fa250881d2..bf770a83c89 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowTablesStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/type/dal/ShowTablesStatement.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ShowFilte import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes; import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.DatabaseSelectRequiredSQLStatementAttribute; import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.FromDatabaseSQLStatementAttribute; +import org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.TablelessDataSourceBroadcastRouteSQLStatementAttribute; import java.util.Optional; @@ -60,6 +61,7 @@ public final class ShowTablesStatement extends DALStatement { @Override public SQLStatementAttributes getAttributes() { - return new SQLStatementAttributes(new DatabaseSelectRequiredSQLStatementAttribute(), new FromDatabaseSQLStatementAttribute(fromDatabase)); + return new SQLStatementAttributes( + new DatabaseSelectRequiredSQLStatementAttribute(), new FromDatabaseSQLStatementAttribute(fromDatabase), new TablelessDataSourceBroadcastRouteSQLStatementAttribute()); } }