enhance: add Slice func for go milvusclient column (#33836)

issue: #33419

Signed-off-by: ThreadDao <yufen.zong@zilliz.com>
This commit is contained in:
ThreadDao 2024-06-17 19:07:58 +08:00 committed by GitHub
parent f993b2913b
commit 2da289c5b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 365 additions and 0 deletions

View File

@ -47,6 +47,21 @@ func (c *ColumnVarCharArray) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnVarCharArray) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnVarCharArray{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnVarCharArray) Get(idx int) (interface{}, error) { func (c *ColumnVarCharArray) Get(idx int) (interface{}, error) {
var r []string // use default value var r []string // use default value

View File

@ -33,6 +33,24 @@ func (c *ColumnBoolArray) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnBoolArray) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
if end == -1 || end > l {
end = l
}
return &ColumnBoolArray{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnBoolArray) Get(idx int) (interface{}, error) { func (c *ColumnBoolArray) Get(idx int) (interface{}, error) {
var r []bool // use default value var r []bool // use default value
@ -132,6 +150,21 @@ func (c *ColumnInt8Array) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnInt8Array) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnInt8Array{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnInt8Array) Get(idx int) (interface{}, error) { func (c *ColumnInt8Array) Get(idx int) (interface{}, error) {
var r []int8 // use default value var r []int8 // use default value
@ -231,6 +264,21 @@ func (c *ColumnInt16Array) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnInt16Array) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnInt16Array{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnInt16Array) Get(idx int) (interface{}, error) { func (c *ColumnInt16Array) Get(idx int) (interface{}, error) {
var r []int16 // use default value var r []int16 // use default value
@ -330,6 +378,21 @@ func (c *ColumnInt32Array) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnInt32Array) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnInt32Array{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnInt32Array) Get(idx int) (interface{}, error) { func (c *ColumnInt32Array) Get(idx int) (interface{}, error) {
var r []int32 // use default value var r []int32 // use default value
@ -429,6 +492,21 @@ func (c *ColumnInt64Array) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnInt64Array) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnInt64Array{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnInt64Array) Get(idx int) (interface{}, error) { func (c *ColumnInt64Array) Get(idx int) (interface{}, error) {
var r []int64 // use default value var r []int64 // use default value
@ -528,6 +606,21 @@ func (c *ColumnFloatArray) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnFloatArray) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnFloatArray{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnFloatArray) Get(idx int) (interface{}, error) { func (c *ColumnFloatArray) Get(idx int) (interface{}, error) {
var r []float32 // use default value var r []float32 // use default value
@ -627,6 +720,21 @@ func (c *ColumnDoubleArray) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnDoubleArray) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnDoubleArray{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnDoubleArray) Get(idx int) (interface{}, error) { func (c *ColumnDoubleArray) Get(idx int) (interface{}, error) {
var r []float64 // use default value var r []float64 // use default value

View File

@ -32,6 +32,7 @@ type Column interface {
Name() string Name() string
Type() entity.FieldType Type() entity.FieldType
Len() int Len() int
Slice(int, int) Column
FieldData() *schemapb.FieldData FieldData() *schemapb.FieldData
AppendValue(interface{}) error AppendValue(interface{}) error
Get(int) (interface{}, error) Get(int) (interface{}, error)

View File

@ -53,6 +53,21 @@ func (c *ColumnJSONBytes) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnJSONBytes) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnJSONBytes{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnJSONBytes) Get(idx int) (interface{}, error) { func (c *ColumnJSONBytes) Get(idx int) (interface{}, error) {
if idx < 0 || idx > c.Len() { if idx < 0 || idx > c.Len() {

View File

@ -33,6 +33,21 @@ func (c *ColumnBool) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnBool) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnBool{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnBool) Get(idx int) (interface{}, error) { func (c *ColumnBool) Get(idx int) (interface{}, error) {
var r bool // use default value var r bool // use default value
@ -120,6 +135,21 @@ func (c *ColumnInt8) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnInt8) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnInt8{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnInt8) Get(idx int) (interface{}, error) { func (c *ColumnInt8) Get(idx int) (interface{}, error) {
var r int8 // use default value var r int8 // use default value
@ -207,6 +237,21 @@ func (c *ColumnInt16) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnInt16) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnInt16{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnInt16) Get(idx int) (interface{}, error) { func (c *ColumnInt16) Get(idx int) (interface{}, error) {
var r int16 // use default value var r int16 // use default value
@ -294,6 +339,21 @@ func (c *ColumnInt32) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnInt32) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnInt32{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnInt32) Get(idx int) (interface{}, error) { func (c *ColumnInt32) Get(idx int) (interface{}, error) {
var r int32 // use default value var r int32 // use default value
@ -381,6 +441,21 @@ func (c *ColumnInt64) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnInt64) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnInt64{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start: end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnInt64) Get(idx int) (interface{}, error) { func (c *ColumnInt64) Get(idx int) (interface{}, error) {
var r int64 // use default value var r int64 // use default value
@ -468,6 +543,21 @@ func (c *ColumnFloat) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnFloat) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnFloat{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnFloat) Get(idx int) (interface{}, error) { func (c *ColumnFloat) Get(idx int) (interface{}, error) {
var r float32 // use default value var r float32 // use default value
@ -555,6 +645,21 @@ func (c *ColumnDouble) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnDouble) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnDouble{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnDouble) Get(idx int) (interface{}, error) { func (c *ColumnDouble) Get(idx int) (interface{}, error) {
var r float64 // use default value var r float64 // use default value
@ -642,6 +747,21 @@ func (c *ColumnString) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnString) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnString{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnString) Get(idx int) (interface{}, error) { func (c *ColumnString) Get(idx int) (interface{}, error) {
var r string // use default value var r string // use default value

View File

@ -51,6 +51,21 @@ func (c *ColumnSparseFloatVector) Len() int {
return len(c.vectors) return len(c.vectors)
} }
func (c *ColumnSparseFloatVector) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnSparseFloatVector{
ColumnBase: c.ColumnBase,
name: c.name,
vectors: c.vectors[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnSparseFloatVector) Get(idx int) (interface{}, error) { func (c *ColumnSparseFloatVector) Get(idx int) (interface{}, error) {
if idx < 0 || idx >= c.Len() { if idx < 0 || idx >= c.Len() {

View File

@ -47,6 +47,21 @@ func (c *ColumnVarChar) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnVarChar) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
return &ColumnVarChar{
ColumnBase: c.ColumnBase,
name: c.name,
values: c.values[start:end],
}
}
// Get returns value at index as interface{}. // Get returns value at index as interface{}.
func (c *ColumnVarChar) Get(idx int) (interface{}, error) { func (c *ColumnVarChar) Get(idx int) (interface{}, error) {
if idx < 0 || idx > c.Len() { if idx < 0 || idx > c.Len() {

View File

@ -34,6 +34,25 @@ func (c *ColumnBinaryVector) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnBinaryVector) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
if end == -1 || end > l {
end = l
}
return &ColumnBinaryVector{
ColumnBase: c.ColumnBase,
name: c.name,
dim: c.dim,
values: c.values[start:end],
}
}
// Dim returns vector dimension // Dim returns vector dimension
func (c *ColumnBinaryVector) Dim() int { func (c *ColumnBinaryVector) Dim() int {
return c.dim return c.dim
@ -120,6 +139,25 @@ func (c *ColumnFloatVector) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnFloatVector) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
if end == -1 || end > l {
end = l
}
return &ColumnFloatVector{
ColumnBase: c.ColumnBase,
name: c.name,
dim: c.dim,
values: c.values[start:end],
}
}
// Dim returns vector dimension // Dim returns vector dimension
func (c *ColumnFloatVector) Dim() int { func (c *ColumnFloatVector) Dim() int {
return c.dim return c.dim
@ -208,6 +246,25 @@ func (c *ColumnFloat16Vector) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnFloat16Vector) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
if end == -1 || end > l {
end = l
}
return &ColumnFloat16Vector{
ColumnBase: c.ColumnBase,
name: c.name,
dim: c.dim,
values: c.values[start:end],
}
}
// Dim returns vector dimension // Dim returns vector dimension
func (c *ColumnFloat16Vector) Dim() int { func (c *ColumnFloat16Vector) Dim() int {
return c.dim return c.dim
@ -294,6 +351,25 @@ func (c *ColumnBFloat16Vector) Len() int {
return len(c.values) return len(c.values)
} }
func (c *ColumnBFloat16Vector) Slice(start, end int) Column {
l := c.Len()
if start > l {
start = l
}
if end == -1 || end > l {
end = l
}
if end == -1 || end > l {
end = l
}
return &ColumnBFloat16Vector{
ColumnBase: c.ColumnBase,
name: c.name,
dim: c.dim,
values: c.values[start:end],
}
}
// Dim returns vector dimension // Dim returns vector dimension
func (c *ColumnBFloat16Vector) Dim() int { func (c *ColumnBFloat16Vector) Dim() int {
return c.dim return c.dim