Skip to content

Commit 75d3fe2

Browse files
committed
change IT logic
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent a3a0525 commit 75d3fe2

2 files changed

Lines changed: 41 additions & 12 deletions

File tree

core/src/main/java/org/opensearch/sql/ast/expression/SearchComparison.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public String toQueryString() {
7070
@Override
7171
public Function toDSLFunction() {
7272
String fieldName = QueryStringUtils.escapeFieldName(field.getField().toString());
73-
String valueStr = value.toQueryString();
73+
String valueStr = value.getLiteral().toString();
7474
if (operator == EQUALS
7575
&& !(valueStr.contains("*")
7676
|| valueStr.contains("?"))) { // for regex case, we cannot use match

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

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,16 @@ public void testWildcardEscaping() throws IOException {
519519
// lucene escaping -> \\\\
520520
// rest request escaping -> \\\\\\\\
521521
// java string escaping ->\\\\\\\\
522+
String targetString = "\\\"C:\\\\\\\\\\\\\\\\Users\\\\\\\\\\\\\\\\admin\\\"";
523+
if (isCalciteEnabled() && !isPushdownDisabled()) {
524+
targetString = "\\\"C:\\\\\\\\Users\\\\\\\\admin\\\"";
525+
}
522526
JSONObject backslashSearch =
523527
executeQuery(
524528
String.format(
525529
"search source=%s"
526-
+ " `attributes.error.type`=\\\"C:\\\\\\\\\\\\\\\\Users\\\\\\\\\\\\\\\\admin\\\""
530+
+ " `attributes.error.type`="
531+
+ targetString
527532
+ " | sort time | fields attributes.error.type",
528533
TEST_INDEX_OTEL_LOGS));
529534
verifyDataRows(backslashSearch, rows("C:\\Users\\admin"));
@@ -712,20 +717,44 @@ public void testSearchWithUpperCaseValue() throws IOException {
712717

713718
@Test
714719
public void testSearchWithInvalidFieldName() throws IOException {
715-
JSONObject result =
716-
executeQuery(
717-
String.format(
718-
"search source=%s nonexistent_field=\\\"value\\\"", TEST_INDEX_OTEL_LOGS));
719-
verifyDataRows(result);
720+
if (!isPushdownDisabled() && isCalciteEnabled()) {
721+
Throwable error =
722+
assertThrows(
723+
Exception.class,
724+
() ->
725+
executeQuery(
726+
String.format(
727+
"search source=%s nonexistent_field=\\\"value\\\"",
728+
TEST_INDEX_OTEL_LOGS)));
729+
assertTrue(error.getMessage().contains("Field [nonexistent_field] not found."));
730+
} else {
731+
JSONObject result =
732+
executeQuery(
733+
String.format(
734+
"search source=%s nonexistent_field=\\\"value\\\"", TEST_INDEX_OTEL_LOGS));
735+
verifyDataRows(result);
736+
}
720737
}
721738

722739
@Test
723740
public void testSearchWithTypeMismatch() throws IOException {
724-
JSONObject result =
725-
executeQuery(
726-
String.format(
727-
"search source=%s severityNumber=\\\"not-a-number\\\"", TEST_INDEX_OTEL_LOGS));
728-
verifyDataRows(result);
741+
if (!isPushdownDisabled() && isCalciteEnabled()) {
742+
Throwable error =
743+
assertThrows(
744+
Exception.class,
745+
() ->
746+
executeQuery(
747+
String.format(
748+
"search source=%s severityNumber=\\\"not-a-number\\\"",
749+
TEST_INDEX_OTEL_LOGS)));
750+
assertTrue(error.getMessage().contains("NumberFormatException"));
751+
} else {
752+
JSONObject result =
753+
executeQuery(
754+
String.format(
755+
"search source=%s severityNumber=\\\"not-a-number\\\"", TEST_INDEX_OTEL_LOGS));
756+
verifyDataRows(result);
757+
}
729758
}
730759

731760
@Test

0 commit comments

Comments
 (0)