Skip to content

Commit 0c2ba70

Browse files
Backport #1586 to 1.3 branch (#1617)
Signed-off-by: Peter Fitzgibbons <[email protected]>
1 parent c2cd527 commit 0c2ba70

File tree

10 files changed

+32
-47
lines changed

10 files changed

+32
-47
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.opensearch.sql.util.MatcherUtils.verifySchema;
2323

2424
import java.io.IOException;
25+
import java.math.BigDecimal;
2526
import java.util.Arrays;
2627
import java.util.HashMap;
2728
import java.util.HashSet;
@@ -1029,7 +1030,7 @@ public void minOnNestedField() throws Exception {
10291030
TEST_INDEX_NESTED_TYPE);
10301031
JSONObject result = executeQuery(query);
10311032
JSONObject aggregation = getAggregation(result, "message.dayOfWeek@NESTED");
1032-
Assert.assertEquals(1.0, (double) aggregation.query("/minDays/value"), 0.0001);
1033+
Assert.assertEquals(1.0, ((BigDecimal) aggregation.query("/minDays/value")).doubleValue(), 0.0001);
10331034
}
10341035

10351036
@Test
@@ -1039,7 +1040,7 @@ public void sumOnNestedField() throws Exception {
10391040
TEST_INDEX_NESTED_TYPE);
10401041
JSONObject result = executeQuery(query);
10411042
JSONObject aggregation = getAggregation(result, "message.dayOfWeek@NESTED");
1042-
Assert.assertEquals(19.0, (double) aggregation.query("/sumDays/value"), 0.0001);
1043+
Assert.assertEquals(19.0, ((BigDecimal) aggregation.query("/sumDays/value")).doubleValue(), 0.0001);
10431044
}
10441045

10451046
@Test

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import static org.opensearch.sql.util.MatcherUtils.kvString;
1717

1818
import java.io.IOException;
19+
import java.math.BigDecimal;
1920
import java.util.ArrayList;
2021
import java.util.function.Function;
2122
import org.hamcrest.BaseMatcher;
@@ -316,7 +317,7 @@ public void aggregationWithoutGroupBy() throws IOException {
316317
JSONObject result = executeQuery(sql);
317318
JSONObject aggregation = getAggregation(result, "message.dayOfWeek@NESTED");
318319

319-
Assert.assertThat((Double) aggregation.query("/avgDay/value"), closeTo(3.166666666, 0.01));
320+
Assert.assertThat(((BigDecimal) aggregation.query("/avgDay/value")).doubleValue(), closeTo(3.166666666, 0.01));
320321
}
321322

322323
@Test
@@ -350,10 +351,10 @@ public void groupByRegularFieldAndSum() throws IOException {
350351
Assert.assertNotNull(msgInfoBuckets);
351352
Assert.assertThat(msgInfoBuckets.length(), equalTo(2));
352353
Assert.assertThat(msgInfoBuckets.query("/0/key"), equalTo("a"));
353-
Assert.assertThat((Double) msgInfoBuckets.query("/0/message.dayOfWeek@NESTED/sumDay/value"),
354+
Assert.assertThat(((BigDecimal) msgInfoBuckets.query("/0/message.dayOfWeek@NESTED/sumDay/value")).doubleValue(),
354355
closeTo(9.0, 0.01));
355356
Assert.assertThat(msgInfoBuckets.query("/1/key"), equalTo("b"));
356-
Assert.assertThat((Double) msgInfoBuckets.query("/1/message.dayOfWeek@NESTED/sumDay/value"),
357+
Assert.assertThat(((BigDecimal) msgInfoBuckets.query("/1/message.dayOfWeek@NESTED/sumDay/value")).doubleValue(),
357358
closeTo(10.0, 0.01));
358359
}
359360

@@ -593,12 +594,12 @@ public void maxAggOnNestedInnerFieldWithoutWhere() throws IOException {
593594
Assert.assertThat(bucket.length(), equalTo(2));
594595
Assert.assertThat(bucket.query("/0/key"), equalTo("Bob Smith"));
595596
Assert.assertThat(
596-
bucket.query("/0/projects.started_year@NESTED/projects.started_year@FILTER/max/value"),
597-
equalTo(2015.0));
597+
((BigDecimal) bucket.query("/0/projects.started_year@NESTED/projects.started_year@FILTER/max/value")).doubleValue(),
598+
closeTo(2015.0, 0.01));
598599
Assert.assertThat(bucket.query("/1/key"), equalTo("Jane Smith"));
599600
Assert.assertThat(
600-
bucket.query("/1/projects.started_year@NESTED/projects.started_year@FILTER/max/value"),
601-
equalTo(2015.0));
601+
((BigDecimal) bucket.query("/1/projects.started_year@NESTED/projects.started_year@FILTER/max/value")).doubleValue(),
602+
closeTo(2015.0, 0.01));
602603
}
603604

604605
@Test
@@ -780,12 +781,12 @@ public void havingMaxAggOnNestedInnerFieldWithoutWhere() throws IOException {
780781
Assert.assertThat(bucket.length(), equalTo(2));
781782
Assert.assertThat(bucket.query("/0/key"), equalTo("Bob Smith"));
782783
Assert.assertThat(
783-
bucket.query("/0/projects.started_year@NESTED/projects.started_year@FILTER/max_0/value"),
784-
equalTo(2015.0));
784+
((BigDecimal) bucket.query("/0/projects.started_year@NESTED/projects.started_year@FILTER/max_0/value")).doubleValue(),
785+
closeTo(2015.0, 0.01));
785786
Assert.assertThat(bucket.query("/1/key"), equalTo("Jane Smith"));
786787
Assert.assertThat(
787-
bucket.query("/1/projects.started_year@NESTED/projects.started_year@FILTER/max_0/value"),
788-
equalTo(2015.0));
788+
((BigDecimal) bucket.query("/1/projects.started_year@NESTED/projects.started_year@FILTER/max_0/value")).doubleValue(),
789+
closeTo(2015.0, 0.01));
789790
}
790791

791792
/***********************************************************

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ public void concat_ws_field_and_string() throws Exception {
501501
}
502502

503503
/**
504-
* Ignore this test case because painless doesn't whitelist String.split function.
504+
* Ignore this test case because painless doesn't allowlist String.split function.
505505
*
506506
* @see <a href="https://www.elastic.co/guide/en/elasticsearch/painless/7.0/painless-api-reference.html">https://www.elastic.co/guide/en/elasticsearch/painless/7.0/painless-api-reference.html</a>
507507
*/
@@ -517,7 +517,7 @@ public void whereConditionLeftFunctionRightVariableEqualTest() throws Exception
517517
}
518518

519519
/**
520-
* Ignore this test case because painless doesn't whitelist String.split function.
520+
* Ignore this test case because painless doesn't allowlist String.split function.
521521
*
522522
* @see <a href="https://www.elastic.co/guide/en/elasticsearch/painless/7.0/painless-api-reference.html">https://www.elastic.co/guide/en/elasticsearch/painless/7.0/painless-api-reference.html</a>
523523
*/
@@ -810,7 +810,7 @@ public void isnullWithMathExpr() throws IOException {
810810
}
811811

812812
/**
813-
* Ignore this test case because painless doesn't whitelist String.split function.
813+
* Ignore this test case because painless doesn't allowlist String.split function.
814814
*
815815
* @see <a href="https://www.elastic.co/guide/en/elasticsearch/painless/7.0/painless-api-reference.html">https://www.elastic.co/guide/en/elasticsearch/painless/7.0/painless-api-reference.html</a>
816816
*/

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package org.opensearch.sql.legacy;
88

99
import static org.hamcrest.Matchers.both;
10+
import static org.hamcrest.Matchers.closeTo;
1011
import static org.hamcrest.Matchers.equalTo;
1112
import static org.hamcrest.core.Is.is;
1213
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT;
@@ -22,6 +23,7 @@
2223

2324
import com.google.common.collect.Ordering;
2425
import java.io.IOException;
26+
import java.math.BigDecimal;
2527
import java.util.ArrayList;
2628
import java.util.List;
2729
import java.util.Locale;
@@ -345,10 +347,10 @@ public void selectFromSubqueryCountAndSum() throws IOException {
345347
TEST_INDEX_ACCOUNT));
346348

347349
assertThat(result.query("/aggregations/count/value"), equalTo(1000));
348-
assertThat(result.query("/aggregations/balance/value"), equalTo(25714837.0));
350+
assertThat(((BigDecimal) result.query("/aggregations/balance/value")).doubleValue(),
351+
closeTo(25714837.0, 0.01));
349352
}
350353

351-
@Ignore("Skip to avoid breaking test due to inconsistency in JDBC schema")
352354
@Test
353355
public void selectFromSubqueryWithoutAliasShouldPass() throws IOException {
354356
JSONObject response = executeJdbcRequest(

integ-test/src/test/java/org/opensearch/sql/util/MatcherUtils.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.google.common.base.Strings;
2323
import com.google.gson.JsonParser;
24+
import java.math.BigDecimal;
2425
import java.util.ArrayList;
2526
import java.util.Arrays;
2627
import java.util.List;
@@ -121,7 +122,7 @@ public static Matcher<JSONObject> kvString(String key, Matcher<String> matcher)
121122
}
122123

123124
public static Matcher<JSONObject> kvDouble(String key, Matcher<Double> matcher) {
124-
return featureValueOf("Json Match", matcher, actual -> (Double) actual.query(key));
125+
return featureValueOf("Json Match", matcher, actual -> ((BigDecimal) actual.query(key)).doubleValue());
125126
}
126127

127128
public static Matcher<JSONObject> kvInt(String key, Matcher<Integer> matcher) {
@@ -231,30 +232,7 @@ public void describeTo(Description description) {
231232

232233
@Override
233234
protected boolean matchesSafely(JSONArray array) {
234-
if (array.length() != expectedObjects.length) {
235-
return false;
236-
}
237-
238-
for (int i = 0; i < expectedObjects.length; i++) {
239-
Object expected = expectedObjects[i];
240-
boolean isEqual;
241-
242-
// Use similar() because JSONObject/JSONArray.equals() only check if same reference
243-
if (expected instanceof JSONObject) {
244-
isEqual = ((JSONObject) expected).similar(array.get(i));
245-
} else if (expected instanceof JSONArray) {
246-
isEqual = ((JSONArray) expected).similar(array.get(i));
247-
} else if (null == expected) {
248-
isEqual = JSONObject.NULL == array.get(i);
249-
} else {
250-
isEqual = expected.equals(array.get(i));
251-
}
252-
253-
if (!isEqual) {
254-
return false;
255-
}
256-
}
257-
return true;
235+
return array.similar(new JSONArray(expectedObjects));
258236
}
259237
};
260238
}

legacy/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ dependencies {
8989
}
9090
}
9191
implementation group: 'com.google.guava', name: 'guava', version: '31.0.1-jre'
92-
compile group: 'org.json', name: 'json', version:'20180813'
92+
compile group: 'org.json', name: 'json', version:'20230227'
9393
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.10'
9494
compile group: 'org.opensearch', name: 'opensearch', version: "${opensearch_version}"
9595
compile project(':sql')

legacy/src/main/java/org/opensearch/sql/legacy/expression/model/ExprValueFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package org.opensearch.sql.legacy.expression.model;
88

9+
import java.math.BigDecimal;
910
import java.util.ArrayList;
1011
import java.util.HashMap;
1112
import java.util.List;
@@ -61,6 +62,8 @@ public static ExprValue from(Object o) {
6162
return booleanValue((Boolean) o);
6263
} else if (o instanceof Double) {
6364
return doubleValue((Double) o);
65+
} else if (o instanceof BigDecimal) {
66+
return doubleValue(((BigDecimal) o).doubleValue());
6467
} else if (o instanceof String) {
6568
return stringValue((String) o);
6669
} else {

opensearch/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies {
3535
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: "${versions.jackson}"
3636
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${versions.jackson_databind}"
3737
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-cbor', version: "${versions.jackson}"
38-
compile group: 'org.json', name: 'json', version:'20180813'
38+
compile group: 'org.json', name: 'json', version:'20230227'
3939
compileOnly group: 'org.opensearch.client', name: 'opensearch-rest-high-level-client', version: "${opensearch_version}"
4040
compile group: 'org.opensearch', name:'opensearch-ml-client', version: '1.3.4.0-SNAPSHOT'
4141

ppl/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ dependencies {
4747
compile "org.antlr:antlr4-runtime:4.7.1"
4848
compile group: 'com.google.guava', name: 'guava', version: '31.0.1-jre'
4949
compile group: 'org.opensearch', name: 'opensearch-x-content', version: "${opensearch_version}"
50-
compile group: 'org.json', name: 'json', version: '20180813'
50+
compile group: 'org.json', name: 'json', version: '20230227'
5151
compile group: 'org.springframework', name: 'spring-context', version: "${spring_version}"
5252
compile group: 'org.springframework', name: 'spring-beans', version: "${spring_version}"
5353
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.17.1'

sql/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dependencies {
4646

4747
compile "org.antlr:antlr4-runtime:4.7.1"
4848
implementation group: 'com.google.guava', name: 'guava', version: '31.0.1-jre'
49-
compile group: 'org.json', name: 'json', version:'20180813'
49+
compile group: 'org.json', name: 'json', version:'20230227'
5050
compile group: 'org.springframework', name: 'spring-context', version: "${spring_version}"
5151
compile group: 'org.springframework', name: 'spring-beans', version: "${spring_version}"
5252
compile project(':common')

0 commit comments

Comments
 (0)