diff --git a/pkg/resources/cortex_search_service.go b/pkg/resources/cortex_search_service.go index e16802adb1c..a25e1ef8bf1 100644 --- a/pkg/resources/cortex_search_service.go +++ b/pkg/resources/cortex_search_service.go @@ -188,7 +188,7 @@ func UpdateCortexSearchService(d *schema.ResourceData, meta interface{}) error { func DeleteCortexSearchService(d *schema.ResourceData, meta interface{}) error { client := meta.(*provider.Context).Client id := helpers.DecodeSnowflakeID(d.Id()).(sdk.SchemaObjectIdentifier) - request := sdk.NewDropCortexSearchServiceRequest(id) + request := sdk.NewDropCortexSearchServiceRequest(id).WithIfExists(true) if err := client.CortexSearchServices.Drop(context.Background(), request); err != nil { return err diff --git a/pkg/sdk/cortex_search_services_def.go b/pkg/sdk/cortex_search_services_def.go index 9e5af2cd926..1b316f2cd8a 100644 --- a/pkg/sdk/cortex_search_services_def.go +++ b/pkg/sdk/cortex_search_services_def.go @@ -40,7 +40,6 @@ var CortexSearchServiceDef = g.NewInterface( PredefinedQueryStructField("QueryDefinition", "string", g.ParameterOptions().NoEquals().NoQuotes().Required().SQL("AS")). // Validations WithValidation(g.ValidIdentifier, "name"). - WithValidation(g.ValidIdentifier, "name"). WithValidation(g.ValidateValueSet, "On"). WithValidation(g.ValidateValueSet, "TargetLag"). WithValidation(g.ConflictingFields, "OrReplace", "IfNotExists"), @@ -102,7 +101,7 @@ var CortexSearchServiceDef = g.NewInterface( Field("Attributes", "[]string"). Field("ServiceUrl", "string"). Field("NumRowsIndexed", "*int"). - Field("Comment", "string"), + OptionalText("Comment"), g.NewQueryStruct("DescribeCortexSearchService"). Describe(). SQL("CORTEX SEARCH SERVICE"). @@ -114,6 +113,7 @@ var CortexSearchServiceDef = g.NewInterface( // Fields Drop(). SQL("CORTEX SEARCH SERVICE"). + IfExists(). Name(). WithValidation(g.ValidIdentifier, "name"), ) diff --git a/pkg/sdk/cortex_search_services_dto_builders_gen.go b/pkg/sdk/cortex_search_services_dto_builders_gen.go index 0c40f9978dc..e9168f16ef4 100644 --- a/pkg/sdk/cortex_search_services_dto_builders_gen.go +++ b/pkg/sdk/cortex_search_services_dto_builders_gen.go @@ -125,3 +125,8 @@ func NewDropCortexSearchServiceRequest( s.name = name return &s } + +func (s *DropCortexSearchServiceRequest) WithIfExists(IfExists bool) *DropCortexSearchServiceRequest { + s.IfExists = &IfExists + return s +} diff --git a/pkg/sdk/cortex_search_services_dto_gen.go b/pkg/sdk/cortex_search_services_dto_gen.go index 4c431442bca..59e016decca 100644 --- a/pkg/sdk/cortex_search_services_dto_gen.go +++ b/pkg/sdk/cortex_search_services_dto_gen.go @@ -50,5 +50,6 @@ type DescribeCortexSearchServiceRequest struct { } type DropCortexSearchServiceRequest struct { - name SchemaObjectIdentifier // required + IfExists *bool + name SchemaObjectIdentifier // required } diff --git a/pkg/sdk/cortex_search_services_gen.go b/pkg/sdk/cortex_search_services_gen.go index 3de7a5a410b..fdf613e78d7 100644 --- a/pkg/sdk/cortex_search_services_gen.go +++ b/pkg/sdk/cortex_search_services_gen.go @@ -28,7 +28,6 @@ type CreateCortexSearchServiceOptions struct { Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` QueryDefinition string `ddl:"parameter,no_quotes,no_equals" sql:"AS"` } - type Attributes struct { attributes bool `ddl:"static" sql:"ATTRIBUTES"` Columns []string `ddl:"list,no_parentheses,no_equals"` @@ -42,7 +41,6 @@ type AlterCortexSearchServiceOptions struct { name SchemaObjectIdentifier `ddl:"identifier"` Set *CortexSearchServiceSet `ddl:"keyword" sql:"SET"` } - type CortexSearchServiceSet struct { TargetLag *string `ddl:"parameter,single_quotes" sql:"TARGET_LAG"` Warehouse *AccountObjectIdentifier `ddl:"identifier,equals" sql:"WAREHOUSE"` @@ -58,7 +56,6 @@ type ShowCortexSearchServiceOptions struct { StartsWith *string `ddl:"parameter,single_quotes,no_equals" sql:"STARTS WITH"` Limit *LimitFrom `ddl:"keyword" sql:"LIMIT"` } - type cortexSearchServiceRow struct { CreatedOn time.Time `db:"created_on"` Name string `db:"name"` @@ -66,7 +63,6 @@ type cortexSearchServiceRow struct { SchemaName string `db:"schema_name"` Comment string `db:"comment"` } - type CortexSearchService struct { CreatedOn time.Time Name string @@ -85,7 +81,6 @@ type DescribeCortexSearchServiceOptions struct { cortexSearchService bool `ddl:"static" sql:"CORTEX SEARCH SERVICE"` name SchemaObjectIdentifier `ddl:"identifier"` } - type cortexSearchServiceDetailsRow struct { Name string `db:"name"` Schema string `db:"schema"` @@ -98,7 +93,6 @@ type cortexSearchServiceDetailsRow struct { NumRowsIndexed int `db:"num_rows_indexed"` Comment string `db:"comment"` } - type CortexSearchServiceDetails struct { Name string Schema string @@ -109,12 +103,13 @@ type CortexSearchServiceDetails struct { Attributes []string ServiceUrl string NumRowsIndexed *int - Comment string + Comment *string } // DropCortexSearchServiceOptions is based on https://docs.snowflake.com/LIMITEDACCESS/cortex-search/sql/drop-cortex-search. type DropCortexSearchServiceOptions struct { drop bool `ddl:"static" sql:"DROP"` cortexSearchService bool `ddl:"static" sql:"CORTEX SEARCH SERVICE"` + IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` name SchemaObjectIdentifier `ddl:"identifier"` } diff --git a/pkg/sdk/cortex_search_services_impl_gen.go b/pkg/sdk/cortex_search_services_impl_gen.go index 48c38380413..b59ef46811a 100644 --- a/pkg/sdk/cortex_search_services_impl_gen.go +++ b/pkg/sdk/cortex_search_services_impl_gen.go @@ -69,11 +69,13 @@ func (r *CreateCortexSearchServiceRequest) toOpts() *CreateCortexSearchServiceOp Comment: r.Comment, QueryDefinition: r.QueryDefinition, } + if r.Attributes != nil { opts.Attributes = &Attributes{ Columns: r.Attributes.Columns, } } + return opts } @@ -82,6 +84,7 @@ func (r *AlterCortexSearchServiceRequest) toOpts() *AlterCortexSearchServiceOpti IfExists: r.IfExists, name: r.name, } + if r.Set != nil { opts.Set = &CortexSearchServiceSet{ TargetLag: r.Set.TargetLag, @@ -89,6 +92,7 @@ func (r *AlterCortexSearchServiceRequest) toOpts() *AlterCortexSearchServiceOpti Comment: r.Set.Comment, } } + return opts } @@ -121,7 +125,8 @@ func (r cortexSearchServiceDetailsRow) convert() *CortexSearchServiceDetails { func (r *DropCortexSearchServiceRequest) toOpts() *DropCortexSearchServiceOptions { opts := &DropCortexSearchServiceOptions{ - name: r.name, + IfExists: r.IfExists, + name: r.name, } return opts } diff --git a/pkg/sdk/cortex_search_services_validations_gen.go b/pkg/sdk/cortex_search_services_validations_gen.go index fe4f90070dd..0a66de26183 100644 --- a/pkg/sdk/cortex_search_services_validations_gen.go +++ b/pkg/sdk/cortex_search_services_validations_gen.go @@ -16,9 +16,6 @@ func (opts *CreateCortexSearchServiceOptions) validate() error { if !ValidObjectIdentifier(opts.name) { errs = append(errs, ErrInvalidObjectIdentifier) } - if !ValidObjectIdentifier(opts.name) { - errs = append(errs, ErrInvalidObjectIdentifier) - } if !valueSet(opts.On) { errs = append(errs, errNotSet("CreateCortexSearchServiceOptions", "On")) }