阅读量:2
parquet-go的CSVWriter
代码:
package main import ( "github.com/xitongsys/parquet-go-source/local" "github.com/xitongsys/parquet-go/writer" "log" ) func main() { var err error md := []string{ "name=Name, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN", "name=address, type=LIST, valuetype=BYTE_ARRAY, valueconvertedtype=UTF8", } //write fw, 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 := 10 for 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, nil case "INT32": return Type_INT32, nil case "INT64": return Type_INT64, nil case "INT96": return Type_INT96, nil case "FLOAT": return Type_FLOAT, nil case "DOUBLE": return Type_DOUBLE, nil case "BYTE_ARRAY": return Type_BYTE_ARRAY, nil case "FIXED_LEN_BYTE_ARRAY": return Type_FIXED_LEN_BYTE_ARRAY, nil } return Type(0), fmt.Errorf("not a valid Type string") }
可以看到这里并没有LIST,也没有MAP。只支持如上一些类型。