From b161aec95e38bad2a843e8697d658e1a058e3a3d Mon Sep 17 00:00:00 2001 From: groot Date: Tue, 13 Sep 2022 13:36:29 +0800 Subject: [PATCH] Support input empty string (#19111) (#19144) Signed-off-by: yhmo Signed-off-by: yhmo Signed-off-by: yhmo --- internal/storage/payload.go | 5 +---- internal/storage/payload_cgo_test.go | 2 +- internal/storage/payload_test.go | 2 +- tests/python_client/testcases/test_insert.py | 17 ----------------- 4 files changed, 3 insertions(+), 23 deletions(-) diff --git a/internal/storage/payload.go b/internal/storage/payload.go index 542f1bac22..f1066d5e47 100644 --- a/internal/storage/payload.go +++ b/internal/storage/payload.go @@ -280,14 +280,11 @@ func (w *PayloadWriter) AddDoubleToPayload(msgs []float64) error { func (w *PayloadWriter) AddOneStringToPayload(msg string) error { length := len(msg) - if length == 0 { - return errors.New("can't add empty string into payload") - } - cmsg := C.CString(msg) clength := C.int(length) defer C.free(unsafe.Pointer(cmsg)) + // the C.AddOneStringToPayload can handle empty string status := C.AddOneStringToPayload(w.payloadWriterPtr, cmsg, clength) return HandleCStatus(&status, "AddOneStringToPayload failed") } diff --git a/internal/storage/payload_cgo_test.go b/internal/storage/payload_cgo_test.go index 5b43818bc1..85e8837ee2 100644 --- a/internal/storage/payload_cgo_test.go +++ b/internal/storage/payload_cgo_test.go @@ -567,7 +567,7 @@ func TestPayload_CGO_ReaderandWriter(t *testing.T) { assert.NotNil(t, err) err = w.AddOneStringToPayload("") - assert.NotNil(t, err) + assert.Nil(t, err) err = w.FinishPayloadWriter() assert.Nil(t, err) err = w.AddOneStringToPayload("c") diff --git a/internal/storage/payload_test.go b/internal/storage/payload_test.go index d88866154d..d013e3b992 100644 --- a/internal/storage/payload_test.go +++ b/internal/storage/payload_test.go @@ -567,7 +567,7 @@ func TestPayload_ReaderAndWriter(t *testing.T) { assert.NotNil(t, err) err = w.AddOneStringToPayload("") - assert.NotNil(t, err) + assert.Nil(t, err) err = w.FinishPayloadWriter() assert.Nil(t, err) err = w.AddOneStringToPayload("c") diff --git a/tests/python_client/testcases/test_insert.py b/tests/python_client/testcases/test_insert.py index 564e40ea90..e5b171f6ef 100644 --- a/tests/python_client/testcases/test_insert.py +++ b/tests/python_client/testcases/test_insert.py @@ -1202,23 +1202,6 @@ class TestInsertString(TestcaseBase): error = {ct.err_code: 0, ct.err_msg: 'Data type is not support.'} collection_w.insert(data=df, check_task=CheckTasks.err_res, check_items=error) - @pytest.mark.tags(CaseLabel.L1) - @pytest.mark.skip(reason="https://github.com/milvus-io/milvus/issues/18872, need to fix") - def test_insert_string_field_empty(self): - """ - target: test create collection with string field - method: 1.create a collection - 2.Insert string field with empty data - expected: raise an error - """ - c_name = cf.gen_unique_str(prefix) - collection_w = self.init_collection_wrap(name=c_name) - nb = 1000 - data = cf.gen_default_list_data(nb) - data[2] = [""for _ in range(nb)] - collection_w.insert(data) - assert collection_w.num_entities == nb - @pytest.mark.tags(CaseLabel.L1) def test_insert_string_field_space(self): """