Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 31437 with keyword query error mysql #34163

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8544d67
Added the With Segment Binder which improves the working of With Quer…
Yash-cor Dec 24, 2024
1653664
Added the changes
Yash-cor Dec 24, 2024
2029eaf
Resolves Merge Conflicts
Yash-cor Dec 26, 2024
068962b
Merge
Yash-cor Dec 26, 2024
f973677
Added unique Alias Exception while using Common Table Expression
Yash-cor Dec 26, 2024
027ea9f
Fix Spotless error
Yash-cor Dec 26, 2024
6c8660a
Merge remote-tracking branch 'refs/remotes/origin/master' into ISSUE_…
Yash-cor Dec 26, 2024
88a1300
Added Release Notes
Yash-cor Dec 26, 2024
e2e18ea
Added SQL bind test case for WithSegmentBinder
Yash-cor Dec 27, 2024
ab34b8e
Added Release Notes
Yash-cor Dec 27, 2024
6a2640c
Resolve Merge Conflict
Yash-cor Dec 27, 2024
2b0c960
Resolve Merge Conflict
Yash-cor Dec 27, 2024
52f639f
Added Release Notes
Yash-cor Dec 27, 2024
949ff51
Solved Spotless and Checkstyle error
Yash-cor Dec 27, 2024
a27ede2
Merge branch 'master' into ISSUE_31437_WITH_KEYWORD_QUERY_ERROR_MYSQL
strongduanmu Dec 30, 2024
893cea5
Merge branch 'apache:master' into ISSUE_31437_WITH_KEYWORD_QUERY_ERRO…
Yash-cor Dec 30, 2024
7fbb92f
Changed the working for Unique Alias Name Exception handling for CTE's
Yash-cor Dec 31, 2024
5023a65
Update Release Notes
Yash-cor Dec 31, 2024
c340ae3
Merge branch 'apache:master' into ISSUE_31437_WITH_KEYWORD_QUERY_ERRO…
Yash-cor Dec 31, 2024
791c956
Changed Release Notes to resolve merge conflict
Yash-cor Dec 31, 2024
7a9cd89
Merge remote-tracking branch 'origin/ISSUE_31437_WITH_KEYWORD_QUERY_E…
Yash-cor Dec 31, 2024
ff11f5e
Sync With Master Branch
Yash-cor Dec 31, 2024
aa99360
Removed the Changes for with Clause in DeleteStatement will raise it …
Yash-cor Dec 31, 2024
03cc31d
Merge branch 'apache:master' into ISSUE_31437_WITH_KEYWORD_QUERY_ERRO…
Yash-cor Jan 2, 2025
01f9e2f
Added SQLBinderIT test case for with clause.
Yash-cor Jan 2, 2025
30e3647
Merge
Yash-cor Jan 2, 2025
0e7a6f1
Merge remote-tracking branch 'origin/ISSUE_31437_WITH_KEYWORD_QUERY_E…
Yash-cor Jan 2, 2025
d32b7d4
Merge branch 'apache:master' into ISSUE_31437_WITH_KEYWORD_QUERY_ERRO…
Yash-cor Jan 7, 2025
67df1d8
Updated documentation for the new Exception created
Yash-cor Jan 7, 2025
56147e3
Added e2e test case for with clause in e2e\sql\resources\cases\dql
Yash-cor Jan 7, 2025
58d2c21
Corrected e2e test case for with clause
Yash-cor Jan 7, 2025
ce53b70
Refactor to sync master branch
Yash-cor Jan 7, 2025
c77d035
Updates for e2e test case failure
Yash-cor Jan 7, 2025
30e9acd
Changes made in e2e test case for db and tbl
Yash-cor Jan 8, 2025
d9ea315
Merge branch 'apache:master' into ISSUE_31437_WITH_KEYWORD_QUERY_ERRO…
Yash-cor Jan 8, 2025
b9131f7
Sync master branch
Yash-cor Jan 8, 2025
5acbb84
Changes in e2e test case
Yash-cor Jan 8, 2025
761355a
Merge branch 'apache:master' into ISSUE_31437_WITH_KEYWORD_QUERY_ERRO…
Yash-cor Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@
1. SQL Binder: Support alter table, drop table sql bind and add test case - [#34154](https://github.com/apache/shardingsphere/pull/34154)
1. SQL Binder: Support rename table statement sql bind and split segment bind to ddl and dml package - [#34158](https://github.com/apache/shardingsphere/pull/34158)
1. SQL Binder: Support copy statement sql bind and add bind test case - [#34159](https://github.com/apache/shardingsphere/pull/34159)
1. SQL Binder: Support truncate table sql bind and add test case - [#34162](https://github.com/apache/shardingsphere/pull/34162
1. SQL Binder: Support truncate table sql bind and add test case - [#34162](https://github.com/apache/shardingsphere/pull/34162)
1. SQL Binder: Support create view, alter view, drop view sql bind logic - [#34167](https://github.com/apache/shardingsphere/pull/34167)
1. SQL Binder: Support load data and load xml sql bind and add test case - [#34177](https://github.com/apache/shardingsphere/pull/34177)
1. Storage: Support setting `hive_conf_list`, `hive_var_list` and `sess_var_list` for jdbcURL when connecting to HiveServer2 - [#33749](https://github.com/apache/shardingsphere/pull/33749)
1. Storage: Support connecting to HiveServer2 through database connection pools other than HikariCP - [#33762](https://github.com/apache/shardingsphere/pull/33762)
1. Storage: Partial support for connecting to embedded ClickHouse `chDB` - [#33786](https://github.com/apache/shardingsphere/pull/33786)
1. Transaction: Support savepoint/release savepoint TCL statements in jdbc adapter -[#34173](https://github.com/apache/shardingsphere/pull/34173)
1. Kernel: Add WithAvailable interface and encrypt with, combine, insert select support checker - [#34175](https://github.com/apache/shardingsphere/pull/34175)
1. SQL Exception: Support with keyword with UniqueCommonTableExpressionException - [#34163](https://github.com/apache/shardingsphere/pull/34163)
1. Transaction: Bump the minimum Seata Client version for Seata AT integration to 2.2.0 - [#33872](https://github.com/apache/shardingsphere/pull/33872)
1. SQL Federation: Upgrade calcite version to 1.38.0 and update all license info in LICENSE file - [#33279](https://github.com/apache/shardingsphere/pull/33279)
1. JDBC: Add show database name for JDBC when execute SHOW COMPUTE NODES - [#33437](https://github.com/apache/shardingsphere/pull/33437)
Expand Down Expand Up @@ -140,7 +143,6 @@
1. Pipeline: Support page query for inventory dumper and data consistency streaming query
1. Pipeline: Use case-insensitive identifiers to enhance the table metadata loader
1. Pipeline: Support primary key columns ordering for standard pipeline table metadata loader
1. Sharding: Optimize sharding table index name rewriting rules and remove unnecessary suffix rewriting - [#31171](https://github.com/apache/shardingsphere/issues/31171)
Yash-cor marked this conversation as resolved.
Show resolved Hide resolved

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private static SubquerySegment bindSubquerySegment(final SubquerySegment segment
SQLStatementBinderContext subqueryBinderContext =
new SQLStatementBinderContext(binderContext.getMetaData(), binderContext.getCurrentDatabaseName(), binderContext.getHintValueContext(), segment.getSelect());
subqueryBinderContext.getExternalTableBinderContexts().putAll(binderContext.getExternalTableBinderContexts());
subqueryBinderContext.getCommonTableExpressionsSegmentsUniqueAliases().addAll(binderContext.getCommonTableExpressionsSegmentsUniqueAliases());
result.setSelect(new SelectStatementBinder(outerTableBinderContexts).bind(segment.getSelect(), subqueryBinderContext));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.TableSegmentBinderContext;
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
import org.apache.shardingsphere.infra.binder.engine.statement.dml.SelectStatementBinder;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.exception.kernel.syntax.UniqueCommonTableExpressionException;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement;

Expand All @@ -46,7 +48,13 @@ public static SubquerySegment bind(final SubquerySegment segment, final SQLState
SQLStatementBinderContext selectBinderContext =
new SQLStatementBinderContext(binderContext.getMetaData(), binderContext.getCurrentDatabaseName(), binderContext.getHintValueContext(), segment.getSelect());
selectBinderContext.getExternalTableBinderContexts().putAll(binderContext.getExternalTableBinderContexts());
selectBinderContext.getCommonTableExpressionsSegmentsUniqueAliases().addAll(binderContext.getCommonTableExpressionsSegmentsUniqueAliases());
SelectStatement boundSelectStatement = new SelectStatementBinder(outerTableBinderContexts).bind(segment.getSelect(), selectBinderContext);
return new SubquerySegment(segment.getStartIndex(), segment.getStopIndex(), boundSelectStatement, segment.getText());
SubquerySegment result = new SubquerySegment(segment.getStartIndex(), segment.getStopIndex(), boundSelectStatement, segment.getText());
selectBinderContext.getCommonTableExpressionsSegmentsUniqueAliases().forEach(each -> {
ShardingSpherePreconditions.checkNotContains(binderContext.getCommonTableExpressionsSegmentsUniqueAliases(), each, () -> new UniqueCommonTableExpressionException(each.toString()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this check happen in MySQL? If yes, please provide MySQL test results.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the logic for UniqueCommonTableAlias check
This check happens in MySQL but in ShardingSphere this check was happening while the query is executed in MySQL database so I have added this check during the creation of Query Context.
Screenshot 2024-12-31 121634

binderContext.getCommonTableExpressionsSegmentsUniqueAliases().add(each);
});
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static SimpleTableSegment bind(final SimpleTableSegment segment, final SQ
IdentifierValue databaseName = getDatabaseName(segment, binderContext);
IdentifierValue schemaName = getSchemaName(segment, binderContext, databaseName);
IdentifierValue tableName = segment.getTableName().getIdentifier();

Yash-cor marked this conversation as resolved.
Show resolved Hide resolved
ShardingSphereSchema schema = binderContext.getMetaData().getDatabase(databaseName.getValue()).getSchema(schemaName.getValue());
checkTableExists(binderContext, schema, schemaName.getValue(), tableName.getValue());
tableBinderContexts.put(new CaseInsensitiveString(segment.getAliasName().orElseGet(tableName::getValue)),
Expand Down Expand Up @@ -166,6 +167,9 @@ private static void checkTableExists(final SQLStatementBinderContext binderConte
if (binderContext.getExternalTableBinderContexts().containsKey(new CaseInsensitiveString(tableName))) {
return;
}
if (binderContext.getCommonTableExpressionsSegmentsUniqueAliases().contains(new CaseInsensitiveString(tableName))) {
return;
}
ShardingSpherePreconditions.checkState(schema.containsTable(tableName), () -> new TableNotFoundException(tableName));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static SubqueryTableSegment bind(final SubqueryTableSegment segment, fina
SQLStatementBinderContext subqueryBinderContext =
new SQLStatementBinderContext(binderContext.getMetaData(), binderContext.getCurrentDatabaseName(), binderContext.getHintValueContext(), segment.getSubquery().getSelect());
subqueryBinderContext.getExternalTableBinderContexts().putAll(binderContext.getExternalTableBinderContexts());
subqueryBinderContext.getCommonTableExpressionsSegmentsUniqueAliases().addAll(binderContext.getCommonTableExpressionsSegmentsUniqueAliases());
SelectStatement boundSubSelect = new SelectStatementBinder(outerTableBinderContexts).bind(segment.getSubquery().getSelect(), subqueryBinderContext);
SubquerySegment boundSubquerySegment = new SubquerySegment(segment.getSubquery().getStartIndex(), segment.getSubquery().getStopIndex(), boundSubSelect, segment.getSubquery().getText());
IdentifierValue subqueryTableName = segment.getAliasSegment().map(AliasSegment::getIdentifier).orElseGet(() -> new IdentifierValue(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.TableSegmentBinderContext;
import org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.type.SimpleTableSegmentBinderContext;
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.exception.kernel.syntax.UniqueCommonTableExpressionException;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.complex.CommonTableExpressionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ColumnProjectionSegment;
Expand Down Expand Up @@ -61,12 +63,18 @@ public static WithSegment bind(final WithSegment segment, final SQLStatementBind
for (CommonTableExpressionSegment each : segment.getCommonTableExpressions()) {
CommonTableExpressionSegment boundCommonTableExpression = CommonTableExpressionSegmentBinder.bind(each, binderContext, segment.isRecursive());
boundCommonTableExpressions.add(boundCommonTableExpression);
if (each.getAliasName().isPresent()) {
ShardingSpherePreconditions.checkNotContains(binderContext.getCommonTableExpressionsSegmentsUniqueAliases(), each.getAliasName(),
() -> new UniqueCommonTableExpressionException(each.getAliasName().get()));
binderContext.getCommonTableExpressionsSegmentsUniqueAliases().add(new CaseInsensitiveString(each.getAliasName().get()));
}
if (segment.isRecursive() && each.getAliasName().isPresent()) {
externalTableBinderContexts.removeAll(new CaseInsensitiveString(each.getAliasName().get()));
}
bindWithColumns(each.getColumns(), boundCommonTableExpression);
each.getAliasName().ifPresent(optional -> externalTableBinderContexts.put(new CaseInsensitiveString(optional), createWithTableBinderContext(boundCommonTableExpression)));
}

Yash-cor marked this conversation as resolved.
Show resolved Hide resolved
return new WithSegment(segment.getStartIndex(), segment.getStopIndex(), boundCommonTableExpressions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;

/**
* SQL statement binder context.
Expand All @@ -47,6 +49,8 @@ public final class SQLStatementBinderContext {

private final SQLStatement sqlStatement;

private final Set<CaseInsensitiveString> commonTableExpressionsSegmentsUniqueAliases = new HashSet<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Collection<CaseInsensitiveString> to replace Set<CaseInsensitiveString>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, dou you think CaseInsensitiveSet is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I am using Collection<String> commonTableExpressionsSegmentsUniqueAliases = new CaseInsensitiveSet<>();

CaseInsensitiveSet will be better as it ease the overhead of creating the object in case of Set


private final Collection<String> usingColumnNames = new CaseInsensitiveSet<>();

private final Collection<ProjectionSegment> joinTableProjectionSegments = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.infra.binder.with;

import com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString;
import org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.type.SimpleTableSegmentBinderContext;
import org.apache.shardingsphere.infra.binder.engine.segment.dml.with.WithSegmentBinder;
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
import org.apache.shardingsphere.infra.hint.HintValueContext;
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.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.complex.CommonTableExpressionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ColumnProjectionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ShorthandProjectionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.WithSegment;
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;
import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLSelectStatement;
import org.junit.jupiter.api.Test;

import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;

public class WithSegmentBinderTest {
Yash-cor marked this conversation as resolved.
Show resolved Hide resolved

@Test
void assertBind() {

MySQLSelectStatement mySQLSelectStatement = new MySQLSelectStatement();
ProjectionsSegment projectionSegment = new ProjectionsSegment(42, 48);
ColumnSegment columnSegment = new ColumnSegment(42, 48, new IdentifierValue("user_id"));
projectionSegment.getProjections().add(new ColumnProjectionSegment(columnSegment));
mySQLSelectStatement.setProjections(projectionSegment);
mySQLSelectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(55, 57, new IdentifierValue("cte"))));

MySQLSelectStatement subqueryMySQLSelectStatement = new MySQLSelectStatement();
ProjectionsSegment subqueryProjectionSegment = new ProjectionsSegment(20, 20);
ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(20, 20);
subqueryProjectionSegment.getProjections().add(shorthandProjectionSegment);
subqueryMySQLSelectStatement.setProjections(subqueryProjectionSegment);
subqueryMySQLSelectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(27, 32, new IdentifierValue("t_user"))));
SubquerySegment subquerySegment = new SubquerySegment(5, 33, subqueryMySQLSelectStatement, "(SELECT * FROM t_user)");
Collection<CommonTableExpressionSegment> commonTableExpressionSegments = new LinkedList<>();
commonTableExpressionSegments.add(new CommonTableExpressionSegment(5, 33, new AliasSegment(5, 7, new IdentifierValue("cte")), subquerySegment));
WithSegment withSegment = new WithSegment(0, 33, commonTableExpressionSegments);
mySQLSelectStatement.setWithSegment(withSegment);

SQLStatementBinderContext binderContext = new SQLStatementBinderContext(createMetaData(), "foo_db", new HintValueContext(), mySQLSelectStatement);
WithSegment actual = WithSegmentBinder.bind(withSegment, binderContext, binderContext.getExternalTableBinderContexts());

assertThat(binderContext.getExternalTableBinderContexts().size(), is(1));
assertThat(binderContext.getCommonTableExpressionsSegmentsUniqueAliases().size(), is(1));
assertThat(actual.getStartIndex(), is(0));
assertTrue(binderContext.getExternalTableBinderContexts().containsKey(new CaseInsensitiveString("cte")));
assertTrue(actual.getCommonTableExpressions().iterator().next().getAliasName().isPresent());
assertThat(actual.getCommonTableExpressions().iterator().next().getAliasName().get(), is("cte"));
assertThat(binderContext.getCommonTableExpressionsSegmentsUniqueAliases().iterator().next(), is(new CaseInsensitiveString("cte")));

SimpleTableSegmentBinderContext simpleTableSegment = (SimpleTableSegmentBinderContext) binderContext.getExternalTableBinderContexts().get(new CaseInsensitiveString("cte")).iterator().next();
ArrayList<ColumnProjectionSegment> columnProjectionSegments = new ArrayList<>();
simpleTableSegment.getProjectionSegments().forEach(each -> columnProjectionSegments.add((ColumnProjectionSegment) each));

assertThat(columnProjectionSegments.get(0).getColumn().getIdentifier().getValue(), is("user_id"));
assertThat(columnProjectionSegments.get(1).getColumn().getIdentifier().getValue(), is("name"));
assertTrue(columnProjectionSegments.get(1).getColumn().getOwner().isPresent());
assertThat(columnProjectionSegments.get(1).getColumn().getOwner().get().getIdentifier().getValue(), is("t_user"));
assertTrue(columnProjectionSegments.get(0).getColumn().getOwner().isPresent());
assertThat(columnProjectionSegments.get(0).getColumn().getOwner().get().getIdentifier().getValue(), is("t_user"));
assertThat(columnProjectionSegments.get(0).getColumn().getIdentifier().getValue(), is("user_id"));
assertThat(columnProjectionSegments.get(1).getColumn().getColumnBoundInfo().getOriginalSchema().getValue(), is("foo_db"));
assertThat(columnProjectionSegments.get(0).getColumn().getColumnBoundInfo().getOriginalSchema().getValue(), is("foo_db"));
assertThat(actual.getCommonTableExpressions().iterator().next().getSubquery().getText(), is("(SELECT * FROM t_user)"));
}

private ShardingSphereMetaData createMetaData() {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class, RETURNS_DEEP_STUBS);
when(schema.getTable("t_user").getAllColumns()).thenReturn(Arrays.asList(
new ShardingSphereColumn("user_id", Types.INTEGER, true, false, false, true, false, false),
new ShardingSphereColumn("name", Types.VARCHAR, false, false, false, true, false, false)));

ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(result.getDatabase("foo_db").getSchema("foo_db")).thenReturn(schema);
when(result.containsDatabase("foo_db")).thenReturn(true);
when(result.getDatabase("foo_db").containsSchema("foo_db")).thenReturn(true);
when(result.getDatabase("foo_db").getSchema("foo_db").containsTable("t_user")).thenReturn(true);
return result;
}

}
Loading
Loading