背景:從clickhouse中導(dǎo)出CSV文件外构,然后將此文件保存到另一個(gè)表中框喳,發(fā)現(xiàn)保存的內(nèi)容包含雙引號(hào)? “XXXX”
導(dǎo)致匹配不上
查clickhose?文檔,在生成CSV時(shí)透硝,字符串中的雙引號(hào)會(huì)以兩個(gè)雙引號(hào)輸出聪蘸,除此之外沒有其他規(guī)則來做字符轉(zhuǎn)義了
而代碼解析CSV時(shí)宪肖,沒有使用 golang?自帶的CSV包,而是自己解析的
r := bytes.NewReader(fileStream)
bufioreader := bufio.NewReader(r)
isFirstLine :=true
line,err := bufioreader.ReadBytes('\n')
iferr != nil || io.EOF == err {
break
}
line = bytes.TrimRight(line,"\r\n")
ifisFirstLine {
line = bytes.TrimPrefix(line,[]byte("\xef\xbb\xbf"))
}
columns := bytes.Split(line,[]byte{','})
這樣就沒有兼容到?雙引號(hào)的情況
查看源碼? encoding\csv\reader.go,發(fā)現(xiàn)其兼容了字符串含有雙引號(hào)和不含雙引號(hào)的情況
func(r *Reader)readRecord(dst []string) ([]string,error)
暫時(shí)解決方案:
clickhouse-client --query=" select member from test format CSV"??sed 's/"http://g'> test.csv
參考文檔:https://clickhouse.yandex/docs/zh/interfaces/formats/#csv