github.com/vc42/parquet-go@v0.0.0-20240320194221-1a9adb5f23f5/parquet_go18_test.go (about)

     1  //go:build go1.18
     2  
     3  package parquet_test
     4  
     5  import (
     6  	"fmt"
     7  	"log"
     8  
     9  	"github.com/vc42/parquet-go"
    10  )
    11  
    12  func ExampleReadFile() {
    13  	type Row struct {
    14  		ID   int64  `parquet:"id"`
    15  		Name string `parquet:"name,zstd"`
    16  	}
    17  
    18  	ExampleWriteFile()
    19  
    20  	rows, err := parquet.ReadFile[Row]("/tmp/file.parquet")
    21  	if err != nil {
    22  		log.Fatal(err)
    23  	}
    24  
    25  	for _, row := range rows {
    26  		fmt.Printf("%d: %q\n", row.ID, row.Name)
    27  	}
    28  
    29  	// Output:
    30  	// 0: "Bob"
    31  	// 1: "Alice"
    32  	// 2: "Franky"
    33  }
    34  
    35  func ExampleWriteFile() {
    36  	type Row struct {
    37  		ID   int64  `parquet:"id"`
    38  		Name string `parquet:"name,zstd"`
    39  	}
    40  
    41  	if err := parquet.WriteFile("/tmp/file.parquet", []Row{
    42  		{ID: 0, Name: "Bob"},
    43  		{ID: 1, Name: "Alice"},
    44  		{ID: 2, Name: "Franky"},
    45  	}); err != nil {
    46  		log.Fatal(err)
    47  	}
    48  
    49  	// Output:
    50  }