Skip to content

Commit

Permalink
fix(arrow/compute): fix scenario where prealloc output is missed
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroshade committed Oct 22, 2024
1 parent c124ae4 commit 37602e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions arrow/compute/cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,13 @@ func (c *CastSuite) checkCastZeroCopy(from arrow.DataType, json string, to arrow
checkCastZeroCopy(c.T(), arr, to, compute.NewCastOptions(to, true))
}

func (c *CastSuite) TestTimestampToTimestampSimpleTimezone() {
c.checkCast(&arrow.TimestampType{Unit: arrow.Microsecond, TimeZone: "Etc/UTC"},
arrow.FixedWidthTypes.Timestamp_us,
`["2023-01-01T19:25:00.123456+00:00", null, "2023-01-01T19:25:00.123456+00:00"]`,
`["2023-01-01T19:25:00.123456+00:00", null, "2023-01-01T19:25:00.123456+00:00"]`)
}

func (c *CastSuite) TestTimestampToTimestamp() {
tests := []struct {
coarse, fine arrow.DataType
Expand Down
13 changes: 8 additions & 5 deletions arrow/compute/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,7 @@ func (s *scalarExecutor) executeSpans(data chan<- Datum) (err error) {

if s.preallocContiguous {
// make one big output alloc
prealloc := s.prepareOutput(int(s.iterLen))
output = *prealloc
output := s.prepareOutput(int(s.iterLen))

output.Offset = 0
var resultOffset int64
Expand All @@ -598,15 +597,19 @@ func (s *scalarExecutor) executeSpans(data chan<- Datum) (err error) {
break
}
output.SetSlice(resultOffset, input.Len)
err = s.executeSingleSpan(&input, &output)
err = s.executeSingleSpan(&input, output)
resultOffset = nextOffset
}
if err != nil {
prealloc.Release()
output.Release()
return
}

return s.emitResult(prealloc, data)
if output.Offset != 0 {
output.SetSlice(0, s.iterLen)
}

return s.emitResult(output, data)
}

// fully preallocating, but not contiguously
Expand Down

0 comments on commit 37602e6

Please sign in to comment.