-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
728 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Parquetgen example | ||
|
||
To generate the code needed to run this example: | ||
|
||
cd cmd/parquetgen | ||
go get ./... | ||
go install | ||
cd ../../examples/people | ||
go generate | ||
|
||
Go generate calls (see the top of main.go for the go:generate command): | ||
|
||
//parquetgen -input main.go -type Person -package main | ||
|
||
which produces a file called parquet.go. Now run: | ||
|
||
go run . | ||
|
||
You should now have a parquet file that encodes a Person struct. To | ||
read the values back run: | ||
|
||
go run . -read people.parquet |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package main | ||
|
||
//go:generate parquetgen -input main.go -type C -package main | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"os" | ||
) | ||
|
||
func main() { | ||
f, err := os.Create("parquet") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
defer f.Close() | ||
|
||
w, err := NewParquetWriter(f, MaxPageSize(2)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
w.Add(C{B: B{Name: "a", A: A{ID: 1}}}) | ||
w.Add(C{B: B{Name: "b", A: A{ID: 2}}}) | ||
w.Add(C{B: B{Name: "c", A: A{ID: 3}}}) | ||
|
||
if err := w.Write(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if err := w.Close(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
f2, err := os.Open("parquet") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer f2.Close() | ||
|
||
r, err := NewParquetReader(f2) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
enc := json.NewEncoder(os.Stdout) | ||
for r.Next() { | ||
var c C | ||
r.Scan(&c) | ||
enc.Encode(c) | ||
} | ||
|
||
if err := r.Error(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
// Being is split out only to show how embedded structs | ||
// are handled. | ||
type A struct { | ||
ID int32 `parquet:"id"` | ||
} | ||
|
||
type B struct { | ||
A | ||
Name string `parquet:"name"` | ||
} | ||
|
||
type C struct { | ||
B | ||
} |
Binary file not shown.
Oops, something went wrong.