github.com/matrixorigin/matrixone@v1.2.0/pkg/util/executor/result.go (about) 1 // Copyright 2023 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package executor 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/vector" 19 ) 20 21 func (res Result) Close() { 22 for _, rows := range res.Batches { 23 rows.Clean(res.mp) 24 } 25 } 26 27 // ReadRows read all rows, apply is used to read cols data in a row. If apply return 28 // false, stop reading. If the query has a lot of data, apply will be called multiple times, giving 29 // a batch of rows for each call. 30 func (res Result) ReadRows(apply func(rows int, cols []*vector.Vector) bool) { 31 for _, rows := range res.Batches { 32 if !apply(rows.RowCount(), rows.Vecs) { 33 return 34 } 35 } 36 } 37 38 // GetFixedRows get fixed rows, int, float, etc. 39 func GetFixedRows[T any](vec *vector.Vector) []T { 40 return vector.MustFixedCol[T](vec) 41 } 42 43 // GetBytesRows get bytes rows, varchar, varbinary, text, json, etc. 44 func GetBytesRows(vec *vector.Vector) [][]byte { 45 n := vec.Length() 46 data, area := vector.MustVarlenaRawData(vec) 47 rows := make([][]byte, 0, n) 48 for idx := range data { 49 rows = append(rows, data[idx].GetByteSlice(area)) 50 } 51 return rows 52 } 53 54 // GetStringRows get bytes rows, varchar, varbinary, text, json, etc. 55 func GetStringRows(vec *vector.Vector) []string { 56 n := vec.Length() 57 data, area := vector.MustVarlenaRawData(vec) 58 rows := make([]string, 0, n) 59 for idx := range data { 60 rows = append(rows, string(data[idx].GetByteSlice(area))) 61 } 62 return rows 63 }