Skip to content

Commit

Permalink
[BigQuery] Specify column names for Append (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Jun 18, 2024
1 parent 0d649bd commit 9eef6e5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions clients/bigquery/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"os"
"strings"

"cloud.google.com/go/bigquery"
"cloud.google.com/go/bigquery/storage/managedwriter"
Expand Down Expand Up @@ -67,9 +68,14 @@ func (s *Store) Append(tableData *optimization.TableData, useTempTable bool) err
return fmt.Errorf("failed to append: %w", err)
}

if _, err = s.Exec(
fmt.Sprintf(`INSERT INTO %s SELECT * FROM %s`, tableID.FullyQualifiedName(), temporaryTableID.FullyQualifiedName()),
); err != nil {
query := fmt.Sprintf(`INSERT INTO %s (%s) SELECT %s FROM %s`,
tableID.FullyQualifiedName(),
strings.Join(sql.QuoteIdentifiers(tableData.ReadOnlyInMemoryCols().GetColumnsToUpdate(), s.Dialect()), ","),
strings.Join(sql.QuoteIdentifiers(tableData.ReadOnlyInMemoryCols().GetColumnsToUpdate(), s.Dialect()), ","),
temporaryTableID.FullyQualifiedName(),
)

if _, err = s.Exec(query); err != nil {
return fmt.Errorf("failed to insert data into target table: %w", err)
}

Expand Down

0 comments on commit 9eef6e5

Please sign in to comment.