|
@@ -24,6 +24,7 @@ import java.time.temporal.TemporalAmount;
|
|
|
|
|
|
import static org.elasticsearch.xpack.ql.expression.predicate.operator.arithmetic.Arithmetics.mod;
|
|
|
import static org.elasticsearch.xpack.ql.tree.Source.EMPTY;
|
|
|
+import static org.elasticsearch.xpack.ql.util.NumericUtils.UNSIGNED_LONG_MAX;
|
|
|
import static org.elasticsearch.xpack.sql.type.SqlDataTypes.INTERVAL_DAY;
|
|
|
import static org.elasticsearch.xpack.sql.type.SqlDataTypes.INTERVAL_DAY_TO_HOUR;
|
|
|
import static org.elasticsearch.xpack.sql.type.SqlDataTypes.INTERVAL_HOUR;
|
|
@@ -243,6 +244,36 @@ public class SqlBinaryArithmeticTests extends ESTestCase {
|
|
|
assertEquals(INTERVAL_MONTH, result.dataType());
|
|
|
}
|
|
|
|
|
|
+ public void testMulIntegerIntervalYearMonthOverflow() {
|
|
|
+ Literal l = interval(Period.ofYears(1).plusMonths(11), INTERVAL_YEAR);
|
|
|
+ ArithmeticException expect = expectThrows(ArithmeticException.class, () -> mul(l, L(Integer.MAX_VALUE)));
|
|
|
+ assertEquals("integer overflow", expect.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testMulLongIntervalYearMonthOverflow() {
|
|
|
+ Literal l = interval(Period.ofYears(1), INTERVAL_YEAR);
|
|
|
+ QlIllegalArgumentException expect = expectThrows(QlIllegalArgumentException.class, () -> mul(l, L(Long.MAX_VALUE)));
|
|
|
+ assertEquals("[9223372036854775807] out of [integer] range", expect.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testMulUnsignedLongIntervalYearMonthOverflow() {
|
|
|
+ Literal l = interval(Period.ofYears(1), INTERVAL_YEAR);
|
|
|
+ QlIllegalArgumentException expect = expectThrows(QlIllegalArgumentException.class, () -> mul(l, L(UNSIGNED_LONG_MAX)));
|
|
|
+ assertEquals("[18446744073709551615] out of [long] range", expect.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testMulLongIntervalDayTimeOverflow() {
|
|
|
+ Literal l = interval(Duration.ofDays(1), INTERVAL_DAY);
|
|
|
+ ArithmeticException expect = expectThrows(ArithmeticException.class, () -> mul(l, L(Long.MAX_VALUE)));
|
|
|
+ assertEquals("Exceeds capacity of Duration: 796899343984252629724800000000000", expect.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testMulUnsignedLongIntervalDayTimeOverflow() {
|
|
|
+ Literal l = interval(Duration.ofDays(1), INTERVAL_DAY);
|
|
|
+ QlIllegalArgumentException expect = expectThrows(QlIllegalArgumentException.class, () -> mul(l, L(UNSIGNED_LONG_MAX)));
|
|
|
+ assertEquals("[18446744073709551615] out of [long] range", expect.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
public void testAddNullInterval() {
|
|
|
Literal literal = interval(Period.ofMonths(1), INTERVAL_MONTH);
|
|
|
Add result = new Add(EMPTY, L(null), literal);
|