88import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_BANK ;
99import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_BANK_WITH_NULL_VALUES ;
1010import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_DOG ;
11+ import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_DOG4 ;
1112import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_WEBLOGS ;
1213import static org .opensearch .sql .util .MatcherUtils .rows ;
1314import static org .opensearch .sql .util .MatcherUtils .verifyOrder ;
@@ -31,6 +32,7 @@ public void init() throws Exception {
3132 loadIndex (Index .BANK_WITH_NULL_VALUES );
3233 loadIndex (Index .DOG );
3334 loadIndex (Index .WEBLOG );
35+ loadIndex (Index .DOG4 );
3436 }
3537
3638 @ Test
@@ -161,4 +163,23 @@ public void testSortThenHead() throws IOException {
161163 executeQuery (String .format ("source=%s | sort age | head 2 | fields age" , TEST_INDEX_BANK ));
162164 verifyOrder (result , rows (28 ), rows (32 ));
163165 }
166+
167+ @ Test
168+ public void testSortFielddata () throws IOException {
169+ JSONObject result =
170+ executeQuery (
171+ String .format ("source=%s | sort dog_name | fields dog_name, age" , TEST_INDEX_DOG4 ));
172+ verifyOrder (result , rows ("M 1" , 2 ), rows ("M 2" , 4 ));
173+ // Even sort with DESC on dog_name, the order is no diff with ASC for fielddata field
174+ // since the field is tokenized. And the behaviour in v3 should be same with v2.
175+ // But the behaviours between pushdown enable and disable are different.
176+ result =
177+ executeQuery (
178+ String .format ("source=%s | sort - dog_name | fields dog_name, age" , TEST_INDEX_DOG4 ));
179+ if (isPushdownEnabled ()) {
180+ verifyOrder (result , rows ("M 1" , 2 ), rows ("M 2" , 4 ));
181+ } else {
182+ verifyOrder (result , rows ("M 2" , 2 ), rows ("M 1" , 4 ));
183+ }
184+ }
164185}
0 commit comments