-
Notifications
You must be signed in to change notification settings - Fork 398
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
Remove empty lines from view_definition to avoid unecessary recreation of resources #3361
base: main
Are you sure you want to change the base?
Remove empty lines from view_definition to avoid unecessary recreation of resources #3361
Conversation
hello @mgyucht do you think this is ready for review? |
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.
This looks good to me. @alexott Do you have any concerns with this?
Only thing is that we should have one integration test to verify this behaves as expected and prevent regression. Look at internal/acceptance/sql_table_test.go
. If you install the Databricks CLI (https://github.com/databricks/cli) and login to your workspace, you should be able to run any test. Can you try to add a test for view definition with multiple lines?
My main concern is things like this:
This will break view definitions like this, where it's split between multiple lines:
will become:
This really should be discussed with the SQL engineering team if it makes sense to do it. But from the error description, the issue is caused by empty lines, not by newlines, so the replacement should be from this regex |
hello @alexott, this will remove both, empty lines and empty lines with spaces, both would cause problems |
I will add the integration test later today @mgyucht |
@mgyucht I have added one acceptance test. Let me know if I should make changes to this test |
hello @mgyucht |
@alvaroqueiroz could you resolve the merge conflict for this one? For this change, could you add a unit test that validates there would not be a change when there is diff between |
…s://github.com/alvaroqueiroz/terraform-provider-databricks into fix-new-lines-causing-replacement-of-resources
done @nkvuong |
@alvaroqueiroz the conflict resolution for |
@nkvuong I have synced my fork with the master, |
@alvaroqueiroz build/fmt is already failing - https://github.com/databricks/terraform-provider-databricks/actions/runs/8466731468/job/23199236255?pr=3361 |
…s://github.com/alvaroqueiroz/terraform-provider-databricks into fix-new-lines-causing-replacement-of-resources
@nkvuong fixed |
this test |
@nkvuong I think I'm not setting up the test correctly for some reason. Even If I use the old |
@alvaroqueiroz for unit testing, you could follow the examples of |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3361 +/- ##
==========================================
+ Coverage 83.51% 83.53% +0.02%
==========================================
Files 178 178
Lines 16708 16718 +10
==========================================
+ Hits 13954 13966 +12
+ Misses 1901 1900 -1
+ Partials 853 852 -1
|
@nkvuong I have tested with ExpectedDiff, I see the same behaviour. func TestResourceSqlTableUpdateView_IgnoreNewlineInDefinition(t *testing.T) {
qa.ResourceFixture{
InstanceState: map[string]string{
"name": "barview",
"catalog_name": "main",
"schema_name": "foo",
"table_type": "VIEW",
"cluster_id": "existingcluster",
"view_definition": "SELECT * FROM main.foo.bar",
},
ExpectedDiff: map[string]*terraform.ResourceAttrDiff{
"catalog_name": {
Old: "main",
New: "main",
RequiresNew: false,
},
"cluster_id": {
Old: "existingcluster",
New: "existingcluster",
RequiresNew: false,
},
"name": {
Old: "barview",
New: "barview",
RequiresNew: false,
},
"schema_name": {
Old: "foo",
New: "foo",
RequiresNew: false,
},
"table_type": {
Old: "VIEW",
New: "VIEW",
RequiresNew: false,
},
"view_definition": {
Old: "SELECT * FROM main.foo.bar",
New: "SELECT * FROM main.foo.bar",
NewComputed: false,
RequiresNew: false,
NewRemoved: false,
Sensitive: false,
},
"column.#": {
Old: "",
New: "",
NewComputed: true,
RequiresNew: true,
},
"properties.%": {
Old: "",
New: "",
NewComputed: true,
RequiresNew: false,
},
},
HCL: `
name = "barview"
catalog_name = "main"
schema_name = "foo"
table_type = "VIEW"
cluster_id = "existingcluster"
view_definition = "SELECT * FROM main.foo.bar "
`,
Resource: ResourceSqlTable(),
ID: "main.foo.barview",
}.ApplyNoError(t)
} |
@alvaroqueiroz Appreciate your work. I see a lot of value in this fix, as this unnecessary detection of changes increases the |
Changes
This PR solves the problem described here: #3330
empty new lines on view_definition cause terraform to plan to change the view definition.
This PR adds the removal of empty lines to
DiffSuppressFunc
to avoid this problemTests
make test
run locallydocs/
folderinternal/acceptance