Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BigQuery] Always use StorageWrite API and dedupe #725

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clients/bigquery/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
describeNameCol = "column_name"
describeTypeCol = "data_type"
describeCommentCol = "description"
useStorageWriteAPI = true
)

type Store struct {
Expand Down Expand Up @@ -71,7 +72,7 @@ func (s *Store) PrepareTemporaryTable(tableData *optimization.TableData, tableCo
}

// Load the data
if s.config.BigQuery.UseStorageWriteAPI {
if useStorageWriteAPI {
return s.putTableViaStorageWriteAPI(context.Background(), bqTempTableID, tableData)
} else {
return s.putTableViaLegacyAPI(context.Background(), bqTempTableID, tableData)
Expand All @@ -90,6 +91,7 @@ func buildLegacyRows(tableData *optimization.TableData, additionalDateFmts []str
return nil, fmt.Errorf("failed to cast col %q: %w", col.Name(), err)
}

fmt.Println("col.Name", col.Name(), "colKind", col.KindDetails, "colVal", colVal, fmt.Sprintf("colVal type: %T", colVal))
if colVal != nil {
data[col.Name()] = colVal
}
Expand Down
5 changes: 5 additions & 0 deletions clients/bigquery/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
}

switch colKind.KindDetails.Kind {
<<<<<<< Updated upstream

Check failure on line 24 in clients/bigquery/cast.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected <<, expected case or default or }

Check failure on line 24 in clients/bigquery/cast.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected <<, expected case or default or }
case typing.String.Kind:

Check failure on line 25 in clients/bigquery/cast.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected case, expected :

Check failure on line 25 in clients/bigquery/cast.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected case, expected :
if val, isOk := colVal.(*decimal.Decimal); isOk {
return val.String(), nil
}

return colVal, nil
=======

Check failure on line 31 in clients/bigquery/cast.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected ==, expected case or default or }

Check failure on line 31 in clients/bigquery/cast.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected ==, expected case or default or }
return fmt.Sprint(colVal), nil

Check failure on line 32 in clients/bigquery/cast.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected return, expected :

>>>>>>> Stashed changes

Check failure on line 34 in clients/bigquery/cast.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected >>, expected case or default or }
case typing.Float.Kind, typing.Integer.Kind, typing.Boolean.Kind:

Check failure on line 35 in clients/bigquery/cast.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected case, expected :
return colVal, nil

Check failure on line 36 in clients/bigquery/cast.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected return at end of statement (compile)
case typing.EDecimal.Kind:
val, isOk := colVal.(*decimal.Decimal)
if !isOk {
Expand Down
2 changes: 2 additions & 0 deletions lib/cdc/relational/debezium.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
type Debezium string

func (d *Debezium) GetEventFromBytes(_ typing.Settings, bytes []byte) (cdc.Event, error) {
fmt.Println("string", string(bytes))

var event util.SchemaEventPayload
if len(bytes) == 0 {
return nil, fmt.Errorf("empty message")
Expand Down
11 changes: 5 additions & 6 deletions lib/config/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import "fmt"
type BigQuery struct {
// PathToCredentials is _optional_ if you have GOOGLE_APPLICATION_CREDENTIALS set as an env var
// Links to credentials: https://cloud.google.com/docs/authentication/application-default-credentials#GAC
PathToCredentials string `yaml:"pathToCredentials"`
DefaultDataset string `yaml:"defaultDataset"`
ProjectID string `yaml:"projectID"`
Location string `yaml:"location"`
BatchSize int `yaml:"batchSize"`
UseStorageWriteAPI bool `yaml:"__useStorageWriteAPI"` // Not officially supported yet.
PathToCredentials string `yaml:"pathToCredentials"`
DefaultDataset string `yaml:"defaultDataset"`
ProjectID string `yaml:"projectID"`
Location string `yaml:"location"`
BatchSize int `yaml:"batchSize"`
}

func (b *BigQuery) LoadDefaultValues() {
Expand Down
7 changes: 7 additions & 0 deletions lib/destination/types/table_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"fmt"
"log/slog"
"maps"
"sync"
Expand All @@ -26,6 +27,12 @@ func NewDwhTableConfig(columns *columns.Columns, colsToDelete map[string]time.Ti
colsToDelete = make(map[string]time.Time)
}

if columns != nil {
for _, col := range columns.GetColumns() {
fmt.Println("colName", col.Name(), "colKind", col.KindDetails)
}
}

return &DwhTableConfig{
columns: columns,
columnsToDelete: colsToDelete,
Expand Down