@@ -30,10 +30,7 @@ public void onMatch(RelOptRuleCall call) {
3030 final LogicalSort sort = call .rel (0 );
3131 final CalciteLogicalIndexScan scan = call .rel (1 );
3232
33- // The LogicalSort is a LIMIT that should be pushed down when its fetch field is not null and
34- // its collation is empty.
35- // For example: `sort name | head 5` should not be pushed down because it has a field collation.
36- if (sort .fetch != null && sort .getCollation ().getFieldCollations ().isEmpty ()) {
33+ if (isLogicalSortLimit (sort )) {
3734 Integer limitValue = extractLimitValue (sort .fetch );
3835 Integer offsetValue = extractOffsetValue (sort .offset );
3936 if (limitValue != null && offsetValue != null ) {
@@ -45,6 +42,18 @@ public void onMatch(RelOptRuleCall call) {
4542 }
4643 }
4744
45+ /**
46+ * The LogicalSort is a LIMIT that should be pushed down when its fetch field is not null and its
47+ * collation is empty. For example: <code>sort name | head 5</code> should not be pushed down
48+ * because it has a field collation.
49+ *
50+ * @param sort The LogicalSort to check.
51+ * @return True if the LogicalSort is a LIMIT that can be pushed down, false otherwise.
52+ */
53+ private static boolean isLogicalSortLimit (LogicalSort sort ) {
54+ return sort .fetch != null && sort .getCollation ().getFieldCollations ().isEmpty ();
55+ }
56+
4857 private static Integer extractLimitValue (RexNode fetch ) {
4958 if (fetch instanceof RexLiteral ) {
5059 return ((RexLiteral ) fetch ).getValueAs (Integer .class );
@@ -53,17 +62,17 @@ private static Integer extractLimitValue(RexNode fetch) {
5362 }
5463
5564 /**
56- * Extracts the offset value from the given ` RexNode` . If the offset is ` null`, it defaults to 0.
57- * For example:
65+ * Extracts the offset value from the given <code> RexNode</code> . If the offset is <code> null
66+ * </code>, it defaults to 0. For example:
5867 *
5968 * <ul>
6069 * <li><code>source=people | head 1</code> will have a <code>null</code> offset, which is
6170 * converted to 0.
6271 * <li><code>source=people | head 1 from 2</code> will have an offset of 2.
6372 * </ul>
6473 *
65- * @param offset The ` RexNode` representing the offset.
66- * @return The extracted offset value, or ` null` if it cannot be determined.
74+ * @param offset The <code> RexNode</code> representing the offset.
75+ * @return The extracted offset value, or <code> null</code> if it cannot be determined.
6776 */
6877 private static Integer extractOffsetValue (RexNode offset ) {
6978 if (Objects .isNull (offset )) {
0 commit comments