Skip to content

Commit

Permalink
changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Sep 20, 2024
1 parent 5e808d1 commit 65ece76
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ import (
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
)

func (w *TaskAssert) HasNotEmptyCreatedOn() *TaskAssert {
w.AddAssertion(func(t *testing.T, o *sdk.Task) error {
func (t *TaskAssert) HasNotEmptyCreatedOn() *TaskAssert {
t.AddAssertion(func(t *testing.T, o *sdk.Task) error {
t.Helper()
if o.CreatedOn == "" {
return fmt.Errorf("expected created on not empty; got: %v", o.CreatedOn)
}
return nil
})
return w
return t
}

func (w *TaskAssert) HasNotEmptyId() *TaskAssert {
w.AddAssertion(func(t *testing.T, o *sdk.Task) error {
func (t *TaskAssert) HasNotEmptyId() *TaskAssert {
t.AddAssertion(func(t *testing.T, o *sdk.Task) error {
t.Helper()
if o.Id == "" {
return fmt.Errorf("expected id not empty; got: %v", o.CreatedOn)
}
return nil
})
return w
return t
}

func (w *TaskAssert) HasPredecessors(ids ...sdk.SchemaObjectIdentifier) *TaskAssert {
w.AddAssertion(func(t *testing.T, o *sdk.Task) error {
func (t *TaskAssert) HasPredecessors(ids ...sdk.SchemaObjectIdentifier) *TaskAssert {
t.AddAssertion(func(t *testing.T, o *sdk.Task) error {
t.Helper()
if len(o.Predecessors) != len(ids) {
return fmt.Errorf("expected %d (%v) predecessors, got %d (%v)", len(ids), ids, len(o.Predecessors), o.Predecessors)
Expand All @@ -48,7 +48,7 @@ func (w *TaskAssert) HasPredecessors(ids ...sdk.SchemaObjectIdentifier) *TaskAss
}
return errors.Join(errs...)
})
return w
return t
}

func (t *TaskAssert) HasTaskRelations(expected sdk.TaskRelations) *TaskAssert {
Expand Down
15 changes: 9 additions & 6 deletions pkg/sdk/tasks_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var task = g.PlainStruct("Task").
Text("Definition").
OptionalText("Condition").
Bool("AllowOverlappingExecution").
OptionalText("ErrorIntegration").
Field("ErrorIntegration", g.KindOfTSlice[AccountObjectIdentifier]()).
OptionalText("LastCommittedOn").
OptionalText("LastSuspendedOn").
Text("OwnerRoleType").
Expand Down Expand Up @@ -146,7 +146,7 @@ var TasksDef = g.NewInterface(
OptionalSessionParameters().
OptionalNumberAssignment("USER_TASK_TIMEOUT_MS", nil).
OptionalNumberAssignment("SUSPEND_TASK_AFTER_NUM_FAILURES", nil).
OptionalTextAssignment("ERROR_INTEGRATION", g.ParameterOptions().NoQuotes()).
OptionalIdentifier("ErrorNotificationIntegration", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Equals().SQL("ERROR_INTEGRATION")).
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()).
OptionalIdentifier("Finalize", g.KindOfT[SchemaObjectIdentifier](), g.IdentifierOptions().Equals().SQL("FINALIZE")).
OptionalNumberAssignment("TASK_AUTO_RETRY_ATTEMPTS", g.ParameterOptions()).
Expand All @@ -157,6 +157,7 @@ var TasksDef = g.NewInterface(
SQL("AS").
Text("sql", g.KeywordOptions().NoQuotes().Required()).
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ValidIdentifierIfSet, "ErrorNotificationIntegration").
WithValidation(g.ConflictingFields, "OrReplace", "IfNotExists"),
taskCreateWarehouse,
).
Expand All @@ -174,15 +175,16 @@ var TasksDef = g.NewInterface(
OptionalNumberAssignment("USER_TASK_TIMEOUT_MS", nil).
OptionalSessionParameters().
OptionalNumberAssignment("SUSPEND_TASK_AFTER_NUM_FAILURES", nil).
OptionalTextAssignment("ERROR_INTEGRATION", g.ParameterOptions().NoQuotes()).
OptionalIdentifier("ErrorNotificationIntegration", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Equals().SQL("ERROR_INTEGRATION")).
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()).
OptionalIdentifier("Finalize", g.KindOfT[SchemaObjectIdentifier](), g.IdentifierOptions().Equals().SQL("FINALIZE")).
OptionalNumberAssignment("TASK_AUTO_RETRY_ATTEMPTS", g.ParameterOptions()).
List("AFTER", g.KindOfT[SchemaObjectIdentifier](), g.ListOptions()).
OptionalTextAssignment("WHEN", g.ParameterOptions().NoQuotes().NoEquals()).
SQL("AS").
Text("sql", g.KeywordOptions().NoQuotes().Required()).
WithValidation(g.ValidIdentifier, "name"),
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ValidIdentifierIfSet, "ErrorNotificationIntegration"),
).
CustomOperation(
"Clone",
Expand Down Expand Up @@ -219,13 +221,14 @@ var TasksDef = g.NewInterface(
OptionalBooleanAssignment("ALLOW_OVERLAPPING_EXECUTION", nil).
OptionalNumberAssignment("USER_TASK_TIMEOUT_MS", nil).
OptionalNumberAssignment("SUSPEND_TASK_AFTER_NUM_FAILURES", nil).
OptionalTextAssignment("ERROR_INTEGRATION", g.ParameterOptions().NoQuotes()).
OptionalIdentifier("ErrorNotificationIntegration", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Equals().SQL("ERROR_INTEGRATION")).
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()).
OptionalSessionParameters().
OptionalNumberAssignment("TASK_AUTO_RETRY_ATTEMPTS", nil).
OptionalNumberAssignment("USER_TASK_MINIMUM_TRIGGER_INTERVAL_IN_SECONDS", nil).
WithValidation(g.AtLeastOneValueSet, "Warehouse", "UserTaskManagedInitialWarehouseSize", "Schedule", "Config", "AllowOverlappingExecution", "UserTaskTimeoutMs", "SuspendTaskAfterNumFailures", "ErrorIntegration", "Comment", "SessionParameters", "TaskAutoRetryAttempts", "UserTaskMinimumTriggerIntervalInSeconds").
WithValidation(g.ConflictingFields, "Warehouse", "UserTaskManagedInitialWarehouseSize"),
WithValidation(g.ConflictingFields, "Warehouse", "UserTaskManagedInitialWarehouseSize").
WithValidation(g.ValidIdentifierIfSet, "ErrorNotificationIntegration"),
g.ListOptions().SQL("SET"),
).
OptionalQueryStructField(
Expand Down
12 changes: 6 additions & 6 deletions pkg/sdk/tasks_dto_builders_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions pkg/sdk/tasks_dto_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type CreateTaskRequest struct {
SessionParameters *SessionParameters
UserTaskTimeoutMs *int
SuspendTaskAfterNumFailures *int
ErrorIntegration *string
ErrorNotificationIntegration *AccountObjectIdentifier
Comment *string
Finalize *SchemaObjectIdentifier
TaskAutoRetryAttempts *int
Expand All @@ -45,21 +45,21 @@ func (r *CreateTaskRequest) GetName() SchemaObjectIdentifier {
}

type CreateOrAlterTaskRequest struct {
name SchemaObjectIdentifier // required
Warehouse *CreateTaskWarehouseRequest
Schedule *string
Config *string
AllowOverlappingExecution *bool
UserTaskTimeoutMs *int
SessionParameters *SessionParameters
SuspendTaskAfterNumFailures *int
ErrorIntegration *string
Comment *string
Finalize *SchemaObjectIdentifier
TaskAutoRetryAttempts *int
After []SchemaObjectIdentifier
When *string
sql string // required
name SchemaObjectIdentifier // required
Warehouse *CreateTaskWarehouseRequest
Schedule *string
Config *string
AllowOverlappingExecution *bool
UserTaskTimeoutMs *int
SessionParameters *SessionParameters
SuspendTaskAfterNumFailures *int
ErrorNotificationIntegration *AccountObjectIdentifier
Comment *string
Finalize *SchemaObjectIdentifier
TaskAutoRetryAttempts *int
After []SchemaObjectIdentifier
When *string
sql string // required
}

func (r *CreateOrAlterTaskRequest) GetName() SchemaObjectIdentifier {
Expand Down Expand Up @@ -103,7 +103,7 @@ type TaskSetRequest struct {
AllowOverlappingExecution *bool
UserTaskTimeoutMs *int
SuspendTaskAfterNumFailures *int
ErrorIntegration *string
ErrorNotificationIntegration *AccountObjectIdentifier
Comment *string
SessionParameters *SessionParameters
TaskAutoRetryAttempts *int
Expand Down
42 changes: 21 additions & 21 deletions pkg/sdk/tasks_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type CreateTaskOptions struct {
SessionParameters *SessionParameters `ddl:"list,no_parentheses"`
UserTaskTimeoutMs *int `ddl:"parameter" sql:"USER_TASK_TIMEOUT_MS"`
SuspendTaskAfterNumFailures *int `ddl:"parameter" sql:"SUSPEND_TASK_AFTER_NUM_FAILURES"`
ErrorIntegration *string `ddl:"parameter,no_quotes" sql:"ERROR_INTEGRATION"`
ErrorNotificationIntegration *AccountObjectIdentifier `ddl:"identifier,equals" sql:"ERROR_INTEGRATION"`
Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"`
Finalize *SchemaObjectIdentifier `ddl:"identifier,equals" sql:"FINALIZE"`
TaskAutoRetryAttempts *int `ddl:"parameter" sql:"TASK_AUTO_RETRY_ATTEMPTS"`
Expand All @@ -52,24 +52,24 @@ type CreateTaskWarehouse struct {

// CreateOrAlterTaskOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-task#create-or-alter-task.
type CreateOrAlterTaskOptions struct {
createOrAlter bool `ddl:"static" sql:"CREATE OR ALTER"`
task bool `ddl:"static" sql:"TASK"`
name SchemaObjectIdentifier `ddl:"identifier"`
Warehouse *CreateTaskWarehouse `ddl:"keyword"`
Schedule *string `ddl:"parameter,single_quotes" sql:"SCHEDULE"`
Config *string `ddl:"parameter,no_quotes" sql:"CONFIG"`
AllowOverlappingExecution *bool `ddl:"parameter" sql:"ALLOW_OVERLAPPING_EXECUTION"`
UserTaskTimeoutMs *int `ddl:"parameter" sql:"USER_TASK_TIMEOUT_MS"`
SessionParameters *SessionParameters `ddl:"list,no_parentheses"`
SuspendTaskAfterNumFailures *int `ddl:"parameter" sql:"SUSPEND_TASK_AFTER_NUM_FAILURES"`
ErrorIntegration *string `ddl:"parameter,no_quotes" sql:"ERROR_INTEGRATION"`
Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"`
Finalize *SchemaObjectIdentifier `ddl:"identifier,equals" sql:"FINALIZE"`
TaskAutoRetryAttempts *int `ddl:"parameter" sql:"TASK_AUTO_RETRY_ATTEMPTS"`
After []SchemaObjectIdentifier `ddl:"parameter,no_equals" sql:"AFTER"`
When *string `ddl:"parameter,no_quotes,no_equals" sql:"WHEN"`
as bool `ddl:"static" sql:"AS"`
sql string `ddl:"keyword,no_quotes"`
createOrAlter bool `ddl:"static" sql:"CREATE OR ALTER"`
task bool `ddl:"static" sql:"TASK"`
name SchemaObjectIdentifier `ddl:"identifier"`
Warehouse *CreateTaskWarehouse `ddl:"keyword"`
Schedule *string `ddl:"parameter,single_quotes" sql:"SCHEDULE"`
Config *string `ddl:"parameter,no_quotes" sql:"CONFIG"`
AllowOverlappingExecution *bool `ddl:"parameter" sql:"ALLOW_OVERLAPPING_EXECUTION"`
UserTaskTimeoutMs *int `ddl:"parameter" sql:"USER_TASK_TIMEOUT_MS"`
SessionParameters *SessionParameters `ddl:"list,no_parentheses"`
SuspendTaskAfterNumFailures *int `ddl:"parameter" sql:"SUSPEND_TASK_AFTER_NUM_FAILURES"`
ErrorNotificationIntegration *AccountObjectIdentifier `ddl:"identifier,equals" sql:"ERROR_INTEGRATION"`
Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"`
Finalize *SchemaObjectIdentifier `ddl:"identifier,equals" sql:"FINALIZE"`
TaskAutoRetryAttempts *int `ddl:"parameter" sql:"TASK_AUTO_RETRY_ATTEMPTS"`
After []SchemaObjectIdentifier `ddl:"parameter,no_equals" sql:"AFTER"`
When *string `ddl:"parameter,no_quotes,no_equals" sql:"WHEN"`
as bool `ddl:"static" sql:"AS"`
sql string `ddl:"keyword,no_quotes"`
}

// CloneTaskOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-task#create-task-clone.
Expand Down Expand Up @@ -112,7 +112,7 @@ type TaskSet struct {
AllowOverlappingExecution *bool `ddl:"parameter" sql:"ALLOW_OVERLAPPING_EXECUTION"`
UserTaskTimeoutMs *int `ddl:"parameter" sql:"USER_TASK_TIMEOUT_MS"`
SuspendTaskAfterNumFailures *int `ddl:"parameter" sql:"SUSPEND_TASK_AFTER_NUM_FAILURES"`
ErrorIntegration *string `ddl:"parameter,no_quotes" sql:"ERROR_INTEGRATION"`
ErrorNotificationIntegration *AccountObjectIdentifier `ddl:"identifier,equals" sql:"ERROR_INTEGRATION"`
Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"`
SessionParameters *SessionParameters `ddl:"list,no_parentheses"`
TaskAutoRetryAttempts *int `ddl:"parameter" sql:"TASK_AUTO_RETRY_ATTEMPTS"`
Expand Down Expand Up @@ -193,7 +193,7 @@ type Task struct {
Definition string
Condition string
AllowOverlappingExecution bool
ErrorIntegration string
ErrorIntegration *AccountObjectIdentifier
LastCommittedOn string
LastSuspendedOn string
OwnerRoleType string
Expand Down
8 changes: 4 additions & 4 deletions pkg/sdk/tasks_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestTasks_Create(t *testing.T) {
}
opts.UserTaskTimeoutMs = Int(5)
opts.SuspendTaskAfterNumFailures = Int(6)
opts.ErrorIntegration = String("some_error_integration")
opts.ErrorNotificationIntegration = Pointer(NewAccountObjectIdentifier("some_error_integration"))
opts.Comment = String("some comment")
opts.Finalize = &finalizerId
opts.TaskAutoRetryAttempts = Int(10)
Expand All @@ -93,7 +93,7 @@ func TestTasks_Create(t *testing.T) {
opts.After = []SchemaObjectIdentifier{otherTaskId}
opts.When = String(`SYSTEM$STREAM_HAS_DATA('MYSTREAM')`)

assertOptsValidAndSQLEquals(t, opts, "CREATE OR REPLACE TASK %s WAREHOUSE = %s SCHEDULE = '10 MINUTE' CONFIG = $${\"output_dir\": \"/temp/test_directory/\", \"learning_rate\": 0.1}$$ ALLOW_OVERLAPPING_EXECUTION = true JSON_INDENT = 10, LOCK_TIMEOUT = 5 USER_TASK_TIMEOUT_MS = 5 SUSPEND_TASK_AFTER_NUM_FAILURES = 6 ERROR_INTEGRATION = some_error_integration COMMENT = 'some comment' FINALIZE = %s TASK_AUTO_RETRY_ATTEMPTS = 10 TAG (%s = 'v1') USER_TASK_MINIMUM_TRIGGER_INTERVAL_IN_SECONDS = 10 AFTER %s WHEN SYSTEM$STREAM_HAS_DATA('MYSTREAM') AS SELECT CURRENT_TIMESTAMP", id.FullyQualifiedName(), warehouseId.FullyQualifiedName(), finalizerId.FullyQualifiedName(), tagId.FullyQualifiedName(), otherTaskId.FullyQualifiedName())
assertOptsValidAndSQLEquals(t, opts, "CREATE OR REPLACE TASK %s WAREHOUSE = %s SCHEDULE = '10 MINUTE' CONFIG = $${\"output_dir\": \"/temp/test_directory/\", \"learning_rate\": 0.1}$$ ALLOW_OVERLAPPING_EXECUTION = true JSON_INDENT = 10, LOCK_TIMEOUT = 5 USER_TASK_TIMEOUT_MS = 5 SUSPEND_TASK_AFTER_NUM_FAILURES = 6 ERROR_INTEGRATION = \"some_error_integration\" COMMENT = 'some comment' FINALIZE = %s TASK_AUTO_RETRY_ATTEMPTS = 10 TAG (%s = 'v1') USER_TASK_MINIMUM_TRIGGER_INTERVAL_IN_SECONDS = 10 AFTER %s WHEN SYSTEM$STREAM_HAS_DATA('MYSTREAM') AS SELECT CURRENT_TIMESTAMP", id.FullyQualifiedName(), warehouseId.FullyQualifiedName(), finalizerId.FullyQualifiedName(), tagId.FullyQualifiedName(), otherTaskId.FullyQualifiedName())
})
}

Expand Down Expand Up @@ -157,14 +157,14 @@ func TestTasks_CreateOrAlter(t *testing.T) {
LockTimeout: Int(5),
}
opts.SuspendTaskAfterNumFailures = Int(6)
opts.ErrorIntegration = String("some_error_integration")
opts.ErrorNotificationIntegration = Pointer(NewAccountObjectIdentifier("some_error_integration"))
opts.Comment = String("some comment")
opts.Finalize = &finalizerId
opts.TaskAutoRetryAttempts = Int(10)
opts.After = []SchemaObjectIdentifier{otherTaskId}
opts.When = String(`SYSTEM$STREAM_HAS_DATA('MYSTREAM')`)

assertOptsValidAndSQLEquals(t, opts, "CREATE OR ALTER TASK %s WAREHOUSE = %s SCHEDULE = '10 MINUTE' CONFIG = $${\"output_dir\": \"/temp/test_directory/\", \"learning_rate\": 0.1}$$ ALLOW_OVERLAPPING_EXECUTION = true USER_TASK_TIMEOUT_MS = 5 JSON_INDENT = 10, LOCK_TIMEOUT = 5 SUSPEND_TASK_AFTER_NUM_FAILURES = 6 ERROR_INTEGRATION = some_error_integration COMMENT = 'some comment' FINALIZE = %s TASK_AUTO_RETRY_ATTEMPTS = 10 AFTER %s WHEN SYSTEM$STREAM_HAS_DATA('MYSTREAM') AS SELECT CURRENT_TIMESTAMP", id.FullyQualifiedName(), warehouseId.FullyQualifiedName(), finalizerId.FullyQualifiedName(), otherTaskId.FullyQualifiedName())
assertOptsValidAndSQLEquals(t, opts, "CREATE OR ALTER TASK %s WAREHOUSE = %s SCHEDULE = '10 MINUTE' CONFIG = $${\"output_dir\": \"/temp/test_directory/\", \"learning_rate\": 0.1}$$ ALLOW_OVERLAPPING_EXECUTION = true USER_TASK_TIMEOUT_MS = 5 JSON_INDENT = 10, LOCK_TIMEOUT = 5 SUSPEND_TASK_AFTER_NUM_FAILURES = 6 ERROR_INTEGRATION = \"some_error_integration\" COMMENT = 'some comment' FINALIZE = %s TASK_AUTO_RETRY_ATTEMPTS = 10 AFTER %s WHEN SYSTEM$STREAM_HAS_DATA('MYSTREAM') AS SELECT CURRENT_TIMESTAMP", id.FullyQualifiedName(), warehouseId.FullyQualifiedName(), finalizerId.FullyQualifiedName(), otherTaskId.FullyQualifiedName())
})
}

Expand Down
Loading

0 comments on commit 65ece76

Please sign in to comment.