diff --git a/internal/distributed/proxy/httpserver/utils.go b/internal/distributed/proxy/httpserver/utils.go index bb44c20e06..8dcde030ee 100644 --- a/internal/distributed/proxy/httpserver/utils.go +++ b/internal/distributed/proxy/httpserver/utils.go @@ -1594,6 +1594,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 1ee77b3cf1..14553c30b1 100644 --- a/internal/proxy/validate_util.go +++ b/internal/proxy/validate_util.go @@ -6,7 +6,6 @@ import ( "reflect" "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" @@ -715,16 +714,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 56b5a2a639..147befe87e 100644 --- a/internal/rootcoord/create_collection_task.go +++ b/internal/rootcoord/create_collection_task.go @@ -23,8 +23,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" "google.golang.org/protobuf/proto" @@ -156,13 +154,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") }