|  | 
| 24 | 24 | 
 | 
| 25 | 25 | import static org.elasticsearch.xpack.ql.expression.predicate.operator.arithmetic.Arithmetics.mod; | 
| 26 | 26 | import static org.elasticsearch.xpack.ql.tree.Source.EMPTY; | 
|  | 27 | +import static org.elasticsearch.xpack.ql.util.NumericUtils.UNSIGNED_LONG_MAX; | 
| 27 | 28 | import static org.elasticsearch.xpack.sql.type.SqlDataTypes.INTERVAL_DAY; | 
| 28 | 29 | import static org.elasticsearch.xpack.sql.type.SqlDataTypes.INTERVAL_DAY_TO_HOUR; | 
| 29 | 30 | import static org.elasticsearch.xpack.sql.type.SqlDataTypes.INTERVAL_HOUR; | 
| @@ -243,6 +244,36 @@ public void testMulNullInterval() { | 
| 243 | 244 |         assertEquals(INTERVAL_MONTH, result.dataType()); | 
| 244 | 245 |     } | 
| 245 | 246 | 
 | 
|  | 247 | +    public void testMulIntegerIntervalYearMonthOverflow() { | 
|  | 248 | +        Literal l = interval(Period.ofYears(1).plusMonths(11), INTERVAL_YEAR); | 
|  | 249 | +        ArithmeticException expect = expectThrows(ArithmeticException.class, () -> mul(l, L(Integer.MAX_VALUE))); | 
|  | 250 | +        assertEquals("integer overflow", expect.getMessage()); | 
|  | 251 | +    } | 
|  | 252 | + | 
|  | 253 | +    public void testMulLongIntervalYearMonthOverflow() { | 
|  | 254 | +        Literal l = interval(Period.ofYears(1), INTERVAL_YEAR); | 
|  | 255 | +        QlIllegalArgumentException expect = expectThrows(QlIllegalArgumentException.class, () -> mul(l, L(Long.MAX_VALUE))); | 
|  | 256 | +        assertEquals("[9223372036854775807] out of [integer] range", expect.getMessage()); | 
|  | 257 | +    } | 
|  | 258 | + | 
|  | 259 | +    public void testMulUnsignedLongIntervalYearMonthOverflow() { | 
|  | 260 | +        Literal l = interval(Period.ofYears(1), INTERVAL_YEAR); | 
|  | 261 | +        QlIllegalArgumentException expect = expectThrows(QlIllegalArgumentException.class, () -> mul(l, L(UNSIGNED_LONG_MAX))); | 
|  | 262 | +        assertEquals("[18446744073709551615] out of [long] range", expect.getMessage()); | 
|  | 263 | +    } | 
|  | 264 | + | 
|  | 265 | +    public void testMulLongIntervalDayTimeOverflow() { | 
|  | 266 | +        Literal l = interval(Duration.ofDays(1), INTERVAL_DAY); | 
|  | 267 | +        ArithmeticException expect = expectThrows(ArithmeticException.class, () -> mul(l, L(Long.MAX_VALUE))); | 
|  | 268 | +        assertEquals("Exceeds capacity of Duration: 796899343984252629724800000000000", expect.getMessage()); | 
|  | 269 | +    } | 
|  | 270 | + | 
|  | 271 | +    public void testMulUnsignedLongIntervalDayTimeOverflow() { | 
|  | 272 | +        Literal l = interval(Duration.ofDays(1), INTERVAL_DAY); | 
|  | 273 | +        QlIllegalArgumentException expect = expectThrows(QlIllegalArgumentException.class, () -> mul(l, L(UNSIGNED_LONG_MAX))); | 
|  | 274 | +        assertEquals("[18446744073709551615] out of [long] range", expect.getMessage()); | 
|  | 275 | +    } | 
|  | 276 | + | 
| 246 | 277 |     public void testAddNullInterval() { | 
| 247 | 278 |         Literal literal = interval(Period.ofMonths(1), INTERVAL_MONTH); | 
| 248 | 279 |         Add result = new Add(EMPTY, L(null), literal); | 
|  | 
0 commit comments