diff --git a/client/ingest_api_batch.go b/client/ingest_api_batch.go index 5599b35e6..2f6d35d5e 100644 --- a/client/ingest_api_batch.go +++ b/client/ingest_api_batch.go @@ -50,7 +50,6 @@ func (b *ingestAPIBatch) Add(row Row) error { for i, val := range row.Values { field := b.fields[i] // val can be string, uint64, int64, []string, []uint64, nil - // TODO how are null values handled by ingest API? cc @seebs. seems like not well... just don't include a key if null // TODO timestamp field might need special handling // TODO check that the Row.Clears field is only used for packed bools, and then issue a warning/error (in IDK) if the ingest API mode is used in conjunction w/ packed bools. if val == nil { @@ -94,7 +93,6 @@ func (b *ingestAPIBatch) Add(row Row) error { } func (b *ingestAPIBatch) Import() error { - // TODO if b.keyed { return b.importKeyed() } diff --git a/client/ingest_api_batch_test.go b/client/ingest_api_batch_test.go index 899fef469..df94ae33d 100644 --- a/client/ingest_api_batch_test.go +++ b/client/ingest_api_batch_test.go @@ -1,6 +1,7 @@ package client import ( + "strings" "testing" "time" @@ -94,22 +95,39 @@ func TestIngestAPIBatchAdd(t *testing.T) { Values: []interface{}{uint64(2), "bkey", "ckey"}, Time: qt, }) - if err != nil { - t.Fatalf("adding row to batch: %v", err) + + checkResult := func(batch *ingestAPIBatch, id string, err error) { + if err != nil { + t.Fatalf("adding row to batch: %v", err) + } + + if batch.recordsK[id]["a"] != uint64(2) { + t.Fatalf("unexpected batch.records: %+v", batch.recordsK) + } + if batch.recordsK[id]["b"] != "bkey" { + t.Fatalf("unexpected batch.records: %+v", batch.recordsK) + } + if batch.recordsK[id]["c"].(map[string]interface{})["time"] != "2007-01-01T15:00:00Z" { + t.Fatalf("unexpected batch.records: %+v", batch.recordsK) + } + if batch.recordsK[id]["c"].(map[string]interface{})["values"] != "ckey" { + t.Fatalf("unexpected batch.records: %+v", batch.recordsK) + } + } + checkResult(batch, "1", err) + + // test wrong type row ID + if err := batch.Add(Row{ID: 64.5}); !strings.Contains(err.Error(), "unsupported rowID") { + t.Fatalf("unexpected error w/ floating point rowID: %v", err) } - if batch.recordsK["1"]["a"] != uint64(2) { - t.Fatalf("unexpected batch.records: %+v", batch.recordsK) - } - if batch.recordsK["1"]["b"] != "bkey" { - t.Fatalf("unexpected batch.records: %+v", batch.recordsK) - } - if batch.recordsK["1"]["c"].(map[string]interface{})["time"] != "2007-01-01T15:00:00Z" { - t.Fatalf("unexpected batch.records: %+v", batch.recordsK) - } - if batch.recordsK["1"]["c"].(map[string]interface{})["values"] != "ckey" { - t.Fatalf("unexpected batch.records: %+v", batch.recordsK) - } + // test that byte slice ID works same as string + err = batch.Add(Row{ + ID: []byte("2"), + Values: []interface{}{uint64(2), "bkey", "ckey"}, + Time: qt, + }) + checkResult(batch, "2", err) }) } @@ -229,6 +247,15 @@ func TestIngestAPIBatch(t *testing.T) { t.Fatalf("adding row: %v", err) } + // test nil value case + if err := batch.Add(Row{ + ID: uint64(8), + Values: []interface{}{nil, nil, nil, nil, nil, nil, nil}, + Time: QuantizedTime{}, + }); err != nil { + t.Fatalf("error adding all nil batch which should affect nothing: %v", err) + } + if err := batch.Import(); err != nil { t.Fatalf("importing row: %v", err) }