diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/combine/CombineSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/combine/CombineSegmentBinder.java index a8c9d3538df67..d3d6180de958a 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/combine/CombineSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/combine/CombineSegmentBinder.java @@ -51,7 +51,7 @@ public static CombineSegment bind(final CombineSegment segment, final SQLStateme private static SubquerySegment bindSubquerySegment(final SubquerySegment segment, final SQLStatementBinderContext binderContext, final Multimap outerTableBinderContexts) { SubquerySegment result = new SubquerySegment(segment.getStartIndex(), segment.getStopIndex(), segment.getText()); - SQLStatementBinderContext subqueryBinderContext = new SQLStatementBinderContext(segment.getSelect(), binderContext.getMetaData(), binderContext.getCurrentDatabaseName()); + SQLStatementBinderContext subqueryBinderContext = new SQLStatementBinderContext(binderContext.getMetaData(), binderContext.getCurrentDatabaseName(), segment.getSelect()); subqueryBinderContext.getExternalTableBinderContexts().putAll(binderContext.getExternalTableBinderContexts()); result.setSelect(new SelectStatementBinder(outerTableBinderContexts).bind(segment.getSelect(), subqueryBinderContext)); return result; 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 3e3a894764c12..6020cc3f1bbdf 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 @@ -172,7 +172,7 @@ private static Optional findInputColumnSegment(final ColumnSegmen } } if (!isFindInputColumn) { - result = findInputColumnSegmentByVariables(segment, binderContext.getVariableNames()).orElse(null); + result = findInputColumnSegmentByVariables(segment, binderContext.getSqlStatement().getVariableNames()).orElse(null); isFindInputColumn = null != result; } if (!isFindInputColumn) { diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/SubquerySegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/SubquerySegmentBinder.java index bcefdbd14f9bc..afaca7dbcdba4 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/SubquerySegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/SubquerySegmentBinder.java @@ -43,7 +43,7 @@ public final class SubquerySegmentBinder { */ public static SubquerySegment bind(final SubquerySegment segment, final SQLStatementBinderContext binderContext, final Multimap outerTableBinderContexts) { - SQLStatementBinderContext selectBinderContext = new SQLStatementBinderContext(segment.getSelect(), binderContext.getMetaData(), binderContext.getCurrentDatabaseName()); + SQLStatementBinderContext selectBinderContext = new SQLStatementBinderContext(binderContext.getMetaData(), binderContext.getCurrentDatabaseName(), segment.getSelect()); selectBinderContext.getExternalTableBinderContexts().putAll(binderContext.getExternalTableBinderContexts()); SelectStatement boundSelectStatement = new SelectStatementBinder(outerTableBinderContexts).bind(segment.getSelect(), selectBinderContext); return new SubquerySegment(segment.getStartIndex(), segment.getStopIndex(), boundSelectStatement, segment.getText()); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/JoinTableSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/JoinTableSegmentBinder.java index 20af49d943801..455d9d7a4936b 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/JoinTableSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/JoinTableSegmentBinder.java @@ -83,7 +83,8 @@ public static JoinTableSegment bind(final JoinTableSegment segment, final SQLSta result.setDerivedUsing(bindUsingColumns(derivedUsingColumns, tableBinderContexts)); result.getDerivedUsing().forEach(each -> binderContext.getUsingColumnNames().add(each.getIdentifier().getValue())); } - result.getDerivedJoinTableProjectionSegments().addAll(getDerivedJoinTableProjectionSegments(result, binderContext.getDatabaseType(), usingColumnsByNaturalJoin, tableBinderContexts)); + result.getDerivedJoinTableProjectionSegments() + .addAll(getDerivedJoinTableProjectionSegments(result, binderContext.getSqlStatement().getDatabaseType(), usingColumnsByNaturalJoin, tableBinderContexts)); binderContext.getJoinTableProjectionSegments().addAll(result.getDerivedJoinTableProjectionSegments()); return result; } 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 be851ce38965e..7ce4a880347a1 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 @@ -45,6 +45,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; +import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateTableStatement; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import java.util.Collection; @@ -101,7 +102,7 @@ private static void fillPivotColumnNamesInBinderContext(final SimpleTableSegment } private static IdentifierValue getDatabaseName(final SimpleTableSegment segment, final SQLStatementBinderContext binderContext) { - DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(binderContext.getDatabaseType()).getDialectDatabaseMetaData(); + DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(binderContext.getSqlStatement().getDatabaseType()).getDialectDatabaseMetaData(); Optional owner = dialectDatabaseMetaData.getDefaultSchema().isPresent() ? segment.getOwner().flatMap(OwnerSegment::getOwner) : segment.getOwner(); return new IdentifierValue(owner.map(optional -> optional.getIdentifier().getValue()).orElse(binderContext.getCurrentDatabaseName())); } @@ -111,7 +112,7 @@ private static IdentifierValue getSchemaName(final SimpleTableSegment segment, f return segment.getOwner().get().getIdentifier(); } // TODO getSchemaName according to search path - DatabaseType databaseType = binderContext.getDatabaseType(); + DatabaseType databaseType = binderContext.getSqlStatement().getDatabaseType(); if ((databaseType instanceof PostgreSQLDatabaseType || databaseType instanceof OpenGaussDatabaseType) && SYSTEM_CATALOG_TABLES.contains(segment.getTableName().getIdentifier().getValue())) { return new IdentifierValue(PG_CATALOG); } @@ -119,7 +120,10 @@ private static IdentifierValue getSchemaName(final SimpleTableSegment segment, f } private static void checkTableExists(final SQLStatementBinderContext binderContext, final String databaseName, final String schemaName, final String tableName) { - if ("dual".equalsIgnoreCase(tableName)) { + if (binderContext.getSqlStatement() instanceof CreateTableStatement) { + return; + } + if ("DUAL".equalsIgnoreCase(tableName)) { return; } if (SystemSchemaManager.isSystemTable(schemaName, tableName)) { @@ -147,7 +151,7 @@ private static SimpleTableSegmentBinderContext createSimpleTableSegmentBinderCon final IdentifierValue databaseName, final IdentifierValue schemaName, final SQLStatementBinderContext binderContext, final IdentifierValue tableName) { Collection projectionSegments = new LinkedList<>(); - QuoteCharacter quoteCharacter = new DatabaseTypeRegistry(binderContext.getDatabaseType()).getDialectDatabaseMetaData().getQuoteCharacter(); + QuoteCharacter quoteCharacter = new DatabaseTypeRegistry(binderContext.getSqlStatement().getDatabaseType()).getDialectDatabaseMetaData().getQuoteCharacter(); for (ShardingSphereColumn each : schema.getTable(tableName.getValue()).getAllColumns()) { ColumnProjectionSegment columnProjectionSegment = new ColumnProjectionSegment(createColumnSegment(segment, databaseName, schemaName, each, quoteCharacter, tableName)); columnProjectionSegment.setVisible(each.isVisible()); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SubqueryTableSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SubqueryTableSegmentBinder.java index fd056f567f1be..bd8b3ae73629f 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SubqueryTableSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SubqueryTableSegmentBinder.java @@ -51,7 +51,7 @@ public static SubqueryTableSegment bind(final SubqueryTableSegment segment, fina final Multimap tableBinderContexts, final Multimap outerTableBinderContexts) { fillPivotColumnNamesInBinderContext(segment, binderContext); - SQLStatementBinderContext subqueryBinderContext = new SQLStatementBinderContext(segment.getSubquery().getSelect(), binderContext.getMetaData(), binderContext.getCurrentDatabaseName()); + SQLStatementBinderContext subqueryBinderContext = new SQLStatementBinderContext(binderContext.getMetaData(), binderContext.getCurrentDatabaseName(), segment.getSubquery().getSelect()); subqueryBinderContext.getExternalTableBinderContexts().putAll(binderContext.getExternalTableBinderContexts()); SelectStatement boundSubSelect = new SelectStatementBinder(outerTableBinderContexts).bind(segment.getSubquery().getSelect(), subqueryBinderContext); SubquerySegment boundSubquerySegment = new SubquerySegment(segment.getSubquery().getStartIndex(), segment.getSubquery().getStopIndex(), boundSubSelect, segment.getSubquery().getText()); @@ -59,7 +59,7 @@ public static SubqueryTableSegment bind(final SubqueryTableSegment segment, fina SubqueryTableSegment result = new SubqueryTableSegment(segment.getStartIndex(), segment.getStopIndex(), boundSubquerySegment); segment.getAliasSegment().ifPresent(result::setAlias); tableBinderContexts.put(new CaseInsensitiveString(subqueryTableName.getValue()), new SimpleTableSegmentBinderContext( - SubqueryTableBindUtils.createSubqueryProjections(boundSubSelect.getProjections().getProjections(), subqueryTableName, binderContext.getDatabaseType()))); + SubqueryTableBindUtils.createSubqueryProjections(boundSubSelect.getProjections().getProjections(), subqueryTableName, binderContext.getSqlStatement().getDatabaseType()))); return result; } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/SQLStatementBinderContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/SQLStatementBinderContext.java index 10d28175fa81e..172660b6ed5fc 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/SQLStatementBinderContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/SQLStatementBinderContext.java @@ -24,7 +24,6 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.binder.engine.segment.from.context.TableSegmentBinderContext; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; @@ -43,9 +42,7 @@ public final class SQLStatementBinderContext { private final String currentDatabaseName; - private final DatabaseType databaseType; - - private final Collection variableNames; + private final SQLStatement sqlStatement; private final Collection usingColumnNames = new CaseInsensitiveSet<>(); @@ -54,11 +51,4 @@ public final class SQLStatementBinderContext { private final Multimap externalTableBinderContexts = LinkedHashMultimap.create(); private final Collection pivotColumnNames = new CaseInsensitiveSet<>(); - - public SQLStatementBinderContext(final SQLStatement sqlStatement, final ShardingSphereMetaData metaData, final String currentDatabaseName) { - this.metaData = metaData; - this.currentDatabaseName = currentDatabaseName; - databaseType = sqlStatement.getDatabaseType(); - variableNames = new CaseInsensitiveSet<>(sqlStatement.getVariableNames()); - } } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DDLStatementBindEngine.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DDLStatementBindEngine.java index fa20588d331aa..66a5f0215532f 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DDLStatementBindEngine.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DDLStatementBindEngine.java @@ -43,7 +43,7 @@ public final class DDLStatementBindEngine { * @return bound DDL statement */ public DDLStatement bind(final DDLStatement statement) { - SQLStatementBinderContext binderContext = new SQLStatementBinderContext(statement, metaData, currentDatabaseName); + SQLStatementBinderContext binderContext = new SQLStatementBinderContext(metaData, currentDatabaseName, statement); if (statement instanceof CursorStatement) { return new CursorStatementBinder().bind((CursorStatement) statement, binderContext); } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DMLStatementBindEngine.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DMLStatementBindEngine.java index 4500a020a86d4..00a1688655de2 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DMLStatementBindEngine.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DMLStatementBindEngine.java @@ -47,7 +47,7 @@ public final class DMLStatementBindEngine { * @return bound DML statement */ public DMLStatement bind(final DMLStatement statement) { - SQLStatementBinderContext binderContext = new SQLStatementBinderContext(statement, metaData, currentDatabaseName); + SQLStatementBinderContext binderContext = new SQLStatementBinderContext(metaData, currentDatabaseName, statement); if (statement instanceof SelectStatement) { return new SelectStatementBinder().bind((SelectStatement) statement, binderContext); } 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 9952c36f686bf..bfaddcd17ba37 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 @@ -33,6 +33,7 @@ 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.statement.dml.SelectStatement; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; @@ -45,6 +46,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class ColumnSegmentBinderTest { @@ -62,8 +64,9 @@ void assertBindWithMultiTablesJoinAndNoOwner() { 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")); - SQLStatementBinderContext binderContext = - new SQLStatementBinderContext(mock(ShardingSphereMetaData.class), "foo_db", databaseType, Collections.emptySet()); + SelectStatement selectStatement = mock(SelectStatement.class); + when(selectStatement.getDatabaseType()).thenReturn(databaseType); + SQLStatementBinderContext binderContext = new SQLStatementBinderContext(mock(ShardingSphereMetaData.class), "foo_db", selectStatement); ColumnSegment actual = ColumnSegmentBinder.bind(columnSegment, SegmentType.JOIN_ON, binderContext, tableBinderContexts, LinkedHashMultimap.create()); assertNotNull(actual.getColumnBoundInfo()); assertNull(actual.getOtherUsingColumnBoundInfo()); @@ -84,8 +87,9 @@ void assertBindFromOuterTable() { 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 = - new SQLStatementBinderContext(mock(ShardingSphereMetaData.class), "foo_db", databaseType, Collections.emptySet()); + SelectStatement selectStatement = mock(SelectStatement.class); + when(selectStatement.getDatabaseType()).thenReturn(databaseType); + SQLStatementBinderContext binderContext = new SQLStatementBinderContext(mock(ShardingSphereMetaData.class), "foo_db", selectStatement); ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("status")); ColumnSegment actual = ColumnSegmentBinder.bind(columnSegment, SegmentType.PROJECTION, binderContext, LinkedHashMultimap.create(), outerTableBinderContexts); assertNotNull(actual.getColumnBoundInfo()); @@ -107,8 +111,9 @@ void assertBindWithSameTableAliasAndSameProjection() { 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 = - new SQLStatementBinderContext(mock(ShardingSphereMetaData.class), "foo_db", databaseType, Collections.emptySet()); + SelectStatement selectStatement = mock(SelectStatement.class); + when(selectStatement.getDatabaseType()).thenReturn(databaseType); + SQLStatementBinderContext binderContext = new SQLStatementBinderContext(mock(ShardingSphereMetaData.class), "foo_db", selectStatement); ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("status")); columnSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("temp"))); assertThrows(AmbiguousColumnException.class, () -> ColumnSegmentBinder.bind(columnSegment, SegmentType.PROJECTION, binderContext, tableBinderContexts, LinkedHashMultimap.create())); @@ -125,8 +130,9 @@ void assertBindWithSameTableAliasAndDifferentProjection() { 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 = - new SQLStatementBinderContext(mock(ShardingSphereMetaData.class), "foo_db", databaseType, Collections.emptySet()); + SelectStatement selectStatement = mock(SelectStatement.class); + when(selectStatement.getDatabaseType()).thenReturn(databaseType); + SQLStatementBinderContext binderContext = new SQLStatementBinderContext(mock(ShardingSphereMetaData.class), "foo_db", selectStatement); ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("status")); columnSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("temp"))); ColumnSegment actual = ColumnSegmentBinder.bind(columnSegment, SegmentType.PROJECTION, binderContext, tableBinderContexts, LinkedHashMultimap.create()); @@ -151,8 +157,9 @@ void assertBindOwner() { tableBinderContexts.put(new CaseInsensitiveString("t_order_item"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundItemIdColumn)))); ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("order_id")); columnSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("t_order"))); - SQLStatementBinderContext binderContext = - new SQLStatementBinderContext(mock(ShardingSphereMetaData.class), "foo_db", databaseType, Collections.emptySet()); + SelectStatement selectStatement = mock(SelectStatement.class); + when(selectStatement.getDatabaseType()).thenReturn(databaseType); + SQLStatementBinderContext binderContext = new SQLStatementBinderContext(mock(ShardingSphereMetaData.class), "foo_db", selectStatement); ColumnSegment actual = ColumnSegmentBinder.bind(columnSegment, SegmentType.JOIN_ON, binderContext, tableBinderContexts, LinkedHashMultimap.create()); assertTrue(actual.getOwner().isPresent()); assertTrue(actual.getOwner().get().getTableBoundInfo().isPresent()); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ExistsSubqueryExpressionBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ExistsSubqueryExpressionBinderTest.java index b8ace4d0b9cac..ce3d1b7b2a28f 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ExistsSubqueryExpressionBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ExistsSubqueryExpressionBinderTest.java @@ -23,12 +23,10 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExistsSubqueryExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionsSegment; +import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLSelectStatement; -import org.apache.shardingsphere.test.fixture.database.MockedDatabaseType; import org.junit.jupiter.api.Test; -import java.util.Collections; - import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; @@ -40,7 +38,7 @@ void assertBindExistsSubqueryExpression() { MySQLSelectStatement selectStatement = new MySQLSelectStatement(); selectStatement.setProjections(new ProjectionsSegment(0, 0)); ExistsSubqueryExpression existsSubqueryExpression = new ExistsSubqueryExpression(0, 0, new SubquerySegment(0, 0, selectStatement, "t_test")); - SQLStatementBinderContext binderContext = new SQLStatementBinderContext(mock(ShardingSphereMetaData.class), "foo_db", new MockedDatabaseType(), Collections.emptyList()); + SQLStatementBinderContext binderContext = new SQLStatementBinderContext(mock(ShardingSphereMetaData.class), "foo_db", mock(SQLStatement.class)); ExistsSubqueryExpression actual = ExistsSubqueryExpressionBinder.bind(existsSubqueryExpression, binderContext, LinkedHashMultimap.create()); assertThat(actual.getStartIndex(), is(existsSubqueryExpression.getStartIndex())); assertThat(actual.getStopIndex(), is(existsSubqueryExpression.getStopIndex())); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/FunctionExpressionSegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/FunctionExpressionSegmentBinderTest.java index de1c871ded843..699ad7cc12923 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/FunctionExpressionSegmentBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/FunctionExpressionSegmentBinderTest.java @@ -22,20 +22,19 @@ import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment; -import org.apache.shardingsphere.test.fixture.database.MockedDatabaseType; +import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; import org.junit.jupiter.api.Test; -import java.util.Collections; - import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; class FunctionExpressionSegmentBinderTest { @Test void assertBindFunctionExpressionSegment() { FunctionSegment functionSegment = new FunctionSegment(0, 0, "CONCAT", "('%','abc','%')"); - SQLStatementBinderContext binderContext = new SQLStatementBinderContext(new ShardingSphereMetaData(), "foo_db", new MockedDatabaseType(), Collections.emptyList()); + SQLStatementBinderContext binderContext = new SQLStatementBinderContext(new ShardingSphereMetaData(), "foo_db", mock(SQLStatement.class)); FunctionSegment actual = FunctionExpressionSegmentBinder.bind(functionSegment, SegmentType.PROJECTION, binderContext, LinkedHashMultimap.create(), LinkedHashMultimap.create()); assertThat(actual.getStartIndex(), is(functionSegment.getStartIndex())); assertThat(actual.getStopIndex(), is(functionSegment.getStopIndex())); 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 96fa3d2005521..f879f813eac35 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 @@ -23,11 +23,9 @@ import org.apache.shardingsphere.infra.binder.engine.segment.from.context.TableSegmentBinderContext; import org.apache.shardingsphere.infra.binder.engine.segment.from.context.type.SimpleTableSegmentBinderContext; import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment; @@ -39,6 +37,7 @@ 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.SQLStatement; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLSelectStatement; import org.junit.jupiter.api.Test; @@ -69,8 +68,7 @@ void assertBind() { ExpressionSegment whereExpressionSegment = new ColumnSegment(86, 91, new IdentifierValue("status")); mysqlSelectStatement.setWhere(new WhereSegment(80, 102, whereExpressionSegment)); SubquerySegment subquerySegment = new SubquerySegment(39, 103, mysqlSelectStatement, "order_id = (SELECT order_id FROM t_order WHERE status = 'SUBMIT')"); - SQLStatementBinderContext sqlStatementBinderContext = new SQLStatementBinderContext( - createMetaData(), "foo_db", TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), Collections.emptySet()); + SQLStatementBinderContext sqlStatementBinderContext = new SQLStatementBinderContext(createMetaData(), "foo_db", mock(SQLStatement.class)); ColumnSegment boundNameColumn = new ColumnSegment(7, 13, 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"))); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/JoinTableSegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/JoinTableSegmentBinderTest.java index be8f8ad761323..785990cce8ef4 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/JoinTableSegmentBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/JoinTableSegmentBinderTest.java @@ -35,6 +35,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.JoinTableSegment; 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.SelectStatement; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; @@ -42,7 +43,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.List; import static org.hamcrest.CoreMatchers.instanceOf; @@ -68,8 +68,9 @@ void assertBindWithAlias() { when(joinTableSegment.getRight()).thenReturn(rightTable); ShardingSphereMetaData metaData = createMetaData(); Multimap tableBinderContexts = LinkedHashMultimap.create(); - JoinTableSegment actual = JoinTableSegmentBinder.bind( - joinTableSegment, new SQLStatementBinderContext(metaData, "foo_db", databaseType, Collections.emptySet()), tableBinderContexts, LinkedHashMultimap.create()); + SelectStatement selectStatement = mock(SelectStatement.class); + when(selectStatement.getDatabaseType()).thenReturn(databaseType); + JoinTableSegment actual = JoinTableSegmentBinder.bind(joinTableSegment, new SQLStatementBinderContext(metaData, "foo_db", selectStatement), tableBinderContexts, LinkedHashMultimap.create()); assertThat(actual.getLeft(), instanceOf(SimpleTableSegment.class)); assertThat(actual.getRight(), instanceOf(SimpleTableSegment.class)); assertJoinTableProjectionSegments(actual.getDerivedJoinTableProjectionSegments()); @@ -106,8 +107,9 @@ void assertBindWithoutAlias() { when(joinTableSegment.getRight()).thenReturn(rightTable); ShardingSphereMetaData metaData = createMetaData(); Multimap tableBinderContexts = LinkedHashMultimap.create(); - JoinTableSegment actual = JoinTableSegmentBinder.bind(joinTableSegment, new SQLStatementBinderContext(metaData, "foo_db", databaseType, Collections.emptySet()), - tableBinderContexts, LinkedHashMultimap.create()); + SelectStatement selectStatement = mock(SelectStatement.class); + when(selectStatement.getDatabaseType()).thenReturn(databaseType); + JoinTableSegment actual = JoinTableSegmentBinder.bind(joinTableSegment, new SQLStatementBinderContext(metaData, "foo_db", selectStatement), tableBinderContexts, LinkedHashMultimap.create()); assertThat(actual.getLeft(), instanceOf(SimpleTableSegment.class)); assertThat(actual.getRight(), instanceOf(SimpleTableSegment.class)); assertJoinTableProjectionSegments(actual.getDerivedJoinTableProjectionSegments()); @@ -128,8 +130,9 @@ void assertBindWithNaturalJoin() { when(joinTableSegment.getJoinType()).thenReturn(JoinType.RIGHT.name()); ShardingSphereMetaData metaData = createMetaData(); Multimap tableBinderContexts = LinkedHashMultimap.create(); - JoinTableSegment actual = JoinTableSegmentBinder.bind(joinTableSegment, new SQLStatementBinderContext(metaData, "foo_db", databaseType, Collections.emptySet()), - tableBinderContexts, LinkedHashMultimap.create()); + SelectStatement selectStatement = mock(SelectStatement.class); + when(selectStatement.getDatabaseType()).thenReturn(databaseType); + JoinTableSegment actual = JoinTableSegmentBinder.bind(joinTableSegment, new SQLStatementBinderContext(metaData, "foo_db", selectStatement), tableBinderContexts, LinkedHashMultimap.create()); assertThat(actual.getLeft(), instanceOf(SimpleTableSegment.class)); assertThat(actual.getRight(), instanceOf(SimpleTableSegment.class)); assertJoinTableProjectionSegmentsWithNaturalJoin(actual.getDerivedJoinTableProjectionSegments()); @@ -164,8 +167,9 @@ void assertBindWithJoinUsing() { when(joinTableSegment.getUsing()).thenReturn(Arrays.asList(new ColumnSegment(0, 0, new IdentifierValue("status")), new ColumnSegment(0, 0, new IdentifierValue("order_id")))); ShardingSphereMetaData metaData = createMetaData(); Multimap tableBinderContexts = LinkedHashMultimap.create(); - JoinTableSegment actual = JoinTableSegmentBinder.bind(joinTableSegment, new SQLStatementBinderContext(metaData, "foo_db", databaseType, Collections.emptySet()), - tableBinderContexts, LinkedHashMultimap.create()); + SelectStatement selectStatement = mock(SelectStatement.class); + when(selectStatement.getDatabaseType()).thenReturn(databaseType); + JoinTableSegment actual = JoinTableSegmentBinder.bind(joinTableSegment, new SQLStatementBinderContext(metaData, "foo_db", selectStatement), tableBinderContexts, LinkedHashMultimap.create()); assertThat(actual.getLeft(), instanceOf(SimpleTableSegment.class)); assertThat(actual.getRight(), instanceOf(SimpleTableSegment.class)); assertJoinTableProjectionSegmentsWithUsing(actual.getDerivedJoinTableProjectionSegments()); @@ -199,8 +203,9 @@ void assertBindWithMultiTableJoin() { when(joinTableSegment.getRight()).thenReturn(rightTable); ShardingSphereMetaData metaData = createMetaData(); Multimap tableBinderContexts = LinkedHashMultimap.create(); - JoinTableSegment actual = JoinTableSegmentBinder.bind(joinTableSegment, - new SQLStatementBinderContext(metaData, "foo_db", databaseType, Collections.emptySet()), tableBinderContexts, LinkedHashMultimap.create()); + SelectStatement selectStatement = mock(SelectStatement.class); + when(selectStatement.getDatabaseType()).thenReturn(databaseType); + JoinTableSegment actual = JoinTableSegmentBinder.bind(joinTableSegment, new SQLStatementBinderContext(metaData, "foo_db", selectStatement), tableBinderContexts, LinkedHashMultimap.create()); assertThat(actual.getLeft(), instanceOf(JoinTableSegment.class)); assertThat(((JoinTableSegment) actual.getLeft()).getLeft(), instanceOf(SimpleTableSegment.class)); assertThat(((JoinTableSegment) actual.getLeft()).getRight(), instanceOf(SimpleTableSegment.class)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinderTest.java index e99a256dfd88a..f49fa42d257bc 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinderTest.java @@ -30,12 +30,12 @@ import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; 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.SelectStatement; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; import java.sql.Types; import java.util.Arrays; -import java.util.Collections; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; @@ -51,8 +51,9 @@ void assertBindTableNotExists() { SimpleTableSegment simpleTableSegment = new SimpleTableSegment(new TableNameSegment(0, 10, new IdentifierValue("t_not_exists"))); ShardingSphereMetaData metaData = createMetaData(); Multimap tableBinderContexts = LinkedHashMultimap.create(); - assertThrows(TableNotFoundException.class, () -> SimpleTableSegmentBinder.bind( - simpleTableSegment, new SQLStatementBinderContext(metaData, "foo_db", databaseType, Collections.emptySet()), tableBinderContexts)); + SelectStatement selectStatement = mock(SelectStatement.class); + when(selectStatement.getDatabaseType()).thenReturn(databaseType); + assertThrows(TableNotFoundException.class, () -> SimpleTableSegmentBinder.bind(simpleTableSegment, new SQLStatementBinderContext(metaData, "foo_db", selectStatement), tableBinderContexts)); } private ShardingSphereMetaData createMetaData() { diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SubqueryTableSegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SubqueryTableSegmentBinderTest.java index 3fd70d8bbd1bd..8cacd05fe7661 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SubqueryTableSegmentBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SubqueryTableSegmentBinderTest.java @@ -44,7 +44,6 @@ import java.sql.Types; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Optional; @@ -73,8 +72,8 @@ void assertBindWithSubqueryTableAlias() { subqueryTableSegment.setAlias(new AliasSegment(0, 0, new IdentifierValue("temp"))); ShardingSphereMetaData metaData = createMetaData(); Multimap tableBinderContexts = LinkedHashMultimap.create(); - SubqueryTableSegment actual = SubqueryTableSegmentBinder.bind(subqueryTableSegment, new SQLStatementBinderContext(metaData, "foo_db", databaseType, Collections.emptySet()), - tableBinderContexts, LinkedHashMultimap.create()); + SubqueryTableSegment actual = + SubqueryTableSegmentBinder.bind(subqueryTableSegment, new SQLStatementBinderContext(metaData, "foo_db", selectStatement), tableBinderContexts, LinkedHashMultimap.create()); assertTrue(actual.getAlias().isPresent()); assertTrue(tableBinderContexts.containsKey(new CaseInsensitiveString("temp"))); List projectionSegments = new ArrayList<>(tableBinderContexts.get(new CaseInsensitiveString("temp")).iterator().next().getProjectionSegments()); @@ -107,8 +106,8 @@ void assertBindWithSubqueryProjectionAlias() { subqueryTableSegment.setAlias(new AliasSegment(0, 0, new IdentifierValue("temp"))); ShardingSphereMetaData metaData = createMetaData(); Multimap tableBinderContexts = LinkedHashMultimap.create(); - SubqueryTableSegment actual = SubqueryTableSegmentBinder.bind(subqueryTableSegment, new SQLStatementBinderContext(metaData, "foo_db", databaseType, Collections.emptySet()), - tableBinderContexts, LinkedHashMultimap.create()); + SubqueryTableSegment actual = + SubqueryTableSegmentBinder.bind(subqueryTableSegment, new SQLStatementBinderContext(metaData, "foo_db", selectStatement), tableBinderContexts, LinkedHashMultimap.create()); assertTrue(actual.getAlias().isPresent()); assertTrue(tableBinderContexts.containsKey(new CaseInsensitiveString("temp"))); List projectionSegments = new ArrayList<>(tableBinderContexts.get(new CaseInsensitiveString("temp")).iterator().next().getProjectionSegments()); @@ -130,8 +129,8 @@ void assertBindWithoutSubqueryTableAlias() { SubqueryTableSegment subqueryTableSegment = new SubqueryTableSegment(0, 0, new SubquerySegment(0, 0, selectStatement, "")); ShardingSphereMetaData metaData = createMetaData(); Multimap tableBinderContexts = LinkedHashMultimap.create(); - SubqueryTableSegment actual = SubqueryTableSegmentBinder.bind(subqueryTableSegment, new SQLStatementBinderContext(metaData, "foo_db", databaseType, Collections.emptySet()), - tableBinderContexts, LinkedHashMultimap.create()); + SubqueryTableSegment actual = + SubqueryTableSegmentBinder.bind(subqueryTableSegment, new SQLStatementBinderContext(metaData, "foo_db", selectStatement), tableBinderContexts, LinkedHashMultimap.create()); assertFalse(actual.getAlias().isPresent()); assertTrue(tableBinderContexts.containsKey(new CaseInsensitiveString(""))); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/DeleteStatementBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/DeleteStatementBinderTest.java index 76f5b0cc1cf6a..8f3dd0b072805 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/DeleteStatementBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/DeleteStatementBinderTest.java @@ -53,7 +53,7 @@ void assertBind() { deleteStatement.setTable(simpleTableSegment); deleteStatement.setWhere(new WhereSegment(0, 0, new BinaryOperationExpression(0, 0, new ColumnSegment(0, 0, new IdentifierValue("status")), new LiteralExpressionSegment(0, 0, 0), "=", "status = 1"))); - DeleteStatement actual = new DeleteStatementBinder().bind(deleteStatement, new SQLStatementBinderContext(deleteStatement, createMetaData(), "foo_db")); + DeleteStatement actual = new DeleteStatementBinder().bind(deleteStatement, new SQLStatementBinderContext(createMetaData(), "foo_db", deleteStatement)); assertThat(actual, not(deleteStatement)); assertThat(actual.getTable(), not(deleteStatement.getTable())); assertThat(actual.getTable(), instanceOf(SimpleTableSegment.class)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/InsertStatementBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/InsertStatementBinderTest.java index f830007032947..afd30cf79758a 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/InsertStatementBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/InsertStatementBinderTest.java @@ -61,7 +61,7 @@ void assertBindInsertValues() { new ColumnSegment(0, 0, new IdentifierValue("user_id")), new ColumnSegment(0, 0, new IdentifierValue("status"))))); insertStatement.getValues().add(new InsertValuesSegment(0, 0, Arrays.asList(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, "OK")))); - InsertStatement actual = new InsertStatementBinder().bind(insertStatement, new SQLStatementBinderContext(insertStatement, createMetaData(), "foo_db")); + InsertStatement actual = new InsertStatementBinder().bind(insertStatement, new SQLStatementBinderContext(createMetaData(), "foo_db", insertStatement)); assertThat(actual, not(insertStatement)); assertTrue(actual.getTable().isPresent()); assertTrue(insertStatement.getTable().isPresent()); @@ -106,7 +106,7 @@ void assertBindInsertSelectWithColumns() { insertStatement.setInsertSelect(new SubquerySegment(0, 0, subSelectStatement, "")); insertStatement.getValues().add(new InsertValuesSegment(0, 0, Arrays.asList(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, "OK")))); - InsertStatement actual = new InsertStatementBinder().bind(insertStatement, new SQLStatementBinderContext(insertStatement, createMetaData(), "foo_db")); + InsertStatement actual = new InsertStatementBinder().bind(insertStatement, new SQLStatementBinderContext(createMetaData(), "foo_db", insertStatement)); assertThat(actual, not(insertStatement)); assertTrue(actual.getTable().isPresent()); assertTrue(insertStatement.getTable().isPresent()); @@ -130,7 +130,7 @@ void assertBindInsertSelectWithoutColumns() { insertStatement.setInsertSelect(new SubquerySegment(0, 0, subSelectStatement, "")); insertStatement.getValues().add(new InsertValuesSegment(0, 0, Arrays.asList(new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, 1), new LiteralExpressionSegment(0, 0, "OK")))); - InsertStatement actual = new InsertStatementBinder().bind(insertStatement, new SQLStatementBinderContext(insertStatement, createMetaData(), "foo_db")); + InsertStatement actual = new InsertStatementBinder().bind(insertStatement, new SQLStatementBinderContext(createMetaData(), "foo_db", insertStatement)); assertThat(actual, not(insertStatement)); assertTrue(actual.getTable().isPresent()); assertTrue(insertStatement.getTable().isPresent()); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/SelectStatementBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/SelectStatementBinderTest.java index 8e9b71f140ba9..b1c7d2fa2a6db 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/SelectStatementBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/SelectStatementBinderTest.java @@ -66,7 +66,7 @@ void assertBind() { SimpleTableSegment simpleTableSegment = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))); selectStatement.setFrom(simpleTableSegment); selectStatement.setWhere(mockWhereSegment()); - SelectStatement actual = new SelectStatementBinder().bind(selectStatement, new SQLStatementBinderContext(selectStatement, createMetaData(), "foo_db")); + SelectStatement actual = new SelectStatementBinder().bind(selectStatement, new SQLStatementBinderContext(createMetaData(), "foo_db", selectStatement)); assertThat(actual, not(selectStatement)); assertTrue(actual.getFrom().isPresent()); assertThat(actual.getFrom().get(), not(simpleTableSegment)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/UpdateStatementBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/UpdateStatementBinderTest.java index 1f9ed80ba46f0..d0eddea62c550 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/UpdateStatementBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/UpdateStatementBinderTest.java @@ -53,7 +53,7 @@ void assertBind() { updateStatement.setTable(simpleTableSegment); updateStatement.setWhere(new WhereSegment(0, 0, new BinaryOperationExpression(0, 0, new ColumnSegment(0, 0, new IdentifierValue("status")), new LiteralExpressionSegment(0, 0, 0), "=", "status = 1"))); - UpdateStatement actual = new UpdateStatementBinder().bind(updateStatement, new SQLStatementBinderContext(updateStatement, createMetaData(), "foo_db")); + UpdateStatement actual = new UpdateStatementBinder().bind(updateStatement, new SQLStatementBinderContext(createMetaData(), "foo_db", updateStatement)); assertThat(actual, not(updateStatement)); assertThat(actual.getTable(), not(updateStatement.getTable())); assertThat(actual.getTable(), instanceOf(SimpleTableSegment.class)); diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/AbstractSQLStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/AbstractSQLStatement.java index 66e9da993bf57..d01c935e48dc8 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/AbstractSQLStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/AbstractSQLStatement.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.sql.parser.statement.core.statement; +import com.cedarsoftware.util.CaseInsensitiveSet; import lombok.Getter; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.CommentSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.ParameterMarkerSegment; @@ -38,7 +39,7 @@ public abstract class AbstractSQLStatement implements SQLStatement { private final Collection commentSegments = new LinkedList<>(); - private final Collection variableNames = new HashSet<>(); + private final Collection variableNames = new CaseInsensitiveSet<>(); @Override public int getParameterCount() {