Skip to content

Commit

Permalink
update bigquery location setting
Browse files Browse the repository at this point in the history
  • Loading branch information
flarco committed Oct 3, 2024
1 parent 751f627 commit c559bcb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions core/dbio/database/database_bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (conn *BigQueryConn) Init() error {
if conn.DatasetID == "" {
conn.DatasetID = conn.GetProp("schema")
}

conn.Location = conn.GetProp("location")

instance := Connection(conn)
Expand Down Expand Up @@ -139,7 +139,17 @@ func (conn *BigQueryConn) getNewClient(timeOut ...int) (client *bigquery.Client,
ctx, cancel := context.WithTimeout(conn.BaseConn.Context().Ctx, time.Duration(to)*time.Second)
defer cancel()

return bigquery.NewClient(ctx, conn.ProjectID, authOption)
client, err = bigquery.NewClient(ctx, conn.ProjectID, authOption)
if err != nil {
return nil, g.Error(err, "Failed to create BigQuery client")
}

// set the location if specified
if conn.Location != "" {
client.Location = conn.Location
}

return client, nil
}

// Connect connects to the database
Expand Down Expand Up @@ -747,6 +757,7 @@ func (conn *BigQueryConn) LoadCSVFromReader(table Table, reader io.Reader, dsCol

loader := client.Dataset(table.Schema).Table(table.Name).LoaderFrom(source)
loader.WriteDisposition = bigquery.WriteAppend
loader.Location = client.Location

job, err := loader.Run(conn.Context().Ctx)
if err != nil {
Expand Down Expand Up @@ -795,6 +806,7 @@ func (conn *BigQueryConn) CopyFromGCS(gcsURI string, table Table, dsColumns []io
gcsRef.MaxBadRecords = 0
loader := client.Dataset(table.Schema).Table(table.Name).LoaderFrom(gcsRef)
loader.WriteDisposition = bigquery.WriteAppend
loader.Location = client.Location

job, err := loader.Run(conn.Context().Ctx)
if err != nil {
Expand Down Expand Up @@ -956,7 +968,7 @@ func (conn *BigQueryConn) CopyToGCS(table Table, gcsURI string) error {

extractor := client.DatasetInProject(conn.ProjectID, table.Schema).Table(table.Name).ExtractorTo(gcsRef)
extractor.DisableHeader = false
extractor.Location = conn.Location
extractor.Location = client.Location

job, err := extractor.Run(conn.Context().Ctx)
if err != nil {
Expand Down

0 comments on commit c559bcb

Please sign in to comment.