From 5e151eed0e4d859598ba2634ffa489a71adbced7 Mon Sep 17 00:00:00 2001 From: pokeeffe-molecula <85502298+pokeeffe-molecula@users.noreply.github.com> Date: Fri, 6 Jan 2023 16:58:37 -0600 Subject: [PATCH] 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 18fe6a35f6cd1f06767b071c4337cb3cf1e54ce9) --- sql3/planner/opinsert.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sql3/planner/opinsert.go b/sql3/planner/opinsert.go index 93cdda4a4..33c20981d 100644 --- a/sql3/planner/opinsert.go +++ b/sql3/planner/opinsert.go @@ -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)