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 #12626

Merged
merged 4 commits into from
Dec 30, 2024

Conversation

shoumoji
Copy link
Contributor

@shoumoji shoumoji commented Dec 20, 2024

Fix: hashicorp/terraform-provider-google#20750

Release Note Template for Downstream PRs (will be copied)

See Write release notes for guidance.

bigquery: fixed DROP COLUMN error with bigquery flexible column names in `google_bigquery_table`

Copy link

google-cla bot commented Dec 20, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Dec 20, 2024
Comment on lines -2087 to +2091
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 ")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If droppedColumns = []string("column1", "column2") ,

backquotedDroppedColumns = []string("`column1`", "`column2`")
droppedColumnsString = "`column1`, DROP COLUMN `column2`"
dropColumnsDDL = "ALTER TABLE <table_id> DROP Column `column1`, DROP COLUMN `column2`"

@shoumoji shoumoji marked this pull request as ready for review December 20, 2024 01:49
Copy link

Hello! I am a robot. Tests will require approval from a repository maintainer to run.

@shuyama1, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 1 file changed, 5 insertions(+), 1 deletion(-))
google-beta provider: Diff ( 1 file changed, 5 insertions(+), 1 deletion(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 128
Passed tests: 114
Skipped tests: 10
Affected tests: 4

Click here to see the affected service packages
  • bigquery

Action taken

Found 4 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccBigQueryTable_DropColumns
  • TestAccBigQueryTable_Update_SchemaWithPolicyTagsToEmptyPolicyTag
  • TestAccBigQueryTable_Update_SchemaWithPolicyTagsToEmptyPolicyTagNames
  • TestAccBigQueryTable_Update_SchemaWithPolicyTagsToNoPolicyTag

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

🟢 Tests passed during RECORDING mode:
TestAccBigQueryTable_DropColumns [Debug log]
TestAccBigQueryTable_Update_SchemaWithPolicyTagsToEmptyPolicyTag [Debug log]
TestAccBigQueryTable_Update_SchemaWithPolicyTagsToEmptyPolicyTagNames [Debug log]
TestAccBigQueryTable_Update_SchemaWithPolicyTagsToNoPolicyTag [Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🟢 All tests passed!

View the build log or the debug log for each test

@wj-chen
Copy link
Member

wj-chen commented Dec 20, 2024

Thank you for the fix! Can you also update the test in

func TestAccBigQueryTable_DropColumns(t *testing.T) {
to cover dropping a column with a reserved word in the name?

Copy link

@shuyama1 This PR has been waiting for review for 3 weekdays. Please take a look! Use the label disable-review-reminders to disable these notifications.

@shoumoji
Copy link
Contributor Author

shoumoji commented Dec 24, 2024

@wj-chen

The test results revealed that the cause of this error is not a reserved word, but rather the use of flexible column name with a dash character.

Therefore, I added tests and update of the issue and PR.
There are no changes to the code, as this issue can be resolved by backquoting the column names.

e.g.

  • Success test case: the column name for
    • reserved word "for"
  • Fail test case: the column name foo-bar, foo&bar and foo=bar
    • no reserved word, but with flexibile column name "-", "&" and "="

@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Dec 24, 2024
@shoumoji shoumoji changed the title Fix error drop column with reserved word Fix error drop column with BigQuery flexible column names Dec 24, 2024
Copy link

@GoogleCloudPlatform/terraform-team @shuyama1 This PR has been waiting for review for 1 week. Please take a look! Use the label disable-review-reminders to disable these notifications.

@modular-magician modular-magician removed the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Dec 26, 2024
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 2 files changed, 17 insertions(+), 5 deletions(-))
google-beta provider: Diff ( 2 files changed, 19 insertions(+), 7 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 128
Passed tests: 117
Skipped tests: 10
Affected tests: 1

Click here to see the affected service packages
  • bigquery

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccBigQueryTable_DropColumns

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

🟢 Tests passed during RECORDING mode:
TestAccBigQueryTable_DropColumns [Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🟢 All tests passed!

View the build log or the debug log for each test

Copy link
Member

@wj-chen wj-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment about indentation otherwise looks good, thank you

@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Dec 27, 2024
@shoumoji
Copy link
Contributor Author

One comment about indentation otherwise looks good, thank you

@wj-chen
Thank you for the review!!
I fixed it.

@modular-magician modular-magician removed the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Dec 30, 2024
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 2 files changed, 17 insertions(+), 5 deletions(-))
google-beta provider: Diff ( 2 files changed, 19 insertions(+), 7 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 128
Passed tests: 118
Skipped tests: 10
Affected tests: 0

Click here to see the affected service packages
  • bigquery

🟢 All tests passed!

View the build log

Copy link
Member

@shuyama1 shuyama1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

google_bigquery_table error attempting to DROP COLUMN with flexible column name
4 participants