mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-29 06:55:27 +08:00
Add collection and segment
Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
parent
6d777b7518
commit
af1f67b9d2
56
reader/collection.go
Normal file
56
reader/collection.go
Normal file
@ -0,0 +1,56 @@
|
||||
package reader
|
||||
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Collection struct {
|
||||
CollectionPtr *C.Collection
|
||||
CollectionName string
|
||||
}
|
||||
|
||||
// TODO: Schema
|
||||
type CollectionSchema string
|
||||
|
||||
func NewCollection(collectionName string, schema CollectionSchema) (*Collection, error) {
|
||||
cName := C.CString(collectionName)
|
||||
cSchema := C.CString(schema)
|
||||
collection, status := C.NewCollection(cName, cSchema)
|
||||
|
||||
if status != 0 {
|
||||
return nil, errors.New("create collection failed")
|
||||
}
|
||||
|
||||
return &Collection{CollectionPtr: collection, CollectionName: collectionName}, nil
|
||||
}
|
||||
|
||||
func DeleteCollection(collection *Collection) error {
|
||||
status := C.DeleteCollection(collection.CollectionPtr)
|
||||
|
||||
if status != 0 {
|
||||
return errors.New("delete collection failed")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collection) GetSegments() ([]*Segment, error) {
|
||||
segments, status := C.GetSegments(c.CollectionPtr)
|
||||
|
||||
if status != 0 {
|
||||
return nil, errors.New("get segments failed")
|
||||
}
|
||||
|
||||
return segments, nil
|
||||
}
|
||||
|
||||
func (c *Collection) CreateSegment() error {
|
||||
status := C.CreateSegment(c.CollectionPtr)
|
||||
|
||||
if status != 0 {
|
||||
return errors.New("create segment failed")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
37
reader/query_node.go
Normal file
37
reader/query_node.go
Normal file
@ -0,0 +1,37 @@
|
||||
package reader
|
||||
|
||||
import "C"
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type QueryNodeTimeSync struct {
|
||||
deleteTimeSync uint64
|
||||
insertTimeSync uint64
|
||||
searchTimeSync uint64
|
||||
}
|
||||
|
||||
type QueryNode struct {
|
||||
Collections []*Collection
|
||||
queryNodeTimeSync *QueryNodeTimeSync
|
||||
}
|
||||
|
||||
func NewQueryNode(ctx context.Context, timeSync uint64) *QueryNode {
|
||||
ctx = context.Background()
|
||||
queryNodeTimeSync := &QueryNodeTimeSync {
|
||||
deleteTimeSync: timeSync,
|
||||
insertTimeSync: timeSync,
|
||||
searchTimeSync: timeSync,
|
||||
}
|
||||
|
||||
return &QueryNode{
|
||||
Collections: nil,
|
||||
queryNodeTimeSync: queryNodeTimeSync,
|
||||
}
|
||||
}
|
||||
|
||||
func (node *QueryNode) AddNewCollection(collectionName string, schema CollectionSchema) error {
|
||||
var collection, err = NewCollection(collectionName, schema)
|
||||
node.Collections = append(node.Collections, collection)
|
||||
return err
|
||||
}
|
||||
39
reader/segment.go
Normal file
39
reader/segment.go
Normal file
@ -0,0 +1,39 @@
|
||||
package reader
|
||||
|
||||
import "C"
|
||||
|
||||
type Segment struct {
|
||||
Id string
|
||||
Status int
|
||||
SegmentCloseTime uint64
|
||||
}
|
||||
|
||||
func (s *Segment) GetRowCount() int64 {
|
||||
// TODO: C type to go type
|
||||
return C.GetRowCount(s)
|
||||
}
|
||||
|
||||
func (s *Segment) GetStatus() int {
|
||||
// TODO: C type to go type
|
||||
return C.GetStatus(s)
|
||||
}
|
||||
|
||||
func (s *Segment) GetMaxTimestamp() uint64 {
|
||||
// TODO: C type to go type
|
||||
return C.GetMaxTimestamp(s)
|
||||
}
|
||||
|
||||
func (s *Segment) GetMinTimestamp() uint64 {
|
||||
// TODO: C type to go type
|
||||
return C.GetMinTimestamp(s)
|
||||
}
|
||||
|
||||
func (s *Segment) GetDeletedCount() uint64 {
|
||||
// TODO: C type to go type
|
||||
return C.GetDeletedCount(s)
|
||||
}
|
||||
|
||||
func (s *Segment) Close() {
|
||||
// TODO: C type to go type
|
||||
C.CloseSegment(s)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user