Skip to content

Commit 3e08047

Browse files
Decimal literal should convert to double in pushdown (opensearch-project#3811) (opensearch-project#3813)
* Decimal literal should convert to double in pushdown * fix In expression * fix style --------- (cherry picked from commit e32c945) Signed-off-by: Lantao Jin <ltjin@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 5175d78 commit 3e08047

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

  • integ-test/src/yamlRestTest/resources/rest-api-spec/test/issues
  • opensearch/src/main/java/org/opensearch/sql/opensearch/request
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
setup:
2+
- do:
3+
query.settings:
4+
body:
5+
transient:
6+
plugins.calcite.enabled : true
7+
plugins.calcite.fallback.allowed : false
8+
9+
---
10+
teardown:
11+
- do:
12+
query.settings:
13+
body:
14+
transient:
15+
plugins.calcite.enabled : false
16+
plugins.calcite.fallback.allowed : true
17+
18+
---
19+
"Decimal literal should convert to double in pushdown":
20+
- skip:
21+
features:
22+
- headers
23+
- do:
24+
bulk:
25+
index: test
26+
refresh: true
27+
body:
28+
- '{"index": {}}'
29+
- '{"balance": 1000}'
30+
- do:
31+
headers:
32+
Content-Type: 'application/json'
33+
ppl:
34+
body:
35+
query: 'source=test | where balance >= 1000.0 | stats avg(balance)'
36+
- match: {"total": 1}
37+
- match: {"schema": [{"name": "avg(balance)", "type": "double"}]}
38+
- match: {"datarows": [[1000.0]]}
39+
40+
- do:
41+
headers:
42+
Content-Type: 'application/json'
43+
ppl:
44+
body:
45+
query: 'source=test | where balance in (999.0, 1000.0) | stats avg(balance)'
46+
- match: {"total": 1}
47+
- match: {"schema": [{"name": "avg(balance)", "type": "double"}]}
48+
- match: {"datarows": [[1000.0]]}

opensearch/src/main/java/org/opensearch/sql/opensearch/request/PredicateAnalyzer.java

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

4141
import com.google.common.base.Throwables;
4242
import com.google.common.collect.Range;
43+
import java.math.BigDecimal;
4344
import java.util.ArrayList;
4445
import java.util.Collection;
4546
import java.util.GregorianCalendar;
@@ -1065,7 +1066,7 @@ Object value() {
10651066
return sargValue();
10661067
} else if (isIntegral()) {
10671068
return longValue();
1068-
} else if (isFloatingPoint()) {
1069+
} else if (isFractional()) {
10691070
return doubleValue();
10701071
} else if (isBoolean()) {
10711072
return booleanValue();
@@ -1080,8 +1081,8 @@ boolean isIntegral() {
10801081
return SqlTypeName.INT_TYPES.contains(literal.getType().getSqlTypeName());
10811082
}
10821083

1083-
boolean isFloatingPoint() {
1084-
return SqlTypeName.APPROX_TYPES.contains(literal.getType().getSqlTypeName());
1084+
boolean isFractional() {
1085+
return SqlTypeName.FRACTIONAL_TYPES.contains(literal.getType().getSqlTypeName());
10851086
}
10861087

10871088
boolean isBoolean() {
@@ -1132,6 +1133,8 @@ Object sargPointValue(Object point, SqlTypeName sqlTypeName) {
11321133
case CHAR:
11331134
case VARCHAR:
11341135
return ((NlsString) point).getValue();
1136+
case DECIMAL:
1137+
return ((BigDecimal) point).doubleValue();
11351138
default:
11361139
return point;
11371140
}

0 commit comments

Comments
 (0)