Skip to content

Commit

Permalink
Fixed detecting full syntax variable override which includes type fie…
Browse files Browse the repository at this point in the history
…ld (#1775)

## Changes
Fixes #1773 

## Tests
Confirmed manually
  • Loading branch information
andrewnester authored Sep 18, 2024
1 parent e220f9d commit bcab6ca
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
21 changes: 18 additions & 3 deletions bundle/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,18 +409,33 @@ func (r *Root) MergeTargetOverrides(name string) error {
var variableKeywords = []string{"default", "lookup"}

// isFullVariableOverrideDef checks if the given value is a full syntax varaible override.
// A full syntax variable override is a map with only one of the following
// keys: "default", "lookup".
// A full syntax variable override is a map with either 1 of 2 keys.
// If it's 2 keys, the keys should be "default" and "type".
// If it's 1 key, the key should be one of the following keys: "default", "lookup".
func isFullVariableOverrideDef(v dyn.Value) bool {
mv, ok := v.AsMap()
if !ok {
return false
}

if mv.Len() != 1 {
// If the map has more than 2 keys, it is not a full variable override.
if mv.Len() > 2 {
return false
}

// If the map has 2 keys, one of them should be "default" and the other is "type"
if mv.Len() == 2 {
if _, ok := mv.GetByString("type"); !ok {
return false
}

if _, ok := mv.GetByString("default"); !ok {
return false
}

return true
}

for _, keyword := range variableKeywords {
if _, ok := mv.GetByString(keyword); ok {
return true
Expand Down
18 changes: 18 additions & 0 deletions bundle/tests/complex_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,21 @@ func TestComplexVariablesOverrideWithMultipleFiles(t *testing.T) {
require.Equalf(t, "false", cluster.NewCluster.SparkConf["spark.speculation"], "cluster: %v", cluster.JobClusterKey)
}
}

func TestComplexVariablesOverrideWithFullSyntax(t *testing.T) {
b, diags := loadTargetWithDiags("variables/complex", "dev")
require.Empty(t, diags)

diags = bundle.Apply(context.Background(), b, bundle.Seq(
mutator.SetVariables(),
mutator.ResolveVariableReferencesInComplexVariables(),
mutator.ResolveVariableReferences(
"variables",
),
))
require.NoError(t, diags.Error())
require.Empty(t, diags)

complexvar := b.Config.Variables["complexvar"].Value
require.Equal(t, map[string]interface{}{"key1": "1", "key2": "2", "key3": "3"}, complexvar)
}
13 changes: 13 additions & 0 deletions bundle/tests/variables/complex/databricks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ variables:
- jar: "/path/to/jar"
- egg: "/path/to/egg"
- whl: "/path/to/whl"
complexvar:
type: complex
description: "A complex variable"
default:
key1: "value1"
key2: "value2"
key3: "value3"


targets:
Expand All @@ -49,3 +56,9 @@ targets:
spark_conf:
spark.speculation: false
spark.databricks.delta.retentionDurationCheck.enabled: false
complexvar:
type: complex
default:
key1: "1"
key2: "2"
key3: "3"

0 comments on commit bcab6ca

Please sign in to comment.