strongduanmu commented on code in PR #19287:
URL: https://github.com/apache/shardingsphere/pull/19287#discussion_r928347331


##########
shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContext.java:
##########
@@ -147,10 +148,28 @@ public List<AggregationProjection> 
getAggregationProjections() {
                 result.add(aggregationProjection);
                 
result.addAll(aggregationProjection.getDerivedAggregationProjections());
             }
+            if (each instanceof ExpressionProjection) {
+                
addExpressionProjectionInsideAggregationProjection((ExpressionProjection) each, 
result);
+            }
         }
         return result;
     }
     
+    private void addExpressionProjectionInsideAggregationProjection(final 
ExpressionProjection expressionProjection, final List<AggregationProjection> 
result) {
+        Collection<Projection> parameters = 
expressionProjection.getParameters();

Review Comment:
   Why is the parameters parameter required in expressionProjection ?



##########
shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java:
##########
@@ -114,11 +120,33 @@ public void 
assertCreateProjectionWhenProjectionSegmentInstanceOfColumnProjectio
     
     @Test
     public void 
assertCreateProjectionWhenProjectionSegmentInstanceOfExpressionProjectionSegment()
 {
-        ExpressionProjectionSegment expressionProjectionSegment = new 
ExpressionProjectionSegment(0, 10, "text");
-        Optional<Projection> actual = new 
ProjectionEngine(DefaultDatabase.LOGIC_NAME,
-                Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema), 
databaseType).createProjection(mock(TableSegment.class), 
expressionProjectionSegment);
-        assertTrue(actual.isPresent());
-        assertThat(actual.get(), instanceOf(ExpressionProjection.class));
+        List<ExpressionSegment> list = getExpressionSegments();
+        list.forEach(expressionSegment -> {
+            ExpressionProjectionSegment expressionProjectionSegment = new 
ExpressionProjectionSegment(0, 10, "text", expressionSegment);
+            Optional<Projection> actual = new 
ProjectionEngine(DefaultDatabase.LOGIC_NAME,
+                    Collections.singletonMap(DefaultDatabase.LOGIC_NAME, 
schema), databaseType).createProjection(mock(TableSegment.class), 
expressionProjectionSegment);
+            assertTrue(actual.isPresent());
+            assertThat(actual.get(), instanceOf(ExpressionProjection.class));
+            if (null != expressionSegment) {
+                ExpressionProjection actualExpressionProjection = 
(ExpressionProjection) actual.get();
+                assertTrue(actualExpressionProjection.getParameters().size() > 
0);
+            }
+        });
+    }
+    
+    private List<ExpressionSegment> getExpressionSegments() {
+        List<ExpressionSegment> list = new ArrayList<>();
+        FunctionSegment functionSegment = new FunctionSegment(7, 28, "IFNULL", 
"IFNULL(MAX(status), 0)");
+        AggregationProjectionSegment parameter = new 
AggregationProjectionSegment(14, 24, AggregationType.MAX, "(status)");
+        functionSegment.getParameters().add(parameter);
+        list.add(functionSegment);
+        

Review Comment:
   Please remove useless blank line.



##########
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/segment/expression/ExpressionAssert.java:
##########
@@ -378,8 +379,12 @@ public static void assertExpression(final 
SQLCaseAssertContext assertContext,
             ProjectionAssert.assertProjection(assertContext,
                     (ExpressionProjectionSegment) actual, 
expected.getExpressionProjection());
         } else if (actual instanceof AggregationProjectionSegment) {
+            ExpectedAggregationProjection expectedAggregationProjection = 
expected.getAggregationProjection();

Review Comment:
   Please move this logic to assertProjection.



##########
shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java:
##########
@@ -114,11 +120,33 @@ public void 
assertCreateProjectionWhenProjectionSegmentInstanceOfColumnProjectio
     
     @Test
     public void 
assertCreateProjectionWhenProjectionSegmentInstanceOfExpressionProjectionSegment()
 {
-        ExpressionProjectionSegment expressionProjectionSegment = new 
ExpressionProjectionSegment(0, 10, "text");
-        Optional<Projection> actual = new 
ProjectionEngine(DefaultDatabase.LOGIC_NAME,
-                Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema), 
databaseType).createProjection(mock(TableSegment.class), 
expressionProjectionSegment);
-        assertTrue(actual.isPresent());
-        assertThat(actual.get(), instanceOf(ExpressionProjection.class));
+        List<ExpressionSegment> list = getExpressionSegments();
+        list.forEach(expressionSegment -> {
+            ExpressionProjectionSegment expressionProjectionSegment = new 
ExpressionProjectionSegment(0, 10, "text", expressionSegment);
+            Optional<Projection> actual = new 
ProjectionEngine(DefaultDatabase.LOGIC_NAME,
+                    Collections.singletonMap(DefaultDatabase.LOGIC_NAME, 
schema), databaseType).createProjection(mock(TableSegment.class), 
expressionProjectionSegment);
+            assertTrue(actual.isPresent());
+            assertThat(actual.get(), instanceOf(ExpressionProjection.class));
+            if (null != expressionSegment) {
+                ExpressionProjection actualExpressionProjection = 
(ExpressionProjection) actual.get();
+                assertTrue(actualExpressionProjection.getParameters().size() > 
0);
+            }
+        });
+    }
+    
+    private List<ExpressionSegment> getExpressionSegments() {
+        List<ExpressionSegment> list = new ArrayList<>();
+        FunctionSegment functionSegment = new FunctionSegment(7, 28, "IFNULL", 
"IFNULL(MAX(status), 0)");
+        AggregationProjectionSegment parameter = new 
AggregationProjectionSegment(14, 24, AggregationType.MAX, "(status)");
+        functionSegment.getParameters().add(parameter);
+        list.add(functionSegment);
+        
+        ExpressionSegment right = new LiteralExpressionSegment(25, 25, 1);
+        ExpressionSegment binaryOperationExpression = new 
BinaryOperationExpression(7, 25, parameter, right, "+", "IFNULL(status, 0)+1");
+        list.add(binaryOperationExpression);
+        

Review Comment:
   Please remove useless blank line.



##########
shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionsContextTest.java:
##########
@@ -128,6 +144,13 @@ private AggregationProjection getAggregationProjection() {
         return new AggregationProjection(AggregationType.COUNT, "(column)", 
"c", mock(DatabaseType.class));
     }
     
+    private ExpressionProjection getContainsParametersExpressionProjection() {
+        AggregationProjection aggregationProjection = new 
AggregationProjection(AggregationType.MAX, "(status)", "IFNULL(MAX(status), 
0)", mock(DatabaseType.class));
+        ExpressionProjection expressionProjection = new 
ExpressionProjection("IFNULL(MAX(status), 0)", null);
+        expressionProjection.getParameters().add(aggregationProjection);
+        return expressionProjection;

Review Comment:
   Please return result here.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to