From 1381fcba4714b811eb3447dab8b144f709849ea5 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 30 Dec 2024 01:11:34 -0800 Subject: [PATCH] Fix error drop column with BigQuery flexible column names (#12626) (#8982) [upstream:102794ac7dd5df142dd4d362c034670b0a5604ff] Signed-off-by: Modular Magician --- .changelog/12626.txt | 3 +++ .../bigquery/resource_bigquery_table.go | 6 +++++- .../bigquery/resource_bigquery_table_test.go | 20 +++++++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 .changelog/12626.txt diff --git a/.changelog/12626.txt b/.changelog/12626.txt new file mode 100644 index 0000000000..f87f1361ec --- /dev/null +++ b/.changelog/12626.txt @@ -0,0 +1,3 @@ +```release-note:bug +bigquery: fixed DROP COLUMN error with bigquery flexible column names in `google_bigquery_table` +``` \ No newline at end of file diff --git a/google-beta/services/bigquery/resource_bigquery_table.go b/google-beta/services/bigquery/resource_bigquery_table.go index 566c42b1b1..55e8ce4925 100644 --- a/google-beta/services/bigquery/resource_bigquery_table.go +++ b/google-beta/services/bigquery/resource_bigquery_table.go @@ -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) diff --git a/google-beta/services/bigquery/resource_bigquery_table_test.go b/google-beta/services/bigquery/resource_bigquery_table_test.go index 27a61de23b..70a898e040 100644 --- a/google-beta/services/bigquery/resource_bigquery_table_test.go +++ b/google-beta/services/bigquery/resource_bigquery_table_test.go @@ -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 ] @@ -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 @@ -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) @@ -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 } @@ -4584,7 +4592,7 @@ resource "google_bigquery_table" "test" { ] EOF - external_catalog_table_options { + external_catalog_table_options { parameters = { owner = "hashicorp-terraform" } @@ -4639,7 +4647,7 @@ resource "google_bigquery_table" "test" { ] EOF - external_catalog_table_options { + external_catalog_table_options { parameters = { owner = "hashicorp-terraform-updated" }