Sitelet https://web.archive.org/web/20210722000254/https://github.com/apache/shardingsphere/issues/11270
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

Remove test only constructor of SelectStatementContext #11270

Open
terrymanu opened this issue Jul 11, 2021 · 4 comments
Open

Remove test only constructor of SelectStatementContext #11270

terrymanu opened this issue Jul 11, 2021 · 4 comments

Comments

@terrymanu
Copy link
Member

@terrymanu terrymanu commented Jul 11, 2021

The first constructor of SelectStatementContext are used for test case only.

Please refactor the test cases to use the second constructor and remove the first one.

@LeeGuoPing
Copy link
Contributor

@LeeGuoPing LeeGuoPing commented Jul 11, 2021

May I do this one?

@terrymanu
Copy link
Member Author

@terrymanu terrymanu commented Jul 11, 2021

Go ahead please

@LeeGuoPing
Copy link
Contributor

@LeeGuoPing LeeGuoPing commented Jul 14, 2021 •

I met some troubles. one is the second constructor when the orderByContext has no elements but the groupByContext has some elements. it will add the groupByContext's elements as orderByContext's auto. In this case, I not found a solution to solve this problem. this method "assertBuildGroupByMemoryMergedResultWithMySQLLimit" has this prolems!
image

image

@LeeGuoPing
Copy link
Contributor

@LeeGuoPing LeeGuoPing commented Jul 14, 2021

And, the other problem is when the test case is Oracle, in the "createPaginationContext" method called a method is

image

oracle is not support, to run the test case 'assertBuildIteratorStreamMergedResultWithOracleLimit' successfully. I write so long code, My idea is right? sorry, I have not read the whole code of this project

@test
public void assertBuildIteratorStreamMergedResultWithOracleLimit() throws SQLException {
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(DatabaseTypeRegistry.getActualDatabaseType("Oracle"));
Map<String, ShardingSphereMetaData> metaDataMap = new HashMap<>();
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
when(metaData.getSchema()).thenReturn(schema);
metaDataMap.put(DefaultSchema.LOGIC_NAME, metaData);
OracleSelectStatement selectStatement = (OracleSelectStatement) buildSelectStatement(new OracleSelectStatement());
ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
when(projectionsSegment.getStartIndex()).thenReturn(0);
when(projectionsSegment.getStopIndex()).thenReturn(0);
when(projectionsSegment.isDistinctRow()).thenReturn(false);
when(projectionsSegment.getProjections()).thenReturn(Collections.emptyList());
selectStatement.setProjections(projectionsSegment);

    LimitSegment limitSegment = mock(LimitSegment.class);
    when(limitSegment.getOffset()).thenReturn(Optional.of(new NumberLiteralRowNumberValueSegment(0, 0, 1, true)));
    when(limitSegment.getRowCount()).thenReturn(Optional.empty());
    WhereSegment whereSegment = mock(WhereSegment.class);

    BinaryOperationExpression binaryOperationExpression = mock(BinaryOperationExpression.class);
    when(binaryOperationExpression.getLeft()).thenReturn(new ColumnSegment(0, 0, new IdentifierValue("row_id")));
    when(binaryOperationExpression.getRight()).thenReturn(new LiteralExpressionSegment(0, 0, 1));
    when(binaryOperationExpression.getOperator()).thenReturn(">=");
    when(whereSegment.getExpr()).thenReturn(binaryOperationExpression);
    selectStatement.setWhere(whereSegment);

    SubqueryTableSegment subqueryTableSegment = mock(SubqueryTableSegment.class);
    SubquerySegment subquerySegment = mock(SubquerySegment.class);
    SelectStatement subSelectStatement = mock(SelectStatement.class);
    ProjectionsSegment subProjectionsSegment = mock(ProjectionsSegment.class);
    TopProjectionSegment topProjectionSegment = mock(TopProjectionSegment.class);
    when(topProjectionSegment.getAlias()).thenReturn("row_id");
    when(subProjectionsSegment.getProjections()).thenReturn(Collections.singletonList(topProjectionSegment));
    when(subSelectStatement.getProjections()).thenReturn(subProjectionsSegment);
    when(subquerySegment.getSelect()).thenReturn(subSelectStatement);
    when(subqueryTableSegment.getSubquery()).thenReturn(subquerySegment);
    selectStatement.setFrom(subqueryTableSegment);
    SelectStatementContext selectStatementContext1 = new SelectStatementContext(metaDataMap, Collections.emptyList(), selectStatement, DefaultSchema.LOGIC_NAME);

    MergedResult actual = resultMerger.merge(createQueryResults(), selectStatementContext1, buildSchema());
    assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class));
    assertThat(((RowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(IteratorStreamMergedResult.class));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants