Created
January 8, 2018 04:11
-
-
Save dg3feiko/7e04eb770a4f0aac0012e45a9cc70f0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/xitongsys/parquet-go/ParquetFile" | |
"github.com/xitongsys/parquet-go/Plugin/JSONWriter" | |
"log" | |
) | |
func main() { | |
md := ` | |
{ | |
"Tag":"name=parquet-go-root", | |
"Fields":[ | |
{"Tag":"name=name, type=UTF8, encoding=PLAIN_DICTIONARY"}, | |
{"Tag":"name=age, type=INT32"}, | |
{"Tag":"name=id, type=INT64"}, | |
{"Tag":"name=weight, type=FLOAT"}, | |
{"Tag":"name=sex, type=BOOLEAN"}, | |
{"Tag":"name=friends, type=LIST", | |
"Fields":[ | |
{"Tag":"name=element", | |
"Fields":[{"Tag":"name=foo, type=UTF8"}, {"Tag":"name=bar, type=UTF8"}] | |
} | |
] | |
} | |
] | |
} | |
` | |
//write | |
fw, _ := ParquetFile.NewLocalFileWriter("json_test.parquet") | |
pw, _ := JSONWriter.NewJSONWriter(md, fw, 1) | |
num := 2 | |
for i := 0; i < num; i++ { | |
rec := ` | |
{ | |
"name":"%s", | |
"age":%d, | |
"id":%d, | |
"weight":%f, | |
"sex":%t, | |
"friends":[{"foo":"foo1", "bar":"bar1"},{"foo":"foo2", "bar":"bar2"}] | |
} | |
` | |
rec = fmt.Sprintf(rec, "Student Name", 20+i%5, i, 50.0+float32(i)*0.1, i%2 == 0) | |
pw.Write(rec) | |
} | |
pw.Flush(true) | |
pw.WriteStop() | |
log.Println("Write Finished") | |
fw.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment