Skip to content
Merged
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
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
}
77 changes: 77 additions & 0 deletions client/index/rtree_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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

import (
"testing"

"github.com/stretchr/testify/suite"
)

type RTreeIndexSuite struct {
suite.Suite
}

func (s *RTreeIndexSuite) TestNewRTreeIndex() {
idx := NewRTreeIndex()
s.Equal(RTREE, idx.IndexType())

params := idx.Params()
s.Equal(string(RTREE), params[IndexTypeKey])
}

func (s *RTreeIndexSuite) TestNewRTreeIndexWithParams() {
idx := NewRTreeIndexWithParams()
s.Equal(RTREE, idx.IndexType())

params := idx.Params()
s.Equal(string(RTREE), params[IndexTypeKey])
}

func (s *RTreeIndexSuite) TestRTreeIndexBuilder() {
idx := NewRTreeIndexBuilder().
Build()

s.Equal(RTREE, idx.IndexType())

params := idx.Params()
s.Equal(string(RTREE), params[IndexTypeKey])
}

func (s *RTreeIndexSuite) TestRTreeIndexBuilderDefaults() {
idx := NewRTreeIndexBuilder().Build()
s.Equal(RTREE, idx.IndexType())

params := idx.Params()
s.Equal(string(RTREE), params[IndexTypeKey])
}

func (s *RTreeIndexSuite) TestRTreeIndexBuilderChaining() {
builder := NewRTreeIndexBuilder()

// Test method chaining
result := builder.Build()

s.Equal(RTREE, result.IndexType())

params := result.Params()
s.Equal(string(RTREE), params[IndexTypeKey])
}

func TestRTreeIndex(t *testing.T) {
suite.Run(t, new(RTreeIndexSuite))
}
2 changes: 2 additions & 0 deletions internal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ if ( BUILD_DISK_ANN STREQUAL "ON" )
ADD_DEFINITIONS(-DBUILD_DISK_ANN=${BUILD_DISK_ANN})
endif ()

ADD_DEFINITIONS(-DBOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL)

# Warning: add_subdirectory(src) must be after append_flags("-ftest-coverage"),
# otherwise cpp code coverage tool will miss src folder
add_subdirectory( thirdparty )
Expand Down
6 changes: 3 additions & 3 deletions internal/core/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class MilvusConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
requires = (
"rocksdb/6.29.5@milvus/dev#b1842a53ddff60240c5282a3da498ba1",
"boost/1.82.0#744a17160ebb5838e9115eab4d6d0c06",
"boost/1.83.0@",
"onetbb/2021.9.0#4a223ff1b4025d02f31b65aedf5e7f4a",
"nlohmann_json/3.11.3#ffb9e9236619f1c883e36662f944345d",
"zstd/1.5.5#34e9debe03bf0964834a09dfbc31a5dd",
Expand Down Expand Up @@ -53,8 +53,8 @@ class MilvusConan(ConanFile):
"proj/9.3.1#38e8bacd0f98467d38e20f46a085b4b3",
"libtiff/4.6.0#32ca1d04c9f024637d49c0c2882cfdbe",
"libgeotiff/1.7.1#0375633ef1116fc067b3773be7fd902f",
"geos/3.12.0#b76c27884c1fa4ee8c9e486337b7dc4e",
"gdal/3.5.3#61a42c933d3440a449cac89fd0866621"
"geos/3.12.0#0b177c90c25a8ca210578fb9e2899c37",
"gdal/3.5.3#61a42c933d3440a449cac89fd0866621",
)
generators = ("cmake", "cmake_find_package")
default_options = {
Expand Down
15 changes: 15 additions & 0 deletions internal/core/src/common/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ class Geometry {
to_wkb_internal();
}

// lightweight constructor: parse wkb but **do not** copy it back to internal buffer,
// which avoids an extra malloc + memcpy. Suitable for short-lived, read-only objects
// where we only need spatial predicates (equals/intersects/…).
explicit Geometry(const void* wkb, size_t size, bool copy_wkb) {
OGRGeometry* geometry = nullptr;
OGRGeometryFactory::createFromWkb(wkb, nullptr, &geometry, size);
AssertInfo(geometry != nullptr,
"failed to construct geometry from wkb data");
geometry_.reset(geometry);
size_ = size;
if (copy_wkb) {
to_wkb_internal();
}
}

explicit Geometry(const char* wkt) {
OGRGeometry* geometry = nullptr;
OGRGeometryFactory::createFromWkt(wkt, nullptr, &geometry);
Expand Down
Loading
Loading