avro-schema-bq

command module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 4 Imported by: 0

README

Go Reference

avro-schema-bq

Convert Apache Avro schema (it supports schemas with array/record types) to BigQuery Table Schema.

go install github.com/go-syar/avro-schema-bq@latest

Usage

avro-bq-schema schema.avsc > bq.json
Create BQ Table with Avro Schema (avsc)

Create BQ Table with Avro schema by providing variables projectID, datasetID, tableID, serviceAccount, schemaFilePath

table.CreateBQTableWithSA(projectID string, datasetID string, tableID string, serviceAccount string, schemaFilePath string) error
// service account := "service-account.json"
Avro Schema (avsc) to BQ Schema (json)
schema.ConvertAvroToBigQuery(avroSchema map[string]interface{}) ([]*bigquery.FieldSchema, error)
Convert .avsc file to map[string]interface{}
	schemaFilePath := $ your-(.avsc)file-path

	avroSchemaContent, err := ioutil.ReadFile(schemaFilePath)
	if err != nil {
		fmt.Println("Error reading Avro schema file:", err)
		return
	}

	var avroSchema map[string]interface{}
	err = json.Unmarshal(avroSchemaContent, &avroSchema)
	if err != nil {
		fmt.Println("Error parsing Avro schema:", err)
		return
	}
Convert the BigQuery schema to JSON
	jsonData, err := json.MarshalIndent(bqFields, "", "    ")
	if err != nil {
		fmt.Println("Error marshaling BigQuery schema to JSON:", err)
		return
	}
Write the JSON BigQuery schema output to a file
	err = ioutil.WriteFile("schema/test_data/bq_schema.json", jsonData, 0644)
	if err != nil {
		fmt.Println("Error writing JSON data to file:", err)
		return
	}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package schema provides functionality for converting AVRO Schema to BQ Schema
Package schema provides functionality for converting AVRO Schema to BQ Schema
Package table provides functionality for converting empty BQ Table with provided AVRO Schema
Package table provides functionality for converting empty BQ Table with provided AVRO Schema

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL