@@ -83,10 +83,9 @@ func NewBigQueryConnector(ctx context.Context, config *protos.BigqueryConfig) (*
83
83
return nil , fmt .Errorf ("failed to create BigQuery client: %v" , err )
84
84
}
85
85
86
- _ , datasetErr := client .DatasetInProject (projectID , datasetID ).Metadata (ctx )
87
- if datasetErr != nil {
88
- logger .Error ("failed to get dataset metadata" , "error" , datasetErr )
89
- return nil , fmt .Errorf ("failed to get dataset metadata: %v" , datasetErr )
86
+ if _ , err := client .DatasetInProject (projectID , datasetID ).Metadata (ctx ); err != nil {
87
+ logger .Error ("failed to get dataset metadata" , "error" , err )
88
+ return nil , fmt .Errorf ("failed to get dataset metadata: %v" , err )
90
89
}
91
90
92
91
storageClient , err := bqsa .CreateStorageClient (ctx )
@@ -166,8 +165,7 @@ func (c *BigQueryConnector) Close() error {
166
165
167
166
// ConnectionActive returns nil if the connection is active.
168
167
func (c * BigQueryConnector ) ConnectionActive (ctx context.Context ) error {
169
- _ , err := c .client .DatasetInProject (c .projectID , c .datasetID ).Metadata (ctx )
170
- if err != nil {
168
+ if _ , err := c .client .DatasetInProject (c .projectID , c .datasetID ).Metadata (ctx ); err != nil {
171
169
return fmt .Errorf ("failed to get dataset metadata: %v" , err )
172
170
}
173
171
@@ -182,12 +180,13 @@ func (c *BigQueryConnector) waitForTableReady(ctx context.Context, datasetTable
182
180
attempt := 0
183
181
184
182
for {
183
+ if err := ctx .Err (); err != nil {
184
+ return err
185
+ }
185
186
if time .Now ().After (deadline ) {
186
187
return fmt .Errorf ("timeout reached while waiting for table %s to be ready" , datasetTable )
187
188
}
188
-
189
- _ , err := table .Metadata (ctx )
190
- if err == nil {
189
+ if _ , err := table .Metadata (ctx ); err == nil {
191
190
return nil
192
191
}
193
192
@@ -768,8 +767,7 @@ func (c *BigQueryConnector) RenameTables(
768
767
769
768
// if _resync table does not exist, log and continue.
770
769
dataset := c .client .DatasetInProject (c .projectID , srcDatasetTable .dataset )
771
- _ , err := dataset .Table (srcDatasetTable .table ).Metadata (ctx )
772
- if err != nil {
770
+ if _ , err := dataset .Table (srcDatasetTable .table ).Metadata (ctx ); err != nil {
773
771
if ! strings .Contains (err .Error (), "notFound" ) {
774
772
return nil , fmt .Errorf ("[renameTable] failed to get metadata for _resync table %s: %w" , srcDatasetTable .string (), err )
775
773
}
@@ -779,8 +777,7 @@ func (c *BigQueryConnector) RenameTables(
779
777
780
778
// if the original table does not exist, log and skip soft delete step
781
779
originalTableExists := true
782
- _ , err = dataset .Table (dstDatasetTable .table ).Metadata (ctx )
783
- if err != nil {
780
+ if _ , err := dataset .Table (dstDatasetTable .table ).Metadata (ctx ); err != nil {
784
781
if ! strings .Contains (err .Error (), "notFound" ) {
785
782
return nil , fmt .Errorf ("[renameTable] failed to get metadata for original table %s: %w" , dstDatasetTable .string (), err )
786
783
}
@@ -860,8 +857,7 @@ func (c *BigQueryConnector) RenameTables(
860
857
861
858
query .DefaultProjectID = c .projectID
862
859
query .DefaultDatasetID = c .datasetID
863
- _ , err := query .Read (ctx )
864
- if err != nil {
860
+ if _ , err := query .Read (ctx ); err != nil {
865
861
return nil , fmt .Errorf ("unable to handle soft-deletes for table %s: %w" , dstDatasetTable .string (), err )
866
862
}
867
863
}
@@ -876,8 +872,7 @@ func (c *BigQueryConnector) RenameTables(
876
872
877
873
query .DefaultProjectID = c .projectID
878
874
query .DefaultDatasetID = c .datasetID
879
- _ , err := query .Read (ctx )
880
- if err != nil {
875
+ if _ , err := query .Read (ctx ); err != nil {
881
876
return nil , fmt .Errorf ("unable to set synced at column for table %s: %w" , srcDatasetTable .string (), err )
882
877
}
883
878
}
@@ -886,8 +881,7 @@ func (c *BigQueryConnector) RenameTables(
886
881
dropQuery := c .queryWithLogging ("DROP TABLE IF EXISTS " + dstDatasetTable .string ())
887
882
dropQuery .DefaultProjectID = c .projectID
888
883
dropQuery .DefaultDatasetID = c .datasetID
889
- _ , err = dropQuery .Read (ctx )
890
- if err != nil {
884
+ if _ , err := dropQuery .Read (ctx ); err != nil {
891
885
return nil , fmt .Errorf ("unable to drop table %s: %w" , dstDatasetTable .string (), err )
892
886
}
893
887
@@ -896,8 +890,7 @@ func (c *BigQueryConnector) RenameTables(
896
890
srcDatasetTable .string (), dstDatasetTable .table ))
897
891
query .DefaultProjectID = c .projectID
898
892
query .DefaultDatasetID = c .datasetID
899
- _ , err = query .Read (ctx )
900
- if err != nil {
893
+ if _ , err := query .Read (ctx ); err != nil {
901
894
return nil , fmt .Errorf ("unable to rename table %s to %s: %w" , srcDatasetTable .string (),
902
895
dstDatasetTable .string (), err )
903
896
}
@@ -925,8 +918,7 @@ func (c *BigQueryConnector) CreateTablesFromExisting(
925
918
newDatasetTable .string (), existingDatasetTable .string ()))
926
919
query .DefaultProjectID = c .projectID
927
920
query .DefaultDatasetID = c .datasetID
928
- _ , err := query .Read (ctx )
929
- if err != nil {
921
+ if _ , err := query .Read (ctx ); err != nil {
930
922
return nil , fmt .Errorf ("unable to create table %s: %w" , newTable , err )
931
923
}
932
924
@@ -950,8 +942,7 @@ func (c *BigQueryConnector) RemoveTableEntriesFromRawTable(
950
942
rawTableIdentifier , tableName , req .NormalizeBatchId , req .SyncBatchId ))
951
943
deleteCmd .DefaultProjectID = c .projectID
952
944
deleteCmd .DefaultDatasetID = c .datasetID
953
- _ , err := deleteCmd .Read (ctx )
954
- if err != nil {
945
+ if _ , err := deleteCmd .Read (ctx ); err != nil {
955
946
c .logger .Error ("failed to remove entries from raw table" , "error" , err )
956
947
}
957
948
0 commit comments