alrou
alrou

Reputation: 51

Bigquery Schema In AVRO Format

Is there any way to export only schema in AVRO format.I tried with BQ show command...but it doesnot support AVRO format.

PS: I need Only schema in avro format not with the data

Upvotes: 0

Views: 2533

Answers (2)

OneCricketeer
OneCricketeer

Reputation: 191884

You could download a very small amount of data then use avro-tools JAR to get the schema

Upvotes: 0

Adrian
Adrian

Reputation: 2113

How about creating an empty table from the table in question, followed by exporting it to avro, what you would get is an avro file with schema and no data.

CREATE TABLE mydataset.empty_table AS SELECT * FROM mytable WHERE  
(partition_column) = 'xx'  AND 1 = 0

Then you can run the following golang snippet to extract AVRO schema

import (
    "os"
    "log"
    "fmt"
    "github.com/linkedin/goavro"
)

func main() {

    avroLocation = "/tmp/myavro.avro"
    reader, err := os.Open("avroLocation")
    if err != nil {
        log.Fatal(err)
    }
    avroReader, err := goavro.NewOCFReader(reader)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%s\n", avroReader.MetaData()["avro.schema"])
}

Upvotes: 1

Related Questions