Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-16060

[C++] subtract_checked support for timestamp("s") and date32

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • None
    • 8.0.0
    • C++

    Description

      This issue surfaced in R. Subtraction between a timestamp and a date only errors when the date is Date32 and the timestamp is expressed in seconds.

      While I understand the subtract kernel doesn't natively support operations between the various temporal types and some magic (aka implicit casting) is taking place (via DispatchBest), I think this is an unexpected behaviour. If Date32 (expressed in days) cannot be converted into seconds, then I would expect all combinations of Date32 and timestamp units to fail. I hope this makes sense.

      Reprex:

      a <- Array$create(as.Date("2022-03-25"))
      b <- Array$create(as.POSIXct("2022-03-26"))
      
      # it only errors when a is date32() and b is timestamp("s")
      a$cast(date32()) - b$cast(timestamp("s"))
      #>  Error: NotImplemented: Function 'subtract_checked' has no kernel matching input types (array[date32[day]], array[timestamp[s]])
      #> /Users/dragos/Documents/arrow/cpp/src/arrow/compute/function.cc:231 DispatchBest(&inputs) 
      
      # it works fine in all other cases
      a$cast(date32()) - b$cast(timestamp("ms"))
      #> Array
      #> <duration[ms]>
      #> [
      #>   -86400000
      #> ]
      
      a$cast(date32()) - b$cast(timestamp("us"))
      #> Array
      #> <duration[us]>
      #> [
      #>   -86400000000
      #> ]
      
      a$cast(date32()) - b$cast(timestamp("ns"))
      #> Array
      #> <duration[ns]>
      #> [
      #>   -86400000000000
      #> ]
      
      # a is date64() and b is timestamp()
      a$cast(date64()) - b$cast(timestamp("s"))
      #> Array
      #> <duration[ms]>
      #> [
      #>   -86400000
      #> ]
      
      a$cast(date64()) - b$cast(timestamp("ms"))
      #> Array
      #> <duration[ms]>
      #> [
      #>   -86400000
      #> ]
      
      a$cast(date64()) - b$cast(timestamp("us"))
      #> Array
      #> <duration[us]>
      #> [
      #>   -86400000000
      #> ]
      
      a$cast(date64()) - b$cast(timestamp("ns"))
      #> Array
      #> <duration[ns]>
      #> [
      #>   -86400000000000
      #> ]
      

      Attachments

        Issue Links

          Activity

            People

              rokm Rok Mihevc
              dragosmg Dragoș Moldovan-Grünfeld
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 20m
                  1h 20m