-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Allow in-place column drop for bigquery table #10170
Conversation
Hello! I am a robot. Tests will require approval from a repository maintainer to run. @hao-nan-li, 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. |
/gcbrun |
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
1 similar comment
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
Tests analyticsTotal tests: Click here to see the affected service packages
Action takenFound 16 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected testsTestAccBigQueryDataTable_expandArray|TestAccBigQueryDataTable_jsonEquivalency|TestAccBigQueryExternalDataTable_CSV|TestAccBigQueryExternalDataTable_CSV_WithSchemaAndConnectionID_UpdateNoConnectionID|TestAccBigQueryExternalDataTable_CSV_WithSchema_UpdateToConnectionID|TestAccBigQueryExternalDataTable_parquetOptions|TestAccBigQueryTable_DropColumn|TestAccBigQueryTable_MaterializedView_DailyTimePartioning_Update|TestAccBigQueryTable_Update_SchemaWithPolicyTagsToEmptyPolicyTag|TestAccBigQueryTable_Update_SchemaWithPolicyTagsToEmptyPolicyTagNames|TestAccBigQueryTable_Update_SchemaWithPolicyTagsToNoPolicyTag|TestAccBigQueryTable_Update_SchemaWithoutPolicyTagsToWithPolicyTags|TestAccBigQueryTable_WithViewAndSchema|TestAccBigQueryTable_allowDestroy|TestAccBigQueryTable_updateTableConstraints|TestAccBigQueryTable_updateView |
|
Tests analyticsTotal tests: Click here to see the affected service packages
Action takenFound 16 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected testsTestAccBigQueryDataTable_expandArray|TestAccBigQueryDataTable_jsonEquivalency|TestAccBigQueryExternalDataTable_CSV|TestAccBigQueryExternalDataTable_CSV_WithSchemaAndConnectionID_UpdateNoConnectionID|TestAccBigQueryExternalDataTable_CSV_WithSchema_UpdateToConnectionID|TestAccBigQueryExternalDataTable_parquetOptions|TestAccBigQueryTable_DropColumn|TestAccBigQueryTable_MaterializedView_DailyTimePartioning_Update|TestAccBigQueryTable_Update_SchemaWithPolicyTagsToEmptyPolicyTag|TestAccBigQueryTable_Update_SchemaWithPolicyTagsToEmptyPolicyTagNames|TestAccBigQueryTable_Update_SchemaWithPolicyTagsToNoPolicyTag|TestAccBigQueryTable_Update_SchemaWithoutPolicyTagsToWithPolicyTags|TestAccBigQueryTable_WithViewAndSchema|TestAccBigQueryTable_allowDestroy|TestAccBigQueryTable_updateTableConstraints|TestAccBigQueryTable_updateView |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you briefly explain why this change is necessary?
mmv1/third_party/terraform/services/bigquery/resource_bigquery_table.go
Outdated
Show resolved
Hide resolved
mmv1/third_party/terraform/services/bigquery/resource_bigquery_table.go
Outdated
Show resolved
Hide resolved
return false, err | ||
} | ||
} | ||
return true, nil | ||
// only pure column drops allowed | ||
return (droppedColumns == 0) || (len(arrayOld) == len(arrayNew)+droppedColumns), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this logic would be more self-descriptive if we also tracked
e.g. "sameColumns" as we loop through the keys and just check old map size against the sum here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "changeableColumns" would be more precise since changing a column's mode would be allowed alongside column drops, let me know if you think we should change this to only column drops without other in-place changes (besides adding columns)
and just check old map size against the sum here instead?
hmm not sure if I get it, if the condition is something like
(droppedColumns == 0) || (len(arrayOld) == changeableColumns+droppedColumns)
then it wouldn't work correctly, for example when changing {col1, col2, col3}
to {col1, col4, col5}
the condition would result in true
(changeableColumns=1
, droppedColumns=2
)
I think we can do something like:
newColumns := len(arrayNew) - changeableColumns
return (droppedColumns == 0) || (newColumns == 0), nil
what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's still include other in-place changes. Naming is hard though - the columns would have the same name but maybe different other attributes. "SameNameColumns"?
Your updated logic looks good.
mmv1/third_party/terraform/services/bigquery/resource_bigquery_table_internal_test.go
Outdated
Show resolved
Hide resolved
mmv1/third_party/terraform/services/bigquery/resource_bigquery_table_internal_test.go
Outdated
Show resolved
Hide resolved
@hao-nan-li many customers are having a hard time managing BigQuery tables when applying some types of changes to the More info: hashicorp/terraform-provider-google#14769 b/298496481 |
/gcbrun |
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
Tests analyticsTotal tests: Click here to see the affected service packages
Action takenFound 4 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected testsTestAccBigQueryTable_DropColumns|TestAccBigQueryTable_Update_SchemaWithPolicyTagsToEmptyPolicyTag|TestAccBigQueryTable_Update_SchemaWithPolicyTagsToEmptyPolicyTagNames|TestAccBigQueryTable_Update_SchemaWithPolicyTagsToNoPolicyTag |
|
mmv1/third_party/terraform/services/bigquery/resource_bigquery_table.go
Outdated
Show resolved
Hide resolved
mmv1/third_party/terraform/services/bigquery/resource_bigquery_table_internal_test.go
Show resolved
Hide resolved
return false, err | ||
} | ||
} | ||
return true, nil | ||
// only pure column drops allowed | ||
return (droppedColumns == 0) || (len(arrayOld) == len(arrayNew)+droppedColumns), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's still include other in-place changes. Naming is hard though - the columns would have the same name but maybe different other attributes. "SameNameColumns"?
Your updated logic looks good.
/gcbrun |
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
1 similar comment
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
Tests analyticsTotal tests: Click here to see the affected service packages
|
Tests analyticsTotal tests: Click here to see the affected service packages
|
Tests analyticsTotal tests: Click here to see the affected service packages
|
mmv1/third_party/terraform/services/bigquery/resource_bigquery_table_internal_test.go
Outdated
Show resolved
Hide resolved
@@ -298,9 +299,13 @@ func resourceBigQueryTableSchemaIsChangeable(old, new interface{}, topLevel bool | |||
resourceBigQueryTableSchemaIsChangeable(mapOld[key], mapNew[key], false); err != nil || !isChangable { | |||
return false, err | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we'd be updating this as we look through mapOld
and comparing key to mapNew
- could you explain how this is working as intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure I understand the question correctly, we are going through the keys in mapOld
and comparing to mapNew
, but we're doing it recursively because of the nature of the schema (nested interfaces). We immediately return false (not changeable) if we encounter an unchangeable case, for example a column that had it's type changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was referring to this block:
if topLevel {
sameNameColumns += 1
}
At a glance, in a single given level, top or nested, sameNameColumns
will be 0 or 1. Additional comments on the variables and the logic here would help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sameNameColumns
is always 0 for any nested level, and could be 0 or more at the top level. I refactored this part of the code, it should still be the same logic but I think It's more readable now and less prone to accidental logic-breaking changes.
Thank you for double checking and making the corresponding change! |
/gcbrun |
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
Tests analyticsTotal tests: Click here to see the affected service packages
|
@hao-nan-li can you take a look |
Partial fix for hashicorp/terraform-provider-google#14769
Column deletion reference: https://cloud.google.com/bigquery/docs/managing-table-schemas#delete_a_column
Release Note Template for Downstream PRs (will be copied)