Skip to content

Commit

Permalink
Fix error drop column with BigQuery flexible column names (#12626) (#…
Browse files Browse the repository at this point in the history
…20797)

[upstream:102794ac7dd5df142dd4d362c034670b0a5604ff]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Dec 30, 2024
1 parent f455356 commit dd86703
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/12626.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
bigquery: fixed DROP COLUMN error with bigquery flexible column names in `google_bigquery_table`
```
6 changes: 5 additions & 1 deletion google/services/bigquery/resource_bigquery_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,11 @@ func resourceBigQueryTableColumnDrop(config *transport_tpg.Config, userAgent str
}

if len(droppedColumns) > 0 {
droppedColumnsString := strings.Join(droppedColumns, ", DROP COLUMN ")
backquotedDroppedColumns := []string{}
for _, column := range droppedColumns {
backquotedDroppedColumns = append(backquotedDroppedColumns, fmt.Sprintf("`%s`", column))
}
droppedColumnsString := strings.Join(backquotedDroppedColumns, ", DROP COLUMN ")

dropColumnsDDL := fmt.Sprintf("ALTER TABLE `%s.%s.%s` DROP COLUMN %s", tableReference.project, tableReference.datasetID, tableReference.tableID, droppedColumnsString)
log.Printf("[INFO] Dropping columns in-place: %s", dropColumnsDDL)
Expand Down
16 changes: 12 additions & 4 deletions google/services/bigquery/resource_bigquery_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ func testAccBigLakeManagedTable(bucketName, connectionID, datasetID, tableID, sc
file_format = "PARQUET"
table_format = "ICEBERG"
}
schema = jsonencode(%s)
depends_on = [
google_project_iam_member.test
]
Expand Down Expand Up @@ -2162,6 +2162,14 @@ resource "google_bigquery_table" "test" {
{
"name": "some_int",
"type": "INTEGER"
},
{
"name": "reserved_word_for",
"type": "STRING"
},
{
"name": "flexible-column-name-dash",
"type": "STRING"
}
]
EOH
Expand Down Expand Up @@ -3070,7 +3078,7 @@ resource "google_bigquery_table" "test" {
# Depends on Iceberg Table Files
depends_on = [
google_storage_bucket_object.empty_data_folder,
google_storage_bucket_object.metadata,
google_storage_bucket_object.metadata,
]
}
`, datasetID, bucketName, tableID)
Expand Down Expand Up @@ -3098,7 +3106,7 @@ resource "google_storage_bucket_object" "datafile" {
# Upload Metadata file
resource "google_storage_bucket_object" "manifest" {
name = "%s"
name = "%s"
content = "gs://${google_storage_bucket.test.name}/${google_storage_bucket_object.datafile.name}"
bucket = google_storage_bucket.test.name
}
Expand Down

0 comments on commit dd86703

Please sign in to comment.