From ab805776062764a94b97020444dd8d94b26e4b10 Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Mon, 17 Jun 2024 18:23:45 -0700 Subject: [PATCH] Move defer up --- clients/bigquery/bigquery.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clients/bigquery/bigquery.go b/clients/bigquery/bigquery.go index 12123a14..132f0176 100644 --- a/clients/bigquery/bigquery.go +++ b/clients/bigquery/bigquery.go @@ -55,6 +55,9 @@ func (s *Store) Append(tableData *optimization.TableData, useTempTable bool) err // For now, we'll need to append this to a temporary table and then append temporary table onto the target table tableID := s.IdentifierFor(tableData.TopicConfig(), tableData.Name()) temporaryTableID := shared.TempTableID(tableID) + + defer func() { _ = ddl.DropTemporaryTable(s, temporaryTableID, false) }() + err := shared.Append(s, tableData, types.AdditionalSettings{ UseTempTable: true, TempTableID: temporaryTableID, @@ -64,8 +67,6 @@ func (s *Store) Append(tableData *optimization.TableData, useTempTable bool) err return fmt.Errorf("failed to append: %w", err) } - defer func() { _ = ddl.DropTemporaryTable(s, temporaryTableID, false) }() - if _, err = s.Exec( fmt.Sprintf(`INSERT INTO %s SELECT * FROM %s`, tableID.FullyQualifiedName(), temporaryTableID.FullyQualifiedName()), ); err != nil {