Skip to content

Commit 92357dc

Browse files
authored
[Fix] Handle edge case for effective_properties in databricks_sql_table (#4153)
## Changes <!-- Summary of your changes that are easy to understand --> It was reported in #4098 that some of the specified options, like, `multiLine`, `recursiveFileLookup` and potentially more, aren't returned as `option.multiLine`, etc., but instead are expanded into full names, like, `spark.sql.dataSourceOptions.multiLine`. This PR changes lookup logic a bit, and if we can't find `option.something`, then we're looking for all options ending with `.something` (only if there are no `.` in the name). Resolves #4098 ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] relevant acceptance tests are passing - [ ] using Go SDK
1 parent 0975310 commit 92357dc

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

catalog/resource_sql_table.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
)
2222

2323
var MaxSqlExecWaitTimeout = 50
24+
var optionPrefixes = []string{"option.", "spark.sql.dataSourceOptions."}
2425

2526
type SqlColumnInfo struct {
2627
Name string `json:"name"`
@@ -67,7 +68,6 @@ type SqlTableInfo struct {
6768
}
6869

6970
func (ti SqlTableInfo) CustomizeSchema(s *common.CustomizableSchema) *common.CustomizableSchema {
70-
7171
caseInsensitiveFields := []string{"name", "catalog_name", "schema_name"}
7272
for _, field := range caseInsensitiveFields {
7373
s.SchemaPath(field).SetCustomSuppressDiff(common.EqualFoldDiffSuppress)
@@ -598,18 +598,31 @@ func ResourceSqlTable() common.Resource {
598598
// If the user specified a property but the value of that property has changed, that will appear
599599
// as a change in the effective property/option. To cause a diff to be detected, we need to
600600
// reset the effective property/option to the requested value.
601-
userSpecifiedProperties := d.Get("properties").(map[string]interface{})
602-
userSpecifiedOptions := d.Get("options").(map[string]interface{})
603-
effectiveProperties := d.Get("effective_properties").(map[string]interface{})
604-
diff := make(map[string]interface{})
601+
userSpecifiedProperties := d.Get("properties").(map[string]any)
602+
userSpecifiedOptions := d.Get("options").(map[string]any)
603+
effectiveProperties := d.Get("effective_properties").(map[string]any)
604+
diff := make(map[string]any)
605605
for k, userSpecifiedValue := range userSpecifiedProperties {
606606
if effectiveValue, ok := effectiveProperties[k]; !ok || effectiveValue != userSpecifiedValue {
607607
diff[k] = userSpecifiedValue
608608
}
609609
}
610-
for k, userSpecifiedValue := range userSpecifiedOptions {
611-
if effectiveValue, ok := effectiveProperties["option."+k]; !ok || effectiveValue != userSpecifiedValue {
612-
diff["option."+k] = userSpecifiedValue
610+
for userOptName, userSpecifiedValue := range userSpecifiedOptions {
611+
var found bool
612+
var effectiveValue any
613+
var effectOptName string
614+
// If the option is not found, check if the user specified the option without the prefix
615+
// i.e. if user specified `multiLine` for JSON, then backend returns `spark.sql.dataSourceOptions.multiLine`
616+
for _, prefix := range optionPrefixes {
617+
effectOptName = prefix + userOptName
618+
if v, ok := effectiveProperties[effectOptName]; ok {
619+
found = true
620+
effectiveValue = v
621+
break
622+
}
623+
}
624+
if !found || effectiveValue != userSpecifiedValue {
625+
diff[effectOptName] = userSpecifiedValue
613626
}
614627
}
615628
if len(diff) > 0 {

catalog/resource_sql_table_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,15 +1625,18 @@ func TestResourceSqlTable_Diff_ExistingResource(t *testing.T) {
16251625
}
16261626
options = {
16271627
"myopt" = "myval"
1628+
"multiLine" = "true"
16281629
}`,
16291630
map[string]string{
16301631
"properties.%": "1",
16311632
"properties.myprop": "myval",
1632-
"options.%": "1",
1633+
"options.%": "2",
16331634
"options.myopt": "myval",
1634-
"effective_properties.%": "2",
1635+
"options.multiLine": "true",
1636+
"effective_properties.%": "3",
16351637
"effective_properties.myprop": "myval",
16361638
"effective_properties.option.myopt": "myval",
1639+
"effective_properties.spark.sql.dataSourceOptions.multiLine": "true",
16371640
},
16381641
nil,
16391642
},

0 commit comments

Comments
 (0)