From e42f4e52d4406be73a890d9c7fa56472c6d6a820 Mon Sep 17 00:00:00 2001 From: Zhengqiang Duan Date: Thu, 12 Dec 2024 16:05:41 +0800 Subject: [PATCH] Refactor ColumnSegmentBoundInfo and correct pass to SQLBindEngine databaseName (#34023) * Refactor ColumnSegmentBoundInfo and correct pass to SQLBindEngine databaseName * Refactor ColumnSegmentBoundInfo and correct pass to SQLBindEngine databaseName * fix unit test * fix unit test * fix unit test * fix unit test --- ...cryptSelectProjectionSupportedChecker.java | 2 +- ...ptPredicateColumnSupportedCheckerTest.java | 15 +++++---- ...tSelectProjectionSupportedCheckerTest.java | 17 +++++----- .../merge/dql/EncryptMergedResultTest.java | 11 ++++--- ...tSelectColumnsEncryptorComparatorTest.java | 5 +-- .../EncryptGeneratorFixtureBuilder.java | 7 ++-- .../EncryptProjectionTokenGeneratorTest.java | 5 +-- .../expression/type/ColumnSegmentBinder.java | 2 +- .../from/type/SimpleTableSegmentBinder.java | 3 +- .../engine/util/SubqueryTableBindUtils.java | 7 ++-- .../projection/impl/ColumnProjectionTest.java | 3 +- .../assign/AssignmentSegmentBinderTest.java | 3 +- .../type/ColumnSegmentBinderTest.java | 20 ++++++------ .../type/SubquerySegmentBinderTest.java | 5 +-- .../connection/ShardingSphereConnection.java | 1 - .../generator/PipelineDDLGenerator.java | 4 +-- .../context/SQLFederationExecutorContext.java | 2 +- .../enumerable/EnumerableScanExecutor.java | 4 +-- .../EnumerableScanExecutorTest.java | 2 +- .../generic/bound/ColumnSegmentBoundInfo.java | 32 ++++++++++++++----- .../generic/bound/TableSegmentBoundInfo.java | 7 ++-- .../handler/distsql/rul/PreviewExecutor.java | 3 +- .../MySQLComFieldListPacketExecutor.java | 8 ++--- .../query/MySQLMultiStatementsHandler.java | 4 +-- .../MySQLComQueryPacketExecutorTest.java | 4 +-- .../MySQLMultiStatementsHandlerTest.java | 2 +- .../OpenGaussComBatchBindExecutorTest.java | 2 +- .../PostgreSQLBatchedStatementsExecutor.java | 5 +-- ...dBatchedStatementsCommandExecutorTest.java | 2 +- ...stgreSQLBatchedStatementsExecutorTest.java | 2 +- 30 files changed, 112 insertions(+), 77 deletions(-) diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedChecker.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedChecker.java index 5cb206098d8ba..a0bdeb2d5c701 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedChecker.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedChecker.java @@ -94,7 +94,7 @@ private boolean containsEncryptProjectionInCombineSegment(final EncryptRule rule private ColumnSegmentBoundInfo getColumnSegmentBoundInfo(final Projection projection) { return projection instanceof ColumnProjection - ? new ColumnSegmentBoundInfo(null, null, ((ColumnProjection) projection).getOriginalTable(), ((ColumnProjection) projection).getOriginalColumn()) + ? new ColumnSegmentBoundInfo(null, ((ColumnProjection) projection).getOriginalTable(), ((ColumnProjection) projection).getOriginalColumn()) : new ColumnSegmentBoundInfo(new IdentifierValue(projection.getColumnLabel())); } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/predicate/EncryptPredicateColumnSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/predicate/EncryptPredicateColumnSupportedCheckerTest.java index e5387f7573171..1c2ef0ba5aff8 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/predicate/EncryptPredicateColumnSupportedCheckerTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/predicate/EncryptPredicateColumnSupportedCheckerTest.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; @@ -66,9 +67,11 @@ void assertCheckWithDifferentEncryptorsInJoinCondition() { private SQLStatementContext mockSelectStatementContextWithDifferentEncryptorsInJoinCondition() { ColumnSegment leftColumn = new ColumnSegment(0, 0, new IdentifierValue("user_name")); - leftColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("t_user"), new IdentifierValue("user_name"))); + leftColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_user"), + new IdentifierValue("user_name"))); ColumnSegment rightColumn = new ColumnSegment(0, 0, new IdentifierValue("user_id")); - rightColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("t_user"), new IdentifierValue("user_id"))); + rightColumn.setColumnBoundInfo( + new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_user"), new IdentifierValue("user_id"))); SelectStatementContext result = mock(SelectStatementContext.class); when(result.getJoinConditions()).thenReturn(Collections.singleton(new BinaryOperationExpression(0, 0, leftColumn, rightColumn, "=", ""))); return result; @@ -82,8 +85,8 @@ void assertCheckWithNotMatchedLikeQueryEncryptor() { private SQLStatementContext mockSelectStatementContextWithLike() { ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("user_name")); - columnSegment.setColumnBoundInfo( - new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("t_user"), new IdentifierValue("user_name"))); + columnSegment.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_user"), + new IdentifierValue("user_name"))); SelectStatementContext result = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); when(result.getTablesContext().findTableNames(Collections.singleton(columnSegment), null)).thenReturn(Collections.singletonMap("user_name", "t_user")); when(result.getColumnSegments()).thenReturn(Collections.singleton(columnSegment)); @@ -100,8 +103,8 @@ void assertCheckSuccess() { private SQLStatementContext mockSelectStatementContextWithEqual() { ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("user_name")); - columnSegment.setColumnBoundInfo( - new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("t_user"), new IdentifierValue("user_name"))); + columnSegment.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_user"), + new IdentifierValue("user_name"))); SelectStatementContext result = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); when(result.getTablesContext().findTableNames(Collections.singleton(columnSegment), null)).thenReturn(Collections.singletonMap("user_name", "t_user")); when(result.getColumnSegments()).thenReturn(Collections.singleton(columnSegment)); diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java index 023781df499f1..6bdb6214a914b 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java @@ -27,6 +27,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.combine.CombineSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ShorthandProjectionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; @@ -91,16 +92,16 @@ private SelectStatementContext mockSelectStatementContext() { when(combineSegment.getLeft().getStartIndex()).thenReturn(0); when(combineSegment.getRight().getStartIndex()).thenReturn(1); when(result.getSqlStatement().getCombine()).thenReturn(Optional.of(combineSegment)); - ColumnProjection leftColumn1 = new ColumnProjection(new IdentifierValue("f"), new IdentifierValue("foo_col_1"), null, databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col_1"))); - ColumnProjection leftColumn2 = new ColumnProjection(new IdentifierValue("f"), new IdentifierValue("foo_col_2"), null, databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col_2"))); + ColumnProjection leftColumn1 = new ColumnProjection(new IdentifierValue("f"), new IdentifierValue("foo_col_1"), null, databaseType, null, null, + new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue("")), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col_1"))); + ColumnProjection leftColumn2 = new ColumnProjection(new IdentifierValue("f"), new IdentifierValue("foo_col_2"), null, databaseType, null, null, + new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue("")), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col_2"))); SelectStatementContext leftSelectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); when(leftSelectStatementContext.getProjectionsContext().getExpandProjections()).thenReturn(Arrays.asList(leftColumn1, leftColumn2)); - ColumnProjection rightColumn1 = new ColumnProjection(new IdentifierValue("b"), new IdentifierValue("bar_col_1"), null, databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("bar_tbl"), new IdentifierValue("bar_col_1"))); - ColumnProjection rightColumn2 = new ColumnProjection(new IdentifierValue("b"), new IdentifierValue("bar_col_2"), null, databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("bar_tbl"), new IdentifierValue("bar_col_2"))); + ColumnProjection rightColumn1 = new ColumnProjection(new IdentifierValue("b"), new IdentifierValue("bar_col_1"), null, databaseType, null, null, + new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue("")), new IdentifierValue("bar_tbl"), new IdentifierValue("bar_col_1"))); + ColumnProjection rightColumn2 = new ColumnProjection(new IdentifierValue("b"), new IdentifierValue("bar_col_2"), null, databaseType, null, null, + new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue("")), new IdentifierValue("bar_tbl"), new IdentifierValue("bar_col_2"))); SelectStatementContext rightSelectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); when(rightSelectStatementContext.getProjectionsContext().getExpandProjections()).thenReturn(Arrays.asList(rightColumn1, rightColumn2)); Map subqueryContexts = new LinkedHashMap<>(2, 1F); diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResultTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResultTest.java index 755a38a13e7da..eb827dd98deab 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResultTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResultTest.java @@ -33,6 +33,7 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -107,8 +108,9 @@ void assertGetValueWithoutEncryptColumn() throws SQLException { @Test void assertGetValueWithEncryptColumn() throws SQLException { - ColumnProjection columnProjection = new ColumnProjection(new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"), new IdentifierValue("foo_alias"), databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"))); + ColumnProjection columnProjection = + new ColumnProjection(new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"), new IdentifierValue("foo_alias"), databaseType, null, null, new ColumnSegmentBoundInfo( + new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"))); when(selectStatementContext.findColumnProjection(1)).thenReturn(Optional.of(columnProjection)); when(selectStatementContext.getTablesContext().getSchemaName()).thenReturn(Optional.of("foo_schema")); EncryptAlgorithm encryptAlgorithm = mock(EncryptAlgorithm.class); @@ -122,8 +124,9 @@ void assertGetValueWithEncryptColumn() throws SQLException { @Test void assertGetValueFailed() throws SQLException { - ColumnProjection columnProjection = new ColumnProjection(new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"), new IdentifierValue("foo_alias"), databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"))); + ColumnProjection columnProjection = + new ColumnProjection(new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"), new IdentifierValue("foo_alias"), databaseType, null, null, new ColumnSegmentBoundInfo( + new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"))); when(selectStatementContext.findColumnProjection(1)).thenReturn(Optional.of(columnProjection)); when(selectStatementContext.getTablesContext().getSchemaName()).thenReturn(Optional.of("foo_schema")); EncryptAlgorithm encryptAlgorithm = mock(EncryptAlgorithm.class); diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/comparator/InsertSelectColumnsEncryptorComparatorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/comparator/InsertSelectColumnsEncryptorComparatorTest.java index 76be5b0c8dcb3..9a73d2b1103cd 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/comparator/InsertSelectColumnsEncryptorComparatorTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/comparator/InsertSelectColumnsEncryptorComparatorTest.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -59,13 +60,13 @@ void assertInsertSelectIsSame() { private ColumnProjection getSelectProjection(final String pwd, final IdentifierValue databaseValue, final IdentifierValue schemaValue) { return new ColumnProjection(new IdentifierValue("table2"), new IdentifierValue(pwd), null, null, null, null, - new ColumnSegmentBoundInfo(databaseValue, schemaValue, new IdentifierValue("table2"), new IdentifierValue(pwd))); + new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(databaseValue, schemaValue), new IdentifierValue("table2"), new IdentifierValue(pwd))); } private ColumnSegment getInsertColumnSegment(final IdentifierValue databaseValue, final IdentifierValue schemaValue, final String tableName, final String columnName) { ColumnSegment result = mock(ColumnSegment.class); when(result.getColumnBoundInfo()) - .thenReturn(new ColumnSegmentBoundInfo(databaseValue, schemaValue, new IdentifierValue(tableName), new IdentifierValue(columnName))); + .thenReturn(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(databaseValue, schemaValue), new IdentifierValue(tableName), new IdentifierValue(columnName))); return result; } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java index 72a37c30d60e1..80287886d790c 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java @@ -50,6 +50,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +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.dml.InsertStatement; @@ -128,10 +129,10 @@ private static InsertStatement createInsertSelectStatement(final boolean contain InsertStatement result = new MySQLInsertStatement(); result.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_user")))); ColumnSegment userIdColumn = new ColumnSegment(0, 0, new IdentifierValue("user_id")); - userIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("t_user"), + userIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("t_user"), new IdentifierValue("user_id"))); ColumnSegment userNameColumn = new ColumnSegment(0, 0, new IdentifierValue("user_name")); - userNameColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), + userNameColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("t_user"), new IdentifierValue("user_name"))); List insertColumns = Arrays.asList(userIdColumn, userNameColumn); if (containsInsertColumns) { @@ -145,7 +146,7 @@ private static InsertStatement createInsertSelectStatement(final boolean contain ProjectionsSegment projections = new ProjectionsSegment(0, 0); projections.getProjections().add(new ColumnProjectionSegment(userIdColumn)); ColumnSegment statusColumn = new ColumnSegment(0, 0, new IdentifierValue("status")); - statusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("t_user"), + statusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("t_user"), new IdentifierValue("status"))); projections.getProjections().add(new ColumnProjectionSegment(statusColumn)); selectStatement.setProjections(projections); diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java index 18b3e0c84ffa5..627e0b4b17151 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java @@ -32,6 +32,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +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.value.identifier.IdentifierValue; @@ -80,7 +81,7 @@ void assertGenerateSQLTokensWhenOwnerMatchTableAlias() { SimpleTableSegment doctorTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor"))); doctorTable.setAlias(new AliasSegment(0, 0, new IdentifierValue("a"))); ColumnSegment column = new ColumnSegment(0, 0, new IdentifierValue("mobile")); - column.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("doctor"), + column.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("doctor"), new IdentifierValue("mobile"))); column.setOwner(new OwnerSegment(0, 0, new IdentifierValue("a"))); ProjectionsSegment projections = mock(ProjectionsSegment.class); @@ -102,7 +103,7 @@ void assertGenerateSQLTokensWhenOwnerMatchTableAliasForSameTable() { SimpleTableSegment doctorTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor"))); doctorTable.setAlias(new AliasSegment(0, 0, new IdentifierValue("a"))); ColumnSegment column = new ColumnSegment(0, 0, new IdentifierValue("mobile")); - column.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("doctor"), + column.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("doctor"), new IdentifierValue("mobile"))); column.setOwner(new OwnerSegment(0, 0, new IdentifierValue("a"))); ProjectionsSegment projections = mock(ProjectionsSegment.class); 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 e1d828befe82d..3e3a894764c12 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 @@ -260,7 +260,7 @@ private static ColumnSegmentBoundInfo createColumnSegmentBoundInfo(final ColumnS : segmentOriginalTable; IdentifierValue segmentOriginalColumn = segment.getColumnBoundInfo().getOriginalColumn(); IdentifierValue originalColumn = Optional.ofNullable(inputColumnSegment).map(optional -> optional.getColumnBoundInfo().getOriginalColumn()).orElse(segmentOriginalColumn); - return new ColumnSegmentBoundInfo(originalDatabase, originalSchema, originalTable, originalColumn); + return new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(originalDatabase, originalSchema), originalTable, originalColumn); } /** 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 8c74c0dd5b49c..e77dc4f7f4ebe 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 @@ -42,6 +42,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +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.value.identifier.IdentifierValue; @@ -158,7 +159,7 @@ private static ColumnSegment createColumnSegment(final SimpleTableSegment segmen final ShardingSphereColumn column, final QuoteCharacter quoteCharacter, final IdentifierValue tableName) { ColumnSegment result = new ColumnSegment(0, 0, new IdentifierValue(column.getName(), quoteCharacter)); result.setOwner(new OwnerSegment(0, 0, segment.getAlias().orElse(tableName))); - result.setColumnBoundInfo(new ColumnSegmentBoundInfo(databaseName, schemaName, tableName, new IdentifierValue(column.getName(), quoteCharacter))); + result.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(databaseName, schemaName), tableName, new IdentifierValue(column.getName(), quoteCharacter))); return result; } } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/util/SubqueryTableBindUtils.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/util/SubqueryTableBindUtils.java index 74026fc429946..40d640b910bd5 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/util/SubqueryTableBindUtils.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/util/SubqueryTableBindUtils.java @@ -33,6 +33,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasAvailable; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import java.util.Collection; @@ -75,9 +76,9 @@ private static ColumnProjectionSegment createColumnProjection(final ColumnProjec if (!Strings.isNullOrEmpty(subqueryTableName.getValue())) { newColumnSegment.setOwner(new OwnerSegment(0, 0, subqueryTableName)); } - newColumnSegment.setColumnBoundInfo( - new ColumnSegmentBoundInfo(originalColumn.getColumn().getColumnBoundInfo().getOriginalDatabase(), originalColumn.getColumn().getColumnBoundInfo().getOriginalSchema(), - originalColumn.getColumn().getColumnBoundInfo().getOriginalTable(), originalColumn.getColumn().getColumnBoundInfo().getOriginalColumn())); + ColumnSegmentBoundInfo columnBoundInfo = originalColumn.getColumn().getColumnBoundInfo(); + newColumnSegment.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(columnBoundInfo.getOriginalDatabase(), columnBoundInfo.getOriginalSchema()), + columnBoundInfo.getOriginalTable(), columnBoundInfo.getOriginalColumn())); ColumnProjectionSegment result = new ColumnProjectionSegment(newColumnSegment); result.setVisible(originalColumn.isVisible()); return result; diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjectionTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjectionTest.java index 0b84d3971e6d9..81d57894a32ea 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjectionTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjectionTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; @@ -53,7 +54,7 @@ void assertGetOriginalTableWithEmptyOriginalTableAndWithOwner() { @Test void assertGetOriginalTable() { ColumnProjection projection = new ColumnProjection(new IdentifierValue("owner"), new IdentifierValue("name"), new IdentifierValue("alias"), databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("tbl"), new IdentifierValue(""))); + null, null, new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(null, null), new IdentifierValue("tbl"), new IdentifierValue(""))); assertThat(projection.getOriginalTable(), is(new IdentifierValue("tbl"))); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/assign/AssignmentSegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/assign/AssignmentSegmentBinderTest.java index 1e7797b0df17b..fa7e5f76aacef 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/assign/AssignmentSegmentBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/assign/AssignmentSegmentBinderTest.java @@ -29,6 +29,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ColumnProjectionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; @@ -47,7 +48,7 @@ class AssignmentSegmentBinderTest { void assertBindAssignmentSegment() { Collection assignments = new LinkedList<>(); ColumnSegment boundOrderIdColumn = new ColumnSegment(0, 0, new IdentifierValue("order_id")); - boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), + boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("t_order"), new IdentifierValue("order_id"))); ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("order_id")); assignments.add(new ColumnAssignmentSegment(0, 0, Collections.singletonList(columnSegment), new LiteralExpressionSegment(0, 0, 1))); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinderTest.java index 86127e9d1fad0..9952c36f686bf 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinderTest.java @@ -54,11 +54,11 @@ class ColumnSegmentBinderTest { void assertBindWithMultiTablesJoinAndNoOwner() { Multimap tableBinderContexts = LinkedHashMultimap.create(); ColumnSegment boundOrderIdColumn = new ColumnSegment(0, 0, new IdentifierValue("order_id")); - boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order"), new IdentifierValue("order_id"))); tableBinderContexts.put(new CaseInsensitiveString("t_order"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderIdColumn)))); ColumnSegment boundItemIdColumn = new ColumnSegment(0, 0, new IdentifierValue("item_id")); - boundItemIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundItemIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order_item"), new IdentifierValue("item_id"))); tableBinderContexts.put(new CaseInsensitiveString("t_order_item"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundItemIdColumn)))); ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("order_id")); @@ -77,11 +77,11 @@ void assertBindWithMultiTablesJoinAndNoOwner() { void assertBindFromOuterTable() { Multimap outerTableBinderContexts = LinkedHashMultimap.create(); ColumnSegment boundOrderStatusColumn = new ColumnSegment(0, 0, new IdentifierValue("status")); - boundOrderStatusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderStatusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order"), new IdentifierValue("status"))); outerTableBinderContexts.put(new CaseInsensitiveString("t_order"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderStatusColumn)))); ColumnSegment boundOrderItemStatusColumn = new ColumnSegment(0, 0, new IdentifierValue("status")); - boundOrderItemStatusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderItemStatusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order_item"), new IdentifierValue("status"))); outerTableBinderContexts.put(new CaseInsensitiveString("t_order_item"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderItemStatusColumn)))); SQLStatementBinderContext binderContext = @@ -100,11 +100,11 @@ void assertBindFromOuterTable() { void assertBindWithSameTableAliasAndSameProjection() { Multimap tableBinderContexts = LinkedHashMultimap.create(); ColumnSegment boundOrderColumn = new ColumnSegment(0, 0, new IdentifierValue("status")); - boundOrderColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order"), new IdentifierValue("status"))); tableBinderContexts.put(new CaseInsensitiveString("temp"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderColumn)))); ColumnSegment boundOrderItemColumn = new ColumnSegment(0, 0, new IdentifierValue("status")); - boundOrderItemColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderItemColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order_item"), new IdentifierValue("status"))); tableBinderContexts.put(new CaseInsensitiveString("temp"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderItemColumn)))); SQLStatementBinderContext binderContext = @@ -118,11 +118,11 @@ void assertBindWithSameTableAliasAndSameProjection() { void assertBindWithSameTableAliasAndDifferentProjection() { Multimap tableBinderContexts = LinkedHashMultimap.create(); ColumnSegment boundOrderColumn = new ColumnSegment(0, 0, new IdentifierValue("order_id")); - boundOrderColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order"), new IdentifierValue("order_id"))); tableBinderContexts.put(new CaseInsensitiveString("temp"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderColumn)))); ColumnSegment boundOrderItemColumn = new ColumnSegment(0, 0, new IdentifierValue("status")); - boundOrderItemColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderItemColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order_item"), new IdentifierValue("status"))); tableBinderContexts.put(new CaseInsensitiveString("temp"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderItemColumn)))); SQLStatementBinderContext binderContext = @@ -142,11 +142,11 @@ void assertBindWithSameTableAliasAndDifferentProjection() { void assertBindOwner() { Multimap tableBinderContexts = LinkedHashMultimap.create(); ColumnSegment boundOrderIdColumn = new ColumnSegment(0, 0, new IdentifierValue("order_id")); - boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order"), new IdentifierValue("order_id"))); tableBinderContexts.put(new CaseInsensitiveString("t_order"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderIdColumn)))); ColumnSegment boundItemIdColumn = new ColumnSegment(0, 0, new IdentifierValue("item_id")); - boundItemIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundItemIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order_item"), new IdentifierValue("item_id"))); tableBinderContexts.put(new CaseInsensitiveString("t_order_item"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundItemIdColumn)))); ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("order_id")); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/SubquerySegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/SubquerySegmentBinderTest.java index d6fe501b167ac..96fa3d2005521 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/SubquerySegmentBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/SubquerySegmentBinderTest.java @@ -36,6 +36,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +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.value.identifier.IdentifierValue; @@ -71,8 +72,8 @@ void assertBind() { SQLStatementBinderContext sqlStatementBinderContext = new SQLStatementBinderContext( createMetaData(), "foo_db", TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), Collections.emptySet()); ColumnSegment boundNameColumn = new ColumnSegment(7, 13, new IdentifierValue("user_id")); - boundNameColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo( - new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("t_order_item"), new IdentifierValue("user_id"))); + boundNameColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo( + new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("t_order_item"), new IdentifierValue("user_id"))); sqlStatementBinderContext.getExternalTableBinderContexts().put(new CaseInsensitiveString("t_order_item"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundNameColumn)))); Multimap outerTableBinderContexts = LinkedHashMultimap.create(); diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java index eff5feae3497e..7da8af0ac3531 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java @@ -288,7 +288,6 @@ public boolean isValid(final int timeout) throws SQLException { @Override public String getSchema() { - // TODO return databaseName for now in getSchema(), the same as before return currentDatabaseName; } diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java index 16b27e2929ecc..d56e58ebc63e2 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java @@ -128,8 +128,8 @@ private String decorateActualSQL(final String databaseName, final String targetT return doDecorateActualTable(replaceMap, sql); } - private SQLStatementContext parseSQL(final String databaseName, final SQLParserEngine parserEngine, final String sql) { - return new SQLBindEngine(null, databaseName, new HintValueContext()).bind(parserEngine.parse(sql, true), Collections.emptyList()); + private SQLStatementContext parseSQL(final String currentDatabaseName, final SQLParserEngine parserEngine, final String sql) { + return new SQLBindEngine(null, currentDatabaseName, new HintValueContext()).bind(parserEngine.parse(sql, true), Collections.emptyList()); } private void appendFromIndexAndConstraint(final Map replaceMap, final String targetTableName, final SQLStatementContext sqlStatementContext) { diff --git a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/context/SQLFederationExecutorContext.java b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/context/SQLFederationExecutorContext.java index 8b24e5e401676..f1db1c7770680 100644 --- a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/context/SQLFederationExecutorContext.java +++ b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/context/SQLFederationExecutorContext.java @@ -31,7 +31,7 @@ @Getter public final class SQLFederationExecutorContext { - private final String databaseName; + private final String currentDatabaseName; private final String schemaName; diff --git a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java index 1aa6915c35653..3a21637fc6bd2 100644 --- a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java +++ b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java @@ -104,7 +104,7 @@ public final class EnumerableScanExecutor implements ScanExecutor { @Override public Enumerable execute(final ShardingSphereTable table, final ScanExecutorContext scanContext) { - String databaseName = executorContext.getDatabaseName(); + String databaseName = executorContext.getCurrentDatabaseName(); String schemaName = executorContext.getSchemaName(); DatabaseType databaseType = optimizerContext.getParserContext(databaseName).getDatabaseType(); if (new SystemDatabase(databaseType).getSystemSchemas().contains(schemaName)) { @@ -206,7 +206,7 @@ private QueryContext createQueryContext(final ShardingSphereMetaData metaData, f optimizerContext.getSqlParserRule().getSqlStatementCache(), optimizerContext.getSqlParserRule().getParseTreeCache()).parse(sql, useCache); List params = getParameters(sqlString.getParamIndexes()); HintValueContext hintValueContext = new HintValueContext(); - SQLStatementContext sqlStatementContext = new SQLBindEngine(metaData, executorContext.getDatabaseName(), hintValueContext).bind(sqlStatement, params); + SQLStatementContext sqlStatementContext = new SQLBindEngine(metaData, executorContext.getCurrentDatabaseName(), hintValueContext).bind(sqlStatement, params); return new QueryContext(sqlStatementContext, sql, params, hintValueContext, federationContext.getQueryContext().getConnectionContext(), metaData, useCache); } diff --git a/kernel/sql-federation/executor/src/test/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutorTest.java b/kernel/sql-federation/executor/src/test/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutorTest.java index 47c57ef397f0b..46de51b87818e 100644 --- a/kernel/sql-federation/executor/src/test/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutorTest.java +++ b/kernel/sql-federation/executor/src/test/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutorTest.java @@ -51,7 +51,7 @@ void assertExecuteWithStatistics() { OptimizerContext optimizerContext = mock(OptimizerContext.class, RETURNS_DEEP_STUBS); when(optimizerContext.getParserContext(any()).getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")); SQLFederationExecutorContext executorContext = mock(SQLFederationExecutorContext.class); - when(executorContext.getDatabaseName()).thenReturn("db"); + when(executorContext.getCurrentDatabaseName()).thenReturn("db"); when(executorContext.getSchemaName()).thenReturn("pg_catalog"); ShardingSphereStatistics statistics = mock(ShardingSphereStatistics.class, RETURNS_DEEP_STUBS); ShardingSphereDatabaseData databaseData = mock(ShardingSphereDatabaseData.class, RETURNS_DEEP_STUBS); diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/ColumnSegmentBoundInfo.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/ColumnSegmentBoundInfo.java index a4b8a674379e9..e3a6f8175ba7e 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/ColumnSegmentBoundInfo.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/ColumnSegmentBoundInfo.java @@ -23,25 +23,41 @@ /** * Column segment bound info. */ -@Getter public final class ColumnSegmentBoundInfo { - private final IdentifierValue originalDatabase; - - private final IdentifierValue originalSchema; + private final TableSegmentBoundInfo tableBoundInfo; + @Getter private final IdentifierValue originalTable; + @Getter private final IdentifierValue originalColumn; public ColumnSegmentBoundInfo(final IdentifierValue originalColumn) { - this(null, null, null, originalColumn); + this(null, null, originalColumn); } - public ColumnSegmentBoundInfo(final IdentifierValue originalDatabase, final IdentifierValue originalSchema, final IdentifierValue originalTable, final IdentifierValue originalColumn) { - this.originalDatabase = null == originalDatabase ? new IdentifierValue("") : originalDatabase; - this.originalSchema = null == originalSchema ? new IdentifierValue("") : originalSchema; + public ColumnSegmentBoundInfo(final TableSegmentBoundInfo tableBoundInfo, final IdentifierValue originalTable, final IdentifierValue originalColumn) { + this.tableBoundInfo = null == tableBoundInfo ? new TableSegmentBoundInfo(null, null) : tableBoundInfo; this.originalTable = null == originalTable ? new IdentifierValue("") : originalTable; this.originalColumn = null == originalColumn ? new IdentifierValue("") : originalColumn; } + + /** + * Get original database. + * + * @return original database + */ + public IdentifierValue getOriginalDatabase() { + return tableBoundInfo.getOriginalDatabase(); + } + + /** + * Get original schema. + * + * @return original schema + */ + public IdentifierValue getOriginalSchema() { + return tableBoundInfo.getOriginalSchema(); + } } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/TableSegmentBoundInfo.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/TableSegmentBoundInfo.java index 97ec0c7f8aaf5..e996a70993b98 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/TableSegmentBoundInfo.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/TableSegmentBoundInfo.java @@ -18,17 +18,20 @@ package org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound; import lombok.Getter; -import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; /** * Table name bound info. */ -@RequiredArgsConstructor @Getter public final class TableSegmentBoundInfo { private final IdentifierValue originalDatabase; private final IdentifierValue originalSchema; + + public TableSegmentBoundInfo(final IdentifierValue originalDatabase, final IdentifierValue originalSchema) { + this.originalDatabase = null == originalDatabase ? new IdentifierValue("") : originalDatabase; + this.originalSchema = null == originalSchema ? new IdentifierValue("") : originalSchema; + } } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java index 5b83098164cc4..ae9a7909c67a3 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java @@ -91,7 +91,8 @@ public Collection getRows(final PreviewStatement sqlSta SQLStatement toBePreviewedStatement = metaData.getGlobalRuleMetaData().getSingleRule(SQLParserRule.class).getSQLParserEngine(database.getProtocolType()).parse(toBePreviewedSQL, false); HintValueContext hintValueContext = connectionContext.getQueryContext().getHintValueContext(); hintValueContext.setSkipMetadataValidate(true); - SQLStatementContext toBePreviewedStatementContext = new SQLBindEngine(metaData, database.getName(), hintValueContext).bind(toBePreviewedStatement, Collections.emptyList()); + String currentDatabaseName = connectionContext.getQueryContext().getConnectionContext().getCurrentDatabaseName().orElse(null); + SQLStatementContext toBePreviewedStatementContext = new SQLBindEngine(metaData, currentDatabaseName, hintValueContext).bind(toBePreviewedStatement, Collections.emptyList()); QueryContext queryContext = new QueryContext(toBePreviewedStatementContext, toBePreviewedSQL, Collections.emptyList(), hintValueContext, connectionContext.getQueryContext().getConnectionContext(), metaData); if (toBePreviewedStatementContext instanceof CursorAvailable && toBePreviewedStatementContext instanceof CursorAware) { diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java index e7ffdbf1a348a..344a5ef30d4f5 100644 --- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java +++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java @@ -63,18 +63,18 @@ public final class MySQLComFieldListPacketExecutor implements CommandExecutor { @Override public Collection execute() throws SQLException { - String databaseName = connectionSession.getCurrentDatabaseName(); - String sql = String.format(SQL, packet.getTable(), databaseName); + String currentDatabaseName = connectionSession.getCurrentDatabaseName(); + String sql = String.format(SQL, packet.getTable(), currentDatabaseName); MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts(); SQLParserRule sqlParserRule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class); SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(TypedSPILoader.getService(DatabaseType.class, "MySQL")).parse(sql, false); HintValueContext hintValueContext = SQLHintUtils.extractHint(sql); - SQLStatementContext sqlStatementContext = new SQLBindEngine(metaDataContexts.getMetaData(), databaseName, hintValueContext).bind(sqlStatement, Collections.emptyList()); + SQLStatementContext sqlStatementContext = new SQLBindEngine(metaDataContexts.getMetaData(), currentDatabaseName, hintValueContext).bind(sqlStatement, Collections.emptyList()); ProxyDatabaseConnectionManager databaseConnectionManager = connectionSession.getDatabaseConnectionManager(); QueryContext queryContext = new QueryContext(sqlStatementContext, sql, Collections.emptyList(), hintValueContext, connectionSession.getConnectionContext(), metaDataContexts.getMetaData()); databaseConnector = DatabaseConnectorFactory.getInstance().newInstance(queryContext, databaseConnectionManager, false); databaseConnector.execute(); - return createColumnDefinition41Packets(databaseName); + return createColumnDefinition41Packets(currentDatabaseName); } private Collection createColumnDefinition41Packets(final String databaseName) throws SQLException { diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java index a4d76ebb4bd31..8341bcd1ea17c 100644 --- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java +++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java @@ -124,7 +124,7 @@ private List extractMultiStatements(final Pattern pattern, final String private QueryContext createQueryContext(final String sql, final SQLStatement sqlStatement) { HintValueContext hintValueContext = SQLHintUtils.extractHint(sql); SQLStatementContext sqlStatementContext = - new SQLBindEngine(metaDataContexts.getMetaData(), connectionSession.getUsedDatabaseName(), hintValueContext).bind(sqlStatement, Collections.emptyList()); + new SQLBindEngine(metaDataContexts.getMetaData(), connectionSession.getCurrentDatabaseName(), hintValueContext).bind(sqlStatement, Collections.emptyList()); return new QueryContext(sqlStatementContext, sql, Collections.emptyList(), hintValueContext, connectionSession.getConnectionContext(), metaDataContexts.getMetaData()); } @@ -170,7 +170,7 @@ private Collection createExecutionContexts() { private ExecutionContext createExecutionContext(final QueryContext queryContext) { RuleMetaData globalRuleMetaData = metaDataContexts.getMetaData().getGlobalRuleMetaData(); - ShardingSphereDatabase currentDatabase = metaDataContexts.getMetaData().getDatabase(connectionSession.getUsedDatabaseName()); + ShardingSphereDatabase currentDatabase = metaDataContexts.getMetaData().getDatabase(connectionSession.getCurrentDatabaseName()); SQLAuditEngine.audit(queryContext, globalRuleMetaData, currentDatabase); return new KernelProcessor().generateExecutionContext(queryContext, globalRuleMetaData, metaDataContexts.getMetaData().getProps()); } diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java index 37cb1228c4165..4f5e961bd0786 100644 --- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java +++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java @@ -124,7 +124,7 @@ void assertIsUpdateResponse() throws SQLException, NoSuchFieldException, Illegal void assertExecuteMultiUpdateStatements() throws SQLException, NoSuchFieldException, IllegalAccessException { when(connectionSession.getAttributeMap().hasAttr(MySQLConstants.OPTION_MULTI_STATEMENTS_ATTRIBUTE_KEY)).thenReturn(true); when(connectionSession.getAttributeMap().attr(MySQLConstants.OPTION_MULTI_STATEMENTS_ATTRIBUTE_KEY).get()).thenReturn(0); - when(connectionSession.getUsedDatabaseName()).thenReturn("foo_db"); + when(connectionSession.getCurrentDatabaseName()).thenReturn("foo_db"); when(packet.getSQL()).thenReturn("update t set v=v+1 where id=1;update t set v=v+1 where id=2;update t set v=v+1 where id=3"); ContextManager contextManager = mock(ContextManager.class); MetaDataContexts metaDataContexts = mockMetaDataContexts(); @@ -142,7 +142,7 @@ void assertExecuteMultiUpdateStatements() throws SQLException, NoSuchFieldExcept void assertExecuteMultiInsertOnDuplicateKeyStatements() throws SQLException, NoSuchFieldException, IllegalAccessException { when(connectionSession.getAttributeMap().hasAttr(MySQLConstants.OPTION_MULTI_STATEMENTS_ATTRIBUTE_KEY)).thenReturn(true); when(connectionSession.getAttributeMap().attr(MySQLConstants.OPTION_MULTI_STATEMENTS_ATTRIBUTE_KEY).get()).thenReturn(0); - when(connectionSession.getUsedDatabaseName()).thenReturn("foo_db"); + when(connectionSession.getCurrentDatabaseName()).thenReturn("foo_db"); when(packet.getSQL()).thenReturn("insert into t (id, v) values(1,1) on duplicate key update v=2;insert into t (id, v) values(2,1) on duplicate key update v=3"); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = mockMetaDataContexts(); 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 ef34bdf065b58..7d3e282e0796e 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 @@ -154,7 +154,7 @@ void assertExecuteWithMultiInsertOnDuplicateKey() throws SQLException { private ConnectionSession mockConnectionSession() throws SQLException { ConnectionSession result = mock(ConnectionSession.class, RETURNS_DEEP_STUBS); - when(result.getUsedDatabaseName()).thenReturn("foo_db"); + when(result.getCurrentDatabaseName()).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); 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 9fb696ed64725..bfe13d152b8d6 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 @@ -105,7 +105,7 @@ void assertExecute() throws SQLException { private ConnectionSession mockConnectionSession() throws SQLException { ConnectionSession result = mock(ConnectionSession.class); when(result.getConnectionContext()).thenReturn(new ConnectionContext(Collections::emptySet)); - when(result.getUsedDatabaseName()).thenReturn("foo_db"); + when(result.getCurrentDatabaseName()).thenReturn("foo_db"); ConnectionContext connectionContext = mockConnectionContext(); when(result.getConnectionContext()).thenReturn(connectionContext); ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class); diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java index 8fa4ff66c726b..09453c5df0225 100644 --- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java +++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java @@ -107,7 +107,8 @@ public PostgreSQLBatchedStatementsExecutor(final ConnectionSession connectionSes } private SQLStatementContext createSQLStatementContext(final List params, final HintValueContext hintValueContext) { - return new SQLBindEngine(metaDataContexts.getMetaData(), connectionSession.getUsedDatabaseName(), hintValueContext).bind(preparedStatement.getSqlStatementContext().getSqlStatement(), params); + return new SQLBindEngine(metaDataContexts.getMetaData(), connectionSession.getCurrentDatabaseName(), hintValueContext).bind(preparedStatement.getSqlStatementContext().getSqlStatement(), + params); } private void prepareForRestOfParametersSet(final Iterator> paramSetsIterator, final SQLStatementContext sqlStatementContext, final HintValueContext hintValueContext) { @@ -129,7 +130,7 @@ private QueryContext createQueryContext(final SQLStatementContext sqlStatementCo private ExecutionContext createExecutionContext(final QueryContext queryContext) { RuleMetaData globalRuleMetaData = metaDataContexts.getMetaData().getGlobalRuleMetaData(); - ShardingSphereDatabase currentDatabase = metaDataContexts.getMetaData().getDatabase(connectionSession.getUsedDatabaseName()); + ShardingSphereDatabase currentDatabase = metaDataContexts.getMetaData().getDatabase(connectionSession.getCurrentDatabaseName()); SQLAuditEngine.audit(queryContext, globalRuleMetaData, currentDatabase); return kernelProcessor.generateExecutionContext(queryContext, globalRuleMetaData, metaDataContexts.getMetaData().getProps()); } 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 2bc45f283654f..cb813d381c6d9 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 @@ -113,7 +113,7 @@ private ConnectionSession mockConnectionSession() throws SQLException { ConnectionSession result = mock(ConnectionSession.class); SQLStatementContext sqlStatementContext = mock(InsertStatementContext.class); when(sqlStatementContext.getSqlStatement()).thenReturn(parserEngine.parse(SQL, false)); - when(result.getUsedDatabaseName()).thenReturn("foo_db"); + when(result.getCurrentDatabaseName()).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 41c0b317820d7..81943995dae02 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 @@ -153,7 +153,7 @@ private ContextManager mockContextManager() { private ConnectionSession mockConnectionSession() { ConnectionSession result = mock(ConnectionSession.class); - when(result.getUsedDatabaseName()).thenReturn("db"); + when(result.getCurrentDatabaseName()).thenReturn("db"); when(result.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager); when(result.getStatementManager()).thenReturn(backendStatement); ConnectionContext connectionContext = new ConnectionContext(Collections::emptySet);