You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "ClaireLytt (via GitHub)" <gi...@apache.org> on 2026/02/05 05:46:29 UTC

[PR] Support '2'::int statement in PostgreSQL and openGauss [shardingsphere]

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

   Fixes https://github.com/apache/shardingsphere/issues/34976
   
   Changes proposed in this pull request:
     -
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [x] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [x] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [x] I have added corresponding unit tests for my changes.
   - [x] I have updated the Release Notes of the current development version. For more details, see [Update Release Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/)
   


-- 
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] Support '2'::int statement in PostgreSQL and openGauss [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on code in PR #37962:
URL: https://github.com/apache/shardingsphere/pull/37962#discussion_r2767595904


##########
parser/sql/engine/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/engine/opengauss/visitor/statement/OpenGaussStatementVisitor.java:
##########
@@ -1393,29 +1394,37 @@ public ASTNode visitSelectLimitValue(final SelectLimitValueContext ctx) {
         if (null != ctx.ALL()) {
             return null;
         }
-        ASTNode astNode = visit(ctx.cExpr());
-        if (astNode instanceof ParameterMarkerExpressionSegment) {
-            return new ParameterMarkerLimitValueSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ((ParameterMarkerExpressionSegment) astNode).getParameterMarkerIndex());
-        }
-        return new NumberLiteralLimitValueSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), Long.parseLong(((ExpressionSegment) astNode).getText()));
+        return toLimitValueSegment(ctx, (ExpressionSegment) visit(ctx.aExpr()));
     }
     
     @Override
     public ASTNode visitSelectOffsetValue(final SelectOffsetValueContext ctx) {
-        ASTNode astNode = visit(ctx.cExpr());
-        if (astNode instanceof ParameterMarkerExpressionSegment) {
-            return new ParameterMarkerLimitValueSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ((ParameterMarkerExpressionSegment) astNode).getParameterMarkerIndex());
-        }
-        return new NumberLiteralLimitValueSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), Long.parseLong(((ExpressionSegment) astNode).getText()));
+        return toLimitValueSegment(ctx, (ExpressionSegment) visit(ctx.aExpr()));
     }
     
     @Override
     public ASTNode visitSelectFetchValue(final SelectFetchValueContext ctx) {
-        ASTNode astNode = visit(ctx.cExpr());
-        if (astNode instanceof ParameterMarkerExpressionSegment) {
-            return new ParameterMarkerLimitValueSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ((ParameterMarkerExpressionSegment) astNode).getParameterMarkerIndex());
+        return toLimitValueSegment(ctx, (ExpressionSegment) visit(ctx.aExpr()));
+    }
+    
+    private LimitValueSegment toLimitValueSegment(final ParserRuleContext ctx, final ExpressionSegment segment) {
+        if (segment instanceof ParameterMarkerExpressionSegment) {
+            return new ParameterMarkerLimitValueSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(),
+                    ((ParameterMarkerExpressionSegment) segment).getParameterMarkerIndex());
+        }
+        if (segment instanceof TypeCastExpression) {
+            return toLimitValueSegment(ctx, ((TypeCastExpression) segment).getExpression());
+        }
+        if (segment instanceof LiteralExpressionSegment) {
+            Object literals = ((LiteralExpressionSegment) segment).getLiterals();
+            if (null == literals) {
+                return ctx instanceof SelectOffsetValueContext
+                        ? new NumberLiteralLimitValueSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), 0L)
+                        : null;
+            }
+            return new NumberLiteralLimitValueSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), Long.parseLong(literals.toString()));
         }
-        return new NumberLiteralLimitValueSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), Long.parseLong(((ExpressionSegment) astNode).getText()));
+        throw new SQLParsingException("Unsupported LIMIT expression: " + segment.getText());

Review Comment:
   Why add this check? openGauss does not support limit segment?



##########
parser/sql/engine/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/engine/opengauss/visitor/statement/OpenGaussStatementVisitor.java:
##########
@@ -1393,29 +1394,37 @@ public ASTNode visitSelectLimitValue(final SelectLimitValueContext ctx) {
         if (null != ctx.ALL()) {
             return null;
         }
-        ASTNode astNode = visit(ctx.cExpr());
-        if (astNode instanceof ParameterMarkerExpressionSegment) {
-            return new ParameterMarkerLimitValueSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ((ParameterMarkerExpressionSegment) astNode).getParameterMarkerIndex());
-        }
-        return new NumberLiteralLimitValueSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), Long.parseLong(((ExpressionSegment) astNode).getText()));
+        return toLimitValueSegment(ctx, (ExpressionSegment) visit(ctx.aExpr()));
     }
     
     @Override
     public ASTNode visitSelectOffsetValue(final SelectOffsetValueContext ctx) {
-        ASTNode astNode = visit(ctx.cExpr());
-        if (astNode instanceof ParameterMarkerExpressionSegment) {
-            return new ParameterMarkerLimitValueSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ((ParameterMarkerExpressionSegment) astNode).getParameterMarkerIndex());
-        }
-        return new NumberLiteralLimitValueSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), Long.parseLong(((ExpressionSegment) astNode).getText()));
+        return toLimitValueSegment(ctx, (ExpressionSegment) visit(ctx.aExpr()));
     }
     
     @Override
     public ASTNode visitSelectFetchValue(final SelectFetchValueContext ctx) {
-        ASTNode astNode = visit(ctx.cExpr());
-        if (astNode instanceof ParameterMarkerExpressionSegment) {
-            return new ParameterMarkerLimitValueSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ((ParameterMarkerExpressionSegment) astNode).getParameterMarkerIndex());
+        return toLimitValueSegment(ctx, (ExpressionSegment) visit(ctx.aExpr()));
+    }
+    
+    private LimitValueSegment toLimitValueSegment(final ParserRuleContext ctx, final ExpressionSegment segment) {

Review Comment:
   Do you think createLimitValueSegment is better?



##########
parser/sql/engine/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/engine/opengauss/visitor/statement/OpenGaussStatementVisitor.java:
##########
@@ -1393,29 +1394,37 @@ public ASTNode visitSelectLimitValue(final SelectLimitValueContext ctx) {
         if (null != ctx.ALL()) {
             return null;
         }
-        ASTNode astNode = visit(ctx.cExpr());
-        if (astNode instanceof ParameterMarkerExpressionSegment) {
-            return new ParameterMarkerLimitValueSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ((ParameterMarkerExpressionSegment) astNode).getParameterMarkerIndex());
-        }
-        return new NumberLiteralLimitValueSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), Long.parseLong(((ExpressionSegment) astNode).getText()));
+        return toLimitValueSegment(ctx, (ExpressionSegment) visit(ctx.aExpr()));

Review Comment:
   Do you think createLimitValueSegment is 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


Re: [PR] Support '2'::int statement in PostgreSQL and openGauss [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu merged PR #37962:
URL: https://github.com/apache/shardingsphere/pull/37962


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