This is an automated email from the ASF dual-hosted git repository.
menghaoranss 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 87b3476cbb7 Use database default schema in SQL context extractor
(#39618)
87b3476cbb7 is described below
commit 87b3476cbb785e38ad88792df78f93e2d31e170d
Author: Haoran Meng <[email protected]>
AuthorDate: Fri Aug 28 18:17:18 2026 +0800
Use database default schema in SQL context extractor (#39618)
---
.../extractor/SQLStatementContextExtractor.java | 7 +++--
.../SQLStatementContextExtractorTest.java | 31 ++++++++++++++++++++++
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractor.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractor.java
index f5b66cb2ea8..a060f83a172 100644
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractor.java
+++
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractor.java
@@ -19,7 +19,6 @@ package
org.apache.shardingsphere.infra.binder.context.extractor;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import
org.apache.shardingsphere.infra.binder.context.available.WhereContextAvailable;
import
org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertSelectContext;
@@ -64,12 +63,12 @@ public final class SQLStatementContextExtractor {
return tableNames;
}
return
sqlStatementContext.getSqlStatement().getAttributes().findAttribute(IndexSQLStatementAttribute.class)
- .map(optional -> getTableNames(database,
sqlStatementContext.getSqlStatement().getDatabaseType(),
optional.getIndexes())).orElse(Collections.emptyList());
+ .map(optional -> getTableNames(database,
optional.getIndexes())).orElse(Collections.emptyList());
}
- private static Collection<String> getTableNames(final
ShardingSphereDatabase database, final DatabaseType databaseType, final
Collection<IndexSegment> indexes) {
+ private static Collection<String> getTableNames(final
ShardingSphereDatabase database, final Collection<IndexSegment> indexes) {
Collection<String> result = new LinkedList<>();
- for (QualifiedTable each : IndexMetaDataUtils.getTableNames(database,
databaseType, indexes)) {
+ for (QualifiedTable each : IndexMetaDataUtils.getTableNames(database,
indexes)) {
result.add(each.getTableName());
}
return result;
diff --git
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractorTest.java
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractorTest.java
index 09a666919b1..2695b29bbbb 100644
---
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractorTest.java
+++
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractorTest.java
@@ -17,12 +17,24 @@
package org.apache.shardingsphere.infra.binder.context.extractor;
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import
org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertSelectContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexNameSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.SQLStatementAttributes;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.attribute.type.IndexSQLStatementAttribute;
+import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import org.junit.jupiter.api.Test;
import java.util.Collection;
@@ -36,6 +48,25 @@ import static org.mockito.Mockito.when;
class SQLStatementContextExtractorTest {
+ @Test
+ void assertGetTableNamesWithDatabaseDefaultSchema() {
+ IndexSegment indexSegment = new IndexSegment(0, 0, new
IndexNameSegment(0, 0, new IdentifierValue("foo_idx")));
+ IndexSQLStatementAttribute indexSQLStatementAttribute =
mock(IndexSQLStatementAttribute.class);
+
when(indexSQLStatementAttribute.getIndexes()).thenReturn(Collections.singleton(indexSegment));
+ SQLStatement sqlStatement = mock(SQLStatement.class);
+ when(sqlStatement.getAttributes()).thenReturn(new
SQLStatementAttributes(indexSQLStatementAttribute));
+ SQLStatementContext sqlStatementContext =
mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.emptyList());
+ when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement);
+ ShardingSphereTable table = new ShardingSphereTable(
+ "foo_tbl", Collections.emptyList(), Collections.singleton(new
ShardingSphereIndex("foo_idx", Collections.emptyList(), false)),
Collections.emptyList());
+ ShardingSphereSchema schema = new
ShardingSphereSchema("foo_default_schema", mock(DatabaseType.class),
Collections.singleton(table), Collections.emptyList());
+ ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
+ when(database.getDefaultSchemaName()).thenReturn("foo_default_schema");
+ when(database.getSchema("foo_default_schema")).thenReturn(schema);
+ assertThat(SQLStatementContextExtractor.getTableNames(database,
sqlStatementContext), is(Collections.singletonList("foo_tbl")));
+ }
+
@Test
void assertGetAllSubqueryContextsForSelectStatement() {
SelectStatementContext selectStatementContext =
mock(SelectStatementContext.class);