Skip to content

Commit

Permalink
Fix json (matrixorigin#10838)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianwan0214 authored Jul 24, 2023
1 parent 7df274c commit 772d70d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/frontend/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"os"
"strconv"
"strings"
"sync"

"github.com/matrixorigin/matrixone/pkg/container/batch"
Expand Down Expand Up @@ -389,6 +390,17 @@ func initExportFirst(oq *outputQueue) {
oq.ep.Index++
}

func formatJsonString(str string, flag bool) string {
if len(str) < 2 {
return "\"" + str + "\""
}
tmp := strings.ReplaceAll(str, "\",", "\"\",")
if tmp[0] != '"' && tmp[len(tmp)-1] != '"' && !flag {
return "\"" + tmp + "\""
}
return tmp
}

func constructByte(obj interface{}, bat *batch.Batch, index int32, ByteChan chan *BatchByte, oq *outputQueue) {
ses := obj.(*Session)
symbol := oq.ep.Symbol
Expand All @@ -404,7 +416,7 @@ func constructByte(obj interface{}, bat *batch.Batch, index int32, ByteChan chan
switch vec.GetType().Oid { //get col
case types.T_json:
val := types.DecodeJson(vec.GetBytesAt(i))
writeByte = appendBytes(writeByte, []byte(val.String()), symbol[j], closeby, flag[j])
writeByte = appendBytes(writeByte, []byte(formatJsonString(val.String(), flag[j])), symbol[j], closeby, flag[j])
case types.T_bool:
val := vector.GetFixedAt[bool](vec, i)
if val {
Expand Down

0 comments on commit 772d70d

Please sign in to comment.