Skip to content

Commit dd8334d

Browse files
committed
Fix IT
Signed-off-by: Lantao Jin <ltjin@amazon.com>
1 parent 1edb107 commit dd8334d

5 files changed

Lines changed: 33 additions & 3 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,11 @@ public enum Index {
604604
"dog",
605605
getDogs3IndexMapping(),
606606
"src/test/resources/dogs3.json"),
607+
DOG4(
608+
TestsConstants.TEST_INDEX_DOG4,
609+
"dog",
610+
getDogIndexMapping(),
611+
"src/test/resources/dogs4.json"),
607612
DOGSSUBQUERY(
608613
TestsConstants.TEST_INDEX_DOGSUBQUERY,
609614
"dog",

integ-test/src/test/java/org/opensearch/sql/legacy/TestsConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class TestsConstants {
1919
public static final String TEST_INDEX_DOG = TEST_INDEX + "_dog";
2020
public static final String TEST_INDEX_DOG2 = TEST_INDEX + "_dog2";
2121
public static final String TEST_INDEX_DOG3 = TEST_INDEX + "_dog3";
22+
public static final String TEST_INDEX_DOG4 = TEST_INDEX + "_dog4";
2223
public static final String TEST_INDEX_DOGSUBQUERY = TEST_INDEX + "_subquery";
2324
public static final String TEST_INDEX_PEOPLE = TEST_INDEX + "_people";
2425
public static final String TEST_INDEX_PEOPLE2 = TEST_INDEX + "_people2";

integ-test/src/test/java/org/opensearch/sql/ppl/SortCommandIT.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK;
99
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK_WITH_NULL_VALUES;
1010
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG;
11+
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG4;
1112
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_WEBLOGS;
1213
import static org.opensearch.sql.util.MatcherUtils.rows;
1314
import 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
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{"index":{"_id":"1"}}
2+
{"dog_name":"M 1","holdersName":"Daenerys","age":2}
3+
{"index":{"_id":"6"}}
4+
{"dog_name":"M 2","holdersName":"Hattie","age":4}

opensearch/src/main/java/org/opensearch/sql/opensearch/storage/scan/AbstractCalciteIndexScan.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,8 @@ public AbstractCalciteIndexScan pushDownSort(List<RelFieldCollation> collations)
255255
String fieldNameKeyword;
256256
if (fieldType instanceof OpenSearchTextType textType) {
257257
fieldNameKeyword = OpenSearchTextType.toKeywordSubField(fieldName, fieldType);
258-
if (fieldName.equals(fieldNameKeyword) && !textType.isFieldData()) {
259-
// can not convert text to keyword, skip pushdown
260-
return null;
258+
if (fieldNameKeyword == null && textType.isFieldData()) {
259+
fieldNameKeyword = fieldName;
261260
}
262261
} else {
263262
fieldNameKeyword = fieldName;

0 commit comments

Comments
 (0)