Last active
March 20, 2018 18:59
-
-
Save spark2ignite/51cbbf00531a29b94367ea8e9cf886dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"context" | |
"fmt" | |
"os" | |
"cloud.google.com/go/bigquery" | |
) | |
func main() { | |
ctx := context.Background() | |
c, err := bigquery.NewClient(ctx, "vadim-playground") | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
uris := []string{ | |
"gs://vadim-playground/logstash_gcs_000b7e5d3235_2016-11-28T21:00.part000.log", | |
"gs://vadim-playground/logstash_gcs_000b7e5d3235_2016-11-28T21:01.part000.log", | |
"gs://vadim-playground/logstash_gcs_000b7e5d3235_2016-11-28T21:03.part000.log" | |
} | |
gcsRef := bigquery.NewGCSReference(uris...) | |
gcsRef.MaxBadRecords = 0 | |
gcsRef.SourceFormat = "CSV" | |
gcsRef.SkipLeadingRows = 1 | |
gcsRef.AutoDetect = true | |
ds := c.Dataset("go_load") | |
loader := ds.Table("dest").LoaderFrom(gcsRef) | |
loader.CreateDisposition = bigquery.CreateIfNeeded | |
job, err := loader.Run(ctx) | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(2) | |
} | |
fmt.Printf("%v", job) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment