Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public static Number floatingMod(Number dividend, Number divisor) {
BigDecimal b0 = new BigDecimal(dividend.toString());
BigDecimal b1 = new BigDecimal(divisor.toString());
BigDecimal result = b0.remainder(b1);
if (dividend instanceof BigDecimal || divisor instanceof BigDecimal) {
return result;
}
return MathUtils.coerceToWidestFloatingType(dividend, divisor, result.doubleValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
setup:
- do:
query.settings:
body:
transient:
plugins.calcite.enabled : true
- do:
bulk:
index: test
refresh: true
body:
- '{"index": {}}'
- '{"id": 3.1}'

---
teardown:
- do:
query.settings:
body:
transient:
plugins.calcite.enabled : false

---
"big decimal literal":
- skip:
features:
- headers
- allowed_warnings
- do:
headers:
Content-Type: 'application/json'
ppl:
body:
query: source=test | eval a = mod(3.1, 2), b = modulus(3.1, 2.0), c = mod(id, 2.0) | fields a,b,c

- match: { total: 1 }
- match: {"datarows": [[1.1,1.1,1.1]]}
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ public void testMod() {
verifyPPLToSparkSQL(root, expectedSparkSql);
}

@Test
public void testModDecimal() {
RelNode root = getRelNode("source=EMP | eval MOD = mod(3.1, 2) | fields MOD");
String expectedLogical =
"LogicalProject(MOD=[MOD(3.1:DECIMAL(2, 1), 2)])\n"
+ " LogicalTableScan(table=[[scott, EMP]])\n";
verifyLogical(root, expectedLogical);
String expectedSparkSql = "SELECT MOD(3.1, 2) `MOD`\nFROM `scott`.`EMP`";
verifyPPLToSparkSQL(root, expectedSparkSql);
}

@Test
public void testPi() {
RelNode root = getRelNode("source=EMP | eval PI = pi() | fields PI");
Expand Down
Loading