File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ public void onMatch(RelOptRuleCall call) {
3232
3333 Integer limitValue = extractLimitValue (sort .fetch );
3434 Integer offsetValue = extractOffsetValue (sort .offset );
35+ // Skip this rule if this is a reverse operation (indicated by row_number)
36+ if (hasRowNumberFunction (sort )) {
37+ return ;
38+ }
3539 if (limitValue != null && offsetValue != null ) {
3640 CalciteLogicalIndexScan newScan = scan .pushDownLimit (limitValue , offsetValue );
3741 if (newScan != null ) {
@@ -40,6 +44,18 @@ public void onMatch(RelOptRuleCall call) {
4044 }
4145 }
4246
47+ /**
48+ * Check if the LogicalSort contains a row_number function, which indicates a reverse operation.
49+ *
50+ * @param sort The LogicalSort to check
51+ * @return True if a row_number function is found, false otherwise
52+ */
53+ private boolean hasRowNumberFunction (LogicalSort sort ) {
54+ // Check if the sort has a row_number function in its digest
55+ String digest = sort .getDigest ();
56+ return digest != null && digest .contains ("row_number" );
57+ }
58+
4359 private static Integer extractLimitValue (RexNode fetch ) {
4460 // fetch is always a integer literal (specified in our PPL/SQL syntax)
4561 if (fetch instanceof RexLiteral ) {
You can’t perform that action at this time.
0 commit comments