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
…8982)

[upstream:102794ac7dd5df142dd4d362c034670b0a5604ff]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Dec 30, 2024
1 parent f16ba81 commit 1381fcb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 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-beta/services/bigquery/resource_bigquery_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,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
20 changes: 14 additions & 6 deletions google-beta/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 @@ -2198,6 +2198,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 @@ -3106,7 +3114,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 @@ -3134,7 +3142,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 Expand Up @@ -4584,7 +4592,7 @@ resource "google_bigquery_table" "test" {
]
EOF
external_catalog_table_options {
external_catalog_table_options {
parameters = {
owner = "hashicorp-terraform"
}
Expand Down Expand Up @@ -4639,7 +4647,7 @@ resource "google_bigquery_table" "test" {
]
EOF
external_catalog_table_options {
external_catalog_table_options {
parameters = {
owner = "hashicorp-terraform-updated"
}
Expand Down

0 comments on commit 1381fcb

Please sign in to comment.