handle insert into timequantum fields with default 'now' time (fb-1868) (#2398)

* handle insert into timequantum fields with default 'now' time

* allocate on the stack

(cherry picked from commit 18fe6a35f6)
This commit is contained in:
pokeeffe-molecula 2023-01-06 16:58:37 -06:00 committed by Joe Friedrich
parent 3b233d271d
commit 5e151eed0e

View file

@ -168,6 +168,9 @@ func (i *insertRowIter) Next(ctx context.Context) (types.Row, error) {
return nil, errors.Wrap(err, "setting up batch")
}
var qbatchTime fbbatch.QuantizedTime
qbatchTime.Set(time.Now().UTC())
// row is the single instance of batch.Row allocated. It is re-used
// throughout the for loop to minimize memory allocation.
var row fbbatch.Row
@ -249,6 +252,22 @@ func (i *insertRowIter) Next(ctx context.Context) (types.Row, error) {
row.Values[posVals[idx]] = eval
}
case pilosa.FieldTypeTime:
row.Time = qbatchTime
switch v := eval.(type) {
case []int64:
uint64s := make([]uint64, len(v))
for i := range v {
if v[i] < 0 {
return nil, sql3.NewErrInternalf("converting negative slice value to uint64: %d", v[i])
}
uint64s[i] = uint64(v[i])
}
row.Values[posVals[idx]] = uint64s
default:
row.Values[posVals[idx]] = eval
}
case pilosa.FieldTypeInt:
if eval != nil {
v, ok := eval.(int64)