This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new af835879c74 handle byte[] pagination parameters in 
PaginationContext(#34289) (#38057)
af835879c74 is described below

commit af835879c74e5c189bc3d32091c564820aff15c1
Author: aMetric <[email protected]>
AuthorDate: Tue Feb 17 16:54:51 2026 +0800

    handle byte[] pagination parameters in PaginationContext(#34289) (#38057)
    
    * handle byte[] pagination parameters in PaginationContext(#34289)
    
    * Apply spotless code format
---
 .../segment/select/pagination/PaginationContext.java   | 13 ++++++++++++-
 .../select/pagination/PaginationContextTest.java       | 15 +++++++++++++++
 .../statement/type/dml/SelectStatementContextTest.java | 18 ++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git 
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/PaginationContext.java
 
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/PaginationContext.java
index d269e8a849a..7d304870cc3 100644
--- 
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/PaginationContext.java
+++ 
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/PaginationContext.java
@@ -31,6 +31,7 @@ import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.paginatio
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.LimitValueSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.rownum.ExpressionRowNumberValueSegment;
 
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Optional;
 
@@ -64,7 +65,7 @@ public final class PaginationContext {
             if (null == obj) {
                 return null;
             }
-            return obj instanceof Long ? (long) obj : (int) obj;
+            return getLongValue(obj);
         }
         if (paginationValueSegment instanceof ExpressionRowNumberValueSegment) 
{
             return ((ExpressionRowNumberValueSegment) 
paginationValueSegment).getValue(params);
@@ -76,6 +77,16 @@ public final class PaginationContext {
         return ((NumberLiteralPaginationValueSegment) 
paginationValueSegment).getValue();
     }
     
+    private Long getLongValue(final Object value) {
+        if (value instanceof Number) {
+            return ((Number) value).longValue();
+        }
+        if (value instanceof byte[]) {
+            return Long.parseLong(new String((byte[]) value, 
StandardCharsets.UTF_8));
+        }
+        return Long.parseLong(value.toString());
+    }
+    
     private Long getValueFromExpression(final ExpressionSegment 
expressionSegment, final List<Object> params) {
         if (expressionSegment instanceof BinaryOperationExpression) {
             return 
getValueFromBinaryOperationExpression((BinaryOperationExpression) 
expressionSegment, params);
diff --git 
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/PaginationContextTest.java
 
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/PaginationContextTest.java
index c2b8ab74a6e..dfe45a71215 100644
--- 
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/PaginationContextTest.java
+++ 
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/PaginationContextTest.java
@@ -34,6 +34,7 @@ import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.paginatio
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
 import org.junit.jupiter.api.Test;
 
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -77,6 +78,11 @@ class PaginationContextTest {
                 getRowCountSegmentWithNumberLiteralPaginationValueSegment(), 
getParameters()).getActualOffset(), is(30L));
     }
     
+    @Test
+    void assertGetActualOffsetWithByteArrayParameters() {
+        assertThat(new PaginationContext(getOffsetSegment(), 
getRowCountSegment(), getByteArrayParameters()).getActualOffset(), is(30L));
+    }
+    
     @Test
     void assertGetActualOffsetWithNullOffsetSegment() {
         assertThat(new PaginationContext(null, getRowCountSegment(), 
getParameters()).getActualOffset(), is(0L));
@@ -93,6 +99,11 @@ class PaginationContextTest {
                 getRowCountSegmentWithNumberLiteralPaginationValueSegment(), 
getParameters()).getActualRowCount().orElse(null), is(20L));
     }
     
+    @Test
+    void assertGetActualRowCountWithByteArrayParameters() {
+        assertThat(new PaginationContext(getOffsetSegment(), 
getRowCountSegment(), 
getByteArrayParameters()).getActualRowCount().orElse(null), is(20L));
+    }
+    
     @Test
     void assertGetActualRowCountWithNullRowCountSegment() {
         assertNull(new PaginationContext(getOffsetSegment(), null, 
getParameters()).getActualRowCount().orElse(null));
@@ -128,6 +139,10 @@ class PaginationContextTest {
         return Arrays.asList(30, 20);
     }
     
+    private List<Object> getByteArrayParameters() {
+        return Arrays.asList("30".getBytes(StandardCharsets.UTF_8), 
"20".getBytes(StandardCharsets.UTF_8));
+    }
+    
     @Test
     void assertGetRevisedOffset() {
         assertThat(new PaginationContext(getOffsetSegment(), 
getRowCountSegment(), getParameters()).getRevisedOffset(), is(0L));
diff --git 
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementContextTest.java
 
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementContextTest.java
index 5d721496747..7090b8ed92f 100644
--- 
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementContextTest.java
+++ 
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementContextTest.java
@@ -67,6 +67,7 @@ import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.paginatio
 import 
org.apache.shardingsphere.infra.binder.context.segment.select.pagination.PaginationContext;
 import org.junit.jupiter.api.Test;
 
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Optional;
@@ -364,6 +365,23 @@ class SelectStatementContextTest {
         assertThat(paginationContext.getActualRowCount(), is(Optional.of(5L)));
     }
     
+    @Test
+    void 
assertBindParametersPopulatePaginationContextWithByteArrayParameters() {
+        SelectStatement selectStatement = new SelectStatement(databaseType);
+        selectStatement.setProjections(new ProjectionsSegment(0, 0));
+        LimitSegment limitSegment = new LimitSegment(0, 0,
+                new ParameterMarkerLimitValueSegment(0, 0, 0), new 
NumberLiteralLimitValueSegment(1, 1, 5L));
+        selectStatement.setLimit(limitSegment);
+        SelectStatementContext selectStatementContext = 
createSelectStatementContext(selectStatement);
+        
selectStatementContext.bindParameters(Collections.singletonList("7".getBytes(StandardCharsets.UTF_8)));
+        PaginationContext paginationContext = 
selectStatementContext.getPaginationContext();
+        assertTrue(paginationContext.getOffsetParameterIndex().isPresent());
+        assertThat(paginationContext.getOffsetParameterIndex().get(), is(0));
+        assertThat(paginationContext.getActualOffset(), is(7L));
+        assertFalse(paginationContext.getRowCountParameterIndex().isPresent());
+        assertThat(paginationContext.getActualRowCount(), is(Optional.of(5L)));
+    }
+    
     private ShardingSphereMetaData createShardingSphereMetaData(final 
ShardingSphereDatabase database) {
         return new ShardingSphereMetaData(Collections.singleton(database), 
mock(ResourceMetaData.class), mock(RuleMetaData.class), 
mock(ConfigurationProperties.class));
     }

Reply via email to