This is an automated email from the ASF dual-hosted git repository.
rubenql pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new ad77a20f28 [CALCITE-5377] RelFieldTrimmer support Sort with dynamic
param
ad77a20f28 is described below
commit ad77a20f286d4b25b26e940e92b40a15acb2e333
Author: xiejiajun
AuthorDate: Sun Nov 13 14:55:20 2022 +0800
[CALCITE-5377] RelFieldTrimmer support Sort with dynamic param
---
.../java/org/apache/calcite/sql2rel/RelFieldTrimmer.java| 13 +
.../java/org/apache/calcite/test/SqlToRelConverterTest.java | 9 +
.../org/apache/calcite/test/SqlToRelConverterTest.xml | 13 +
3 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
b/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
index 1862725f84..f1560b7f81 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java
@@ -48,7 +48,6 @@ import org.apache.calcite.rel.type.RelDataTypeField;
import org.apache.calcite.rel.type.RelDataTypeImpl;
import org.apache.calcite.rex.RexBuilder;
import org.apache.calcite.rex.RexCorrelVariable;
-import org.apache.calcite.rex.RexDynamicParam;
import org.apache.calcite.rex.RexFieldAccess;
import org.apache.calcite.rex.RexLiteral;
import org.apache.calcite.rex.RexNode;
@@ -666,20 +665,10 @@ public class RelFieldTrimmer implements ReflectiveVisitor
{
return result(sort, Mappings.createIdentity(fieldCount));
}
-// leave the Sort unchanged in case we have dynamic limits
-if (sort.offset instanceof RexDynamicParam
-|| sort.fetch instanceof RexDynamicParam) {
- return result(sort, inputMapping);
-}
-
relBuilder.push(newInput);
-final int offset =
-sort.offset == null ? 0 : RexLiteral.intValue(sort.offset);
-final int fetch =
-sort.fetch == null ? -1 : RexLiteral.intValue(sort.fetch);
final ImmutableList fields =
relBuilder.fields(RexUtil.apply(inputMapping, collation));
-relBuilder.sortLimit(offset, fetch, fields);
+relBuilder.sortLimit(sort.offset, sort.fetch, fields);
// The result has the same mapping as the input gave us. Sometimes we
// return fields that the consumer didn't ask for, because the filter
diff --git
a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index ad3c6cc0a5..63885e7a10 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -2598,6 +2598,15 @@ class SqlToRelConverterTest extends SqlToRelTestBase {
sql(sql).withTrim(true).ok();
}
+ /** Test case for
+ * https://issues.apache.org/jira/browse/CALCITE-5377";>[CALCITE-5377]
+ * RelFieldTrimmer support Sort with dynamic param. */
+ @Test void testDynamicParameterSortWithTrim() {
+final String sql = "select ename from "
++ "(select * from emp order by sal limit ? offset ?) a";
+sql(sql).withTrim(true).ok();
+ }
+
/** Test case for
* https://issues.apache.org/jira/browse/CALCITE-3183";>[CALCITE-3183]
* Trimming method for Filter rel uses wrong traitSet. */
diff --git
a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
index bcb6066040..eb23e84764 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -1616,6 +1616,19 @@ LogicalProject(FAKE2=[ITEM($0, 'fake_col2')])
+
+
+
+
+
+
+
+