Skip to content

Commit

Permalink
initial code for geo
Browse files Browse the repository at this point in the history
add geospatial interface in src common

change type define and add segcore support

add storage & chunkdata support

feature: go package storage & proxy & typeutil support geospatial type in internal and typeutil in pkg

Signed-off-by: tasty-gumi <1021989072@qq.com>

add geospatial interface in src common

change type define and add segcore support

change: use wkb only in core

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix:the geospatial only use std::string as FieldDataImpl template paramters && add geospatial data generation && pass chunk ,growing , sealed test

fix : merge confilcts after rebase ,test nullable not pass due to upstream

feat:basic GIS Function expr and visitor impl and GIS proto support && add:storage test of geo data

Signed-off-by: tasty-gumi <1021989072@qq.com>

feat:add proxy validate (pass httpserver test) && plan parser of geospatialfunction

fix:sealedseg && go tidy

fix:go mod

feat:can produce wkt result for pymilvus client

feat: add parser and query operator for geos filed && print geos binlog as wkt

fix:fielddataimpl interface
Signed-off-by: tasty-gumi <1021989072@qq.com>

fix: some format of code && segmentfault debug for rebase

Signed-off-by: tasty-gumi <1021989072@qq.com>

add: import util test for parquet and mix compaction test

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix: delete useless file and fix error for rebase

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix: git rebase for custom function feat

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix:rename geospatial field && update proto && rewrite Geometry class with smart pointer

Signed-off-by: tasty-gumi <1021989072@qq.com>

add:last commit miss add files

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix: geospatial name replace in test files && fix geomertry and parser

fix:remove some file change for dev

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix:remove size in if && add destory in ~Geometry()

Signed-off-by: tasty-gumi <1021989072@qq.com>

add:conan file gdal rep

Signed-off-by: tasty-gumi <1021989072@qq.com>

remove:gdal fPIC

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix: for rebase

Signed-off-by: tasty-gumi <1021989072@qq.com>

remove:log_warn

Signed-off-by: tasty-gumi <1021989072@qq.com>

remove:gdal shared

Signed-off-by: tasty-gumi <1021989072@qq.com>

remove:tbbproxy

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix:add gdal option && update go mod

Signed-off-by: tasty-gumi <1021989072@qq.com>

dev:change some scripts

Signed-off-by: tasty-gumi <1021989072@qq.com>

remove: dev scripts

Signed-off-by: tasty-gumi <1021989072@qq.com>

add:conan files dependency of gdal

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix:fmt cpp code

Signed-off-by: tasty-gumi <1021989072@qq.com>

add:delete geos-config in cmake_bulid/bin which may cause permission deny

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix: add go client geometry interface && fix group by test

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix: mod tidy for tests go client

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix:memory leak in test and go fmt

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix: datagen function remove pkoffset

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix: go-client test add entity.geometry

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix: fix test args and add some annotations

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix:name and remove wkt marshl MaxDecimalDigits limit

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix:misspell

Signed-off-by: tasty-gumi <1021989072@qq.com>

fix:go client test

Signed-off-by: tasty-gumi <1021989072@qq.com>
  • Loading branch information
tasty-gumi committed Nov 8, 2024
1 parent ebc3c82 commit 9fba036
Show file tree
Hide file tree
Showing 98 changed files with 3,866 additions and 743 deletions.
12 changes: 12 additions & 0 deletions client/column/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ func FieldDataColumn(fd *schemapb.FieldData, begin, end int) (Column, error) {
}
return NewColumnJSONBytes(fd.GetFieldName(), data.JsonData.GetData()[begin:end]).WithIsDynamic(isDynamic), nil

case schemapb.DataType_Geometry:
data, ok := fd.GetScalars().GetData().(*schemapb.ScalarField_GeometryData)
if !ok {
return nil, errFieldDataTypeNotMatch
}
if end < 0 {
return NewColumnGeometryBytes(fd.GetFieldName(), data.GeometryData.GetData()[begin:]), nil
}
return NewColumnGeometryBytes(fd.GetFieldName(), data.GeometryData.GetData()[begin:end]), nil

case schemapb.DataType_FloatVector:
vectors := fd.GetVectors()
x, ok := vectors.GetData().(*schemapb.VectorField_FloatVector)
Expand Down Expand Up @@ -524,6 +534,8 @@ func DefaultValueColumn(name string, dataType entity.FieldType) (Column, error)
return NewColumnVarChar(name, nil), nil
case entity.FieldTypeJSON:
return NewColumnJSONBytes(name, nil), nil
case entity.FieldTypeGeometry:
return NewColumnGeometryBytes(name, nil), nil

default:
return nil, fmt.Errorf("default value unsupported data type %s", dataType)
Expand Down
118 changes: 118 additions & 0 deletions client/column/geometry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package column

import (
"fmt"

"github.com/cockroachdb/errors"

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

type ColumnGeometryBytes struct {
ColumnBase
name string
values [][]byte
}

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

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

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

func (c *ColumnGeometryBytes) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnGeometryBytes{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}

// Get returns value at index as interface{}.
func (c *ColumnGeometryBytes) 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 *ColumnGeometryBytes) GetAsString(idx int) (string, error) {
bs, err := c.ValueByIdx(idx)
if err != nil {
return "", err
}
return string(bs), nil
}

// FieldData return column data mapped to schemapb.FieldData.
func (c *ColumnGeometryBytes) FieldData() *schemapb.FieldData {
fd := &schemapb.FieldData{
Type: schemapb.DataType_Geometry,
FieldName: c.name,
}

fd.Field = &schemapb.FieldData_Scalars{
Scalars: &schemapb.ScalarField{
Data: &schemapb.ScalarField_GeometryData{
GeometryData: &schemapb.GeometryArray{
Data: c.values,
},
},
},
}

return fd
}

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

// AppendValue append value into column.
func (c *ColumnGeometryBytes) AppendValue(i interface{}) error {
var v []byte
switch raw := i.(type) {
case []byte:
v = raw
case string:
v = []byte(raw)
default:
return fmt.Errorf("expect geometry compatible type([]byte, struct, map), got %T", i)
}
c.values = append(c.values, v)

return nil
}

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

func NewColumnGeometryBytes(name string, values [][]byte) *ColumnGeometryBytes {
return &ColumnGeometryBytes{
name: name,
values: values,
}
}
85 changes: 85 additions & 0 deletions client/column/geometry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package column

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

"github.com/stretchr/testify/suite"

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

type ColumnGeometryBytesSuite struct {
suite.Suite
}

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

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

v := make([][]byte, columnLen)
column := NewColumnGeometryBytes(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 := make([]byte, 10)
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)

err = column.AppendValue(&struct{ Tag string }{Tag: "abc"})
s.NoError(err)

err = column.AppendValue(map[string]interface{}{"Value": 123})
s.NoError(err)

err = column.AppendValue(1)
s.Error(err)
})
}

func TestColumnGeometryBytes(t *testing.T) {
suite.Run(t, new(ColumnGeometryBytesSuite))
}
8 changes: 8 additions & 0 deletions client/entity/field_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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 @@ -83,6 +85,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 @@ -119,6 +123,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 @@ -158,6 +164,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
4 changes: 2 additions & 2 deletions client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ 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.3.4-0.20240815123953-6dab6fcd6454
github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20241030021526-9c3238c276f7
github.com/milvus-io/milvus/pkg v0.0.2-0.20240801085213-a642a26ed4c6
github.com/quasilyte/go-ruleguard/dsl v0.3.22
github.com/samber/lo v1.27.0
github.com/stretchr/testify v1.9.0
github.com/tidwall/gjson v1.17.1
go.uber.org/atomic v1.10.0
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
)
Expand Down Expand Up @@ -109,6 +108,7 @@ require (
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.20.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,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.3.4-0.20240815123953-6dab6fcd6454 h1:JmZCYjMPpiE4ksZw0AUxXWkDY7wwA4fhS+SO1N211Vw=
github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20240815123953-6dab6fcd6454/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs=
github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20241030021526-9c3238c276f7 h1:u02klF3sJg/AaPJ8rzzuG4io4sRjf87fd1sInf93/9A=
github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20241030021526-9c3238c276f7/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs=
github.com/milvus-io/milvus/pkg v0.0.2-0.20240801085213-a642a26ed4c6 h1:dotu470D/DkctdLHsTCCmuvAD3h5C8gkFhMxb0Zlu7A=
github.com/milvus-io/milvus/pkg v0.0.2-0.20240801085213-a642a26ed4c6/go.mod h1:tdeEcpeaAcrIJgrr6LVzu7SYl9zn18dNKZwPmCUb0Io=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
Expand Down
16 changes: 16 additions & 0 deletions client/milvusclient/client_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,22 @@ func (s *MockSuiteBase) getJSONBytesFieldData(name string, data [][]byte, isDyna
}
}

func (s *MockSuiteBase) getGeometryBytesFieldData(name string, data [][]byte) *schemapb.FieldData {
return &schemapb.FieldData{
Type: schemapb.DataType_Geometry,
FieldName: name,
Field: &schemapb.FieldData_Scalars{
Scalars: &schemapb.ScalarField{
Data: &schemapb.ScalarField_GeometryData{
GeometryData: &schemapb.GeometryArray{
Data: data,
},
},
},
},
}
}

func (s *MockSuiteBase) getFloatVectorFieldData(name string, dim int64, data []float32) *schemapb.FieldData {
return &schemapb.FieldData{
Type: schemapb.DataType_FloatVector,
Expand Down
4 changes: 4 additions & 0 deletions client/row/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ func AnyToColumns(rows []interface{}, schemas ...*entity.Schema) ([]column.Colum
data := make([][]byte, 0, rowsLen)
col := column.NewColumnJSONBytes(field.Name, data)
nameColumns[field.Name] = col
case entity.FieldTypeGeometry:
data := make([][]byte, 0, rowsLen)
col := column.NewColumnGeometryBytes(field.Name, data)
nameColumns[field.Name] = col
case entity.FieldTypeArray:
col := NewArrayColumn(field)
if col == nil {
Expand Down
Loading

0 comments on commit 9fba036

Please sign in to comment.