From eb81e6ed0128fc0be9b3765f434f02edd1bc9de9 Mon Sep 17 00:00:00 2001 From: "cai.zhang" Date: Wed, 3 Dec 2025 23:27:11 +0800 Subject: [PATCH] fix: Fix setting default value for geometry by restful (#46058) issue: #46056 Signed-off-by: Cai Zhang --- internal/distributed/proxy/httpserver/utils.go | 12 ++++++++++++ internal/proxy/validate_util.go | 10 ++-------- internal/rootcoord/create_collection_task.go | 10 +--------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/internal/distributed/proxy/httpserver/utils.go b/internal/distributed/proxy/httpserver/utils.go index e34e220912..342ca824ed 100644 --- a/internal/distributed/proxy/httpserver/utils.go +++ b/internal/distributed/proxy/httpserver/utils.go @@ -1725,6 +1725,18 @@ func convertDefaultValue(value interface{}, dataType schemapb.DataType) (*schema } return data, nil + case schemapb.DataType_Geometry: + v, ok := value.(string) + if !ok { + return nil, merr.WrapErrParameterInvalidMsg(`cannot use "%v"(type: %T) as geometry default value`, value, value) + } + data := &schemapb.ValueField{ + Data: &schemapb.ValueField_StringData{ + StringData: v, + }, + } + return data, nil + case schemapb.DataType_String, schemapb.DataType_VarChar: v, ok := value.(string) if !ok { diff --git a/internal/proxy/validate_util.go b/internal/proxy/validate_util.go index e52e8c548f..ada82f1d83 100644 --- a/internal/proxy/validate_util.go +++ b/internal/proxy/validate_util.go @@ -7,7 +7,6 @@ import ( "github.com/samber/lo" "github.com/twpayne/go-geom/encoding/wkb" - "github.com/twpayne/go-geom/encoding/wkbcommon" "github.com/twpayne/go-geom/encoding/wkt" "go.uber.org/zap" @@ -848,16 +847,11 @@ func (v *validateUtil) checkGeometryFieldData(field *schemapb.FieldData, fieldSc msg := fmt.Sprintf("geometry field '%v' is illegal, array type mismatch", field.GetFieldName()) return merr.WrapErrParameterInvalid("need geometry array", "got nil", msg) } - + var err error for index, wktdata := range geometryArray { // ignore parsed geom, the check is during insert task pre execute,so geo data became wkb // fmt.Println(strings.Trim(string(wktdata), "\"")) - geomT, err := wkt.Unmarshal(wktdata) - if err != nil { - log.Warn("insert invalid Geometry data!! The wkt data has errors", zap.Error(err)) - return merr.WrapErrIoFailedReason(err.Error()) - } - wkbArray[index], err = wkb.Marshal(geomT, wkb.NDR, wkbcommon.WKBOptionEmptyPointHandling(wkbcommon.EmptyPointHandlingNaN)) + wkbArray[index], err = common.ConvertWKTToWKB(wktdata) if err != nil { log.Warn("insert invalid Geometry data!! Transform to wkb failed, has errors", zap.Error(err)) return merr.WrapErrIoFailedReason(err.Error()) diff --git a/internal/rootcoord/create_collection_task.go b/internal/rootcoord/create_collection_task.go index abe8a7f9ae..b7d7abe74f 100644 --- a/internal/rootcoord/create_collection_task.go +++ b/internal/rootcoord/create_collection_task.go @@ -22,8 +22,6 @@ import ( "strconv" "github.com/cockroachdb/errors" - "github.com/twpayne/go-geom/encoding/wkb" - "github.com/twpayne/go-geom/encoding/wkt" "go.uber.org/zap" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -140,13 +138,7 @@ func (t *createCollectionTask) checkMaxCollectionsPerDB(ctx context.Context, db2 } func checkGeometryDefaultValue(value string) error { - geomT, err := wkt.Unmarshal(value) - if err != nil { - log.Warn("invalid default value for geometry field", zap.Error(err)) - return merr.WrapErrParameterInvalidMsg("invalid default value for geometry field") - } - _, err = wkb.Marshal(geomT, wkb.NDR) - if err != nil { + if _, err := common.ConvertWKTToWKB(value); err != nil { log.Warn("invalid default value for geometry field", zap.Error(err)) return merr.WrapErrParameterInvalidMsg("invalid default value for geometry field") }