Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-4498

Timestamp timezone conversion causes a crash

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: Impala 2.8.0
    • Fix Version/s: Impala 2.8.0
    • Component/s: Backend
    • Labels:

      Description

      The following query causes a crash:

      select from_utc_timestamp(CAST("1400-01-01 05:00:00" as TIMESTAMP), "PST")
      

      from impalad.ERROR:

      terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_year> >'
        what():  Year is out of valid range: 1400..10000
      

        Issue Links

          Activity

          Hide
          dhecht Dan Hecht added a comment -

          Taras Bobrovytsky nice find. It's good to include the backtraces on any crashes. I've collected it for this one:

          #4  0x00007fdf5b9e7d91 in std::terminate () at ../../../../gcc-4.9.2/libstdc++-v3/libsupc++/eh_terminate.cc:57
          #5  0x00007fdf5b9e7fa8 in __cxxabiv1::__cxa_throw (obj=0x862e380,
              tinfo=0x4084520 <typeinfo for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_year> >>,
              dest=0x11b5f30 <boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_year> >::~clone_impl()>)
              at ../../../../gcc-4.9.2/libstdc++-v3/libsupc++/eh_throw.cc:87
          #6  0x00000000011b36d8 in boost::throw_exception<boost::gregorian::bad_year> (e=...) at /home/dhecht/toolchain/boost-1.57.0/include/boost/throw_exception.hpp:69
          #7  0x00000000011b04b4 in boost::CV::simple_exception_policy<unsigned short, (unsigned short)1400, (unsigned short)10000, boost::gregorian::bad_year>::on_error ()
              at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/constrained_value.hpp:110
          #8  0x00000000011ac8bc in boost::CV::constrained_value<boost::CV::simple_exception_policy<unsigned short, (unsigned short)1400, (unsigned short)10000, boost::gregorian::bad_year> >::assign (
              this=0x7fded1551ec0, value=1399) at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/constrained_value.hpp:69
          #9  0x00000000011aaafa in boost::CV::constrained_value<boost::CV::simple_exception_policy<unsigned short, (unsigned short)1400, (unsigned short)10000, boost::gregorian::bad_year> >::constrained_value (
              this=0x7fded1551ec0, value=1399) at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/constrained_value.hpp:48
          #10 0x00000000011a9f6c in boost::gregorian::greg_year::greg_year (this=0x7fded1551ec0, year=1399) at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/gregorian/greg_year.hpp:41
          #11 0x00000000011ad446 in boost::date_time::gregorian_calendar_base<boost::date_time::year_month_day_base<boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day>, unsigned int>::from_day_number (dayNumber=2232399) at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/gregorian_calendar.ipp:122
          #12 0x00000000011ab13f in boost::date_time::date<boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration>::year (this=0x7fded1551f80)
              at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/date.hpp:79
          #13 0x00000000018880f4 in boost::local_time::local_date_time_base<boost::posix_time::ptime, boost::date_time::time_zone_base<boost::posix_time::ptime, char> >::check_dst (d=..., td=..., tz=...)
              at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/local_time/local_date_time.hpp:203
          #14 0x0000000001887e3f in boost::local_time::local_date_time_base<boost::posix_time::ptime, boost::date_time::time_zone_base<boost::posix_time::ptime, char> >::is_dst (this=0x7fded15521f0)
              at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/local_time/local_date_time.hpp:241
          #15 0x0000000001887284 in boost::local_time::local_date_time_base<boost::posix_time::ptime, boost::date_time::time_zone_base<boost::posix_time::ptime, char> >::local_time (this=0x7fded15521f0)
              at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/local_time/local_date_time.hpp:270
          #16 0x0000000001885e03 in impala::TimestampFunctions::FromUtc (context=0x4cd1f68, ts_val=..., tz_string_val=...) at /home/dhecht/src/Impala/be/src/exprs/timestamp-functions.cc:73
          #17 0x00000000018c2656 in impala::ScalarFnCall::InterpretEval<impala_udf::TimestampVal> (this=0xa613400, context=0xa683f00, row=0x0) at /home/dhecht/src/Impala/be/src/exprs/scalar-fn-call.cc:579
          #18 0x00000000018a51ab in impala::ScalarFnCall::GetTimestampVal (this=0xa613400, context=0xa683f00, row=0x0) at /home/dhecht/src/Impala/be/src/exprs/scalar-fn-call.cc:693
          #19 0x000000000185652b in impala::ExprContext::GetValue (this=0xa683f00, e=0xa613400, row=0x0) at /home/dhecht/src/Impala/be/src/exprs/expr-context.cc:295
          #20 0x0000000001856093 in impala::ExprContext::GetValue (this=0xa683f00, row=0x0) at /home/dhecht/src/Impala/be/src/exprs/expr-context.cc:228
          #21 0x00000000013d159f in impala::Tuple::MaterializeExprs<false, false> (this=0xa6ce000, row=0x0, desc=..., materialize_expr_ctxs=0x4cd1510, pool=0x93789c8, non_null_string_values=0x0,
              total_string_lengths=0x0, num_non_null_string_values=0x7fded15528e8) at /home/dhecht/src/Impala/be/src/runtime/tuple.cc:219
          #22 0x000000000177f1b8 in impala::Tuple::MaterializeExprs<false, false> (this=0xa6ce000, row=0x0, desc=..., materialize_expr_ctxs=std::vector of length 1, capacity 1 = {...}, pool=0x93789c8,
              non_null_string_values=0x0, total_string_lengths=0x0) at /home/dhecht/src/Impala/be/src/runtime/tuple.h:151
          #23 0x0000000001782543 in impala::UnionNode::MaterializeExprs (this=0x9126300, exprs=std::vector of length 1, capacity 1 = {...}, row=0x0, tuple_buf=0xa6ce000 "", dst_batch=0x93789a0)
              at /home/dhecht/src/Impala/be/src/exec/union-node.cc:201
          #24 0x00000000017818ea in impala::UnionNode::GetNext (this=0x9126300, state=0x912d600, row_batch=0x93789a0, eos=0x7fded1552edf) at /home/dhecht/src/Impala/be/src/exec/union-node.cc:179
          #25 0x00000000019ba81c in impala::PlanFragmentExecutor::ExecInternal (this=0x8609098) at /home/dhecht/src/Impala/be/src/runtime/plan-fragment-executor.cc:362
          #26 0x00000000019ba510 in impala::PlanFragmentExecutor::Exec (this=0x8609098) at /home/dhecht/src/Impala/be/src/runtime/plan-fragment-executor.cc:337
          #27 0x0000000001512cda in impala::FragmentMgr::FragmentExecState::Exec (this=0x8608d00) at /home/dhecht/src/Impala/be/src/service/fragment-exec-state.cc:59
          #28 0x000000000150a440 in impala::FragmentMgr::FragmentThread (this=0x930a600, fragment_instance_id=...) at /home/dhecht/src/Impala/be/src/service/fragment-mgr.cc:86
          #29 0x000000000150e1c2 in boost::_mfi::mf1<void, impala::FragmentMgr, impala::TUniqueId>::operator() (this=0x9ce7680, p=0x930a600, a1=...)
              at /home/dhecht/toolchain/boost-1.57.0/include/boost/bind/mem_fn_template.hpp:165
          #30 0x000000000150df7f in boost::_bi::list2<boost::_bi::value<impala::FragmentMgr*>, boost::_bi::value<impala::TUniqueId> >::operator()<boost::_mfi::mf1<void, impala::FragmentMgr, impala::TUniqueId>, boost::_bi::list0> (this=0x9ce7690, f=..., a=...) at /home/dhecht/toolchain/boost-1.57.0/include/boost/bind/bind.hpp:313
          #31 0x000000000150d8a9 in boost::_bi::bind_t<void, boost::_mfi::mf1<void, impala::FragmentMgr, impala::TUniqueId>, boost::_bi::list2<boost::_bi::value<impala::FragmentMgr*>, boost::_bi::value<impala::TUniqueId> > >::operator() (this=0x9ce7680) at /home/dhecht/toolchain/boost-1.57.0/include/boost/bind/bind_template.hpp:20
          #32 0x000000000150d23c in boost::detail::function::void_function_obj_invoker0<boost::_bi::bind_t<void, boost::_mfi::mf1<void, impala::FragmentMgr, impala::TUniqueId>, boost::_bi::list2<boost::_bi::value<i
          
          Show
          dhecht Dan Hecht added a comment - Taras Bobrovytsky nice find. It's good to include the backtraces on any crashes. I've collected it for this one: #4 0x00007fdf5b9e7d91 in std::terminate () at ../../../../gcc-4.9.2/libstdc++-v3/libsupc++/eh_terminate.cc:57 #5 0x00007fdf5b9e7fa8 in __cxxabiv1::__cxa_throw (obj=0x862e380, tinfo=0x4084520 <typeinfo for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_year> >>, dest=0x11b5f30 <boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_year> >::~clone_impl()>) at ../../../../gcc-4.9.2/libstdc++-v3/libsupc++/eh_throw.cc:87 #6 0x00000000011b36d8 in boost::throw_exception<boost::gregorian::bad_year> (e=...) at /home/dhecht/toolchain/boost-1.57.0/include/boost/throw_exception.hpp:69 #7 0x00000000011b04b4 in boost::CV::simple_exception_policy<unsigned short , (unsigned short )1400, (unsigned short )10000, boost::gregorian::bad_year>::on_error () at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/constrained_value.hpp:110 #8 0x00000000011ac8bc in boost::CV::constrained_value<boost::CV::simple_exception_policy<unsigned short , (unsigned short )1400, (unsigned short )10000, boost::gregorian::bad_year> >::assign ( this =0x7fded1551ec0, value=1399) at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/constrained_value.hpp:69 #9 0x00000000011aaafa in boost::CV::constrained_value<boost::CV::simple_exception_policy<unsigned short , (unsigned short )1400, (unsigned short )10000, boost::gregorian::bad_year> >::constrained_value ( this =0x7fded1551ec0, value=1399) at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/constrained_value.hpp:48 #10 0x00000000011a9f6c in boost::gregorian::greg_year::greg_year ( this =0x7fded1551ec0, year=1399) at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/gregorian/greg_year.hpp:41 #11 0x00000000011ad446 in boost::date_time::gregorian_calendar_base<boost::date_time::year_month_day_base<boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day>, unsigned int >::from_day_number (dayNumber=2232399) at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/gregorian_calendar.ipp:122 #12 0x00000000011ab13f in boost::date_time::date<boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration>::year ( this =0x7fded1551f80) at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/date.hpp:79 #13 0x00000000018880f4 in boost::local_time::local_date_time_base<boost::posix_time::ptime, boost::date_time::time_zone_base<boost::posix_time::ptime, char > >::check_dst (d=..., td=..., tz=...) at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/local_time/local_date_time.hpp:203 #14 0x0000000001887e3f in boost::local_time::local_date_time_base<boost::posix_time::ptime, boost::date_time::time_zone_base<boost::posix_time::ptime, char > >::is_dst ( this =0x7fded15521f0) at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/local_time/local_date_time.hpp:241 #15 0x0000000001887284 in boost::local_time::local_date_time_base<boost::posix_time::ptime, boost::date_time::time_zone_base<boost::posix_time::ptime, char > >::local_time ( this =0x7fded15521f0) at /home/dhecht/toolchain/boost-1.57.0/include/boost/date_time/local_time/local_date_time.hpp:270 #16 0x0000000001885e03 in impala::TimestampFunctions::FromUtc (context=0x4cd1f68, ts_val=..., tz_string_val=...) at /home/dhecht/src/Impala/be/src/exprs/timestamp-functions.cc:73 #17 0x00000000018c2656 in impala::ScalarFnCall::InterpretEval<impala_udf::TimestampVal> ( this =0xa613400, context=0xa683f00, row=0x0) at /home/dhecht/src/Impala/be/src/exprs/scalar-fn-call.cc:579 #18 0x00000000018a51ab in impala::ScalarFnCall::GetTimestampVal ( this =0xa613400, context=0xa683f00, row=0x0) at /home/dhecht/src/Impala/be/src/exprs/scalar-fn-call.cc:693 #19 0x000000000185652b in impala::ExprContext::GetValue ( this =0xa683f00, e=0xa613400, row=0x0) at /home/dhecht/src/Impala/be/src/exprs/expr-context.cc:295 #20 0x0000000001856093 in impala::ExprContext::GetValue ( this =0xa683f00, row=0x0) at /home/dhecht/src/Impala/be/src/exprs/expr-context.cc:228 #21 0x00000000013d159f in impala::Tuple::MaterializeExprs< false , false > ( this =0xa6ce000, row=0x0, desc=..., materialize_expr_ctxs=0x4cd1510, pool=0x93789c8, non_null_string_values=0x0, total_string_lengths=0x0, num_non_null_string_values=0x7fded15528e8) at /home/dhecht/src/Impala/be/src/runtime/tuple.cc:219 #22 0x000000000177f1b8 in impala::Tuple::MaterializeExprs< false , false > ( this =0xa6ce000, row=0x0, desc=..., materialize_expr_ctxs=std::vector of length 1, capacity 1 = {...}, pool=0x93789c8, non_null_string_values=0x0, total_string_lengths=0x0) at /home/dhecht/src/Impala/be/src/runtime/tuple.h:151 #23 0x0000000001782543 in impala::UnionNode::MaterializeExprs ( this =0x9126300, exprs=std::vector of length 1, capacity 1 = {...}, row=0x0, tuple_buf=0xa6ce000 "", dst_batch=0x93789a0) at /home/dhecht/src/Impala/be/src/exec/union-node.cc:201 #24 0x00000000017818ea in impala::UnionNode::GetNext ( this =0x9126300, state=0x912d600, row_batch=0x93789a0, eos=0x7fded1552edf) at /home/dhecht/src/Impala/be/src/exec/union-node.cc:179 #25 0x00000000019ba81c in impala::PlanFragmentExecutor::ExecInternal ( this =0x8609098) at /home/dhecht/src/Impala/be/src/runtime/plan-fragment-executor.cc:362 #26 0x00000000019ba510 in impala::PlanFragmentExecutor::Exec ( this =0x8609098) at /home/dhecht/src/Impala/be/src/runtime/plan-fragment-executor.cc:337 #27 0x0000000001512cda in impala::FragmentMgr::FragmentExecState::Exec ( this =0x8608d00) at /home/dhecht/src/Impala/be/src/service/fragment-exec-state.cc:59 #28 0x000000000150a440 in impala::FragmentMgr::FragmentThread ( this =0x930a600, fragment_instance_id=...) at /home/dhecht/src/Impala/be/src/service/fragment-mgr.cc:86 #29 0x000000000150e1c2 in boost::_mfi::mf1<void, impala::FragmentMgr, impala::TUniqueId>:: operator () ( this =0x9ce7680, p=0x930a600, a1=...) at /home/dhecht/toolchain/boost-1.57.0/include/boost/bind/mem_fn_template.hpp:165 #30 0x000000000150df7f in boost::_bi::list2<boost::_bi::value<impala::FragmentMgr*>, boost::_bi::value<impala::TUniqueId> >:: operator ()<boost::_mfi::mf1<void, impala::FragmentMgr, impala::TUniqueId>, boost::_bi::list0> ( this =0x9ce7690, f=..., a=...) at /home/dhecht/toolchain/boost-1.57.0/include/boost/bind/bind.hpp:313 #31 0x000000000150d8a9 in boost::_bi::bind_t<void, boost::_mfi::mf1<void, impala::FragmentMgr, impala::TUniqueId>, boost::_bi::list2<boost::_bi::value<impala::FragmentMgr*>, boost::_bi::value<impala::TUniqueId> > >:: operator () ( this =0x9ce7680) at /home/dhecht/toolchain/boost-1.57.0/include/boost/bind/bind_template.hpp:20 #32 0x000000000150d23c in boost::detail::function::void_function_obj_invoker0<boost::_bi::bind_t<void, boost::_mfi::mf1<void, impala::FragmentMgr, impala::TUniqueId>, boost::_bi::list2<boost::_bi::value<i
          Hide
          tarasbob Taras Bobrovytsky added a comment -

          The following queries cause a similar crash as well:

          select to_utc_timestamp(CAST("1400-01-01 05:00:00" as TIMESTAMP), "JST")
          

          Surprisingly, this query doesn't cause a crash, but returns an invalid date (year 10,000):

          select from_utc_timestamp(CAST("9999-12-31 21:00:00" as TIMESTAMP), "JST")
          

          It might be a good idea to investigate if other timestamp functions might cause a crash if the result of the function is outside the valid year range 1400..9999.

          Show
          tarasbob Taras Bobrovytsky added a comment - The following queries cause a similar crash as well: select to_utc_timestamp(CAST( "1400-01-01 05:00:00" as TIMESTAMP), "JST" ) Surprisingly, this query doesn't cause a crash, but returns an invalid date (year 10,000): select from_utc_timestamp(CAST( "9999-12-31 21:00:00" as TIMESTAMP), "JST" ) It might be a good idea to investigate if other timestamp functions might cause a crash if the result of the function is outside the valid year range 1400..9999.
          Hide
          dhecht Dan Hecht added a comment -

          I suspect the various add interval ones will crash too. Those do have 'try' blocks, but they are in the IR where exceptions won't work.

          Show
          dhecht Dan Hecht added a comment - I suspect the various add interval ones will crash too. Those do have 'try' blocks, but they are in the IR where exceptions won't work.
          Hide
          srus Silvius Rus added a comment -

          Michael Brown, would it make sense to add these patterns to the query generator?

          Show
          srus Silvius Rus added a comment - Michael Brown , would it make sense to add these patterns to the query generator?
          Hide
          tarmstrong Tim Armstrong added a comment -

          I'm discovering that's some quirkiness with the boost APIs - there are ways of constructing out-of-range time/date objects that throw an exception as soon as you start to do something non-trivial to them. In some cases, e.g. Taras' last example, these leak out of the function that created them.

          Show
          tarmstrong Tim Armstrong added a comment - I'm discovering that's some quirkiness with the boost APIs - there are ways of constructing out-of-range time/date objects that throw an exception as soon as you start to do something non-trivial to them. In some cases, e.g. Taras' last example, these leak out of the function that created them.
          Hide
          tarmstrong Tim Armstrong added a comment -

          The issue with year 10000 that Taras ran into is a separate issue: IMPALA-4549

          Show
          tarmstrong Tim Armstrong added a comment - The issue with year 10000 that Taras ran into is a separate issue: IMPALA-4549
          Hide
          tarmstrong Tim Armstrong added a comment -

          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

          Show
          tarmstrong Tim Armstrong added a comment - 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

            People

            • Assignee:
              tarmstrong Tim Armstrong
              Reporter:
              tarasbob Taras Bobrovytsky
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development