IMPALA-4498: crash in to_utc_timestamp/from_utc_timestamp

The bugs was that the functions did not check whether the conversion
pushed the value out of range. The fix is to use boost's validation
immediately to check the validity of the timestamp and catch any
exceptions thrown.

It would be preferable to avoid the exceptions, but Boost does not
provide a straightforward way to disable the exceptions or extract
potentially-invalid values from a date object.

Testing:
Added expression tests that exercise out-of-range cases. Also
added additional tests to confirm that date addition and subtraction
weren't affected by similar bugs.

Change-Id: Idc427b06ac33ec874a05cb98d01c00e970d3dde6
Reviewed-on: http://gerrit.cloudera.org:8080/5251
Reviewed-by: Tim Armstrong <tarmstrong@cloudera.com>
Tested-by: Impala Public Jenkins
This commit is contained in:
Tim Armstrong
2016-11-28 15:29:37 -08:00
committed by Impala Public Jenkins
parent 730ac1bae1
commit 1495b2007d
3 changed files with 147 additions and 19 deletions

View File

@@ -2574,3 +2574,51 @@ where (cast(a.string_col as string) > 'a');
---- TYPES
INT
====
---- QUERY
# Test from_utc_timestamp() returning out-of-range result.
select from_utc_timestamp(CAST("1400-01-01 05:00:00" as TIMESTAMP), "PST")
from alltypes
limit 1
---- RESULTS
NULL
---- TYPES
TIMESTAMP
---- ERRORS
UDF WARNING: Timestamp '1400-01-01 05:00:00' did not convert to a valid local time in timezone 'PST'
====
---- QUERY
# Test from_utc_timestamp() returning out-of-range result.
select to_utc_timestamp(CAST("1400-01-01 05:00:00" as TIMESTAMP), "JST")
from alltypes
limit 1
---- RESULTS
NULL
---- TYPES
TIMESTAMP
---- ERRORS
UDF WARNING: Timestamp '1400-01-01 05:00:00' in timezone 'JST' could not be converted to UTC
====
---- QUERY
# Test out-of-range value handling when adding dates.
select CAST('9999-12-31 21:00:00' AS TIMESTAMP) + INTERVAL 367 DAYS
from alltypes
limit 1
---- RESULTS
NULL
---- TYPES
TIMESTAMP
---- ERRORS
UDF WARNING: Cannot add interval 367: Year is out of valid range: 1400..10000
====
---- QUERY
# Test out-of-range value handling when subtracting dates.
select CAST('1400-01-01 21:00:00' AS TIMESTAMP) - INTERVAL 1 DAYS
from alltypes
limit 1
---- RESULTS
NULL
---- TYPES
TIMESTAMP
---- ERRORS
UDF WARNING: Cannot subtract interval 1: Year is out of valid range: 1400..10000
====