From ccd2e7ea63f3fc4fce667844bc3a702f78cf3a7e Mon Sep 17 00:00:00 2001 From: Pranitha-malae <56414132+Pranitha-malae@users.noreply.github.com> Date: Thu, 20 Oct 2022 16:51:21 -0500 Subject: [PATCH] resolving bool null field ingestion error (#2254) * resolving bool null field ingestion error * testing issues * adding null support for bools * updating the null bool field ingestion * trying to resolve issue when ingesting null value for bool type * adding a clearing support for bool type * resolving issues with bool null value ingestion * updating the jwt go package version and removing changes made in docker compose file * reverting jwt go version * removing v4 of jwt * adding a comment in test file to see if sonar cloud accepts this file --- client/batch.go | 1 - idk/ingest.go | 27 +++++++++++++++++++++------ idk/ingest_test.go | 16 +++++++++++++++- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/client/batch.go b/client/batch.go index 8e5943189..0bbff77e5 100644 --- a/client/batch.go +++ b/client/batch.go @@ -668,7 +668,6 @@ func (b *Batch) Add(rec Row) error { } b.rowIDs[i][len(b.rowIDs[i])-1] = clearSentinel } - default: return errors.Errorf("Clearing a value '%v' Type %[1]T is not currently supported (field '%s')", val, field.Name()) } diff --git a/idk/ingest.go b/idk/ingest.go index 58ad6600b..76e00d1c0 100644 --- a/idk/ingest.go +++ b/idk/ingest.go @@ -1539,6 +1539,16 @@ func (m *Main) batchFromSchema(schema []Field) ([]Recordizer, pilosaclient.Recor } return errors.Wrapf(err, "converting field %d:%+v, val:%+v", i, idkField, rawRec[i]) }) + case BoolField: + recordizers = append(recordizers, func(rawRec []interface{}, rec *pilosaclient.Row) (err error) { + switch rawRec[i].(type) { + case DeleteSentinel: + rec.Values[valIdx] = nil + default: + rec.Values[valIdx], err = idkField.PilosafyVal(rawRec[i]) + } + return errors.Wrapf(err, "converting field %d:%+v, val:%+v", i, idkField, rawRec[i]) + }) default: recordizers = append(recordizers, func(rawRec []interface{}, rec *pilosaclient.Row) (err error) { rec.Values[valIdx], err = idkField.PilosafyVal(rawRec[i]) @@ -1605,12 +1615,17 @@ func (m *Main) batchFromSchema(schema []Field) ([]Recordizer, pilosaclient.Recor fields = append(fields, m.index.Field(fld.DestName(), pilosaclient.OptFieldTypeBool())) valIdx := len(fields) - 1 recordizers = append(recordizers, func(rawRec []interface{}, rec *pilosaclient.Row) (err error) { - val, err := idkField.PilosafyVal(rawRec[i]) - if err != nil { - return errors.Wrapf(err, "booling '%v' of %[1]T", val) - } - if b, ok := val.(bool); ok { - rec.Values[valIdx] = b + switch rawRec[i].(type) { + case DeleteSentinel: + rec.Values[valIdx] = nil + default: + val, err := idkField.PilosafyVal(rawRec[i]) + if err != nil { + return errors.Wrapf(err, "booling '%v' of %[1]T", val) + } + if b, ok := val.(bool); ok { + rec.Values[valIdx] = b + } } return errors.Wrapf(err, "converting field %d:%+v, val:%+v", i, idkField, rawRec[i]) }) diff --git a/idk/ingest_test.go b/idk/ingest_test.go index 942d9499f..63cd78553 100644 --- a/idk/ingest_test.go +++ b/idk/ingest_test.go @@ -1648,6 +1648,20 @@ func TestBoolIngest(t *testing.T) { expFalse: nil, expNull: []string{"a1"}, }, + { + src: newTestSource( + []Field{ + StringField{NameVal: "user_id"}, + BoolField{NameVal: "bool_val"}, + }, + [][]interface{}{ + {"a1", DELETE_SENTINEL}, + }, + ), + expTrue: nil, + expFalse: nil, + expNull: []string{"a1"}, + }, } var ing *Main @@ -1696,7 +1710,7 @@ func TestBoolIngest(t *testing.T) { assert.Equal(t, test.expFalse, resp.Result().Row().Keys) } - // Check null. + // Check nil. This is used to test the ingestion of nil and null. { resp, err := client.Query(idx.Difference(idx.All(), idx.Union(fld.Row(true), fld.Row(false)))) assert.NoError(t, err)