github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/json_unquote/json_unquote.go (about) 1 // Copyright 2022 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 json_unquote 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/nulls" 19 "github.com/matrixorigin/matrixone/pkg/container/types" 20 ) 21 22 func StringSingle(v []byte) (string, error) { 23 bj, err := types.ParseSliceToByteJson(v) 24 if err != nil { 25 return "", err 26 } 27 return bj.Unquote() 28 } 29 func JsonSingle(v []byte) (string, error) { 30 bj := types.DecodeJson(v) 31 return bj.Unquote() 32 } 33 34 func StringBatch(xs [][]byte, rs []string, nsp *nulls.Nulls) ([]string, error) { 35 for i, v := range xs { 36 if nsp.Contains(uint64(i)) { 37 continue 38 } 39 bj, err := types.ParseSliceToByteJson(v) 40 if err != nil { 41 return nil, err 42 } 43 r, err := bj.Unquote() 44 if err != nil { 45 return nil, err 46 } 47 rs[i] = r 48 } 49 return rs, nil 50 } 51 52 func JsonBatch(xs [][]byte, rs []string, nsp *nulls.Nulls) ([]string, error) { 53 for i, v := range xs { 54 if nsp.Contains(uint64(i)) { 55 continue 56 } 57 bj := types.DecodeJson(v) 58 r, err := bj.Unquote() 59 if err != nil { 60 return nil, err 61 } 62 rs[i] = r 63 } 64 return rs, nil 65 }