Skip to content

Commit 0736444

Browse files
committed
Fix ITs that are affected by allowing implicit coercion from number to string (1915/2055)
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 6286e90 commit 0736444

3 files changed

Lines changed: 29 additions & 34 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalcitePPLBasicIT.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.junit.jupiter.api.Test;
1818
import org.opensearch.client.Request;
1919
import org.opensearch.client.ResponseException;
20-
import org.opensearch.sql.exception.SemanticCheckException;
2120
import org.opensearch.sql.ppl.PPLIntegTestCase;
2221

2322
public class CalcitePPLBasicIT extends PPLIntegTestCase {
@@ -454,17 +453,28 @@ public void testBetweenWithDifferentTypes2() throws IOException {
454453
verifyDataRows(actual, rows("Hattie", 36), rows("Elinor", 36));
455454
}
456455

456+
@Test
457+
public void testBetweenWithMixedTypes() throws IOException {
458+
JSONObject actual =
459+
executeQuery(
460+
String.format(
461+
"source=%s | where age between '35' and 38 | fields firstname, age",
462+
TEST_INDEX_BANK));
463+
verifyDataRows(actual, rows("Hattie", 36), rows("Elinor", 36));
464+
}
465+
457466
@Test
458467
public void testBetweenWithIncompatibleTypes() {
468+
// Plan: CAST(NUMBER_TO_STRING(38.5:DECIMAL(3, 1))):INTEGER)
459469
Throwable e =
460470
assertThrowsWithReplace(
461-
SemanticCheckException.class,
471+
NumberFormatException.class,
462472
() ->
463473
executeQuery(
464474
String.format(
465475
"source=%s | where age between '35' and 38.5 | fields firstname, age",
466476
TEST_INDEX_BANK)));
467-
verifyErrorMessageContains(e, "BETWEEN expression types are incompatible");
477+
verifyErrorMessageContains(e, "For input string: \\\"38.5\\\"");
468478
}
469479

470480
@Test

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteWhereCommandIT.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55

66
package org.opensearch.sql.calcite.remote;
77

8+
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT;
9+
import static org.opensearch.sql.util.MatcherUtils.rows;
10+
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;
11+
12+
import java.io.IOException;
13+
import org.json.JSONObject;
14+
import org.junit.jupiter.api.Test;
815
import org.opensearch.sql.ppl.WhereCommandIT;
916

1017
public class CalciteWhereCommandIT extends WhereCommandIT {
@@ -14,9 +21,14 @@ public void init() throws Exception {
1421
enableCalcite();
1522
}
1623

17-
@Override
18-
protected String getIncompatibleTypeErrMsg() {
19-
return "In expression types are incompatible: fields type LONG, values type [INTEGER, INTEGER,"
20-
+ " STRING]";
24+
@Test
25+
public void testInWithMixedType() throws IOException {
26+
// Mixed type coercion only work with Calcite enabled
27+
JSONObject result =
28+
executeQuery(
29+
String.format(
30+
"source=%s | where balance in (4180, 5686, '6077') | fields firstname",
31+
TEST_INDEX_ACCOUNT));
32+
verifyDataRows(result, rows("Hattie"), rows("Dale"), rows("Hughes"));
2133
}
2234
}

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package org.opensearch.sql.ppl;
77

8-
import static org.hamcrest.CoreMatchers.containsString;
98
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT;
109
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK_WITH_NULL_VALUES;
1110
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATE_TIME;
@@ -15,11 +14,8 @@
1514
import static org.opensearch.sql.util.MatcherUtils.verifySchema;
1615

1716
import java.io.IOException;
18-
import java.util.stream.Collectors;
19-
import org.hamcrest.MatcherAssert;
2017
import org.json.JSONObject;
2118
import org.junit.jupiter.api.Test;
22-
import org.opensearch.sql.data.type.ExprCoreType;
2319

2420
public class WhereCommandIT extends PPLIntegTestCase {
2521

@@ -242,29 +238,6 @@ public void testWhereWithNotIn() throws IOException {
242238
verifyDataRows(result, rows("Amber"), rows("Dale"));
243239
}
244240

245-
@Test
246-
public void testInWithIncompatibleType() {
247-
Exception e =
248-
assertThrows(
249-
Exception.class,
250-
() -> {
251-
executeQuery(
252-
String.format(
253-
"source=%s | where balance in (4180, 5686, '6077') | fields firstname",
254-
TEST_INDEX_ACCOUNT));
255-
});
256-
MatcherAssert.assertThat(e.getMessage(), containsString(getIncompatibleTypeErrMsg()));
257-
}
258-
259-
protected String getIncompatibleTypeErrMsg() {
260-
return String.format(
261-
"function expected %s, but got %s",
262-
ExprCoreType.coreTypes().stream()
263-
.map(type -> String.format("[%s,%s]", type.typeName(), type.typeName()))
264-
.collect(Collectors.joining(",", "{", "}")),
265-
"[LONG,STRING]");
266-
}
267-
268241
@Test
269242
public void testFilterScriptPushDown() throws IOException {
270243
JSONObject actual =

0 commit comments

Comments
 (0)