@@ -411,16 +411,26 @@ public void testFilterWithSearchCall() throws IOException {
411411
412412 @ Test
413413 public void testExplainWithReverse () throws IOException {
414- String result =
415- executeWithReplace (
416- "explain source=opensearch-sql_test_index_account | sort age | reverse | head 5" );
414+ String query = "source=opensearch-sql_test_index_account | reverse | head 5" ;
415+ var result = explainQueryToString (query );
416+ String expected = loadExpectedPlan ("explain_reverse_fallback.json" );
417+ assertJsonEqualsIgnoreId (expected , result );
418+ }
417419
418- // Verify that the plan contains a LogicalSort with fetch (from head 5)
419- assertTrue (result .contains ("LogicalSort" ) && result .contains ("fetch=[5]" ));
420+ @ Test
421+ public void testExplainWithReversePushdown () throws IOException {
422+ String query = "source=opensearch-sql_test_index_account | sort - age | reverse" ;
423+ var result = explainQueryToString (query );
424+ String expected = loadExpectedPlan ("explain_reverse_pushdown_single.json" );
425+ assertJsonEqualsIgnoreId (expected , result );
426+ }
420427
421- // Verify that reverse added a ROW_NUMBER and another sort (descending)
422- assertTrue (result .contains ("ROW_NUMBER()" ));
423- assertTrue (result .contains ("dir0=[DESC]" ));
428+ @ Test
429+ public void testExplainWithReversePushdownMultipleFields () throws IOException {
430+ String query = "source=opensearch-sql_test_index_account | sort - age, + firstname | reverse" ;
431+ var result = explainQueryToString (query );
432+ String expected = loadExpectedPlan ("explain_reverse_pushdown_multiple.json" );
433+ assertJsonEqualsIgnoreId (expected , result );
424434 }
425435
426436 @ Test
0 commit comments