Skip to content

Commit 1bf2390

Browse files
pipelines and bundle run: specify refresh and full-refresh together (#3300)
## Changes For pipelines run and bundle run command flags: - Allows to specify list of tables for refresh and full-refresh at the same time. - however, other flags are still mutually exclusive, and can not be specified with refresh or full-refresh. ## Why Matching OSS spark implementation and allows for more flexible running of tables ## Tests Unit tests included. Follow up with acceptance tests: #3301 --------- Co-authored-by: Jeffery Cheng <[email protected]>
1 parent cfb8158 commit 1bf2390

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
* Fixed auth login ignoring DATABRICKS_CONFIG_FILE environmental variable when saving profile ([#3266](https://github.com/databricks/cli/pull/3266))
1111

1212
### Bundles
13+
* Modified run flag validation to allow `--refresh` and `--full-refresh` flags to be used together ([#3300](https://github.com/databricks/cli/pull/3300))
1314

1415
### API Changes

bundle/run/pipeline_options.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,24 @@ func (o *PipelineOptions) Define(fs *flag.FlagSet) {
3737

3838
// Validate returns if the combination of options is valid.
3939
func (o *PipelineOptions) Validate(pipeline *resources.Pipeline) error {
40-
var set []string
40+
var mutuallyExclusiveFlags []string
41+
4142
if o.RefreshAll {
42-
set = append(set, "--refresh-all")
43-
}
44-
if len(o.Refresh) > 0 {
45-
set = append(set, "--refresh")
43+
mutuallyExclusiveFlags = append(mutuallyExclusiveFlags, "--refresh-all")
4644
}
4745
if o.FullRefreshAll {
48-
set = append(set, "--full-refresh-all")
49-
}
50-
if len(o.FullRefresh) > 0 {
51-
set = append(set, "--full-refresh")
46+
mutuallyExclusiveFlags = append(mutuallyExclusiveFlags, "--full-refresh-all")
5247
}
5348
if o.ValidateOnly {
54-
set = append(set, "--validate-only")
49+
mutuallyExclusiveFlags = append(mutuallyExclusiveFlags, "--validate-only")
5550
}
56-
if len(set) > 1 {
57-
return fmt.Errorf("pipeline run arguments are mutually exclusive (got %s)", strings.Join(set, ", "))
51+
52+
if len(mutuallyExclusiveFlags) > 1 {
53+
return fmt.Errorf("%s pipeline run flags are mutually exclusive", strings.Join(mutuallyExclusiveFlags, ", "))
54+
} else if len(mutuallyExclusiveFlags) == 1 && (len(o.Refresh) > 0 || len(o.FullRefresh) > 0) {
55+
return fmt.Errorf("cannot use --refresh or --full-refresh together with %s, these flags are mutually exclusive", strings.Join(mutuallyExclusiveFlags, ""))
5856
}
57+
5958
return nil
6059
}
6160

bundle/run/pipeline_options_test.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,20 @@ func TestPipelineOptionsValidateSuccessWithSingleOption(t *testing.T) {
6767
}
6868
}
6969

70+
func TestPipelineOptionsValidateSuccessWithRefreshAndFullRefresh(t *testing.T) {
71+
fs, opts := setupPipelineOptions(t)
72+
err := fs.Parse([]string{`--refresh=arg1,arg2`, `--full-refresh=arg3,arg4`})
73+
require.NoError(t, err)
74+
err = opts.Validate(nil)
75+
assert.NoError(t, err)
76+
assert.Equal(t, []string{"arg1", "arg2"}, opts.Refresh)
77+
assert.Equal(t, []string{"arg3", "arg4"}, opts.FullRefresh)
78+
}
79+
7080
func TestPipelineOptionsValidateFailureWithMultipleOptions(t *testing.T) {
7181
args := []string{
7282
`--refresh-all`,
73-
`--refresh=arg1,arg2,arg3`,
7483
`--full-refresh-all`,
75-
`--full-refresh=arg1,arg2,arg3`,
7684
`--validate-only`,
7785
}
7886
for i := range args {
@@ -84,7 +92,29 @@ func TestPipelineOptionsValidateFailureWithMultipleOptions(t *testing.T) {
8492
err := fs.Parse([]string{args[i], args[j]})
8593
require.NoError(t, err)
8694
err = opts.Validate(nil)
87-
assert.ErrorContains(t, err, "pipeline run arguments are mutually exclusive")
95+
assert.ErrorContains(t, err, "pipeline run flags are mutually exclusive")
96+
}
97+
}
98+
}
99+
100+
func TestPipelineOptionsValidateFailureWithRefreshAndMutuallyExclusiveFlags(t *testing.T) {
101+
args := []string{
102+
`--refresh=arg1`,
103+
`--full-refresh=arg1`,
104+
}
105+
mutuallyExclusiveArgs := []string{
106+
`--refresh-all`,
107+
`--full-refresh-all`,
108+
`--validate-only`,
109+
}
110+
111+
for _, refreshArg := range args {
112+
for _, exclusiveArg := range mutuallyExclusiveArgs {
113+
fs, opts := setupPipelineOptions(t)
114+
err := fs.Parse([]string{refreshArg, exclusiveArg})
115+
require.NoError(t, err)
116+
err = opts.Validate(nil)
117+
assert.ErrorContains(t, err, "cannot use --refresh or --full-refresh together with")
88118
}
89119
}
90120
}

0 commit comments

Comments
 (0)