parquet-go的CSVWriter
代码:
package mainimport ("github.com/xitongsys/parquet-go-source/local""github.com/xitongsys/parquet-go/writer""log"
)func main() {var err errormd := []string{"name=Name, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN","name=address, type=LIST, valuetype=BYTE_ARRAY, valueconvertedtype=UTF8",}//writefw, err := local.NewLocalFileWriter("csv.parquet")if err != nil {log.Println("Can't open file", err)return}pw, err := writer.NewCSVWriter(md, fw, 4)if err != nil {log.Println("Can't create csv writer", err)return}num := 10for i := 0; i < num; i++ {data2 := []interface{}{"Student Name",[]string{"string1", "string2", "string3"},}if err = pw.Write(data2); err != nil {log.Println("Write error", err)}}if err = pw.WriteStop(); err != nil {log.Println("WriteStop error", err)}log.Println("Write Finished")fw.Close()}
执行这段代码会报错:
pw, err := writer.NewCSVWriter(md, fw, 4)
报错如下:
failed to create schema from tag map: type LIST: not a valid Type string
分析原因后是CSVWriter不支持LIST。
具体报错在这里:
if t, err := parquet.TypeFromString(info.Type); err == nil {schema.Type = &t} else {return nil, fmt.Errorf("type " + info.Type + ": " + err.Error())
}
进入parquet.TypeFromString()
func TypeFromString(s string) (Type, error) {switch s {case "BOOLEAN":return Type_BOOLEAN, nilcase "INT32":return Type_INT32, nilcase "INT64":return Type_INT64, nilcase "INT96":return Type_INT96, nilcase "FLOAT":return Type_FLOAT, nilcase "DOUBLE":return Type_DOUBLE, nilcase "BYTE_ARRAY":return Type_BYTE_ARRAY, nilcase "FIXED_LEN_BYTE_ARRAY":return Type_FIXED_LEN_BYTE_ARRAY, nil}return Type(0), fmt.Errorf("not a valid Type string")
}
可以看到这里并没有LIST,也没有MAP。只支持如上一些类型。