github.com/fraugster/parquet-go@v0.12.0/examples/read-low-level/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "io" 7 "log" 8 "os" 9 10 goparquet "github.com/fraugster/parquet-go" 11 ) 12 13 func main() { 14 flag.Parse() 15 16 if len(flag.Args()) == 0 { 17 log.Fatalf("Usage: %s <parquet-file>...", os.Args[0]) 18 } 19 20 for _, file := range flag.Args() { 21 if err := printFile(file); err != nil { 22 log.Printf("Failed to print file %s: %v", file, err) 23 } 24 } 25 } 26 27 func printFile(file string) error { 28 r, err := os.Open(file) 29 if err != nil { 30 return err 31 } 32 defer r.Close() 33 34 fr, err := goparquet.NewFileReader(r) 35 if err != nil { 36 return err 37 } 38 39 log.Printf("Printing file %s", file) 40 log.Printf("Schema: %s", fr.GetSchemaDefinition()) 41 42 count := 0 43 for { 44 row, err := fr.NextRow() 45 if err == io.EOF { 46 break 47 } 48 if err != nil { 49 return fmt.Errorf("reading record failed: %w", err) 50 } 51 52 log.Printf("Record %d:", count) 53 for k, v := range row { 54 if vv, ok := v.([]byte); ok { 55 v = string(vv) 56 } 57 log.Printf("\t%s = %v", k, v) 58 } 59 60 count++ 61 } 62 63 log.Printf("End of file %s (%d records)", file, count) 64 return nil 65 }