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/12/11 06:05:46 UTC

[GitHub] [shardingsphere] xinglijun1973 opened a new pull request, #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum

xinglijun1973 opened a new pull request, #20257:
URL: https://github.com/apache/shardingsphere/pull/20257

   Fixes #14334, #13814:
   Oracle pagination and sorting doesn' t work properly #14334,
   Using sum function does not return data #13814.
   
   Changes proposed in this pull request:
   -if use oracle's rownun alias in where, it means use the "order by"/"group by" exists in  the rownum's from sub query, 
   ex: `select * from (select t.*, rownum r from (select * from a order by a.name)t ) where r<10`
   will rewrite to:
   `select * from (select t.*, rownum r from (select * from a order by a.name)t ) where r<10 orde by name`, so
   -first, resolve ‘rownum alias’ and ‘the indeed oracelSelectStatement’ relation in `OracleDMLStatementVisitor`, save the relation in `OracelSelectStatement.rowNumSelect` map
   -second, using the relation above, in `SelectStatementContext`, if use rownum alias in where, update 'order by'/'group by' context.
   


-- 
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


[GitHub] [shardingsphere] xinglijun1973 commented on a diff in pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum

Posted by GitBox <gi...@apache.org>.
xinglijun1973 commented on code in PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#discussion_r1056085782


##########
sql-parser/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java:
##########
@@ -512,6 +515,31 @@ public ASTNode visitQueryBlock(final QueryBlockContext ctx) {
         if (null != ctx.modelClause()) {
             result.setModelSegment((ModelSegment) visit(ctx.modelClause()));
         }
+        Map<String, OracleSelectStatement> rowNumSelect = getRowNumSelect(result);
+        if (rowNumSelect.size() > 0) {
+            result.setRowNumSelect(rowNumSelect);

Review Comment:
   great! I had 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


[GitHub] [shardingsphere] xinglijun1973 commented on a diff in pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum

Posted by GitBox <gi...@apache.org>.
xinglijun1973 commented on code in PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#discussion_r1005199957


##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/OracleSelectStatementContextDialect.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.statement.dml;
+
+import java.util.Collection;
+import java.util.Optional;
+
+import org.apache.shardingsphere.infra.binder.segment.select.groupby.GroupByContext;
+import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByContext;
+import org.apache.shardingsphere.infra.binder.segment.select.projection.ProjectionsContext;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.dml.OracleSelectStatement;
+
+/**
+ * Oracle Select SQL statement context dialect.
+ */
+public final class OracleSelectStatementContextDialect implements SelectStatementContextDialect {

Review Comment:
   had it merged



-- 
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


Re: [PR] Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu closed pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery  to its outer statement if the subquery selects oracle rownum
URL: https://github.com/apache/shardingsphere/pull/20257


-- 
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


[GitHub] [shardingsphere] xinglijun1973 closed pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum

Posted by GitBox <gi...@apache.org>.
xinglijun1973 closed pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery  to its outer statement if the subquery selects oracle rownum
URL: https://github.com/apache/shardingsphere/pull/20257


-- 
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


[GitHub] [shardingsphere] strongduanmu commented on pull request #20257: 14334

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#issuecomment-1231093343

   Hi @xinglijun1973, can you modify the pr title for friendly search?


-- 
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


[GitHub] [shardingsphere] xinglijun1973 closed pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum

Posted by GitBox <gi...@apache.org>.
xinglijun1973 closed pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery  to its outer statement if the subquery selects oracle rownum
URL: https://github.com/apache/shardingsphere/pull/20257


-- 
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


[GitHub] [shardingsphere] strongduanmu commented on a diff in pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on code in PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#discussion_r1060293690


##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java:
##########
@@ -130,6 +162,53 @@ private Map<Integer, SelectStatementContext> createSubqueryContexts(final Shardi
         return result;
     }
     
+    private Map<String, SelectStatementContext> resolveRownumAndContextMap() {

Review Comment:
   Do you think getRownumSelectStatementContext may be better?



##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngine.java:
##########
@@ -115,32 +114,38 @@ private boolean containsProjection(final OrderByItemSegment orderByItem, final C
     }
     
     private boolean isSameColumn(final Projection projection, final ColumnSegment columnSegment) {
-        Collection<ColumnProjection> columns = getColumnProjections(projection);
+        Collection<Projection> columns = expandProjection(projection);
         if (columns.isEmpty()) {
             return false;
         }
         boolean columnSegmentPresent = columnSegment.getOwner().isPresent();
-        for (ColumnProjection each : columns) {
+        for (Projection each : columns) {
             if (columnSegmentPresent ? isSameQualifiedName(each, columnSegment.getQualifiedName()) : isSameName(each, columnSegment.getQualifiedName())) {
                 return true;
             }
         }
         return false;
     }
     
-    private Collection<ColumnProjection> getColumnProjections(final Projection projection) {
-        Collection<ColumnProjection> result = new LinkedList<>();
-        if (projection instanceof ColumnProjection) {
-            result.add((ColumnProjection) projection);
-        }
+    /**
+     * Expand projection, such as ShorthandProjection.
+     * 
+     * @param projection the projection to expand
+     * @return expanded projections
+     */
+    public static Collection<Projection> expandProjection(final Projection projection) {
+        Collection<Projection> result = new LinkedList<>();
         if (projection instanceof ShorthandProjection) {
             result.addAll(((ShorthandProjection) projection).getColumnProjections());
+        } else if (!(projection instanceof DerivedProjection)) {
+            result.add(projection);
         }
         return result;
     }
     
-    private boolean isSameName(final ColumnProjection projection, final String text) {
-        return SQLUtil.getExactlyValue(text).equalsIgnoreCase(projection.getName());
+    private boolean isSameName(final Projection projection, final String text) {
+        String expression = projection.getExpression();
+        return SQLUtil.getExactlyValue(text).equalsIgnoreCase(expression.substring(expression.indexOf('.') + 1));

Review Comment:
   Why we need `expression.substring(expression.indexOf('.') + 1)`?



##########
infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContextTest.java:
##########
@@ -605,4 +613,67 @@ private ProjectionSegment getColumnProjectionSegmentWithoutOwner(final boolean h
         columnProjectionSegment.setAlias(new AliasSegment(0, 0, new IdentifierValue(hasAlias ? "n" : null)));
         return columnProjectionSegment;
     }
+    
+    @Test
+    public void assertContainsOrderbyForOracleRownum() {
+        // select * from (select t.*, rownum r from (select * from a order by name)t ) where r<10
+        OracleSelectStatement selectStatement = new OracleSelectStatement();
+        ProjectionsSegment projections = new ProjectionsSegment(0, 0);
+        projections.getProjections().add(new ShorthandProjectionSegment(0, 0));
+        selectStatement.setProjections(projections);
+        ExpressionSegment expr = new BinaryOperationExpression(0, 0, new ColumnSegment(0, 0, new IdentifierValue("r")), new LiteralExpressionSegment(0, 0, 10), "<", "r<10");
+        WhereSegment where = new WhereSegment(0, 0, expr);
+        selectStatement.setWhere(where);
+        SelectStatement subStatement = createSubStatementOfAssertContainsOrderbyForOracleRownum();
+        TableSegment from = new SubqueryTableSegment(new SubquerySegment(26, 87, subStatement));
+        selectStatement.setFrom(from);
+        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
+        when(database.getSchemas()).thenReturn(mockSchemas());
+        ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class),
+                mock(ConfigurationProperties.class));
+        SelectStatementContext selectStatementContext = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+        assertTrue(selectStatementContext.getOrderByContext().getItems().size() > 0);
+    }
+    
+    private SelectStatement createSubStatementOfAssertContainsOrderbyForOracleRownum() {
+        // select t.*, rownum r from (select * from a order by a.name)t
+        final SelectStatement subStatement = new OracleSelectStatement();
+        ProjectionsSegment subProjections = new ProjectionsSegment(0, 0);
+        ShorthandProjectionSegment subShorthandProjection = new ShorthandProjectionSegment(0, 0);
+        subShorthandProjection.setOwner(new OwnerSegment(0, 0, new IdentifierValue("t")));
+        subProjections.getProjections().add(subShorthandProjection);
+        ColumnProjectionSegment subRownumProjection = new ColumnProjectionSegment(new ColumnSegment(0, 0, new IdentifierValue("rownum")));
+        subRownumProjection.setAlias(new AliasSegment(0, 0, new IdentifierValue("r")));
+        subProjections.getProjections().add(subRownumProjection);
+        subStatement.setProjections(subProjections);
+        SelectStatement subsubSelectStatement = createSubSubStatementOfAssertContainsOrderbyForOracleRownum();
+        SubquerySegment subsubSeg = new SubquerySegment(39, 70, subsubSelectStatement);
+        TableSegment subsubQuery = new SubqueryTableSegment(subsubSeg);
+        subsubQuery.setAlias(new AliasSegment(0, 0, new IdentifierValue("t")));
+        subStatement.setFrom(subsubQuery);
+        return subStatement;
+    }
+    
+    private SelectStatement createSubSubStatementOfAssertContainsOrderbyForOracleRownum() {
+        // select a.* from a order by a.name
+        SelectStatement subsubSelectStatement = new OracleSelectStatement();
+        ProjectionsSegment subsubProjections = new ProjectionsSegment(0, 0);
+        ShorthandProjectionSegment shorthandSegment = new ShorthandProjectionSegment(0, 0);
+        shorthandSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("a")));
+        subsubProjections.getProjections().add(shorthandSegment);
+        subsubSelectStatement.setProjections(subsubProjections);
+        subsubSelectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(28, 29, new IdentifierValue("a"))));
+        LinkedList<OrderByItemSegment> orderByItems = new LinkedList<OrderByItemSegment>();
+        orderByItems.add(new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("name")), OrderDirection.ASC, NullsOrderType.FIRST));
+        subsubSelectStatement.setOrderBy(new OrderBySegment(0, 0, orderByItems));
+        return subsubSelectStatement;

Review Comment:
   Please rename subsubSelectStatement to result.



##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java:
##########
@@ -130,6 +162,53 @@ private Map<Integer, SelectStatementContext> createSubqueryContexts(final Shardi
         return result;
     }
     
+    private Map<String, SelectStatementContext> resolveRownumAndContextMap() {
+        Map<SelectStatement, SelectStatementContext> subqueryStatementAndContextMap = new HashMap<>();
+        for (SelectStatementContext subSelectContext : subqueryContexts.values()) {
+            subqueryStatementAndContextMap.put(subSelectContext.getSqlStatement(), subSelectContext);
+        }
+        Map<String, SelectStatementContext> result = new HashMap<>();
+        for (ProjectionSegment proj : getSqlStatement().getProjections().getProjections()) {

Review Comment:
   Please rename proj to each.



##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngine.java:
##########
@@ -115,32 +114,38 @@ private boolean containsProjection(final OrderByItemSegment orderByItem, final C
     }
     
     private boolean isSameColumn(final Projection projection, final ColumnSegment columnSegment) {
-        Collection<ColumnProjection> columns = getColumnProjections(projection);
+        Collection<Projection> columns = expandProjection(projection);

Review Comment:
   Do you think rename `expandProjection` to `getExpandedProjections` will be better?



-- 
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


[GitHub] [shardingsphere] strongduanmu commented on a diff in pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on code in PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#discussion_r1002860735


##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/OracleSelectStatementContextDialect.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.statement.dml;
+
+import java.util.Collection;
+import java.util.Optional;
+
+import org.apache.shardingsphere.infra.binder.segment.select.groupby.GroupByContext;
+import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByContext;
+import org.apache.shardingsphere.infra.binder.segment.select.projection.ProjectionsContext;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.dml.OracleSelectStatement;
+
+/**
+ * Oracle Select SQL statement context dialect.
+ */
+public final class OracleSelectStatementContextDialect implements SelectStatementContextDialect {

Review Comment:
   Can logic from OracleSelectStatementContextDialect be merged into SelectStatementContext ?



##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionUtil.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.segment.select.projection;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.DerivedProjection;
+import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ShorthandProjection;
+
+/**
+ * projection util. 
+ */
+public class ProjectionUtil {
+    
+    /**
+     * expand projection, such as ShorthandProjection.
+     * @param projection the projection to expand
+     * @return expanded projections
+     */
+    public static Collection<Projection> expandProjection(final Projection projection) {

Review Comment:
   Can we get expand projections by projection context?



##########
infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java:
##########
@@ -602,4 +604,33 @@ private ProjectionSegment getColumnProjectionSegmentWithoutOwner(final boolean h
         columnProjectionSegment.setAlias(new AliasSegment(0, 0, new IdentifierValue(hasAlias ? "n" : null)));
         return columnProjectionSegment;
     }
+    
+    @Test
+    public void assertGroupbyWithPagingForOracle() {
+        // select rownum , city, count(1) from t_user group by city
+        ProjectionsSegment innerProjections = new ProjectionsSegment(0, 0);
+        ColumnProjectionSegment rownumProjectionSegment = new ColumnProjectionSegment(new ColumnSegment(0, 0, new IdentifierValue("ROWNUM")));
+        rownumProjectionSegment.setAlias(new AliasSegment(0, 0, new IdentifierValue("pagerow_")));
+        innerProjections.getProjections().add(rownumProjectionSegment);
+        ColumnSegment cityColumnSegment = new ColumnSegment(0, 0, new IdentifierValue("city"));
+        innerProjections.getProjections().add(new ColumnProjectionSegment(cityColumnSegment));
+        innerProjections.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "(1)"));
+        OracleSelectStatement innerSelectStatement = new OracleSelectStatement();
+        innerSelectStatement.setProjections(innerProjections);
+        innerSelectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_user"))));
+        innerSelectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(new ColumnOrderByItemSegment(cityColumnSegment, OrderDirection.ASC))));
+        

Review Comment:
   Please remove this useless black line.



##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContextDialect.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.statement.dml;
+
+import org.apache.shardingsphere.infra.binder.segment.select.groupby.GroupByContext;
+import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByContext;
+import org.apache.shardingsphere.infra.binder.segment.select.projection.ProjectionsContext;
+
+/**
+ * Select SQL statement context dialect.
+ */
+public interface SelectStatementContextDialect {
+    
+    /**
+     * update GroupbyContext.
+     * @param groupByContext groupByContext
+     */
+    default void updateGroupbyContext(final GroupByContext groupByContext) {
+        

Review Comment:
   Please remove useless blank line.



-- 
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


[GitHub] [shardingsphere] strongduanmu commented on pull request #20257: Fix Oracle pagination and sorting problem: add ‘order by’ of the subquery to its outer statement if the subquery selects oracle rownum

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#issuecomment-1233054059

   > @strongduanmu done
   
   Good job, I will review this pr again.


-- 
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


[GitHub] [shardingsphere] xinglijun1973 commented on a diff in pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum

Posted by GitBox <gi...@apache.org>.
xinglijun1973 commented on code in PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#discussion_r1004183861


##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/ProjectionUtil.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.segment.select.projection;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.DerivedProjection;
+import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ShorthandProjection;
+
+/**
+ * projection util. 
+ */
+public class ProjectionUtil {
+    
+    /**
+     * expand projection, such as ShorthandProjection.
+     * @param projection the projection to expand
+     * @return expanded projections
+     */
+    public static Collection<Projection> expandProjection(final Projection projection) {

Review Comment:
   It's to expand a column projection (especially Shorthand Projection), but projection context contains all projections. 



-- 
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


[GitHub] [shardingsphere] xinglijun1973 closed pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum

Posted by GitBox <gi...@apache.org>.
xinglijun1973 closed pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery  to its outer statement if the subquery selects oracle rownum
URL: https://github.com/apache/shardingsphere/pull/20257


-- 
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


[GitHub] [shardingsphere] xinglijun1973 commented on pull request #20257: 14334

Posted by GitBox <gi...@apache.org>.
xinglijun1973 commented on PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#issuecomment-1221510474

   had fixed
   
   
   
   ---Original---
   From: "Zhengqiang ***@***.***&gt;
   Date: Sat, Aug 20, 2022 21:52 PM
   To: ***@***.***&gt;;
   Cc: ***@***.******@***.***&gt;;
   Subject: Re: [apache/shardingsphere] 14334 (PR #20257)
   
   
   
   
    
   @strongduanmu requested changes on this pull request.
    
   Hi @xinglijun1973, thank you for your contribution. Can you fix ci error first?
    
   —
   Reply to this email directly, view it on GitHub, or unsubscribe.
   You are receiving this because you were mentioned.Message ID: ***@***.***&gt;


-- 
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


[GitHub] [shardingsphere] codecov-commenter commented on pull request #20257: 14334

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#issuecomment-1221703429

   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/20257?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#20257](https://codecov.io/gh/apache/shardingsphere/pull/20257?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d64408a) into [master](https://codecov.io/gh/apache/shardingsphere/commit/674961b1398f9986ac7ba51aec5797f984ff07f5?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (674961b) will **decrease** coverage by `0.02%`.
   > The diff coverage is `62.50%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #20257      +/-   ##
   ============================================
   - Coverage     60.40%   60.38%   -0.03%     
   + Complexity     2438     2437       -1     
   ============================================
     Files          3915     3917       +2     
     Lines         55353    55395      +42     
     Branches       9410     9425      +15     
   ============================================
   + Hits          33437    33450      +13     
   - Misses        19057    19078      +21     
   - Partials       2859     2867       +8     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/20257?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...nt/select/orderby/engine/OrderByContextEngine.java](https://codecov.io/gh/apache/shardingsphere/pull/20257/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtYmluZGVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9iaW5kZXIvc2VnbWVudC9zZWxlY3Qvb3JkZXJieS9lbmdpbmUvT3JkZXJCeUNvbnRleHRFbmdpbmUuamF2YQ==) | `72.72% <50.00%> (-15.74%)` | :arrow_down: |
   | [...ct/statement/oracle/dml/OracleSelectStatement.java](https://codecov.io/gh/apache/shardingsphere/pull/20257/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvZGlhbGVjdC9zdGF0ZW1lbnQvb3JhY2xlL2RtbC9PcmFjbGVTZWxlY3RTdGF0ZW1lbnQuamF2YQ==) | `50.00% <50.00%> (ø)` | |
   | [...r/statement/impl/OracleDMLStatementSQLVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/20257/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci1vcmFjbGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NxbC9wYXJzZXIvb3JhY2xlL3Zpc2l0b3Ivc3RhdGVtZW50L2ltcGwvT3JhY2xlRE1MU3RhdGVtZW50U1FMVmlzaXRvci5qYXZh) | `76.85% <75.00%> (-0.07%)` | :arrow_down: |
   | [.../handler/distsql/ral/RALBackendHandlerFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/20257/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC9oYW5kbGVyL2Rpc3RzcWwvcmFsL1JBTEJhY2tlbmRIYW5kbGVyRmFjdG9yeS5qYXZh) | `78.72% <0.00%> (-4.61%)` | :arrow_down: |
   | [...ser/core/kernel/KernelDistSQLStatementVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/20257/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZGlzdHNxbC9zaGFyZGluZ3NwaGVyZS1kaXN0c3FsLXBhcnNlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZGlzdHNxbC9wYXJzZXIvY29yZS9rZXJuZWwvS2VybmVsRGlzdFNRTFN0YXRlbWVudFZpc2l0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...ql/parser/core/TrafficDistSQLStatementVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/20257/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUta2VybmVsL3NoYXJkaW5nc3BoZXJlLXRyYWZmaWMvc2hhcmRpbmdzcGhlcmUtdHJhZmZpYy1kaXN0c3FsL3NoYXJkaW5nc3BoZXJlLXRyYWZmaWMtZGlzdHNxbC1wYXJzZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3RyYWZmaWMvZGlzdHNxbC9wYXJzZXIvY29yZS9UcmFmZmljRGlzdFNRTFN0YXRlbWVudFZpc2l0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...istsql/ral/updatable/CreateTrafficRuleHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/20257/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC9oYW5kbGVyL2Rpc3RzcWwvcmFsL3VwZGF0YWJsZS9DcmVhdGVUcmFmZmljUnVsZUhhbmRsZXIuamF2YQ==) | | |
   | [...ta/pipeline/postgresql/util/FreemarkerManager.java](https://codecov.io/gh/apache/shardingsphere/pull/20257/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUta2VybmVsL3NoYXJkaW5nc3BoZXJlLWRhdGEtcGlwZWxpbmUvc2hhcmRpbmdzcGhlcmUtZGF0YS1waXBlbGluZS1kaWFsZWN0L3NoYXJkaW5nc3BoZXJlLWRhdGEtcGlwZWxpbmUtcG9zdGdyZXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvZGF0YS9waXBlbGluZS9wb3N0Z3Jlc3FsL3V0aWwvRnJlZW1hcmtlck1hbmFnZXIuamF2YQ==) | | |
   | [...distsql/ral/updatable/AlterTrafficRuleHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/20257/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC9oYW5kbGVyL2Rpc3RzcWwvcmFsL3VwZGF0YWJsZS9BbHRlclRyYWZmaWNSdWxlSGFuZGxlci5qYXZh) | | |
   | [.../distsql/ral/updatable/DropTrafficRuleHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/20257/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC9oYW5kbGVyL2Rpc3RzcWwvcmFsL3VwZGF0YWJsZS9Ecm9wVHJhZmZpY1J1bGVIYW5kbGVyLmphdmE=) | | |
   | ... and [8 more](https://codecov.io/gh/apache/shardingsphere/pull/20257/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
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


[GitHub] [shardingsphere] xinglijun1973 commented on pull request #20257: Fix Oracle pagination and sorting problem: add ‘order by’ of the subquery to its outer statement if the subquery selects oracle rownum

Posted by GitBox <gi...@apache.org>.
xinglijun1973 commented on PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#issuecomment-1231151733

   @strongduanmu 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


Re: [PR] Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#issuecomment-1763899502

   Since this pr has long time no reponse, I will close it.


-- 
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


[GitHub] [shardingsphere] strongduanmu commented on a diff in pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on code in PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#discussion_r1046657230


##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java:
##########
@@ -111,11 +113,26 @@ public SelectStatementContext(final ShardingSphereMetaData metaData, final List<
         ColumnExtractor.extractColumnSegments(columnSegments, whereSegments);
         subqueryContexts = createSubqueryContexts(metaData, params, defaultDatabaseName);
         tablesContext = new TablesContext(getAllTableSegments(), subqueryContexts, getDatabaseType());
-        String databaseName = tablesContext.getDatabaseName().orElse(defaultDatabaseName);
+        Optional<SelectStatementContext> rownumSelectContext;
+        if (sqlStatement instanceof OracleSelectStatement && sqlStatement.getWhere().isPresent()) {

Review Comment:
   Can we extract if condition to a private method.



##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java:
##########
@@ -130,6 +147,42 @@ private Map<Integer, SelectStatementContext> createSubqueryContexts(final Shardi
         return result;
     }
     
+    private Optional<SelectStatementContext> findRownumSelectStatementContext() {
+        WhereSegment where = getSqlStatement().getWhere().get();
+        Optional<OracleSelectStatement> rownumSelectStatement = Optional.empty();
+        if (where.getExpr() instanceof BinaryOperationExpression) {
+            rownumSelectStatement = findRownumSelectStatement((BinaryOperationExpression) where.getExpr(), (OracleSelectStatement) getSqlStatement());
+        }
+        Optional<SelectStatementContext> rownumSelectContext = Optional.empty();
+        if (rownumSelectStatement.isPresent()) {
+            rownumSelectContext = findContextFromSubQueryContext(subqueryContexts.values(), rownumSelectStatement.get());
+        }
+        return rownumSelectContext;
+    }
+    
+    private Optional<OracleSelectStatement> findRownumSelectStatement(final BinaryOperationExpression expr, final OracleSelectStatement selectStatement) {
+        ExpressionSegment left = expr.getLeft();
+        if (left instanceof ColumnSegment) {
+            String rowNumAlias = ((ColumnSegment) left).getIdentifier().getValue();
+            return selectStatement.getRowNumSelect().containsKey(rowNumAlias) ? Optional.of(selectStatement.getRowNumSelect().get(rowNumAlias)) : Optional.empty();
+        }
+        if (left instanceof BinaryOperationExpression) {
+            return findRownumSelectStatement((BinaryOperationExpression) left, selectStatement);
+        }
+        return Optional.empty();
+    }
+    
+    private Optional<SelectStatementContext> findContextFromSubQueryContext(final Collection<SelectStatementContext> subQueryContexts, final OracleSelectStatement selectStatement) {
+        Optional<SelectStatementContext> statementContext = Optional.empty();
+        for (SelectStatementContext subSelectContext : subQueryContexts) {
+            if (subSelectContext.getSqlStatement() == selectStatement) {
+                statementContext = Optional.of(subSelectContext);
+                break;
+            }
+        }
+        return statementContext;

Review Comment:
   Please rename rownumSelectContext to result.



##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java:
##########
@@ -130,6 +147,42 @@ private Map<Integer, SelectStatementContext> createSubqueryContexts(final Shardi
         return result;
     }
     
+    private Optional<SelectStatementContext> findRownumSelectStatementContext() {
+        WhereSegment where = getSqlStatement().getWhere().get();
+        Optional<OracleSelectStatement> rownumSelectStatement = Optional.empty();
+        if (where.getExpr() instanceof BinaryOperationExpression) {
+            rownumSelectStatement = findRownumSelectStatement((BinaryOperationExpression) where.getExpr(), (OracleSelectStatement) getSqlStatement());
+        }
+        Optional<SelectStatementContext> rownumSelectContext = Optional.empty();
+        if (rownumSelectStatement.isPresent()) {
+            rownumSelectContext = findContextFromSubQueryContext(subqueryContexts.values(), rownumSelectStatement.get());
+        }
+        return rownumSelectContext;

Review Comment:
   Please rename rownumSelectContext to result.



##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionsContextEngine.java:
##########
@@ -115,32 +114,37 @@ private boolean containsProjection(final OrderByItemSegment orderByItem, final C
     }
     
     private boolean isSameColumn(final Projection projection, final ColumnSegment columnSegment) {
-        Collection<ColumnProjection> columns = getColumnProjections(projection);
+        Collection<Projection> columns = expandProjection(projection);
         if (columns.isEmpty()) {
             return false;
         }
         boolean columnSegmentPresent = columnSegment.getOwner().isPresent();
-        for (ColumnProjection each : columns) {
+        for (Projection each : columns) {
             if (columnSegmentPresent ? isSameQualifiedName(each, columnSegment.getQualifiedName()) : isSameName(each, columnSegment.getQualifiedName())) {
                 return true;
             }
         }
         return false;
     }
     
-    private Collection<ColumnProjection> getColumnProjections(final Projection projection) {
-        Collection<ColumnProjection> result = new LinkedList<>();
-        if (projection instanceof ColumnProjection) {
-            result.add((ColumnProjection) projection);
-        }
+    /**
+     * expand projection, such as ShorthandProjection.

Review Comment:
   Please keep the first letter uppercase in javadoc, and add a new line between javadoc and param doc.



##########
sql-parser/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java:
##########
@@ -512,6 +515,31 @@ public ASTNode visitQueryBlock(final QueryBlockContext ctx) {
         if (null != ctx.modelClause()) {
             result.setModelSegment((ModelSegment) visit(ctx.modelClause()));
         }
+        Map<String, OracleSelectStatement> rowNumSelect = getRowNumSelect(result);
+        if (rowNumSelect.size() > 0) {
+            result.setRowNumSelect(rowNumSelect);

Review Comment:
   Can we move this logic into StatementContext for processing? The SQLVisitor should be processed according to SQL semantics, and some processing for kernel functions should be placed in StatementContext.



-- 
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


[GitHub] [shardingsphere] xinglijun1973 commented on a diff in pull request #20257: Fix Oracle pagination and sorting/grouping problem: add ‘order by’/'group by' of the subquery to its outer statement if the subquery selects oracle rownum

Posted by GitBox <gi...@apache.org>.
xinglijun1973 commented on code in PR #20257:
URL: https://github.com/apache/shardingsphere/pull/20257#discussion_r1056085782


##########
sql-parser/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/impl/OracleDMLStatementSQLVisitor.java:
##########
@@ -512,6 +515,31 @@ public ASTNode visitQueryBlock(final QueryBlockContext ctx) {
         if (null != ctx.modelClause()) {
             result.setModelSegment((ModelSegment) visit(ctx.modelClause()));
         }
+        Map<String, OracleSelectStatement> rowNumSelect = getRowNumSelect(result);
+        if (rowNumSelect.size() > 0) {
+            result.setRowNumSelect(rowNumSelect);

Review Comment:
   great! I had tried.



-- 
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