You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/06/30 05:47:06 UTC

[GitHub] [shardingsphere] Bpazy commented on a diff in pull request #18713: Add more unit test for SelectStatementContext

Bpazy commented on code in PR #18713:
URL: https://github.com/apache/shardingsphere/pull/18713#discussion_r910626917


##########
shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java:
##########
@@ -484,7 +489,85 @@ private void assertContainsSubqueryWhereEmpty(final SelectStatement selectStatem
         assertTrue(new SelectStatementContext(
                 Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME).isContainsSubquery());
     }
+
+    @Test
+    public void assertContainsDollarParameterMarkerForMySQL() {
+        assertContainsDollarParameterMarker(new MySQLSelectStatement());
+    }
+    
+    @Test
+    public void assertContainsDollarParameterMarkerForOracle() {
+        assertContainsDollarParameterMarker(new OracleSelectStatement());
+    }
     
+    @Test
+    public void assertContainsDollarParameterMarkerForPostgreSQL() {
+        assertContainsDollarParameterMarker(new PostgreSQLSelectStatement());
+    }
+    
+    @Test
+    public void assertContainsDollarParameterMarkerForSQL92() {
+        assertContainsDollarParameterMarker(new SQL92SelectStatement());
+    }
+    
+    @Test
+    public void assertContainsDollarParameterMarkerForSQLServer() {
+        assertContainsDollarParameterMarker(new SQLServerSelectStatement());
+    }
+    
+    private void assertContainsDollarParameterMarker(final SelectStatement selectStatement) {
+        ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
+        when(projectionsSegment.getProjections()).thenReturn(Lists.newArrayList(new ParameterMarkerExpressionSegment(0, 0, 0, ParameterMarkerType.DOLLAR)));
+        selectStatement.setProjections(projectionsSegment);
+        SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), Collections.emptyList(),
+                selectStatement, DefaultDatabase.LOGIC_NAME);
+        assertTrue(selectStatementContext.isContainsDollarParameterMarker());
+        
+        selectStatement.setProjections(new ProjectionsSegment(0, 0));
+        JoinTableSegment joinTableSegment = new JoinTableSegment();
+        joinTableSegment.setCondition(new ParameterMarkerExpressionSegment(0, 0, 0, ParameterMarkerType.DOLLAR));
+        selectStatement.setFrom(joinTableSegment);
+        selectStatementContext = new SelectStatementContext(
+                Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+        assertTrue(selectStatementContext.isContainsDollarParameterMarker());
+    }
+
+    @Test
+    public void assertContainsPartialDistinctAggregationForMySQL() {
+        assertContainsPartialDistinctAggregation(new MySQLSelectStatement());
+    }
+
+    @Test
+    public void assertContainsPartialDistinctAggregationForOracle() {
+        assertContainsPartialDistinctAggregation(new OracleSelectStatement());
+    }
+
+    @Test
+    public void assertContainsPartialDistinctAggregationForPostgreSQL() {
+        assertContainsPartialDistinctAggregation(new PostgreSQLSelectStatement());
+    }
+
+    @Test
+    public void assertContainsPartialDistinctAggregationForSQL92() {
+        assertContainsPartialDistinctAggregation(new SQL92SelectStatement());
+    }
+
+    @Test
+    public void assertContainsPartialDistinctAggregationForSQLServer() {
+        assertContainsPartialDistinctAggregation(new SQLServerSelectStatement());
+    }
+
+    private void assertContainsPartialDistinctAggregation(final SelectStatement selectStatement) {
+        ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
+        projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "(*)"));
+        projectionsSegment.getProjections().add(new AggregationDistinctProjectionSegment(0, 10, AggregationType.COUNT, "(1)", "distinctExpression"));
+        selectStatement.setProjections(projectionsSegment);
+

Review Comment:
   Done



##########
shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java:
##########
@@ -484,7 +489,85 @@ private void assertContainsSubqueryWhereEmpty(final SelectStatement selectStatem
         assertTrue(new SelectStatementContext(
                 Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME).isContainsSubquery());
     }
+
+    @Test
+    public void assertContainsDollarParameterMarkerForMySQL() {
+        assertContainsDollarParameterMarker(new MySQLSelectStatement());
+    }
+    
+    @Test
+    public void assertContainsDollarParameterMarkerForOracle() {
+        assertContainsDollarParameterMarker(new OracleSelectStatement());
+    }
     
+    @Test
+    public void assertContainsDollarParameterMarkerForPostgreSQL() {
+        assertContainsDollarParameterMarker(new PostgreSQLSelectStatement());
+    }
+    
+    @Test
+    public void assertContainsDollarParameterMarkerForSQL92() {
+        assertContainsDollarParameterMarker(new SQL92SelectStatement());
+    }
+    
+    @Test
+    public void assertContainsDollarParameterMarkerForSQLServer() {
+        assertContainsDollarParameterMarker(new SQLServerSelectStatement());
+    }
+    
+    private void assertContainsDollarParameterMarker(final SelectStatement selectStatement) {
+        ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
+        when(projectionsSegment.getProjections()).thenReturn(Lists.newArrayList(new ParameterMarkerExpressionSegment(0, 0, 0, ParameterMarkerType.DOLLAR)));

Review Comment:
   Done



##########
shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java:
##########
@@ -484,7 +489,85 @@ private void assertContainsSubqueryWhereEmpty(final SelectStatement selectStatem
         assertTrue(new SelectStatementContext(
                 Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME).isContainsSubquery());
     }
+
+    @Test
+    public void assertContainsDollarParameterMarkerForMySQL() {
+        assertContainsDollarParameterMarker(new MySQLSelectStatement());
+    }
+    
+    @Test
+    public void assertContainsDollarParameterMarkerForOracle() {
+        assertContainsDollarParameterMarker(new OracleSelectStatement());
+    }
     
+    @Test
+    public void assertContainsDollarParameterMarkerForPostgreSQL() {
+        assertContainsDollarParameterMarker(new PostgreSQLSelectStatement());
+    }
+    
+    @Test
+    public void assertContainsDollarParameterMarkerForSQL92() {
+        assertContainsDollarParameterMarker(new SQL92SelectStatement());
+    }
+    
+    @Test
+    public void assertContainsDollarParameterMarkerForSQLServer() {
+        assertContainsDollarParameterMarker(new SQLServerSelectStatement());
+    }
+    
+    private void assertContainsDollarParameterMarker(final SelectStatement selectStatement) {
+        ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
+        when(projectionsSegment.getProjections()).thenReturn(Lists.newArrayList(new ParameterMarkerExpressionSegment(0, 0, 0, ParameterMarkerType.DOLLAR)));
+        selectStatement.setProjections(projectionsSegment);
+        SelectStatementContext selectStatementContext = new SelectStatementContext(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(ShardingSphereDatabase.class)), Collections.emptyList(),
+                selectStatement, DefaultDatabase.LOGIC_NAME);
+        assertTrue(selectStatementContext.isContainsDollarParameterMarker());
+        

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org