github.com/fraugster/parquet-go@v0.12.0/cmd/parquet-tool/cmds/schema.go (about)

     1  package cmds
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"os"
     7  
     8  	goparquet "github.com/fraugster/parquet-go"
     9  	"github.com/spf13/cobra"
    10  )
    11  
    12  func init() {
    13  	rootCmd.AddCommand(schemaCmd)
    14  }
    15  
    16  var schemaCmd = &cobra.Command{
    17  	Use:   "schema file-name.parquet",
    18  	Short: "Print the parquet file schema",
    19  	Run: func(cmd *cobra.Command, args []string) {
    20  		if len(args) != 1 {
    21  			_ = cmd.Usage()
    22  			os.Exit(1)
    23  		}
    24  		fl, err := os.Open(args[0])
    25  		if err != nil {
    26  			log.Fatalf("Can not open the file: %q", err)
    27  		}
    28  		defer fl.Close()
    29  
    30  		reader, err := goparquet.NewFileReader(fl)
    31  		if err != nil {
    32  			log.Fatalf("Failed to read the parquet header: %q", err)
    33  		}
    34  
    35  		fmt.Print(reader.GetSchemaDefinition())
    36  	},
    37  }