Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/column/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ func FieldDataColumn(fd *schemapb.FieldData, begin, end int) (Column, error) {
case schemapb.DataType_JSON:
return parseScalarData(fd.GetFieldName(), fd.GetScalars().GetJsonData().GetData(), begin, end, validData, NewColumnJSONBytes, NewNullableColumnJSONBytes)

case schemapb.DataType_Geometry:
return parseScalarData(fd.GetFieldName(), fd.GetScalars().GetGeometryWktData().GetData(), begin, end, validData, NewColumnGeometryWKT, NewNullableColumnGeometryWKT)

case schemapb.DataType_FloatVector:
vectors := fd.GetVectors()
x, ok := vectors.GetData().(*schemapb.VectorField_FloatVector)
Expand Down
9 changes: 8 additions & 1 deletion client/column/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ func values2FieldData[T any](values []T, fieldType entity.FieldType, dim int) *s
entity.FieldTypeInt64,
entity.FieldTypeVarChar,
entity.FieldTypeString,
entity.FieldTypeJSON:
entity.FieldTypeJSON,
entity.FieldTypeGeometry:
fd.Field = &schemapb.FieldData_Scalars{
Scalars: values2Scalars(values, fieldType), // scalars,
}
Expand Down Expand Up @@ -198,6 +199,12 @@ func values2Scalars[T any](values []T, fieldType entity.FieldType) *schemapb.Sca
Data: data,
},
}
case entity.FieldTypeGeometry:
var strVals []string
strVals, ok = any(values).([]string)
scalars.Data = &schemapb.ScalarField_GeometryWktData{
GeometryWktData: &schemapb.GeometryWktArray{Data: strVals},
}
}
// shall not be accessed
if !ok {
Expand Down
91 changes: 91 additions & 0 deletions client/column/geometry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package column

import (
"github.com/cockroachdb/errors"

"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
"github.com/milvus-io/milvus/client/v2/entity"
)

type ColumnGeometryWKT struct {
*genericColumnBase[string]
}

// Name returns column name.
func (c *ColumnGeometryWKT) Name() string {
return c.name
}

// Type returns column entity.FieldType.
func (c *ColumnGeometryWKT) Type() entity.FieldType {
return entity.FieldTypeGeometry
}

// Len returns column values length.
func (c *ColumnGeometryWKT) Len() int {
return len(c.values)
}

func (c *ColumnGeometryWKT) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnGeometryWKT{
genericColumnBase: c.genericColumnBase.slice(start, end),
}
}

// Get returns value at index as interface{}.
func (c *ColumnGeometryWKT) Get(idx int) (interface{}, error) {
if idx < 0 || idx >= c.Len() {
return nil, errors.New("index out of range")
}
return c.values[idx], nil
}

func (c *ColumnGeometryWKT) GetAsString(idx int) (string, error) {
return c.ValueByIdx(idx)
}

// FieldData return column data mapped to schemapb.FieldData.
func (c *ColumnGeometryWKT) FieldData() *schemapb.FieldData {
fd := c.genericColumnBase.FieldData()
return fd
}

// ValueByIdx returns value of the provided index.
func (c *ColumnGeometryWKT) ValueByIdx(idx int) (string, error) {
if idx < 0 || idx >= c.Len() {
return "", errors.New("index out of range")
}
return c.values[idx], nil
}

// AppendValue append value into column.
func (c *ColumnGeometryWKT) AppendValue(i interface{}) error {
s, ok := i.(string)
if !ok {
return errors.New("expect geometry WKT type(string)")
}
c.values = append(c.values, s)
return nil
}

// Data returns column data.
func (c *ColumnGeometryWKT) Data() []string {
return c.values
}

func NewColumnGeometryWKT(name string, values []string) *ColumnGeometryWKT {
return &ColumnGeometryWKT{
genericColumnBase: &genericColumnBase[string]{
name: name,
fieldType: entity.FieldTypeGeometry,
values: values,
},
}
}
76 changes: 76 additions & 0 deletions client/column/geometry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package column

import (
"fmt"
"math/rand"
"testing"
"time"

"github.com/stretchr/testify/suite"

"github.com/milvus-io/milvus/client/v2/entity"
)

type ColumnGeometryWKTSuite struct {
suite.Suite
}

func (s *ColumnGeometryWKTSuite) SetupSuite() {
rand.Seed(time.Now().UnixNano())
}

func (s *ColumnGeometryWKTSuite) TestAttrMethods() {
columnName := fmt.Sprintf("column_Geometrywkt_%d", rand.Int())
columnLen := 8 + rand.Intn(10)

v := make([]string, columnLen)
column := NewColumnGeometryWKT(columnName, v)

s.Run("test_meta", func() {
ft := entity.FieldTypeGeometry
s.Equal("Geometry", ft.Name())
s.Equal("Geometry", ft.String())
pbName, pbType := ft.PbFieldType()
s.Equal("Geometry", pbName)
s.Equal("Geometry", pbType)
})

s.Run("test_column_attribute", func() {
s.Equal(columnName, column.Name())
s.Equal(entity.FieldTypeGeometry, column.Type())
s.Equal(columnLen, column.Len())
s.EqualValues(v, column.Data())
})

s.Run("test_column_field_data", func() {
fd := column.FieldData()
s.NotNil(fd)
s.Equal(fd.GetFieldName(), columnName)
})

s.Run("test_column_valuer_by_idx", func() {
_, err := column.ValueByIdx(-1)
s.Error(err)
_, err = column.ValueByIdx(columnLen)
s.Error(err)
for i := 0; i < columnLen; i++ {
v, err := column.ValueByIdx(i)
s.NoError(err)
s.Equal(column.values[i], v)
}
})

s.Run("test_append_value", func() {
item := "POINT (30.123 -10.456)"
err := column.AppendValue(item)
s.NoError(err)
s.Equal(columnLen+1, column.Len())
val, err := column.ValueByIdx(columnLen)
s.NoError(err)
s.Equal(item, val)
})
}

func TestColumnGeometryWKT(t *testing.T) {
suite.Run(t, new(ColumnGeometryWKTSuite))
}
21 changes: 11 additions & 10 deletions client/column/nullable.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ package column

var (
// scalars
NewNullableColumnBool NullableColumnCreateFunc[bool, *ColumnBool] = NewNullableColumnCreator(NewColumnBool).New
NewNullableColumnInt8 NullableColumnCreateFunc[int8, *ColumnInt8] = NewNullableColumnCreator(NewColumnInt8).New
NewNullableColumnInt16 NullableColumnCreateFunc[int16, *ColumnInt16] = NewNullableColumnCreator(NewColumnInt16).New
NewNullableColumnInt32 NullableColumnCreateFunc[int32, *ColumnInt32] = NewNullableColumnCreator(NewColumnInt32).New
NewNullableColumnInt64 NullableColumnCreateFunc[int64, *ColumnInt64] = NewNullableColumnCreator(NewColumnInt64).New
NewNullableColumnVarChar NullableColumnCreateFunc[string, *ColumnVarChar] = NewNullableColumnCreator(NewColumnVarChar).New
NewNullableColumnString NullableColumnCreateFunc[string, *ColumnString] = NewNullableColumnCreator(NewColumnString).New
NewNullableColumnFloat NullableColumnCreateFunc[float32, *ColumnFloat] = NewNullableColumnCreator(NewColumnFloat).New
NewNullableColumnDouble NullableColumnCreateFunc[float64, *ColumnDouble] = NewNullableColumnCreator(NewColumnDouble).New
NewNullableColumnJSONBytes NullableColumnCreateFunc[[]byte, *ColumnJSONBytes] = NewNullableColumnCreator(NewColumnJSONBytes).New
NewNullableColumnBool NullableColumnCreateFunc[bool, *ColumnBool] = NewNullableColumnCreator(NewColumnBool).New
NewNullableColumnInt8 NullableColumnCreateFunc[int8, *ColumnInt8] = NewNullableColumnCreator(NewColumnInt8).New
NewNullableColumnInt16 NullableColumnCreateFunc[int16, *ColumnInt16] = NewNullableColumnCreator(NewColumnInt16).New
NewNullableColumnInt32 NullableColumnCreateFunc[int32, *ColumnInt32] = NewNullableColumnCreator(NewColumnInt32).New
NewNullableColumnInt64 NullableColumnCreateFunc[int64, *ColumnInt64] = NewNullableColumnCreator(NewColumnInt64).New
NewNullableColumnVarChar NullableColumnCreateFunc[string, *ColumnVarChar] = NewNullableColumnCreator(NewColumnVarChar).New
NewNullableColumnString NullableColumnCreateFunc[string, *ColumnString] = NewNullableColumnCreator(NewColumnString).New
NewNullableColumnFloat NullableColumnCreateFunc[float32, *ColumnFloat] = NewNullableColumnCreator(NewColumnFloat).New
NewNullableColumnDouble NullableColumnCreateFunc[float64, *ColumnDouble] = NewNullableColumnCreator(NewColumnDouble).New
NewNullableColumnJSONBytes NullableColumnCreateFunc[[]byte, *ColumnJSONBytes] = NewNullableColumnCreator(NewColumnJSONBytes).New
NewNullableColumnGeometryWKT NullableColumnCreateFunc[string, *ColumnGeometryWKT] = NewNullableColumnCreator(NewColumnGeometryWKT).New
// array
NewNullableColumnBoolArray NullableColumnCreateFunc[[]bool, *ColumnBoolArray] = NewNullableColumnCreator(NewColumnBoolArray).New
NewNullableColumnInt8Array NullableColumnCreateFunc[[]int8, *ColumnInt8Array] = NewNullableColumnCreator(NewColumnInt8Array).New
Expand Down
8 changes: 8 additions & 0 deletions client/entity/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func (t FieldType) Name() string {
return "Array"
case FieldTypeJSON:
return "JSON"
case FieldTypeGeometry:
return "Geometry"
case FieldTypeBinaryVector:
return "BinaryVector"
case FieldTypeFloatVector:
Expand Down Expand Up @@ -92,6 +94,8 @@ func (t FieldType) String() string {
return "Array"
case FieldTypeJSON:
return "JSON"
case FieldTypeGeometry:
return "Geometry"
case FieldTypeBinaryVector:
return "[]byte"
case FieldTypeFloatVector:
Expand Down Expand Up @@ -128,6 +132,8 @@ func (t FieldType) PbFieldType() (string, string) {
return "VarChar", "string"
case FieldTypeJSON:
return "JSON", "JSON"
case FieldTypeGeometry:
return "Geometry", "Geometry"
case FieldTypeBinaryVector:
return "[]byte", ""
case FieldTypeFloatVector:
Expand Down Expand Up @@ -167,6 +173,8 @@ const (
FieldTypeArray FieldType = 22
// FieldTypeJSON field type JSON
FieldTypeJSON FieldType = 23
// FieldTypeGeometry field type Geometry
FieldTypeGeometry FieldType = 24
// FieldTypeBinaryVector field type binary vector
FieldTypeBinaryVector FieldType = 100
// FieldTypeFloatVector field type float vector
Expand Down
2 changes: 1 addition & 1 deletion client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/blang/semver/v4 v4.0.0
github.com/cockroachdb/errors v1.9.1
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.17
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.18-0.20250822062940-e34629021786
github.com/milvus-io/milvus/pkg/v2 v2.5.7
github.com/quasilyte/go-ruleguard/dsl v0.3.22
github.com/samber/lo v1.27.0
Expand Down
4 changes: 2 additions & 2 deletions client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfr
github.com/mediocregopher/radix/v3 v3.4.2/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8=
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.17 h1:LDOodBVtc2AYxcgc51vDwe+gJp96s6yhJLfdGbLrK+0=
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.17/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs=
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.18-0.20250822062940-e34629021786 h1:GspXs2i+sm2GE4n46VRWBjSCQjqtJDIwwcye+gFyxZA=
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.18-0.20250822062940-e34629021786/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs=
github.com/milvus-io/milvus/pkg/v2 v2.5.7 h1:b45jq1s1v03AekFucs2/dkkXohB57gEx7gspJuAkfbY=
github.com/milvus-io/milvus/pkg/v2 v2.5.7/go.mod h1:pImw1IGNS7k/5yvlZV2tZi5vZu1VQRlQij+r39d+XnI=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
Expand Down
1 change: 1 addition & 0 deletions client/index/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ const (
Sorted IndexType = "STL_SORT"
Inverted IndexType = "INVERTED"
BITMAP IndexType = "BITMAP"
RTREE IndexType = "RTREE"
)
70 changes: 70 additions & 0 deletions client/index/rtree.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Licensed to the LF AI & Data foundation under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package index

var _ Index = rtreeIndex{}

// rtreeIndex represents an RTree index for geometry fields
type rtreeIndex struct {
baseIndex
}

func (idx rtreeIndex) Params() map[string]string {
params := map[string]string{
IndexTypeKey: string(RTREE),
}
return params
}

// NewRTreeIndex creates a new RTree index with default parameters
func NewRTreeIndex() Index {
return rtreeIndex{
baseIndex: baseIndex{
indexType: RTREE,
},
}
}

// NewRTreeIndexWithParams creates a new RTree index with custom parameters
func NewRTreeIndexWithParams() Index {
return rtreeIndex{
baseIndex: baseIndex{
indexType: RTREE,
},
}
}

// RTreeIndexBuilder provides a fluent API for building RTree indexes
type RTreeIndexBuilder struct {
index rtreeIndex
}

// NewRTreeIndexBuilder creates a new RTree index builder
func NewRTreeIndexBuilder() *RTreeIndexBuilder {
return &RTreeIndexBuilder{
index: rtreeIndex{
baseIndex: baseIndex{
indexType: RTREE,
},
},
}
}

// Build returns the constructed RTree index
func (b *RTreeIndexBuilder) Build() Index {
return b.index
}
Loading
Loading