Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-31790

cast scenarios may generate different results between Hive and Spark

    XMLWordPrintableJSON

Details

    • Documentation
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.4.5
    • 3.0.0
    • Documentation
    • None

    Description

      `CAST(n,TIMESTAMPTYPE)` If n is Byte/Short/Int/Long data type, Hive treat n as milliseconds unit , while Spark SQL as seconds unit. so the cast result is different,please be care when you use it.

      For example:

      In spark
      spark-sql> select cast(1586318188000 as timestamp);
      52238-06-04 13:06:400.0
      spark-sql> select cast(1586318188 as timestamp);
      2020-04-08 11:56:28
      
      In Hive
      hive> select cast(1586318188000 as timestamp);
      2020-04-08 11:56:28
      
      hive> select cast(1586318188 as timestamp);
      1970-01-19 16:38:38.188

       

      Attachments

        Activity

          People

            小郭飞飞刀 philipse
            小郭飞飞刀 philipse
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: