Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error drop column with BigQuery flexible column names #20797

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading