diff --git a/client/column/array.go b/client/column/array.go index 1bd4561016..5eb701b75f 100644 --- a/client/column/array.go +++ b/client/column/array.go @@ -47,6 +47,21 @@ func (c *ColumnVarCharArray) Len() int { 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{}. func (c *ColumnVarCharArray) Get(idx int) (interface{}, error) { var r []string // use default value diff --git a/client/column/array_gen.go b/client/column/array_gen.go index 9081d73fc7..393f8d636b 100644 --- a/client/column/array_gen.go +++ b/client/column/array_gen.go @@ -33,6 +33,24 @@ func (c *ColumnBoolArray) Len() int { 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{}. func (c *ColumnBoolArray) Get(idx int) (interface{}, error) { var r []bool // use default value @@ -132,6 +150,21 @@ func (c *ColumnInt8Array) Len() int { 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{}. func (c *ColumnInt8Array) Get(idx int) (interface{}, error) { var r []int8 // use default value @@ -231,6 +264,21 @@ func (c *ColumnInt16Array) Len() int { 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{}. func (c *ColumnInt16Array) Get(idx int) (interface{}, error) { var r []int16 // use default value @@ -330,6 +378,21 @@ func (c *ColumnInt32Array) Len() int { 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{}. func (c *ColumnInt32Array) Get(idx int) (interface{}, error) { var r []int32 // use default value @@ -429,6 +492,21 @@ func (c *ColumnInt64Array) Len() int { 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{}. func (c *ColumnInt64Array) Get(idx int) (interface{}, error) { var r []int64 // use default value @@ -528,6 +606,21 @@ func (c *ColumnFloatArray) Len() int { 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{}. func (c *ColumnFloatArray) Get(idx int) (interface{}, error) { var r []float32 // use default value @@ -627,6 +720,21 @@ func (c *ColumnDoubleArray) Len() int { 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{}. func (c *ColumnDoubleArray) Get(idx int) (interface{}, error) { var r []float64 // use default value diff --git a/client/column/columns.go b/client/column/columns.go index 0a9eb1a556..ff1bb7da6a 100644 --- a/client/column/columns.go +++ b/client/column/columns.go @@ -32,6 +32,7 @@ type Column interface { Name() string Type() entity.FieldType Len() int + Slice(int, int) Column FieldData() *schemapb.FieldData AppendValue(interface{}) error Get(int) (interface{}, error) diff --git a/client/column/json.go b/client/column/json.go index 7628419472..a1c1470897 100644 --- a/client/column/json.go +++ b/client/column/json.go @@ -53,6 +53,21 @@ func (c *ColumnJSONBytes) Len() int { 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{}. func (c *ColumnJSONBytes) Get(idx int) (interface{}, error) { if idx < 0 || idx > c.Len() { diff --git a/client/column/scalar_gen.go b/client/column/scalar_gen.go index 023dadaa7b..9045a1b9b0 100644 --- a/client/column/scalar_gen.go +++ b/client/column/scalar_gen.go @@ -33,6 +33,21 @@ func (c *ColumnBool) Len() int { 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{}. func (c *ColumnBool) Get(idx int) (interface{}, error) { var r bool // use default value @@ -120,6 +135,21 @@ func (c *ColumnInt8) Len() int { 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{}. func (c *ColumnInt8) Get(idx int) (interface{}, error) { var r int8 // use default value @@ -207,6 +237,21 @@ func (c *ColumnInt16) Len() int { 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{}. func (c *ColumnInt16) Get(idx int) (interface{}, error) { var r int16 // use default value @@ -294,6 +339,21 @@ func (c *ColumnInt32) Len() int { 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{}. func (c *ColumnInt32) Get(idx int) (interface{}, error) { var r int32 // use default value @@ -381,6 +441,21 @@ func (c *ColumnInt64) Len() int { 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{}. func (c *ColumnInt64) Get(idx int) (interface{}, error) { var r int64 // use default value @@ -468,6 +543,21 @@ func (c *ColumnFloat) Len() int { 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{}. func (c *ColumnFloat) Get(idx int) (interface{}, error) { var r float32 // use default value @@ -555,6 +645,21 @@ func (c *ColumnDouble) Len() int { 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{}. func (c *ColumnDouble) Get(idx int) (interface{}, error) { var r float64 // use default value @@ -642,6 +747,21 @@ func (c *ColumnString) Len() int { 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{}. func (c *ColumnString) Get(idx int) (interface{}, error) { var r string // use default value diff --git a/client/column/sparse.go b/client/column/sparse.go index a9058c8c5c..96cb51d849 100644 --- a/client/column/sparse.go +++ b/client/column/sparse.go @@ -51,6 +51,21 @@ func (c *ColumnSparseFloatVector) Len() int { 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{}. func (c *ColumnSparseFloatVector) Get(idx int) (interface{}, error) { if idx < 0 || idx >= c.Len() { diff --git a/client/column/varchar.go b/client/column/varchar.go index 63aff96ae9..de96e3fe47 100644 --- a/client/column/varchar.go +++ b/client/column/varchar.go @@ -47,6 +47,21 @@ func (c *ColumnVarChar) Len() int { 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{}. func (c *ColumnVarChar) Get(idx int) (interface{}, error) { if idx < 0 || idx > c.Len() { diff --git a/client/column/vector_gen.go b/client/column/vector_gen.go index e2ab3e3f87..5d817d5812 100644 --- a/client/column/vector_gen.go +++ b/client/column/vector_gen.go @@ -34,6 +34,25 @@ func (c *ColumnBinaryVector) Len() int { 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 func (c *ColumnBinaryVector) Dim() int { return c.dim @@ -120,6 +139,25 @@ func (c *ColumnFloatVector) Len() int { 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 func (c *ColumnFloatVector) Dim() int { return c.dim @@ -208,6 +246,25 @@ func (c *ColumnFloat16Vector) Len() int { 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 func (c *ColumnFloat16Vector) Dim() int { return c.dim @@ -294,6 +351,25 @@ func (c *ColumnBFloat16Vector) Len() int { 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 func (c *ColumnBFloat16Vector) Dim() int { return c.dim