Skip to content

Commit

Permalink
Wrap error and also delete temp table once it's inserted.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Jun 18, 2024
1 parent edf6033 commit 83d6d0a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions clients/bigquery/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ func (s *Store) Append(tableData *optimization.TableData, useTempTable bool) err
return fmt.Errorf("failed to append: %w", err)
}

_, err = s.Exec(
defer func() { _ = ddl.DropTemporaryTable(s, temporaryTableID, false) }()

if _, err = s.Exec(
fmt.Sprintf(`INSERT INTO %s SELECT * FROM %s`, tableID.FullyQualifiedName(), temporaryTableID.FullyQualifiedName()),
)
return err
); err != nil {
return fmt.Errorf("failed to insert data into target table: %w", err)
}

return nil
}

func (s *Store) PrepareTemporaryTable(tableData *optimization.TableData, tableConfig *types.DwhTableConfig, tempTableID sql.TableIdentifier, _ types.AdditionalSettings, createTempTable bool) error {
Expand Down

0 comments on commit 83d6d0a

Please sign in to comment.